
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
.
Fostered the development of
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:
: Python interoperability with Swift.
: Enables use of Swift within Jupyter notebooks.
: Provides a robust benchmarking suite for Swift code.
Spun off several other open source efforts:
: Parallel programming, data structures, graph algorithms, and more.
: Static analysis of tensor shape mismatches.
Swift Evolution proposals pitched, implemented, and accepted:
: User-defined "Dynamic Member Lookup" Types (@dynamicMemberLookup)
: Introduce user-defined dynamically "callable" types (@dynamicCallable)
: Make Numeric refine a new AdditiveArithmetic protocol
: 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
, or start from a
! Read more in our
.
Install locally: You can
download a pre-built Swift for TensorFlow package
. After installation, you can follow these
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
image, with all drivers and the toolchain pre-installed. Instructions can be found in the
.
Compile from source: If you'd like to customize Swift for TensorFlow or contribute back, follow our
on building Swift for TensorFlow from source.
Tutorials
TutorialLast Updated
March 2019
Protocol-Oriented Programming & Generics
August 2019
March 2019
March 2019
Sharp Edges in Differentiability
November 2020
March 2019
December 2019
Introducing X10, an XLA-Based Backend
May 2020Resources
TensorFlow Swift API Reference
Forums
The discussions happened on the
[email protected] mailing list
.
Swift for TensorFlow is a new way to develop machine learning models. It gives you the power of
directly integrated into the
. 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
, or differentiate with respect to an entire model by calling method
. These differentiation APIs are not just available for Tensor-related concepts—they are generalized for all types that conform to the
protocol, including Float, Double, SIMD vectors, and your own data structures.
// Custom differentiable type. structModel:Differentiable{varw:Floatvarb:Floatfunc applied(to input:Float)->Float{return w * input + b }} // Differentiate using `gradient(at:_:in:)`. letmodel=Model(w:4, b:3)letinput:Float=2let(𝛁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.0Beyond 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 letnp=Python.import("numpy")letarray= np.arange(100).reshape(10,10) // Create a 10x10 numpy array. lettensor=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
DocumentLast UpdatedStatus
April 2018Current
Swift for TensorFlow Design Overview
April 2018Outdated
May 2020CurrentTechnology 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.
DocumentLast UpdatedStatus
Swift Differentiable Programming Manifesto
January 2020Current
Swift Differentiable Programming Implementation Overview
August 2019Current
Swift Differentiable Programming Design Overview
June 2019Outdated
March 2019Outdated
Differentiable Functions and Differentiation APIs
March 2019Outdated
Dynamic Property Iteration using Key Paths
March 2019Current
Hierarchical Parameter Iteration and Optimization
March 2019Current
First-Class Automatic Differentiation in Swift: A Manifesto
October 2018Outdated
Automatic Differentiation Whitepaper
April 2018Outdated
April 2018Current
April 2018OutdatedSource code
Compiler and standard library development happens on the main branch of the
repository.
Additional code repositories that make up the core of the project include:
: high-level API familiar to Keras users.
Swift for TensorFlow is no longer a fork of the official Swift language; development was previously done on the tensorflow branch of the
repository. Language additions were designed to fit with the direction of Swift and are going through the
process.
Jupyter Notebook support
support for Swift is under development at
.
Model garden
is a repository of machine learning models built with Swift for TensorFlow. It intended to provide examples of how to use Swift for TensorFlow, to allow for end-to-end tests of machine learning APIs, and to host model benchmarking infrastructure.
SwiftAI
is a high-level API for Swift for TensorFlow, modeled after the
.
Community
Swift for TensorFlow discussions happen on the
[email protected] mailing list
.
Bugs reports and feature requests
Before reporting an issue, please check the
to see if your question has already been addressed.
For questions about general use or feature requests, please send an email to the
or search for relevant issues in the
.
For the most part, the core team's development is also tracked in
.
Contributing
We welcome contributions from everyone. Read the
for information on how to get started.
Code of conduct
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
The Swift for TensorFlow community is guided by our
, which we encourage everybody to read before participating.