
English: 
♪ (music) ♪
Hi there, everyone.
I'm excited to introduce a new project
that we've been working on
that takes a new project
to improve usability of TensorFlow.
And we care so much about usability here
that we're going all the way back
to first principles
of the computation we're performing.
But first, why usability?
I felt that everyone here agrees
that productivity
in machine learning is critical,
because it leads to a faster pace
of innovation and progress in our field.
Of course, we just want to build
beautiful things for TensorFlow users,
so that's a big piece of it as well.
But if you look
at machine learning frameworks
there's two major approaches.
The most familiar
are the graph building approaches
where you explicitly define a graph
and then execute it
to run your computation.
This is great for performance,
but isn't always the best for usability.
In contrast, the define-by-run approaches
like eager execution

Chinese: 
大家好。
我很高兴能够介绍一个我们一直
在进行的新项目，
需要一个新项目才能提高
TensorFlow 的可用性。
我们非常关心可用性，
所以我们回到我们正在执行
的计算的首要原则。
但首先，为什么在乎可用性？
我觉得这里的每个人都会同意
机器学习的生产力是至关重要的，
因为它可以加快我们领域创新和进步的速度。
当然，我们只是想为 TensorFlow
的用户打造美丽的东西，
所以这也是它的一大部分。
但是如果你看看机器学习框架，
有两种主要的方法。
最熟悉的是图形构建方法，
你可以明确定义图形，
然后执行它来运行你的计算。
这对于性能很好，
但对于可用性并不一定是最好的。
相比之下，像急切执行这样的定义式运行方式

English: 
aren't always the best for performance,
but allow you to use language control flow
and other things that make them
a lot easier to use.
The interesting thing
about both approaches
is that they're really
about allowing Python to understand
the difference between
the Tensor computation in your code
and all the other non-Tensor stuff,
like command line option processing
and visualization,
and the other things you do.
So, I think it's interesting
to look at how these actually work.
In the case of eager execution,
for example, you write your model
and Python starts out by parsing it,
and then it feeds every statement
at a time to the interpreter.
And if it's a Tensor operation,
it fires up TensorFlow and hands it off,
and TensorFlow takes care
of your Tensor operations.
Otherwise, the Python interpreter runs it.
The key thing about eager execution
and graph building
is that they're designed
within the constraints
of what you can do as a Python library.
Now, if you crack open the compiler
and look at it from what could we do
with the compiler and language involved,

Chinese: 
对于性能并不一定是最好的，
但它可以让你使用语言控制流程
和其他东西，使它们更容易使用。
这两种方法的有趣之处在于
它们确实允许 Python 了解
代码中张量计算
与所有其他非张量东西，如命令行选项处理和可视化
以及你所做的其他事情之间的区别。
所以，我认为看看这些是怎么运作的十分有趣。
在急切执行的情况下，打个比方，
你编写你的模型，
然后 Python 开始解析它，
然后它把每条语句一次性发送给解释器。
如果是张量操作，
它会触发 TensorFlow 并交给它，
TensorFlow 会处理你的张量操作。
否则，Python 解释器会运作它。
关于急切执行和图形构建的关键
在于它们是在你作为 Python 库
所可以执行的约束条件下设计的。
现在，如果你打开编译器
并从我们可以用编译器来做什么
和涉及的语言的方面来看待它，

Chinese: 
可以应用很多其他的方法
来解决这个特定的问题，
这就是我们正在做的。
关于编译器很酷的一件事情是，
在你解析代码之后，
编译器可以看到整个程序和
所有的 Tensor 操作符。
所以我们要做的是为编译器增加一个新的阶段，
自动将这些张量操作
从程序中取出，
为你构建一个标准的 TensorFlow 图形，
然后将其交给 TensorFlow。
由于它是标准的 TensorFlow 图形，
你可以完全访问 TensorFlow
可以执行的所有操作，
并且包括所有设备。
我们认为这种方法是非常好的组合，
因为你可以获得 TensorFlow
的所有功能和灵活性，
但是你也可以获得执行的可用性。
但有一个问题。总会有一个问题，对吧？
这里的问题是我们不能
用 Python 来做到这一点。
至少，不能如果要达到我们所期望的可靠性，
因为它不支持我们需要的那种编译器分析。
那是什么意思？
编译器必须能够在流经你的程序时推理值。
它必须推理控制流程和函数调用。

