Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Latest commit

 

History

History
458 lines (336 loc) · 28 KB

Installation.md

File metadata and controls

458 lines (336 loc) · 28 KB

Install Swift for TensorFlow

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.

Releases

Release notes for v0.13.0

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

Release notes for v0.12.0

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

Release notes for v0.11.0

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

Release notes for v0.10.0

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

Release notes for v0.9.0

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

Release notes for v0.8.0

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

Release notes for v0.7.0

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

Release notes for v0.6.0

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

Release notes for v0.5.0

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.

Development Snapshots

Download
Xcode 12 (November 17, 2020)
Ubuntu 20.04 (CPU) (Nightly)
Ubuntu 18.04 (CPU) (Nightly)
Ubuntu 18.04 (CPU, CUDA 11.0) (Nightly)
Ubuntu 18.04 (CPU, CUDA 10.2) (Nightly)
Ubuntu 18.04 (CPU, CUDA 10.1) (Nightly)
Windows (October 29, 2020)
NVIDIA Jetson, JetPack 4.4 (CPU, CUDA 10.2) (v0.12-rc1)
Older Packages

Xcode

Xcode 12

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.

Using Downloads

macOS

Requirements

  • macOS 10.15 or later
  • Xcode 12.2 Beta 3 or later

Installation

  1. Download the latest package release.

  2. Run the package installer, which will install an Xcode toolchain into /Library/Developer/Toolchains/.

  3. 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.

  4. Open Xcode's Preferences, navigate to Components > Toolchains, and select the installed Swift for TensorFlow toolchain.

  5. 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.

Select toolchain in Xcode preferences.

  1. Selecting a Swift toolchain affects the Xcode IDE only. To use the Swift toolchain with command-line tools, use xcrun --toolchain swift and xcodebuild -toolchain swift, or add the Swift toolchain to your path as follows:

    $ export PATH=/Library/Developer/Toolchains/swift-latest/usr/bin:"${PATH}"
  2. 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}"

Linux

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.

Requirements

  • Ubuntu 18.04 (64-bit)

Supported Target Platforms

  • Ubuntu 18.04 (64-bit)

Additional Requirements

  • 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.

Installation

  1. 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.)

  1. Download the latest binary release above.

The swift-tensorflow-<VERSION>-<PLATFORM>.tar.gz file is the toolchain itself.

  1. 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.

  1. 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

Requirements

  • 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

Installation

  1. 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
  1. Install CMake from cmake.

  2. 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.

  3. 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.

Google Cloud Platform

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

CPU Instance

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}

GPU Instance

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}

Verify the Installation

Create a text file test.swift with the following contents:

import TensorFlow
var x = Tensor<Float>([[1, 2], [3, 4]])
print(x + x)
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.

To build on Linux/MacOS

Run these commands to verify the installation.

$ swiftc test.swift
$ test

To build on Windows

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.

Verify Output

If you see this output, you have successfully installed Swift for TensorFlow!

[[2.0, 4.0],
 [6.0, 8.0]]