To install Swift for TensorFlow, download one of the packages below and follow the instructions for your operating system. After installation, you can use the full suite of Swift tools, including swift
(Swift REPL/interpreter) and swiftc
(Swift compiler). See here for more details about using Swift for TensorFlow.
Note:
- As a shortcut, see the GCP section for instructions on using a Deep Learning VM image to spin up a pre-configured environment.
- If you want to modify the Swift for TensorFlow source code or build with a custom version of TensorFlow, see here for instructions on building from source.
- Swift for TensorFlow is an early stage project. It has been released to enable open source development and is not yet ready for general use by machine learning developers.
Download | Version | Date |
---|---|---|
Xcode 12.3 | v0.12 | November 17, 2020 |
Ubuntu 20.04 (CPU Only) | v0.13 | January 21, 2021 |
Ubuntu 18.04 (CPU Only) | v0.13 | January 21, 2021 |
Ubuntu 18.04 (CUDA 11.0) | v0.13 | January 21, 2021 |
Ubuntu 18.04 (CUDA 10.2) | v0.13 | January 21, 2021 |
Ubuntu 18.04 (CUDA 10.1) | v0.13 | January 21, 2021 |
Windows | v0.12 | November 12, 2020 |
Older Packages
Download | Version | Date |
---|---|---|
Xcode 12.3 | v0.12 | November 17, 2020 |
Ubuntu 20.04 (CPU Only) | v0.12 | November 12, 2020 |
Ubuntu 18.04 (CPU Only) | v0.12 | November 12, 2020 |
Ubuntu 18.04 (CUDA 11.0) | v0.12 | November 12, 2020 |
Ubuntu 18.04 (CUDA 10.2) | v0.12 | November 12, 2020 |
Ubuntu 18.04 (CUDA 10.1) | v0.12 | November 12, 2020 |
Windows | v0.12 | November 12, 2020 |
Download | Version | Date |
---|---|---|
Xcode 12 | v0.11 | August 11, 2020 |
Ubuntu 20.04 (CPU Only) | v0.11 | August 11, 2020 |
Ubuntu 18.04 (CPU Only) | v0.11 | August 11, 2020 |
Ubuntu 18.04 (CUDA 10.2) | v0.11 | August 11, 2020 |
Ubuntu 18.04 (CUDA 10.1) | v0.11 | August 11, 2020 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.10 | June 16, 2020 |
Ubuntu 18.04 (CPU Only) | v0.10 | June 16, 2020 |
Ubuntu 18.04 (CUDA 10.2) | v0.10 | June 16, 2020 |
Ubuntu 18.04 (CUDA 10.1) | v0.10 | June 16, 2020 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.9 | May 08, 2020 |
Ubuntu 18.04 (CPU, TPU) | v0.9 | Apr 30, 2020 |
Ubuntu 18.04 (CPU, CUDA 10.2, TPU) | v0.9 | Apr 30, 2020 |
Ubuntu 18.04 (CPU, CUDA 10.1, TPU) | v0.9 | Apr 30, 2020 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.8 | Mar 17, 2020 |
Ubuntu 18.04 (CPU Only) | v0.8 | Mar 17, 2020 |
Ubuntu 18.04 (CUDA 10.1) | v0.8 | Mar 17, 2020 |
Ubuntu 18.04 (CUDA 10.0) | v0.8 | Mar 17, 2020 |
Ubuntu 18.04 (CUDA 9.2) | v0.8 | Mar 17, 2020 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.7.0 | Feb 12, 2020 |
Ubuntu 18.04 (CPU Only) | v0.7.0 | Feb 12, 2020 |
Ubuntu 18.04 (CUDA 10.1) | v0.7.0 | Feb 12, 2020 |
Ubuntu 18.04 (CUDA 10.0) | v0.7.0 | Feb 12, 2020 |
Ubuntu 18.04 (CUDA 9.2) | v0.7.0 | Feb 12, 2020 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.6.0 | Dec 10, 2019 |
Ubuntu 18.04 (CPU Only) | v0.6.0 | Dec 10, 2019 |
Ubuntu 18.04 (CUDA 10.1) | v0.6.0 | Dec 10, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.6.0 | Dec 10, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.6.0 | Dec 10, 2019 |
Download | Version | Date |
---|---|---|
Xcode 11 | v0.5.0 | Sep 19, 2019 |
Ubuntu 18.04 (CPU Only) | v0.5.0 | Sep 19, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.5.0 | Sep 19, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.5.0 | Sep 19, 2019 |
Download | Version | Date |
---|---|---|
Xcode 11 beta | v0.4.0 | July 25, 2019 |
Ubuntu 18.04 (CPU Only) | v0.4.0 | July 25, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.4.0 | July 25, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.4.0 | July 25, 2019 |
Download | Version | Date |
---|---|---|
Xcode 10 | v0.3.1 | April 30, 2019 |
Ubuntu 18.04 (CPU Only) | v0.3.1 | April 30, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.3.1 | April 30, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.3.1 | April 30, 2019 |
Download | Version | Date |
---|---|---|
Xcode 10 | v0.3 | April 23, 2019 |
Ubuntu 18.04 (CPU Only) | v0.3 | April 23, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.3 | April 23, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.3 | April 23, 2019 |
Download | Version | Date |
---|---|---|
Xcode 10 | v0.2 | March 1, 2019 |
Ubuntu 18.04 (CPU Only) | v0.2 | March 1, 2019 |
Ubuntu 18.04 (CUDA 10.0) | v0.2 | March 1, 2019 |
Ubuntu 18.04 (CUDA 9.2) | v0.2 | March 1, 2019 |
Note: We cannot build Ubuntu 20.04 toolchains with CUDA support until Ubuntu 20.04 Docker images with CUDNN are ready. In the meantime, you may be able to run Ubuntu 18.04 toolchains on Ubuntu 20.04 using the tips in #512.
Older Packages
Download |
---|
September 16, 2020 |
September 3, 2020 |
August 26, 2020 |
August 19, 2020 |
August 18, 2020 |
August 13, 2020 |
August 5, 2020 |
July 29, 2020 |
July 16, 2020 |
July 11, 2020 |
July 2, 2020 |
Note: Currently, the Xcode toolchains above only support macOS development. iOS/tvOS/watchOS are not supported.
- macOS 10.15 or later
- Xcode 12.2 Beta 3 or later
-
Download the latest package release.
-
Run the package installer, which will install an Xcode toolchain into
/Library/Developer/Toolchains/
. -
An Xcode toolchain (
.xctoolchain
) includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift. -
Open Xcode's
Preferences
, navigate toComponents > Toolchains
, and select the installed Swift for TensorFlow toolchain. -
Xcode uses the selected toolchain for building Swift code, debugging, and even code completion and syntax coloring. You'll see a new toolchain indicator in Xcode's toolbar when Xcode is using a Swift toolchain. Select the Xcode toolchain to go back to Xcode's built-in tools.
-
Selecting a Swift toolchain affects the Xcode IDE only. To use the Swift toolchain with command-line tools, use
xcrun --toolchain swift
andxcodebuild -toolchain swift
, or add the Swift toolchain to your path as follows:$ export PATH=/Library/Developer/Toolchains/swift-latest/usr/bin:"${PATH}"
-
CUDA-only: If you downloaded a CUDA GPU-enabled toolchain, add the library path(s) for CUDA and cuDNN to
$LD_LIBRARY_PATH
:$ export LD_LIBRARY_PATH=/usr/local/cuda/lib:"${LD_LIBRARY_PATH}"
Packages for Linux are tar archives including a copy of the Swift compiler, lldb, and related tools. You can install them anywhere as long as the extracted tools are in your PATH. Note that nothing prevents Swift from being ported to other Linux distributions beyond the ones mentioned below. These are only the distributions where these binaries have been built and tested.
- Ubuntu 18.04 (64-bit)
- Ubuntu 18.04 (64-bit)
- For GPU toolchains:
- CUDA Toolkit 10.1, 10.2, or 11.0
- CuDNN 7.6.0 onwards (CUDA 10.1)
- An NVIDIA GPU with compute compatibility 3.5, 3.7, 6.0, 6.1, 7.0, or 7.5.
For detailed instructons on setting up CUDA and CuDNN, please see the TensorFlow Docs.
- Install required dependencies:
$ sudo apt-get install clang libpython-dev libblocksruntime-dev
(Note: You may also need to install other dependencies, if you are unable to run swift
or other tools below.)
- Download the latest binary release above.
The swift-tensorflow-<VERSION>-<PLATFORM>.tar.gz
file is the toolchain itself.
- Extract the archive with the following command:
$ tar xzf swift-tensorflow-<VERSION>-<PLATFORM>.tar.gz
This creates a usr/
directory in the location of the archive.
- Add the Swift toolchain to your path as follows:
$ export PATH=$(pwd)/usr/bin:"${PATH}"
You can now execute the swiftc
command to build Swift projects.
Note: If you are using a CUDA build and you have an NVIDIA GPU with a compute capability other than 3.5 or 7.0, then you will experience a ~10 minute delay the first time you execute a TensorFlow operation, while TensorFlow compiles kernels for your GPU's compute capability. The program will not print anything out and it will appear to be frozen.
- Windows 10 October 2018 Update (RedStone 5 - 10.0.17763.0) or later1
- Visual Studio 2017 or later (Visual Studio 2019 is recommended)
- CMake 3.16 or later
- Install Visual Studio from Microsoft.
The following table lists the required set of installed components:
Component | ID |
---|---|
MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.25) | Microsoft.VisualStudio.Component.VC.Tools.x86.x64 |
Windows Univeral C Runtime | Microsoft.VisualStudio.Component.Windows10SDK |
Windows 10 SDK (10.0.17763.0)2 | Microsoft.VisualStudio.Component.Windows10SDK.17763 |
The following table lists the additional recommended set of installed components:
Component | ID |
---|---|
C++ ATL for latest v142 build tools (x86 & x64)3 | Microsoft.VisualStudio.Component.VC.ATL |
C++ CMake tools for Windows4 | Microsoft.VisualStudio.Component.VC.CMake.Project |
Git for Windows5 | Microsoft.VisualStudio.Component.Git |
Python 3 64-bit (3.7.5)6 | Component.CPython.x64 |
-
Install CMake from cmake.
-
Download and run the latest release from Swift for TensorFlow. The installer will install a toolchain into
%SystemDrive%\Library\Developer\Toolchains
. The toolchain (.xctoolchain
) includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift. -
Deploy the Windows SDK modulemaps from an (elevated) "Administrator"
x64 Native Tools for VS2019 Command Prompt
shell7:
:: NOTE: the following additional command may be required for older snapshots:
:: set SDKROOT=%SystemDrive%\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
1 You can check which version of Windows you are currently running by opening command prompt and entering winver
.
2 You may install a newer SDK if you desire. 17763 is listed here to match the minimum Windows release supported.
3 Needed for parts of lldb.
4 Provides ninja
which is needed for building projects. You may download it from ninja-build instead.
5 Provides git
to clone projects from GitHub. You may download it from git-scm instead.
6 Provides python
needed for Python integration. You may download it from python instead.
7 This will need to be re-run every time Visual Studio is updated.
Experimental
To save on setup time, you can leverage one of the Swift for Tensorflow Deep Learning VM images to quickly spin up a pre-configured Ubuntu instance with an installed toolchain. To view the available images (currently experimental):
gcloud compute images list \
--project deeplearning-platform-release \
--no-standard-images | \
grep swift
To create a small CPU instance:
gcloud compute instances create s4tf-ubuntu \
--image-project=deeplearning-platform-release \
--image-family=swift-latest-cpu-ubuntu-1804 \
--maintenance-policy=TERMINATE \
--machine-type=n1-standard-2 \
--boot-disk-size=256GB
This will create a single n1-standard-2
instance with the Swift
toolchain installed. Once the instance is up, connect to it:
gcloud compute ssh s4tf-ubuntu \
--zone ${ZONE}
To create a GPU instance, the first step is to identify a zone that contains the type of GPU you'd like to use, since not all zones have availability:
export GPU_TYPE="v100"
gcloud compute accelerator-types list | grep ${GPU_TYPE}
Using these results, set your zone:
export ZONE="us-west1-b"
To create an instance with an attached V100 GPU:
gcloud compute instances create s4tf-ubuntu-${GPU_TYPE} \
--zone=${ZONE} \
--image-project=deeplearning-platform-release \
--image-family=swift-latest-gpu-ubuntu-1804 \
--maintenance-policy=TERMINATE \
--accelerator="type=nvidia-tesla-${GPU_TYPE},count=1" \
--metadata="install-nvidia-driver=True" \
--machine-type=n1-highmem-2 \
--boot-disk-size=256GB
This will create a single n1-highmem-2
instance with an attached accelerator
and the Swift toolchain installed with all CUDA libraries.
Note: If this command fails due to lack of quota, you will need to find
a zone with available quota or request an increase. Using the search feature in
the Quotas section of the GCP Console, you can view your current
usage and submit an increase request (e.g. search for "V100" or the value you
used in $GPU_TYPE
).
Once the instance is up, connect to it:
gcloud compute ssh s4tf-ubuntu-${GPU_TYPE} \
--zone ${ZONE}
Create a text file test.swift
with the following contents:
import TensorFlow
var x = Tensor<Float>([[1, 2], [3, 4]])
print(x + x)
Run swift-models
git clone https://github.com/tensorflow/swift-models.git
cd swift-models
swift run
Swift will print an error with a list of executable names that exercise different models.
Issue swift run
executable-name to select the model you're interested in.
Run these commands to verify the installation.
$ swiftc test.swift
$ test
Run these commands to verify the installation.
$ set SDKROOT=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
$ swiftc -sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows -emit-executable -o test.exe test.swift
$ test.exe
N.B. Interpreter mode and direct invocation from VS 2019 are currently not supported on Windows.
If you see this output, you have successfully installed Swift for TensorFlow!
[[2.0, 4.0],
[6.0, 8.0]]