English: 
there is a whole other set of approaches
that can be applied to solving 
this particular problem
and that's what we're doing.
The cool thing about a compiler
is that after you parse your code,
the compiler can see the entire program
and all the Tensor ops in it.
And so what we're doing
is we'll add a new stage to the compiler
that automatically takes
these Tensor operations
out of your program,
builds a standard
TensorFlow graph for you,
and then hands it to TensorFlow.
Since it's a standard TensorFlow graph,
you get full access to all things
that TensorFlow can do,
including all the devices.
Now, we think that this approach
is a really great combination,
because you get all the power
and flexibility of TensorFlow,
but you also get the usability
of your execution as well.
But there's a catch.
There's always a catch, right?
The catch here is that
we can't do this with Python.
At least, not with
the reliability we expect,
because it doesn't support
the kind of compiler analysis we need.
And what do we mean by that?
The compiler has to be able
to reason about values
as they flow through your program.
It has to reason about control flow
and function calls.

English: 
It has to reason about variable aliasing
and other things like that.
If we can't directly use Python,
then, as users, of course,
we care a lot about all the nice things
we've come to love about Python,
including the ability to use
all the standard Python APIs.
So, I know what you're thinking.
"Does this mean that we're talking
about doing a new language?"
That's definitely an approach to solve
the technical requirements we want,
and if we do new language,
we can obviously build
all the nice things we want into it.
But this comes at a cost
because it turns out
that we'd be foregoing
the benefits of having a community.
That includes things like tools
and libraries, but also things like books,
which some people still use.
And even more significantly,
this would take years of time to get right
and machine learning just moves too fast.
No, we think it's better
to use an existing language.
But here we have to be careful,
because to do this right,
we have to make significant improvements
to the compiler and the language
and we need to be able
to do this in a reasonable amount of time.

Chinese: 
它必须推理可变别名和其他类似的东西。
如果我们不能直接使用 Python，
那么作为用户，我们当然会关注
我们喜欢的 Python 的所有方面，
包括使用所有标准 Python API 的能力。
我知道你在想什么。
“这是否意味着我们正在谈论着
要做一种新语言？”
这绝对是解决我们想要的技术需求的一种方法，
如果我们使用新的语言，
我们显然可以将所有我们想要的东西
构建在它里面。
但是这需要付出代价，因为事实证明，
我们不能享受有一个社区的好处。
这包括诸如工具和图书馆之类的东西，还有书籍等
这是一些人仍在使用的东西。
更重要的是，
这需要花费数年的时间才能使它正常运行，
而机器学习更新的速度太快了。
不，我们认为使用现有语言会更好。
但是在这里我们必须小心，
因为要做得正确无误，
我们必须对编译器和语言进行重大的改进，
并且我们需要能够在合理的时间内完成此事。

English: 
So, of course, this brings us
to the Swift programming language.
Now, I assume that most of you
are not very familiar with Swift,
so here's a quick introduction.
Swift is designed
with a lightweight syntax
and it's really geared toward
being easy to use and learn.
Swift draws together best practices
from lots of different places,
including things
like functional programming and generics.
Swift builds on LVM, which means, 
of course, that it has an interpreter
and it has scripting capabilities as well.
Swift is great in notebook environments,
and these are really awesome
when you're interactively
developing in real time.
Swift is also open source.
It's portable to lots of platforms
and has a big community of people.
The number one thing
that's most important to us
is it has a fully open design environment,
called "Swift Evolution,"
which allows us to propose
first-class machine learning
language and compiler features
directly for integration into Swift.

Chinese: 
所以，当然，这将我们带入了 Swift 编程语言。
现在，我假定你们大多数人
对 Swift 都不是很熟悉，
所以这里有一个简短的介绍。
Swift 被设计为简单的语法，
它旨向易于使用和学习。
Swift将许多不同地方的最佳实践结合在一起，
包括函数式编程和泛型等。
Swift 的构建是基于 LVM，
当然这意味着它有一个解释器，
它也具有写脚本功能。
Swift在笔记本电脑环境中表现出色，
当你进行实时交互式开发时，它们真的很棒。
Swift 也是开源的。
它可以移植到很多平台上，
并且拥有一个大的社区。
对我们来说最重要的第一件事是
它有一个名为 “Swift Evolution”
的完全开放的设计环境，
它允许我们直接提出
一流的机器学习语言和编译器功能，
以便集成到 Swift 中。

