Swift for TensorFlow

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

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…

4 Likes

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

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…

30 Likes

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.

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

Got it. Will edit my post to something more appropriate :slight_smile: thanks for the reminder :slight_smile:

I’ve been making iOS apps with Swift since it first came out 5 years ago, and doing ML on iOS devices for the past 3 years. Swift has gone through many changes in that time and is only now becoming a stable language. I expect Swift for TF to be unstable for another while to come.

It’s certainly possible to use Swift on the backend already and there are a number of frameworks for doing so (Vapor, Kitura). But it’s still very much early days for Swift outside the macOS / iOS ecosystem.

I wouldn’t expect Swift for TF to be usable for practical applications of ML on mobile / embedded devices for a few more years. Even TF Lite is only just now becoming a realistic choice and it’s not even the best choice on iOS.

The idea of using just a single tool for the entire ML pipeline (i.e. Swift for TF), front-end and backend, is a nice dream but not even close to a reality right now.

If you’re interested in the possibilities offered by Swift for TF, then by all means get involved. But realize that stuff is going to break a lot. Don’t get into Swift for TF at this point when your goal is to get actual data science / machine learning work done. :wink:

7 Likes

Thank you for your answer! Very useful perspective. I think even the fact that there’s an inkling of a possibility of having a somewhat less fragemented research-to-deployment pipeline like the one you are mentioning, compounded with the obvious benefits of the language, makes this a very exciting project.

P.S. I’m also enjoying your blog posts very much!

My one worry is that Swift has changed a lot over the years. I’ve got code written in Swift versions 1 - 3 that no longer runs and would require a massive rewrite on my part. I think we’re mostly past that point now and the language will no longer see such big changes, but on the other hand a large portion of ML practitioners still haven’t moved on from Python 2. I’d hate to see that happen too in the Swift for TF ecosystem where some developers are stuck on Swift version N, some on version N+1, some on version N+2, and so on.

2 Likes

Here is a great blog post from my online friend and ML / graphics programming expert Brad Larson about using Swift for TensorFlow to train AlexNet: https://www.perceptuallabs.com/blog/2019/2/27/training-alexnet-using-swift-for-tensorflow

6 Likes

Hi

Thanks for that insight.
I would like to add it is my understanding that this version of Swift relies on Xcode 10 which is only available on the later versions of OSX operating system, correct me if I am wrong.
So for myself on a 2009 architecture I can only get Xcode 7 as I would need a later version of OSX greater than 10.11.6 , which are incompatible with the 2009 architecture, to get Xcode 10 . Therefore I would have to use my later Ubuntu 16.04 box; would I need to go to 18.04 or higher for Swift?

This sort of begs the question is there a specification of the architecture we would need for the upcoming course and if so perhaps it could be published for those who want to follow along with the notebooks etc. I am sure it is in hand so please forgive my panic.

It seems there are some ready built packages for ‘Swift for Tensorflow’ but are only for >= OSX 10.13.5 and Ubuntu 18.04. Further looking through the Swift github README says there in no GPU support and that Ubuntu 14.04 or 16.04 are required to build the above image.

I guess I may build the image but how the dependencies will affect my environment I have no Idea. It’s been a long time since I have done this sort of thing. For what I remember a fresh install of operating systems and source is required especially if it is shared with others. Perhaps best done in a virtual environment for which I don’t really have the resources.

1 Like

my wish is avoiding XCode as an IDE :wink: wasnt there a way to use notebooks? https://twitter.com/Pranjal_Yadav/status/1104819086050107394

2 Likes

If your old mac has ssd try this : http://dosdude1.com/mojave/
but backup your data first :wink:

3 Likes

I haven’t looked in detail at Swift for TF yet but I wouldn’t think Xcode is the preferred tool for it. Using a notebook environment such as Google Colab seems more suitable.

That’s a great thing, I would say. I’ve started learning Swift a couple of years ago but wasn’t able to figure out what to do with it except iOS/macOS development :smile:

That’s a great idea to include these topics into course. Looking forward to starting using Swift in high-performance computations domains. Does anybody want to start a kind of study group?

By the way, I believe that objc.io is a great source to learn about intermediate-to-advanced topics of Swift language. Their Advanced Swift and Functional Swift books are great sources of knowledge.

4 Likes

Today, I read deeper into the Swift language specification and I would argue there lies the hidden opportunity of truly modular neuronal networks.

I used to study CS with a major in concurrency verification especially w.r.t. programming language support and statical verification on compiler level.

An often overlooked pain point in programming languages design is the deep integration of the type system into the way the language handles composition i.e inheritance. I think Java’s incoherent collections that ultimately lead to the introduction of raw types to enable broken generics remains the prime example of how bad that can turn over time.

Modern functional programming languages support traits and mixins but doing them safe and sane in a statically typed language that yields high performance isn’t exactly an easy feat. Scala did a reasonable job but still suffers from sluggish performance due to the JVM legacy.

Swift, however, nails performance, type safety, and protocol based mixins. That already allows a lot of elegant composition, but also allows easier concurrency due simpler type checking against protocols that specify required constraints.

For neural networks, the big deal is the easy composition through programming against multiple interfaces as to plug together implementing traits in a typesafe way.

I can’t wait to see trait based programming converging with language level support for deep learning in a statically typed functional language. It would change AI system design in the most profound way as to compose complex AI system from smaller modules in a language that takes care of the rest during compilation.
TensorFlow tries to do that on the framework level, but boy is that an overhead for something that should be done in the programming language.

12 Likes

Great news!
It is always exciting to learn a new language and get one more superpower in developers toolbox. Are there any plans regarding TensorFlow lite on Swift?

https://groups.google.com/a/tensorflow.org/forum/#!topic/swift/s48m3F93wro

That said, our priorities for now are in the research and education spaces (e.g. our collaboration with fast.ai) for now. We want to focus the whole team on one domain to make it really good. (We don’t want to spread ourselves too thin.) In due time, we absolutely will expand our scope to include running on mobile and IoT devices.

1 Like

Right now you can use TF Lite from Swift but you have to write a simple C wrapper since TF Lite is C++ and Swift can’t talk to C++ directly. (But if you’re doing ML on iOS or macOS, then TF Lite isn’t necessarily the best choice.)