An excerpt from the repository, fetched Nov 13, 2026.
Read the project’s introduction
Swift for TensorFlow (Archived)
Swift for TensorFlow was an experiment in the next-generation platform for machine learning, incorporating the latest research across machine learning, compilers, differentiable programming, systems design, and beyond. It was archived in February 2021. Some significant achievements from this project include:
Added language-integrated differentiable programming into the Swift language. This work continues in the official Swift compiler.
Developed a mutable-value-semantics-oriented deep learning API.
Fostered the development of a model garden with more than 30 models from a variety of deep learning disciplines.
Enabled novel research that combines deep learning with probabilistic graphical models for 3D motion tracking and beyond.
Powered a(n almost) pure-Swift prototype of a GPU+CPU runtime supporting parallel map.
Spun off multiple open source side efforts which continue to be under active development:
PythonKit: Python interoperability with Swift.
swift-jupyter: Enables use of Swift within Jupyter notebooks.
swift-benchmark: Provides a robust benchmarking suite for Swift code.
Spun off several other open source efforts:
penguin: Parallel programming, data structures, graph algorithms, and more.
Tensors Fitting Perfectly: Static analysis of tensor shape mismatches.
Swift Evolution proposals pitched, implemented, and accepted:
SE-0195: User-defined "Dynamic Member Lookup" Types (@dynamicMemberLookup)
SE-0216: Introduce user-defined dynamically "callable" types (@dynamicCallable)
SE-0233: Make Numeric refine a new AdditiveArithmetic protocol
SE-0253: Callable values of user-defined nominal types (func callAsFunction)
This site will not receive further updates. The API documentation and binary downloads will continue to be accessible as well as the Open Design Review meeting recordings.
Getting started
Using Swift for TensorFlow
Google Colaboratory: The fastest way to get started is to try out Swift
for TensorFlow right in your browser. Just open up a tutorial,
or start from a blank notebook!
Read more in our usage guide.
Install locally: You can download a pre-built Swift for TensorFlow
package. After installation, you can follow these
step-by-step instructions to build and execute a Swift script on
your computer.
Run on GCP: You can spin up a GCE instance using a Swift for TensorFlow
Deep Learning VM image, with all drivers and the toolchain
pre-installed. Instructions can be found in the
Installation Guide.
Compile from source: If you'd like to customize Swift for TensorFlow or
contribute back, follow our instructions
on building Swift for TensorFlow from source.
Tutorials
Tutorial
Last Updated
A Swift Tour
March 2019
Protocol-Oriented Programming & Generics
August 2019
Python Interoperability
March 2019
Custom Differentiation
March 2019
Sharp Edges in Differentiability
November 2020
Model Training Walkthrough
March 2019
Raw TensorFlow Operators
December 2019
Introducing X10, an XLA-Based Backend
May 2020
Resources
Models and Examples
TensorFlow Swift API Reference
Release Notes
Known Issues
Frequently Asked Questions
TensorFlow Blog Posts
Forums
The discussions happened on the
swift@tensorflow.org mailing list.
Why Swift for TensorFlow?
Swift for TensorFlow is a new way to develop machine learning models. It
gives you the power of
TensorFlow directly integrated into the
Swift programming language. We believe that
machine learning paradigms are so important that they deserve
first-class language and compiler support.
A fundamental primitive in machine learning is gradient-based optimization:
computing function derivatives to optimize parameters. With Swift for
TensorFlow, you can easily differentiate functions using differential
operators like gradient(of:), or differentiate with respect to an entire
model by calling method gradient(in:). These differentiation APIs
are not just available for Tensor-related concepts—they are
generalized for all types that conform to the Differentiable
protocol, including Float, Double, SIMD vectors, and your own data
structures.
// Custom differentiable type.
struct Model: Differentiable {
var w: Float
var b: Float
func applied(to input: Float) -> Float {
return w * input + b
}
}
// Differentiate using `gradient(at:_:in:)`.
let model = Model(w: 4, b: 3)
let input: Float = 2
let (𝛁model, 𝛁input) = gradient(at: model, input) { model, input in
model.applied(to: input)
}
print(𝛁model) // Model.TangentVector(w: 2.0, b: 1.0)
print(𝛁input) // 4.0
Beyond derivatives, the Swift for TensorFlow project comes with a sophisticated toolchain
to make users more productive. You can run Swift interactively in a Jupyter
notebook, and get helpful autocomplete suggestions to help you explore the
massive API surface of a modern deep learning library. You can get started
right in your browser in
seconds!
Migrating to Swift for TensorFlow is really easy thanks to Swift's powerful
Python integration. You can incrementally migrate your Python code over (or
continue to use your favorite Python libraries), because you can easily call
your favorite Python library with a familiar syntax:
import TensorFlow
import Python
let np = Python.import("numpy")
let array = np.arange(100).reshape(10, 10) // Create a 10x10 numpy array.
let tensor = Tensor<Float>(numpy: array) // Seamless integration!
Documentation
Beware: the project is moving very quickly, and thus some of these documents
are slightly out of date as compared to the current state-of-the-art.
Overview
Document
Last Updated
Status
Why Swift for TensorFlow?
April 2018
Current
Swift for TensorFlow Design Overview
April 2018
Outdated
Supported Backends
May 2020
Current
Technology deep dive
The Swift for TensorFlow project builds on top of powerful theoretical
foundations. For insight into some of the underlying technologies, check
out the following documentation.
Document
Last Updated
Status
Swif
Read the full README on GitHub