English: 
If you bring all of this together
that we've been talking about here,
I'm happy to introduce
Swift for TensorFlow.
Swift for TensorFlow gives you
the full performance of graphs,
you can use native language control flow,
has built-in support
for automatic differentiation,
it can detect errors in your code
without even running it,
and it has full access to Python APIs.
Instead of telling you about it,
here is Richard Wei to show it to you now.
Thank you, Chris.
(applause)
I'm thrilled to show you
Swift for TensorFlow.
Swift is a high-performance,
modern programming language.
And today, for the very first time,
Swift has a full-power
TensorFlow built right in.
I'm going to walk through
three major styles of programming:
scripting, interpreting, and notebooks.
So, first let me show you
the Swift interpreter.

Chinese: 
如果将所有这些我们在这里一直在讨论的问题，
我很高兴为你介绍 TensorFlow 的 Swift。
TensorFlow 的 Swift 为你提供了
图形的完整性能，
你可以使用母语控制流程，
有内置支持自动分化，
甚至可以在没有运行的情况下找出代码中的错误，
并且它可以完全访问 Python API。
与其告向你解释你，
让 Richard Wei 现在来向你展示它。
谢谢你，Chris。
我很高兴能够向你展示 TensorFlow 的 Swift 。
Swift 是一种高性能的现代编程语言。
今天，Swift 第一次
有了一个内置的全功能的 TensorFlow。
我将介绍三种主要的编程风格：
写脚本，口译和笔记本。
因此，首先让我向你展示 Swift 解释器。

Chinese: 
这是一个 Swift 解释器。
当我键入一些代码时，Swift 会评估它
并打印结果，就像 Python 一样。
现在，我们导入 TensorFlow。
我可以从一些缩放器创建一个张量。
我可以直接执行任何 TensorFlow 操作
并查看结果，
就像在急于执行一样。
例如，一个 a + a
或 [ACE] 矩阵产品本身。
当然，循环就是能操作。
我可以把[它]的结果列印出来。
解释器非常有趣，但我喜欢在
更多互动的环境中使用 TensorFlow，
就像 Jupyter Notebook 一样，
让我们​​看看它们是如何运作的。

English: 
This is a Swift interpreter.
When I type some code, Swift evaluates it
and prints the result, just like Python.
Now, let's import TensorFlow.
(keyboard clacking)
I can create a Tensor from some scalers.
(keyboard clacking)
I can do any TensorFlow operation directly
and see the result,
just like I would with eager execution.
For example, a + a,
or [ACE] matrix product with itself.
Of course, loops just work.
I can print the result [of it].
Interpreter is a lot of fun to work with,
but I like using TensorFlow
in a more interactive environment,
just like Jupyter Notebook,
so let's see how they work.

Chinese: 
这是一个 Swift 笔记本。
它在右侧显示了所有的结果。
所以，这里有一个更有趣的代码：
享受函数。
所以，在这里我有一个
sigmoid 函数在循环内。
当我点击这个按钮时，
它显示了这个函数随着时间的推移
产生的所有值的轨迹。
作为机器学习开发人员，我经常喜欢区分函数。
现在，当我输入时 -
因为我们能够改进编程语言，
所以我们在 Swift 中创建了一流的自动分化。
当我输入“渐变效果”时，它会显示渐变效果。
Swift 自动计算渐变并给出结果。
所以，这里是 S 形渐变。

English: 
This is a Swift notebook.
It shows all the results on the right.
So, here's a more interesting code:
Fun with Functions.
So, here I have
a sigmoid function inside a loop.
Now, as I click on this button,
it shows a trace of all values
produced by this function over time.
Now, as a machine learning developer,
I often like to differentiate functions.
Now, when I type in--
Well, since we were able to improve
the programming language,
we built first-class
automatic differentiation
right into Swift.
Now, when I type in "gradient effects,"
it shows the gradient.
Swift computes the gradient automatically
and gives me the result.
So, here's the gradient sigmoid.

