{"id":13427104,"url":"https://github.com/tensorflow/swift","last_synced_at":"2025-09-30T08:31:47.278Z","repository":{"id":38416732,"uuid":"130902948","full_name":"tensorflow/swift","owner":"tensorflow","description":"Swift for TensorFlow","archived":true,"fork":false,"pushed_at":"2022-01-12T19:55:30.000Z","size":3627,"stargazers_count":6127,"open_issues_count":37,"forks_count":609,"subscribers_count":258,"default_branch":"main","last_synced_at":"2024-12-26T06:31:48.166Z","etag":null,"topics":["differentiable-programming","machine-learning","tensorflow"],"latest_commit_sha":null,"homepage":"https://tensorflow.org/swift","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tensorflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-24T19:18:14.000Z","updated_at":"2024-12-18T12:31:13.000Z","dependencies_parsed_at":"2022-08-09T04:00:09.838Z","dependency_job_id":null,"html_url":"https://github.com/tensorflow/swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensorflow","download_url":"https://codeload.github.com/tensorflow/swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234722054,"owners_count":18876896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["differentiable-programming","machine-learning","tensorflow"],"created_at":"2024-07-31T00:01:53.875Z","updated_at":"2025-09-30T08:31:46.500Z","avatar_url":"https://github.com/tensorflow.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook","HarmonyOS","Swift"],"sub_categories":["Windows Manager","General-Purpose Machine Learning"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/logo.png\"\u003e\n\u003c/p\u003e\n\n# Swift for TensorFlow (Archived)\n\nSwift 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:\n\n* Added [language-integrated differentiable programming](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147) into the Swift language.  This work continues in the official Swift compiler. \n* Developed a mutable-value-semantics-oriented [deep learning API](https://github.com/tensorflow/swift-apis).\n* Fostered the development of [a model garden](https://github.com/tensorflow/swift-models) with more than [30 models from a variety of deep learning disciplines](https://github.com/tensorflow/swift-models#examples).\n* Enabled novel research that [combines deep learning with probabilistic graphical models](https://github.com/borglab/SwiftFusion) for 3D motion tracking and beyond.\n* Powered a(n almost) pure-Swift prototype of a [GPU+CPU runtime supporting parallel map](https://github.com/ewconnell/swiftrt).\n* Spun off multiple open source side efforts which continue to be under active development:\n  * [PythonKit](https://github.com/pvieito/PythonKit): Python interoperability with Swift.\n  * [swift-jupyter](https://github.com/google/swift-jupyter): Enables use of Swift within Jupyter notebooks.\n  * [swift-benchmark](https://github.com/google/swift-benchmark): Provides a robust benchmarking suite for Swift code.\n* Spun off several other open source efforts:\n  * [penguin](https://github.com/saeta/penguin): Parallel programming, data structures, graph algorithms, and more.\n  * [Tensors Fitting Perfectly](https://github.com/google-research/swift-tfp): Static analysis of tensor shape mismatches.\n* Swift Evolution proposals pitched, implemented, and accepted:\n  * [SE-0195](https://github.com/apple/swift-evolution/blob/main/proposals/0195-dynamic-member-lookup.md): User-defined \"Dynamic Member Lookup\" Types (`@dynamicMemberLookup`)\n  * [SE-0216](https://github.com/apple/swift-evolution/blob/main/proposals/0216-dynamic-callable.md): Introduce user-defined dynamically \"callable\" types (`@dynamicCallable`)\n  * [SE-0233](https://github.com/apple/swift-evolution/blob/main/proposals/0233-additive-arithmetic-protocol.md): Make `Numeric` refine a new `AdditiveArithmetic` protocol\n  * [SE-0253](https://github.com/apple/swift-evolution/blob/main/proposals/0253-callable.md): Callable values of user-defined nominal types (`func callAsFunction`)\n\nThis 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](https://docs.google.com/document/d/1Fm56p5rV1t2Euh6WLtBFKGqI43ozC3EIjReyLk-LCLU/edit).\n\n\n## Getting started\n\n### Using Swift for TensorFlow\n\n- **Google Colaboratory**: The fastest way to get started is to try out Swift\n   for TensorFlow right in your browser. Just open up [a tutorial](#tutorials-),\n   or start from a [blank notebook][blank_notebook]!\n   Read more in our [usage guide](Usage.md).\n\n- **Install locally**: You can [download a pre-built Swift for TensorFlow\n   package](Installation.md). After installation, you can follow these\n   [step-by-step instructions](Usage.md) to build and execute a Swift script on\n   your computer.\n\n- **Run on GCP**: You can spin up a GCE instance using a Swift for TensorFlow\n  [Deep Learning VM][dlvm] image, with all drivers and the toolchain\n  pre-installed. Instructions can be found in the\n  [Installation Guide](Installation.md).\n\n- **Compile from source**: If you'd like to customize Swift for TensorFlow or\n   contribute back, follow our [instructions][instructions]\n   on building Swift for TensorFlow from source.\n\n### Tutorials ![](https://www.tensorflow.org/images/colab_logo_32px.png)\n\nTutorial | Last Updated |\n-------- | ------------ |\n[A Swift Tour](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/a_swift_tour.ipynb) | March 2019\n[Protocol-Oriented Programming \u0026 Generics](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/protocol_oriented_generics.ipynb) | August 2019\n[Python Interoperability](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/python_interoperability.ipynb) | March 2019\n[Custom Differentiation](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/custom_differentiation.ipynb) | March 2019\n[Sharp Edges in Differentiability](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/Swift_autodiff_sharp_edges.ipynb) | November 2020\n[Model Training Walkthrough](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/model_training_walkthrough.ipynb) | March 2019\n[Raw TensorFlow Operators](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/raw_tensorflow_operators.ipynb) | December 2019\n[Introducing X10, an XLA-Based Backend](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/introducing_x10.ipynb) | May 2020\n\n### Resources\n\n- [Models and Examples](https://github.com/tensorflow/swift-models)\n- [TensorFlow Swift API Reference](https://www.tensorflow.org/swift/api_docs/Structs/Tensor)\n- [Release Notes](RELEASES.md)\n- [Known Issues](KNOWN_ISSUES.md)\n- [Frequently Asked Questions](FAQ.md)\n- [TensorFlow Blog Posts](https://blog.tensorflow.org/search?label=Swift)\n\n### Forums\n\nThe discussions happened on the\n[swift@tensorflow.org mailing list](https://groups.google.com/a/tensorflow.org/d/forum/swift).\n\n## Why Swift for TensorFlow?\n\nSwift for TensorFlow is a new way to develop machine learning models. It\ngives you the power of\n[TensorFlow](https://www.tensorflow.org) directly integrated into the\n[Swift programming language](https://swift.org/about). We believe that\nmachine learning paradigms are so important that they deserve\n**first-class language and compiler support**.\n\nA fundamental primitive in machine learning is gradient-based optimization:\ncomputing function derivatives to optimize parameters. With Swift for\nTensorFlow, you can easily differentiate functions using differential\noperators like [`gradient(of:)`](https://www.tensorflow.org/swift/api_docs/Functions#/s:10TensorFlow8gradient2of15CotangentVectorQzxcq_xc_tAA14DifferentiableRzSFR_AaFR_AdaFPQy_Rs_r0_lF), or differentiate with respect to an entire\nmodel by calling method [`gradient(in:)`](https://www.tensorflow.org/swift/api_docs/Protocols/Differentiable#/s:10TensorFlow14DifferentiablePAAE8gradient2in15CotangentVectorQzqd__xXE_tSFRd__AaBRd__AfCQyd__Rsd__lF). These differentiation APIs\nare not just available for `Tensor`-related concepts—they are\ngeneralized for all types that conform to the [`Differentiable`](https://www.tensorflow.org/swift/api_docs/Protocols/Differentiable)\nprotocol, including `Float`, `Double`, SIMD vectors, and your own data\nstructures.\n\n```swift\n// Custom differentiable type.\nstruct Model: Differentiable {\n    var w: Float\n    var b: Float\n    func applied(to input: Float) -\u003e Float {\n        return w * input + b\n    }\n}\n\n// Differentiate using `gradient(at:_:in:)`.\nlet model = Model(w: 4, b: 3)\nlet input: Float = 2\nlet (𝛁model, 𝛁input) = gradient(at: model, input) { model, input in\n    model.applied(to: input)\n}\n\nprint(𝛁model) // Model.TangentVector(w: 2.0, b: 1.0)\nprint(𝛁input) // 4.0\n```\n\nBeyond derivatives, the Swift for TensorFlow project comes with a sophisticated toolchain\nto make users more productive. You can run Swift interactively in a Jupyter\nnotebook, and get helpful autocomplete suggestions to help you explore the\nmassive API surface of a modern deep learning library. You can [get started\nright in your browser in\nseconds](https://colab.research.google.com/github/tensorflow/swift/blob/main/docs/site/tutorials/model_training_walkthrough.ipynb)!\n\nMigrating to Swift for TensorFlow is really easy thanks to Swift's powerful\nPython integration. You can incrementally migrate your Python code over (or\ncontinue to use your favorite Python libraries), because you can easily call\nyour favorite Python library with a familiar syntax:\n\n```swift\nimport TensorFlow\nimport Python\n\nlet np = Python.import(\"numpy\")\n\nlet array = np.arange(100).reshape(10, 10)  // Create a 10x10 numpy array.\nlet tensor = Tensor\u003cFloat\u003e(numpy: array)  // Seamless integration!\n```\n\n## Documentation\n\n\u003e Beware: the project is moving very quickly, and thus some of these documents\n\u003e are slightly out of date as compared to the current state-of-the-art.\n\n### Overview\n\nDocument | Last Updated | Status |\n-------- | ------------ | ------ |\n[Why *Swift* for TensorFlow?](docs/WhySwiftForTensorFlow.md) | April 2018 | Current\n[Swift for TensorFlow Design Overview](docs/DesignOverview.md) | April 2018 | Outdated\n[Supported Backends](docs/SupportedBackends.md) | May 2020 | Current\n\n### Technology deep dive\n\nThe Swift for TensorFlow project builds on top of powerful theoretical\nfoundations. For insight into some of the underlying technologies, check\nout the following documentation.\n\nDocument | Last Updated | Status |\n-------- | ------------ | ------ |\n[Swift Differentiable Programming Manifesto](https://github.com/apple/swift/blob/main/docs/DifferentiableProgramming.md) | January 2020 | Current\n[Swift Differentiable Programming Implementation Overview](https://docs.google.com/document/d/1_BirmTqdotglwNTOcYAW-ib6mx_jl-gH9Dbg4WmHZh0) | August 2019 | Current\n[Swift Differentiable Programming Design Overview](https://docs.google.com/document/d/1bPepWLfRQa6CtXqKA8CDQ87uZHixNav-TFjLSisuKag/edit?usp=sharing) | June 2019 | Outdated\n[Differentiable Types](docs/DifferentiableTypes.md) | March 2019 | Outdated\n[Differentiable Functions and Differentiation APIs](docs/DifferentiableFunctions.md) | March 2019 | Outdated\n[Dynamic Property Iteration using Key Paths](docs/DynamicPropertyIteration.md) | March 2019 | Current\n[Hierarchical Parameter Iteration and Optimization](docs/ParameterOptimization.md) | March 2019 | Current\n[First-Class Automatic Differentiation in Swift: A Manifesto](https://gist.github.com/rxwei/30ba75ce092ab3b0dce4bde1fc2c9f1d) | October 2018 | Outdated\n[Automatic Differentiation Whitepaper](docs/AutomaticDifferentiation.md) | April 2018 | Outdated\n[Python Interoperability](docs/PythonInteroperability.md) | April 2018 | Current\n[Graph Program Extraction](docs/GraphProgramExtraction.md) | April 2018 | Outdated\n\n## Source code\n\nCompiler and standard library development happens on the `main` branch of the\n[apple/swift](https://github.com/apple/swift/tree/main) repository.\n\nAdditional code repositories that make up the core of the project include:\n\n - [Deep learning library](https://github.com/tensorflow/swift-apis): high-level\n   API familiar to Keras users.\n\n\u003e Swift for TensorFlow is **no longer** a fork of the official Swift language;\n\u003e development was previously done on the `tensorflow` branch of the\n\u003e [apple/swift](https://github.com/apple/swift/tree/tensorflow) repository.\n\u003e Language additions were designed to fit with the direction of Swift and are\n\u003e going through the [Swift Evolution](https://github.com/apple/swift-evolution)\n\u003e process.\n\n### Jupyter Notebook support\n\n[Jupyter Notebook](http://jupyter.org/) support for Swift is under development at\n[google/swift-jupyter](https://github.com/google/swift-jupyter).\n\n### Model garden\n\n[tensorflow/swift-models](https://github.com/tensorflow/swift-models) is a\nrepository of machine learning models built with Swift for TensorFlow. It\nintended to provide examples of how to use Swift for TensorFlow, to allow for\nend-to-end tests of machine learning APIs, and to host model benchmarking\ninfrastructure.\n\n### SwiftAI\n\n[fastai/swiftai](https://github.com/fastai/swiftai) is a high-level API for\nSwift for TensorFlow, modeled after the\n[fastai Python library](https://github.com/fastai/fastai).\n\n## Community\n\nSwift for TensorFlow discussions happen on the\n[swift@tensorflow.org mailing list](https://groups.google.com/a/tensorflow.org/d/forum/swift).\n\n### Bugs reports and feature requests\n\nBefore reporting an issue, please check the [Frequently Asked Questions](FAQ.md)\nto see if your question has already been addressed.\n\nFor questions about general use or feature requests, please send an email to\nthe [mailing list](mailto:swift@tensorflow.org) or search for relevant issues\nin the [JIRA issue tracker](https://bugs.swift.org/projects/TF/issues/?filter=allopenissues).\n\nFor the most part, the core team's development is also tracked in\n[JIRA](https://bugs.swift.org/secure/RapidBoard.jspa?rapidView=17\u0026projectKey=TF\u0026view=planning).\n\n### Contributing\n\nWe welcome contributions from everyone. Read the [contributing\nguide](Contributing.md) for information on how to get started.\n\n### Code of conduct\n\nIn the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, gender identity and expression, level of\nexperience, education, socio-economic status, nationality, personal appearance,\nrace, religion, or sexual identity and orientation.\n\nThe Swift for TensorFlow community is guided by our [Code of\nConduct](CODE_OF_CONDUCT.md), which we encourage everybody to read before\nparticipating.\n\n[blank_notebook]: https://colab.research.google.com/notebook#create=true\u0026language=swift\n[dlvm]: https://cloud.google.com/ai-platform/deep-learning-vm/docs\n[instructions]: https://github.com/apple/swift/tree/tensorflow#building-swift-for-tensorflow\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensorflow%2Fswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fswift/lists"}