Swift for TensorFlow

(Walter Wiggins) #1

Just announced today at the TensorFlow Dev Summit: Swift for TensorFlow will be integrated into 2 of the lessons for the upcoming Part 2 course with guest teacher Chris Lattner! Based on the presentation, it looks like it has great potential for adding flexibility to DL/AI model development.


https://www.fast.ai/2019/03/06/fastai-swift/

@jeremy I’m really pumped to be a part of this new chapter in fast.ai. For those of us who aren’t familiar with the Swift language, do you recommend we do any pre-learning in advance of these lessons?

Anyone else have any recommended basic tutorials or intro resources for Swift?

17 Likes

#2

The Swift for TensorFlow project is currently focusing on 2 kinds of users:

  1. Advanced ML researchers who are limited by current ML frameworks. Swift for TensorFlow’s advantages include a seamless integration with a modern general-purpose language, allowing for more dynamic and sophisticated models. Fast abstractions can be developed “in user-space” (as opposed to in C/C++ aka “framework-space”), resulting in modular APIs that can be easily customized.
  2. ML learners who are just getting started with machine learning. Thanks to Swift’s support for quality tooling (e.g. context-aware autocomplete), Swift for TensorFlow can be one of the most productive ways to get started learning the fundamentals of machine learning.
2 Likes

(Javier) #3

thank you for sharing, yeah, and for windows 10 pc users, any tips about compiling swift in windows 10? so far I’ve found this option: https://swiftforwindows.github.io/

1 Like

#4

If you have a mac or an ipad, I highly recommend to download the playground app and open the introduction of the official Swift book in it. It’s a great introduction, and it’s interactive.

20 Likes

(Alex Rigler) #5

Yes I also found the TensorFlow Dev Summit presentation really impressive and worth a watch. The python interop was so cool!

The new and improved TensorFlow documentation has a great walkthrough which can be run through Colab. Tip: run an empty swift notebook alongside to write the code out yourself.

The Tensorflow/Swift repo that @miwojc linked to has a lot to read through (I haven’t got too far yet) and the swift-jupyter repo has a lot of the info you’ll need with setting up tooling if/when you want to get out of the Colab environment.

I also plan on rereading Jeremy’s original article on Swift this time while exploring the BaseMath library he developed.

12 Likes

(Renato Hermoza) #6

Any recommendation on trying swift in ubuntu?

1 Like

(Davide Boschetto) #7

I just read the official announcement of fast.ai embracing Swift for Tensorflow. I’m very excited about this, and I now understand even more the “invitation” process behind Part 2. This is a fantastic move by fastai founders and maintainers: the untapped potential is really huge, so let’s hope we can give you all the PR and research reasoning you need!
It’s now even more amazing to be part of this.

Thank you all, again.

5 Likes

(Fabrizio) #8

Wait a minute!! Swift is a great language, and Swift4TensorFlow is a cool initiative … but the only drawback I can see concerns training models even normal ones. For what I understood, right now if you want to train a medium size model(read noCPU) on a mac you have to use TPUs that are provided only by Google itself and are quite expansive. That is ok for Google’s folks who got all those resources for free, but for the rest of us? Am I wrong ??

BTW, ubuntu users can use Swift for Linux with Swift-Jupyter and should be able to use their own GPUs.

3 Likes

(Swagato Chatterjee) #9

I think Colab gives you TPUs, I don’t know how to get hold of their address though

0 Likes

(Jeff Hale) #10

You can get TPUs for free in colab. Just choose Runtime from the menu. Then Change Runtime Type. Then select TPU from the dropdown.

0 Likes

(Fabrizio) #11

Yes, you’re right colab gives us TPU for free. But I have no idea about its performance. Moreover, as mac user I love Xcode and I think it makes the difference while coding in swift.

0 Likes

(Brian Smith) #12

I just installed Swift on my Azure fastai Data Science VM just following the instructions for Ubuntu 16.04 from swift.org . I’m not sure of the intricacies of GPU support though for Swift on the NC6 VM (K80).

1 Like

(Renato Hermoza) #13

I hope we get good coding tools outside macs environment. On VSCode this pluging appears to be interesting https://github.com/vknabel/vscode-swift-development-environment, will test it soon.

1 Like

(Henri Palacci) #14

Hey all - I’m super excited about this part of the course! I dipped my toes into the Swift stuff yesterday. I started setting up a VsCode env - this guide proved super useful: Swift Development with Visual Studio Code

The vscode environment works well, and I just run the scripts from a terminal.

As an aside, I’d be happy to have a discussion about the implications of being able to code an ML model in Swift for production:

  • in the medium term it makes integrating ML models into iOS and OSX apps easier. My view on this is that for many applications you’re better off developing prototypes with a proper cloud backend and webapp frontend. Works on all platforms right from the start, no worries about compressing your model so inference runs on mobile, scaleable, …
  • In that paradigm (cloud backend + web frontend), is Swift a good candidate for backend dev? This would be nice as you could imagine a full-Swift backend. Seems like some frameworks exist for swift backend development: Perfect framework. I haven’t tested this and wonder what the community thinks of Swift as a backend language.
  • In the case of an existing backend, or in the case where we don’t want to develop a backend in Swift, how can we call Swift TF binaries from the gold standard backend armada? (Golang, NodeJS, Python, Ruby)
  • Embedded development: if we want to deploy a custom model to an embedded device, could Swift be a good drop-in replacement for C++? Not sure what the state of embedded swift is.

I’d be happy to talk and explore these issues more in the coming weeks and during the course!

10 Likes

(Junxian) #15

I am learning Swift from:
https://www.hackingwithswift.com/

And in here you have the basics(well written):
https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html

2 Likes

(Francesco Gianferrari Pini) #16

Another point in my opinion is the maturity of all Swift ecosystem on ML/DL. In order to train models we need a huge stack for image pre/processing, NLP libraries, visualization etc. I know that Python as a language is far from perfect but is ripe of all this kind of goodies that give a huge boost of productivity and let you focus on the important stuff…

3 Likes

(Henri Palacci) #17

This is where in theory the Python interop should help ? Haven’t explored that yet at all.

0 Likes

(Jeremy Howard (Admin)) #18

Yup you wouldn’t want to shift your day to day use to Swift until that stuff exists (although the Python interop is a useful filler in the meantime).

To me, the exciting thing here is being able to be a pioneer on a new project that seems very likely to be really important in the coming years. Such an opportunity doesn’t come along very often.

If you want to join in, we’ve created a new category for discussing this: #harebrain .

Yup, that’s our new code name! It’s swift and fast like a hare, and it’s being developed in conjunction with Google Brain, and it’s such a big and crazy goal we have you could call it harebrained…

28 Likes

#19

Where one can start learning ML with S4TF please? Guides/resources will be much appreciated. Thank you! :slight_smile:

ML learners who are just getting started with machine learning. Thanks to Swift’s support for quality tooling (e.g. context-aware autocomplete), Swift for TensorFlow can be one of the most productive ways to get started learning the fundamentals of machine learning.

0 Likes

#21

As Jeremy said here please don’t at-mention very busy people like Chris unless you really think they are the only person that can answer your question.
We’re very happy to have him on the forum, but we wouldn’t him deleting his account because of the number of notifications he receives :wink:

2 Likes