English: 
Now, let's look at some Python code.
Let's think about Python.
Well, as a machine learning developer, 
I've been using Python a lot
and I know there are
many great Python libraries.
Just today, my colleague, Dan,
sent me a data set in pickle format.
I can directly use Python APIs to load it.
All I have to do
is to type in "import Python,"
and Swift uses a Python API,
pickle, to be specific, to load the data.
Here you can see the data
right in the Swift notebook.
So, here's the Swift notebook.
Now, some people
like to run training script
directly in command line.

Chinese: 
我们来看看一些 Python 代码。
让我们来思考一下 Python。
那么，作为一名机器学习开发人员，
我一直在使用 Python，
并且我知道有很多很棒的 Python 库。
就在今天，我的同事 Dan 向我发送了
一个 pickle 格式的数据集。
我可以直接使用 Python API 来加载它。
我所要做的就是输入 “导入 Python”，
Swift 使用一个 Python API，
严格说起来是 pickle，来加载数据。
在这里你可以在 Swift 笔记本中看到数据。
所以，这是 Swift 笔记本。
有些人喜欢直接在命令行上运行脚本训练。

English: 
So, let me show you how to train
a simple model in command line.
So, here is a simple MNIST model.
In this model, I'm using TensorFlow's
data set API to load training data.
As I scroll down, I have the forward pass,
backward pass, gradient descent,
all defined in the training loop.
Now, I usually like to work on the go,
so this code has been working
on a CPU on my laptop.
But when I want to get
more performance, what do I do?
Well, why don't I just enable Cloud TPU?
So, all I have to do is add one line
to enable TPU execution.
When I save this file, open a terminal
to run this training script,
it's initializing TPU

Chinese: 
所以，让我告诉你如何在命令行中
训练一个简单的模型。
这是一个简单的 MNIST 模型。
在这个模型中，我使用 TensorFlow 的
数据集 API 来加载训练数据。
当我向下滚动时，我有前进传球，
后传球，渐变下降，
全部都在训练循环中定义。
我通常喜欢在旅途中工作，
所以此代码一直在我的笔记本电脑上使用 CPU。
但是当我想要使用更多的性能时，
我该怎么做？为什么我不直接启用云端 TPU？
所以，我所要做的就是添加一行
来启用 TPU 执行。
当我保存这个文件时，打开一个终端
来运行这个训练脚本，它正在初始化 TPU，

English: 
and the Swift compiler
automatically partitions this program
into a normal subprogram
and a TensorFlow graph.
And TensorFlow is sending this graph
to the TensorFlow XLA compiler
for TPU execution.
Now, it's running and we're waiting
for the TPU to give the result.
Look, loss is going down!
All right!
Why don't we simply open TensorBoard
and see the training curve.
Now I can see the entire
training history in TensorBoard.
So, this is looking great.
Now, this is Swift for TensorFlow.
It's an interactive programming experience
with supercomputing performance
at your fingertips.

Chinese: 
Swift 编译器自动将这个程序分成
一个普通的子程序和一个 TensorFlow 图形。
TensorFlow 将此图发送到
TensorFlow XLA 编译器
为进行 TPU 执行。
现在，它正在运行，
并且我们正在等待 TPU 给出结果。
看，损失正在下降！太好了！
我们打开 TensorBoard
来查看训练曲线吧。
现在我可以在 TensorBoard上
看到整个训练历史。
所以，这看起来很棒。
这是 TensorFlow 的 Swift。
这是一个交互式编程体验，
超级计算性能在体验里触手可及。

English: 
Back to you, Chris.
(Chris) Thanks, Richard.
(applause)
All right, to recap quickly,
Richard showed you
that Swift has an interpreter
and it works just like you'd expect.
Now, I know that it's super frustrating
to be working on a program,
and two hours into a training run
you get a shape error or a type mismatch.
Swift is designed to catch errors early,
and we've started building in support
for catching TensorFlow-specific mistakes
right into TensorFlow.
We showed that you can directly use
arbitrary Python APIs
and other dynamic languages
directly from Swift,
which gives you full access
to the data science ecosystem
and any other Python APIs
that you just love to use.
Swift is also generating
standard TensorFlow graphs,
including control flow,
which give you the full performance
of the session API.
Of course, graphs are also awesome
because they give you access
to everything that TensorFlow can do,

