TensorFlow
Integrating automatic differentiation directly into the Swift compiler eliminates the industry's two-language divide by letting engineers build models and performance-critical algorithms without C++ glue code.
AI-assisted summary of Swift for TensorFlow: The Next-Generation Machine Learning Framework (TF Dev Summit '19) — original source. Check the original for full context.
Source published:
Key ideas
- Swift for TensorFlow integrates first-class automatic differentiation directly into the Swift language and compiler rather than packaging it as an external library. (15:39)
- The framework provides native, zero-overhead interoperability with Python, enabling developers to import libraries like NumPy, Matplotlib, and OpenAI Gym inside pure Swift code. (12:08)
- Swift addresses the two-language problem by allowing low-level algorithms like Monte Carlo tree search and high-level neural networks to execute in the same language without C++ rewrites. (26:42)
- Fast.ai announced a collaboration with the Swift for TensorFlow team, including an upcoming deep learning course co-taught by Jeremy Howard and Chris Lattner alongside the release of version 0.2. (28:45)
Detailed notes
## Background Presented by Distinguished Engineer Chris Lattner and Software Engineer Brennan Saeta at the TensorFlow Dev Summit 2019, this video was published on the official TensorFlow YouTube channel on March 7, 2019. The session introduces Swift for TensorFlow, focusing on language-integrated automatic differentiation and next-generation tooling built to enhance researcher productivity beyond TensorFlow 2.
## TL;DR To overcome the friction of bridging dynamic Python prototyping with C++ production systems, the TensorFlow team developed Swift for TensorFlow, integrating automatic differentiation directly into the Swift programming language and compiler. The presentation showcases interactive Google Colab workflows featuring familiar Keras-style architectures, custom layers with compile-time error detection, and gradient accumulation for simulating distributed training. The speakers demonstrate seamless bidirectional interoperability with Python libraries like NumPy, Matplotlib, and OpenAI Gym, alongside first-class differentiable programming across custom user types. Concluding with a live demo of a MiniGo player running Monte Carlo tree search and neural network evaluations entirely in pure Swift, the team announces their 0.2 release and an educational partnership with Fast.ai.
## Atmosphere & style The presentation carries an energetic, forward-looking developer-conference atmosphere, blending ambitious language-design philosophy with practical, rapid-fire live coding. Chris Lattner and Brennan Saeta share an easy, natural stage rapport, trading off between architectural vision and interactive Google Colab demonstrations punctuated by lighthearted jokes about quick typing and calculus fundamentals. Watching the talk feels intellectually invigorating and pragmatic, moving from the pain points of the classic 'two-language problem' to tangible, browser-based breakthroughs that spark genuine optimism for the future of differentiable programming.
## Bulletin - [15:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=939s) Swift for TensorFlow integrates first-class automatic differentiation directly into the Swift language and compiler rather than packaging it as an external library. - [12:08](https://www.youtube.com/watch?v=s65BigoMV_I&t=728s) The framework provides native, zero-overhead interoperability with Python, enabling developers to import libraries like NumPy, Matplotlib, and OpenAI Gym inside pure Swift code. - [26:42](https://www.youtube.com/watch?v=s65BigoMV_I&t=1602s) Swift addresses the two-language problem by allowing low-level algorithms like Monte Carlo tree search and high-level neural networks to execute in the same language without C++ rewrites. - [28:45](https://www.youtube.com/watch?v=s65BigoMV_I&t=1725s) Fast.ai announced a collaboration with the Swift for TensorFlow team, including an upcoming deep learning course co-taught by Jeremy Howard and Chris Lattner alongside the release of version 0.2.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=s65BigoMV_I&t=0s) Existing machine learning workflows frequently stall at production boundaries, requiring C++ glue code to bridge dynamic eager training with deployment. - [00:00](https://www.youtube.com/watch?v=s65BigoMV_I&t=0s) Swift's open language evolution enables modifying compiler internals directly to embed deep learning primitives and automatic differentiation at the language level. - [02:12](https://www.youtube.com/watch?v=s65BigoMV_I&t=132s) Model definitions adopt a familiar Keras-style syntax while prioritizing handwritten training loops for algorithmic control. - [02:12](https://www.youtube.com/watch?v=s65BigoMV_I&t=132s) Native Google Colab integration enables zero-setup Swift kernel execution and rapid iterative development in the browser. - [06:35](https://www.youtube.com/watch?v=s65BigoMV_I&t=395s) Static type checking and compiler analysis catch typographical errors and tensor shape mismatches prior to heavyweight runtime execution. - [09:05](https://www.youtube.com/watch?v=s65BigoMV_I&t=545s) Custom micro-batch gradient accumulation inside handwritten training loops lets individual researchers simulate large-batch cluster execution on a single accelerator. - [10:33](https://www.youtube.com/watch?v=s65BigoMV_I&t=633s) Bidirectional Python interoperability enables incremental codebase migration and direct calls to existing Python libraries without manual C-API wrappers. - [15:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=939s) The @differentiable attribute directs the compiler to derive analytical derivatives automatically for standard numerical functions and user-defined structs conforming to Differentiable. - [15:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=939s) Discrete types like Int trigger compile-time errors when differentiated, enforcing mathematical validity directly in the type system. - [21:13](https://www.youtube.com/watch?v=s65BigoMV_I&t=1273s) Custom gradients bridging foreign C functions or custom operations are expressed by returning the forward output alongside a pullback closure. - [21:13](https://www.youtube.com/watch?v=s65BigoMV_I&t=1273s) Developers can build user-space debugging tools, such as in-line gradient inspectors, without relying on specialized framework runtime hooks. - [24:42](https://www.youtube.com/watch?v=s65BigoMV_I&t=1482s) Native compilation, automatic TensorFlow graph extraction, and the absence of a Global Interpreter Lock give Swift a high-performance eager execution model. - [26:42](https://www.youtube.com/watch?v=s65BigoMV_I&t=1602s) Pure Swift implementations of systems like MiniGo demonstrate that search-heavy reinforcement learning pipelines can eliminate the performance bottlenecks of Python without C++ rewrites. - [28:45](https://www.youtube.com/watch?v=s65BigoMV_I&t=1725s) The release of version 0.2 delivers foundational compiler and runtime infrastructure as the project works toward broader production readiness.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=s65BigoMV_I&t=0s) Innovating Beyond TensorFlow 2 with Swift
Chris Lattner and Brennan Saeta introduce a new initiative from the TensorFlow team designed to push the boundaries of machine learning beyond the newly minted TensorFlow 2. While TensorFlow 2 incorporates years of deep learning lessons, existing workflows still hit significant roadblocks when moving from research to production. Specifically, while eager mode streamlines dynamic model training, deployment often forces developers to write boilerplate C++ code just to drive execution. Similarly, integrating machine learning into larger production applications still requires heavy C++ glue code. Lattner argues that addressing these persistent friction points requires re-examining the entire stack, reaching past runtime libraries down into the programming language and compiler itself. As Chris Lattner explains, “We think that applying new solutions to old problems can help push machine learning even further than before.”
To achieve this, the team turned to Swift, an open-source, cross-platform language built for clarity, safety, and expressive API design. Swift combines static typing with type inference, giving developers the syntax conciseness of dynamic languages while catching programming errors early at compile time. Because Swift features an open language evolution process, the TensorFlow team can evolve the language and its compiler primitives directly—specifically to support first-class automatic differentiation and reusable mathematical types.
```mermaid flowchart TD accTitle: Swift for TensorFlow Stack Innovation accDescr: Diagram showing how Swift for TensorFlow integrates the language, compiler, and runtime to eliminate C++ deployment glue. subgraph LanguageCompiler["Language & Compiler Layer"] Swift["Swift Language & Open Evolution"] Diff["First-Class Automatic Differentiation"] StaticCheck["Static Analysis & Type Inference"] end subgraph Execution["Execution & Runtime Layer"] Model["Dynamic Model Definition"] Opt["Direct Optimization & Execution"] end Swift --> Diff Swift --> StaticCheck Diff --> Model StaticCheck --> Model Model --> Opt ```
- Eager mode simplifies dynamic training but traditionally leaves a gap at deployment time, requiring C++ glue code. - Integrating models into larger end-user software systems frequently demands rewriting or bridging through C++. - Swift’s open evolution model allows direct language-level modifications to support deep learning primitives rather than treating the language as an external wrapper.
---
[02:12](https://www.youtube.com/watch?v=s65BigoMV_I&t=132s) Keras-Style Model Definition and Browser Workflow in Google Colab
Chris Lattner illustrates how model definitions in Swift for TensorFlow feel immediately familiar to existing practitioners. The syntax closely mirrors Keras, where layers are declared and then composed within a forward function in a clean, sequential flow. Rather than hiding the mechanics behind rigid training abstractions, the framework encourages writing training loops by hand. Lattner notes that crafting handwritten training loops provides researchers with complete control and flexibility to experiment with unconventional architectures and algorithmic variations.
Transitioning from slides to a live development environment, Brennan Saeta demonstrates how easy it is to start writing Swift for TensorFlow code without local installation hassles. The framework is integrated natively into Google Colab, allowing users to run interactive Swift Jupyter notebooks directly inside a web browser tab. Saeta instantiates the demo model, sets up a stochastic gradient descent (SGD) optimizer, feeds in synthetic random training data, and runs the training loop, verifying that the training loss decreases over successive steps.
- The model declaration mirrors the familiar Keras API to lower the barrier to entry for incoming practitioners. - Handwritten training loops are prioritized to give researchers maximal freedom over the forward and backward execution mechanics. - Swift for TensorFlow is pre-installed in Google Colab, enabling zero-setup experimentation in browser-hosted notebooks.
---
[04:09](https://www.youtube.com/watch?v=s65BigoMV_I&t=249s) Iterating in 90 Seconds: Skip Connections and Residual Networks
Brennan Saeta demonstrates the rapid iteration cycle made possible by the interactive Colab environment. In machine learning research, initial models rarely fit the final objective without structural tuning. Drawing on modern deep learning literature, Saeta decides to enhance the baseline model by making it deeper and adding residual skip connections to stabilize gradient propagation. He issues a live challenge to implement the structural changes, update the forward pass, and retrain the model in under 90 seconds.
Using Tab autocomplete directly in the browser, Saeta quickly adds an extra dense layer, adjusts tensor shapes to match dimensions for addition, and updates the forward execution logic. The forward pass captures the output of the initial flattening layer into a temporary variable, pushes it through the first dense layer, and performs an element-wise addition of the skip connection directly before invoking the second dense layer. Re-instantiating and executing the network immediately demonstrates a substantially lower training loss compared to the initial sequential baseline.
- Autocomplete in the Colab Swift kernel assists with rapid typing, shape alignment, and parameter completion. - The forward pass uses basic tensor arithmetic (`dense2.applied to tmp + tmp2 in context`) to assemble residual pathways. - The model with skip connections exhibits significantly faster loss reduction over identical synthetic batches.
---
[06:35](https://www.youtube.com/watch?v=s65BigoMV_I&t=395s) Custom Layer Abstraction and Static Error Checking
Moving beyond off-the-shelf sequential layers, Brennan Saeta shows how researchers can invent new building blocks from scratch. To illustrate this, he drafts a custom "double bias dense layer" that augments the standard weight matrix and single bias vector with an additional bias parameter. With a deadpan joke about typing the full implementation in 15 seconds, Saeta reveals the layer structure: an initializer that accepts input and output dimensions, explicit parameter fields ($W$, $B_1$, $B_2$), and a forward call that multiplies the inputs by weights and adds both biases.
Saeta then integrates the custom layer into a new model and runs it against a handwritten training loop. Here, the Swift compiler's static analysis surfaces an immediate advantage by pinpointing human errors before long training jobs fail at runtime. Saeta purposefully exposes a typo in the loss call, where `softmaxCrossEntropy` was passed a misspelled argument label. The compiler immediately flags the exact line and guides the fix. Although this particular experimental layer yields worse loss than the previous model, it highlights how painless it is to explore and debug unorthodox mathematical hypotheses. As Saeta remarks, “Swift for TensorFlow was designed for researchers. And researchers often need to do more than just change models and change the way the architecture fits together.”
- Custom layers define internal parameters directly as properties, with initializers handling tensor allocation. - The forward pass operates as a standard mathematical function without cumbersome layer-wrapping overhead. - Compile-time checking catches argument label typos and mismatched dimensions before executing heavyweight compute graphs.
---
[09:05](https://www.youtube.com/watch?v=s65BigoMV_I&t=545s) Simulating Large-Batch Cluster Training with Gradient Accumulation
Saeta broadens the discussion to infrastructure and training dynamics, highlighting the gap between high-end industrial hardware and the everyday developer setup. Modern state-of-the-art breakthroughs frequently rely on massive TPU superpods or large GPU clusters that demand very large batch sizes to stay computationally saturated. However, individual researchers often have to work with limited hardware, such as a single workstation GPU under a desk, making true large-scale distributed runs inaccessible during early prototyping.
To bridge this gap, Saeta demonstrates how the flexibility of handwritten training loops allows researchers to simulate massive data-parallel cluster execution on a single card. Rather than being restricted by an opaque, rigid `model.fit()` engine, a developer can simply add an inner loop inside each training epoch to accumulate gradients across multiple smaller micro-batches before calling the optimizer. As Brennan Saeta points out regarding the realities of experimental research, “Swift for TensorFlow is, again, designed for researchers. And researchers need to be able to customize everything, right? That's the whole point of research.”
- Large distributed clusters and TPU pods require scaling up batch sizes to maintain hardware efficiency. - Individual researchers can simulate massive-batch distributed regimes on a single machine by implementing custom inner forward-backward accumulation loops. - Handwritten control flow in Swift makes altering standard gradient calculation behavior straightforward without overriding complex framework internals.
[10:33](https://www.youtube.com/watch?v=s65BigoMV_I&t=633s) Simulating Distributed Training and Swift’s Interoperability Vision
Brennan Saeta demonstrates how straightforward it is to express distributed training patterns in Swift for TensorFlow. By wrapping the model execution inside a four-iteration loop, taking gradients at each step, and aggregating them into a single `grads` variable, the code simulates execution across four independent accelerators—such as four GPUs or TPUs—operating in a data-parallel fashion over a batch four times larger than normal. Once aggregated, the optimizer updates the model weights in a synchronous data-parallel process. Brennan emphasizes that this capability provides researchers with immense flexibility without requiring massive distributed infrastructure code.
Chris Lattner returns to highlight the broader developer experience, noting that tooling advantages like early compile-time error detection and code completion are not just about typing fewer characters, but are essential for discovering APIs naturally. He explains how Swift’s heritage influenced their architectural choices: Swift has long featured native, zero-overhead C interoperability, allowing developers to import C header files and call C functions directly without manual wrappers or boilerplate code. The TensorFlow team ported this exact design philosophy directly to Python, bridging the two languages without clunky glue code. As Chris Lattner puts it: “And one of the cool things about this is that that allows you to combine the power of Swift for TensorFlow with all the advantages of the Python ecosystem.”
[12:08](https://www.youtube.com/watch?v=s65BigoMV_I&t=728s) Seamless Python Interoperability: NumPy, Matplotlib, and OpenAI Gym
Brennan Saeta demonstrates how Swift interoperates with Python, acknowledging that the Python data science ecosystem is extraordinarily rich and that researchers shouldn't have to give up their favorite libraries when adopting Swift. In a Jupyter notebook running Swift, Brennan imports `TensorFlow` alongside the `Python` module. Once imported, the `Python` object provides an entry point to import any installed Python library dynamically. He imports `matplotlib.pyplot` and `numpy as np`, seamlessly calling `np.linspace`, `np.sin`, and `np.cos`, and then passing those values directly into `pyplot` to render an inline chart. Brennan jokes that while the snippet looks exactly like the Python code developers write every day, it is completely pure Swift under the hood.
```mermaid flowchart LR accTitle: Swift and Python Interoperability Architecture accDescr: Diagram showing how Swift code communicates through the Python bridge to standard Python libraries and OpenAI Gym. subgraph SwiftRuntime["Swift for TensorFlow Runtime"] Code["Swift Script / Notebook Cell"] Bridge["Python Interop Bridge"] end subgraph PythonEcosystem["Python Ecosystem"] NP["NumPy & Matplotlib"] Gym["OpenAI Gym (CartPole-v0)"] end Code --> Bridge Bridge -->|"Call linspace, sin, plot"| NP Bridge -->|"Step environment & get state"| Gym Gym -->|"Return observation & reward"| Bridge ```
To prove that the bridge handles serious workloads beyond basic array math, Brennan loads OpenAI Gym to train a reinforcement learning agent directly in the browser. Using the CartPole-v0 environment, he constructs a two-layer sequential neural network in Swift, defines hyperparameters, and implements an episode training loop. The loop uses Gym's Python environment to step through actions and extract observations, computes model gradients using Swift, applies updates through a Swift optimizer, and records mean rewards across episodes. The resulting training metrics are immediately plotted using Python’s NumPy and Matplotlib.
Chris Lattner notes that this interoperability is designed for bidirectional workflows, making it possible to combine Swift for TensorFlow with Python TensorFlow code so that teams can migrate existing codebases incrementally rather than performing risky rewrites. Chris jokes about the math foundations of ML: “Now, I think it's fair to say that calculus is an integral part of machine learning.”
- Importing Python in Swift requires only `import Python` and calling `Python.import("package_name")`. - The OpenAI Gym demonstration trains an agent on the `CartPole-v0` control environment using a simple sequential dense network written in pure Swift. - Python variables and methods in Swift can be invoked with standard dot-notation and familiar argument conventions without writing manual C-API bindings.
[15:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=939s) First-Class Language Differentiable Programming
Chris Lattner and Brennan Saeta pivot to what they view as Swift for TensorFlow’s core technical innovation: language-integrated automatic differentiation. Rather than treating differentiation as an external library call or an operation bound strictly to a monolithic tensor class, Swift builds differentiable programming directly into the grammar and compiler of the language itself. Brennan breaks down the mechanics by defining a standard mathematical Swift function called `myFunction` that takes two standard 64-bit floating-point numbers (`Double`), performs products, quotients, and sums, and returns a `Double`. Simply attaching the `@differentiable` attribute instructs the Swift compiler to derive the analytic derivative automatically at compile time.
To query the computed derivative, developers call `gradient`, passing a closure and the evaluation point. Brennan demonstrates taking partial derivatives with respect to specific arguments as well as retrieving the full gradient vector. For deep learning routines where forward predictions are needed alongside backpropagation—such as computing training accuracy or logging losses—Swift provides `valueWithGradient`, which evaluates the function once and returns a tuple containing both the forward output value and the gradient. Brennan highlights that Swift tuples feature named fields rather than mere positional indices, which makes debugging output clean and readable. As Brennan Saeta points out regarding the types involved: “It's just plain old double. This is because automatic differentiation is built right into the language in Swift for TensorFlow.”
```mermaid flowchart TD accTitle: Swift Automatic Differentiation Flow accDescr: Flowchart illustrating how functions annotated with differentiable compile down to gradients and named tuples. Func["Function definition: myFunction(a, b)"] --> Attrib["Annotate with @differentiable"] Attrib --> Compiler["Swift Compiler Derives Derivative"] Compiler --> GradCall["Call gradient(at: point)"] Compiler --> ValGradCall["Call valueWithGradient(at: point)"] GradCall --> GradOnly["Output: Gradient Vector / Partial"] ValGradCall --> NamedTuple["Output: Named Tuple (value, gradient)"] ```
Brennan emphasizes that automatic differentiation is fully extensible to custom, user-defined data structures. He creates a 2D geometric `Point` struct containing `x` and `y` coordinates and conforms it to the `Differentiable` protocol. While the compiler can often synthesize differentiation rules automatically, Brennan advocates explicitly annotating helper methods with `@differentiable` to document intent and trigger compile-time validation. He shows how the compiler catches errors: annotating an integer-returning helper function with `@differentiable` immediately throws a compilation error explaining that `Int` does not conform to `Differentiable`, since integers are discrete values that cannot support infinitesimal steps.
Finally, Brennan writes an extension on `Point` to compute Euclidean vector magnitude. Wanting to illustrate how Swift interfaces with external C code, he intentionally bypasses Swift's native math libraries to invoke the standard C library's double-precision square root function (`sqrt`). When he marks the magnitude function `@differentiable`, the compiler instantly halts with an error: it cannot differentiate through the external C `sqrt` function because it lacks automatic differentiation metadata, setting up the need for custom derivative registration.
- The `gradient(at:...)` function accepts an evaluation point and the mathematical closure to differentiate. - `valueWithGradient` returns both the computed forward value and gradient in a structured, named tuple. - Non-continuous or discrete types like `Int` fail type checking when marked `@differentiable` because they do not satisfy mathematical differentiability requirements. - External foreign-function interfaces (such as C's `sqrt`) cannot be automatically differentiated by the compiler without explicit derivative registration.
[21:13](https://www.youtube.com/watch?v=s65BigoMV_I&t=1273s) Custom Gradients and Building an In-Code Gradient Debugger
Continuing his live demonstration in Colab, Brennan Saeta encounters an error when differentiating a function that calls `sqrt`. He explains that `sqrt` is an external C function compiled by a standard C compiler, and because standard C compilers cannot automatically generate derivatives, Swift for TensorFlow flags that it cannot differentiate it out of the box. Rather than seeing this as an obstacle, Brennan welcomes the error: “This is excellent, because it gives me a great excuse to show you how to write custom gradients.” He defines a wrapper called `mySqrt` that invokes the underlying C function during the forward pass. For the backward pass, the function returns a tuple: the first element is the normal evaluated value, while the second element is a pullback closure that defines the backward pass and captures whatever values are required from the forward pass. Substituting `mySqrt` into the earlier `magnitude` method resolves the error immediately.
Brennan then demonstrates how effortlessly custom types and operations can be combined by writing what he terms a “silly function” marked with the `@differentiable` attribute. This function accepts two `Point` instances and a `Double`, evaluates dot products and magnitudes, and returns a `Double`. Swift for TensorFlow differentiates smoothly across these mixed types, producing full gradients and partial derivatives with respect to individual arguments. Taking this capability a step further, Brennan illustrates how users can build their own debugging tools directly in user-space Swift code. Often, model developers need visibility into the exact gradient values flowing through intermediate stages of a computation. To solve this, Brennan writes a simple `gradientDebugger` function. In the forward pass, it acts as an identity function that takes a `Double` and returns it unmodified; in the backward pass, it intercepts the gradient value, prints it to the console, and returns it downstream. When inserted into the `silly function` right after `a.dot(b)`, running the backward pass prints the exact gradient (`3.80`) directly inside the notebook.
```mermaid flowchart LR accTitle: Custom Gradient and Pullback Flow accDescr: Diagram showing how a custom differentiable function splits into forward computation and a backward pullback closure.
subgraph ForwardPass["Forward Pass"] X["Input x"] --> Core["Compute mySqrt(x)"] Core --> Out["Forward Value: y"] end
subgraph BackwardPass["Backward Pass (Pullback)"] Capture["Captured Values from Forward Pass"] -.-> PB["Pullback Closure"] GradIn["Incoming Gradient dy"] --> PB PB --> GradOut["Propagated Gradient dx"] end
Core --> Capture ```
- When bridging C functions into differentiable Swift code, users implement a custom derivative returning the forward output alongside a pullback closure. - Swift enables mixing and matching arbitrary differentiable data types—such as custom structs (`Point`) alongside primitive floats (`Double`)—within the same differentiable function. - Custom gradient debuggers can be implemented as lightweight identity wrappers that print intermediate gradient values during backpropagation without dedicated runtime hooks.
[24:42](https://www.youtube.com/watch?v=s65BigoMV_I&t=1482s) Language Integration, Performance, and the Two-Language Problem
Taking the stage again, Chris Lattner reflects on the historical foundations of automatic differentiation, observing that while the underlying algorithms date back to the 1970s, it required deep language integration to make them truly practical for modern machine learning workflows. He emphasizes that this unified design opens the door to brand-new research paradigms and refers attendees to extensive online design documents for those wanting to explore the implementation details. Turning to execution speed, Chris explains that Swift is fast because of its native low-level compiler optimization, its absence of a Global Interpreter Lock (GIL) to impede concurrent execution, and sophisticated compiler passes that automatically extract TensorFlow computation graphs behind the scenes. Bringing these elements together, Chris asserts: “The consequence of all this together is that we think Swift has the world's most advanced eager mode.”
Chris then addresses why raw performance and language unity matter beyond simple benchmarks, noting an increasingly painful industry bottleneck: teams prototype neural networks in high-level frameworks but must orchestrate them within larger, performance-critical host applications. Traditionally, this requires exporting computation graphs and writing complex C++ glue code to drive the models. DeepMind's AlphaGo Zero illustrates this friction vividly. The project blends three major components: deep neural networks, Monte Carlo tree search (MCTS) algorithms to explore game states, and massive distributed execution across Tensor Processing Unit (TPU) clusters. While world-class teams can successfully link high-level Python models with C++ tree search, Chris stresses that the friction holds back broader scientific progress: “And if you're an advanced team like DeepMind, you can totally do this. But it's much more difficult than it should be. And we think that breaking down barriers like this can lead to new breakthroughs in science.”
[26:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=1599s) Live Demo: MiniGo and Pure Swift Monte Carlo Tree Search
To show how Swift eliminates the need to rewrite search algorithms in C++, Chris hands the presentation back to Brennan Saeta to showcase MiniGo, an open-source Go engine inspired by AlphaGo Zero. Brennan notes that while the MiniGo team initially wrote their system in standard TensorFlow and achieved great results on a single machine, they ran into severe performance walls when attempting to scale across large TPU pods. Because Python could not keep up with the accelerators, the team had to rewrite critical components like Monte Carlo tree search in C++.
Brennan reveals that the Swift for TensorFlow team reimplemented MCTS and the entire self-play pipeline of MiniGo entirely in pure Swift, running interactively right inside a Colab notebook. In the live demo, Brennan runs a game loop where a game configuration sets up two participants: a neural-network-backed Monte Carlo tree search player competing against a random-move player. The cell executes immediately, displaying the white and black players exchanging moves directly on screen. Brennan highlights that because Swift handles both high-level neural networks and low-level search logic seamlessly, researchers no longer face the artificial split between prototyping and performance: “We think that Swift for TensorFlow is going to unlock whole new classes of algorithms and research, because of how easy it is to do everything in one language with no barriers, no having to rewrite things into C++.”
[28:45](https://www.youtube.com/watch?v=s65BigoMV_I&t=1725s) Fast.ai Collaboration, the 0.2 Release, and the Road Ahead
Chris Lattner returns to highlight the significance of running an end-to-end AlphaGo-style pipeline inside a standard workbook, reiterating that removing engineering barriers will unlock novel hybrid techniques across the research community. However, he insists that Swift for TensorFlow is not designed solely for elite researchers: Swift is widely used across the world to teach introductory programming, making educational accessibility a foundational pillar of the project. To that end, Chris introduces a video message from Jeremy Howard, co-founder of Fast.ai. Jeremy describes Fast.ai's mission to democratize state-of-the-art deep learning—pointing to their sub-$25 ImageNet training speed records and world-class NLP classifiers—before announcing that their upcoming course will feature a major Swift component co-taught by someone who “knows Swift pretty well.”
On stage, Brennan quips, “Chris, I think he means you,” to which Chris laughs, “Yeah, we'll see how this goes.” Chris shares his enthusiasm for co-teaching the next generation of students while working directly with Jeremy to shape high-level, human-centered APIs for Swift for TensorFlow. Wrapping up the session, Chris emphasizes that Swift for TensorFlow remains pure TensorFlow at its core, fully integrated with the broader ecosystem and tooling. He summarizes the project's availability: - The project is fully open source on GitHub with an active community. - All session demonstrations and tutorials are publicly accessible and runnable immediately in Google Colab. - The project has officially shipped its 0.2 release, establishing the foundational compiler and runtime infrastructure. - Chris notes that high-level APIs are actively under development and the platform is not yet intended for production use, inviting advanced researchers to jump in early, test the programming model, and help shape its future.
[31:12](https://www.youtube.com/watch?v=s65BigoMV_I&t=1872s) Session Outro and Closing Music
The presentation comes to an end as the outro music plays, concluding the Swift for TensorFlow technical session at the TensorFlow Dev Summit 2019.
## Notable quotes > [26:39](https://www.youtube.com/watch?v=s65BigoMV_I&t=1599s) We think that Swift for TensorFlow is going to unlock whole new classes of algorithms and research, because of how easy it is to do everything in one language with no barriers, no having to rewrite things into C++. — Brennan Saeta
> [06:35](https://www.youtube.com/watch?v=s65BigoMV_I&t=395s) Swift for TensorFlow was designed for researchers. And researchers often need to do more than just change models and change the way the architecture fits together. — Brennan Saeta
## Mentioned AlphaGo Zero, Brennan Saeta, Chris Lattner, DeepMind, Fast.ai, Google Colab, Jeremy Howard, Keras, Matplotlib, MiniGo, NumPy, OpenAI Gym, Python, Swift, Swift for TensorFlow, TensorFlow, TensorFlow 2, Terra Monk
## Video description TensorFlow is about innovation. In this Swift for TensorFlow session, you will learn about language-integrated automatic differentiation, and tooling optimized for your productivity.
See the revamped dev site → https://www.tensorflow.org/
Watch all TensorFlow Dev Summit '19 sessions → http://bit.ly/TFDS19Sessions Event homepage → http://bit.ly/TFDS19
Subscribe to the TensorFlow YouTube channel → https://bit.ly/TensorFlow1
Speakers: Chris Lattner, Distinguished Engineer Brennan Saeta, Software Engineer
Music by Terra Monk → http://bit.ly/TerraMonkTFDS Event Photo Album → http://bit.ly/TFSummit19
event: TensorFlow Dev Summit 2019; re_ty: Publish; product: TensorFlow - General; fullname: Chris Lattner;
[Source](https://www.youtube.com/watch?v=s65BigoMV_I)