Chinese: 
我把它交回给你，Chris。
谢谢，Richard。
好吧，快速回顾一下，Richard 向你展示了
Swift 有一个翻译器，
它的运作方式就像你所期望的那样。
我知道做一个程序是非常令人沮丧的，
在两个小时的训练过程中
你会遇到形状错误或类型不匹配。
Swift 旨在尽早发现错误，
并且我们已经开始构建
将 TensorFlow 特定的错误
直接引入 TensorFlow 的支持。
我们向你展示，你可以直接使用任意 Python API
和其他直接来自 Swift 的动态语言，
从而使你可以完全访问数据科学生态系统
以及你喜欢使用的其他 Python API。
Swift 还生成标准的 TensorFlow 图表，
包括流程控制，
它可以为你提供 API 会话的完整性能。
当然，图表也非常棒，
因为它们让你能够访问 
TensorFlow 可以做的所有事情，

English: 
including devices spanning the range
from the tiniest Raspberry Pi
all the way up to a TPU supercomputer.
Now, you may be wondering
when do you get this, what does this mean?
This is still an early-stage project,
but I'm happy to say
that we're looking forward 
to our open source release next month.
And not only are we releasing the code,
we're releasing technical white papers
and documents that explain how it works.
And we're also moving
our design discussions
out into the public onto Google Groups,
so that everybody
who wants to can participate.
Now, we're not done yet.
So, we have basic support
for automatic differentiation
built right into the compiler
on the language.
But we're also really interested
in extending it to support exotic cases,
like recursion, and even differentiating
custom data structures.
Compatibility issues
are also super frustrating,
particularly if you accidentally
use an op or a dtype
that's not supported by your device.
Swift has great support for detecting
availability issues like this,
and we're looking forward to wiring this
right into support TensorFlow.
We're also interested in high-level APIs,

Chinese: 
包括从最小的 Raspberry Pi
一直到 TPU 超级计算机的各种设备。
你可能想知道你什么时候会得到这个，
这是什么意思？
这仍然是项目的早期阶段，
但我很高兴地说，
我们期待在下个月发布我们的开源代码。
我们不仅要发布代码，
还要发布技术白皮书
和解释其运作原理的文档。
此外，我们还将设计的讨论
公开到 Google 群组，
让所有想参与的人都能参与其中。
我们还没有结束。
所以，我们为在语言上内置在编译器里
的自动分化提供了基本的支持。
但我们也非常有兴趣将其扩展
为支持异常情况，
如递归，甚至区分自定义数据结构。
兼容性问题也非常令人头疼，
特别是如果你不小心使用
设备不支持的操作系统或 dtype。
Swift 对检测这种可用性问题
提供了很好的支持，
我们期待将这一权利加入
TensorFlow 支持。
我们也对高级 API 感兴趣，

Chinese: 
但是对此我们要谨慎一点。
我们现在有一些原型，
但我们真的很想与社区合作，
评估，迭代并设计多种不同的方法，
并尝试这些方法，
然后根据真实世界的经验
来决定使用哪个最佳的方法。
这是一个 TensorFlow 的 Swift 超级快速游览。
TensorFlow 的 Swift 将
TensorFlow 的强大功能和灵活性
与全新的可用性标准相结合。
我们认为这将你的生产力带至顶端。
TensorFlow 的 Swift 也是一个处于早期阶段的项目，
因此我们希望为你对它感兴趣
并帮助我们构建它的未来。
谢谢。

English: 
but with this, we want to be
a little bit cautious.
We have some prototypes now,
but we'd really like to work
with the community
and evaluate and iterate
and design multiple different approaches
and actually experiment with these,
and then settle on the best one
based on real-world experience.
This has been a super quick tour
of Swift for TensorFlow.
Swift for TensorFlow combines
the power and flexibility of TensorFlow
with a whole new standard for usability.
We think it will take your productivity
and shoot it to the roof.
Swift for TensorFlow
is also an early-stage project
and so we'd really love
for you to get interested
and help us to build this future.
Thank you.
(applause)
♪ (music) ♪
