Swift for TensorFlow

This is an issue with Swift-Jupyter, but it doesn’t seem to be a breaking incompatibility…unless it relates to the issue I’ve been having with Python interoperability…

I’ve addressed this in the latest update to my Medium post, which contains other updates, too. Guess I should’ve waited to publish until after I had tested out more than the first *.ipynb

The conda instruction you reference above was a copy-paste error. But it turns out that adding those libraries doesn’t help you. I’ve added another step to the setup in my post that addresses the issue of getting GPU functionality.

Finally - back to the Python interoperability issue - I’ve been unsuccessful in getting Python imports to work. I think it’s somehow stemming from the following: in python_interoperability.ipynb, the call import Python imports Python2.7 instead of Python3.6.

1 Like

I didn’t use the requirements.txt - I don’t like that it pins all those specific versions. I don’t think it’s a good approach. IIRC I already had all the prereqs in a standard fastai conda environment.

1 Like

Just moved this to the #harebrain forum BTW.

1 Like

@saeta Perhaps you could update the install docs to remove these issues:

  • PYTHON_LIBRARY env var
  • conda env approach
  • Remove pinned versions from requirements.txt

Whilst pinned requirements are great for production situations, they can be troublesome for folks looking to use current versions of stuff and to use their existing environments where possible. In this case, my existing env worked fine without any of the pinned versions, which is handy since I didn’t have to set up my notebook configuration again, and I can easily switch between kernels.

2 Likes

Adding @dan-zheng since he just posted a useful link:

1 Like

This got me on the right track. I now have Swift-Jupyter working via a streamlined approach using conda, as described in my reply to the other thread: How to Set Up Jupyter Notebooks for S4TF on Docker

I’ll update my Medium post shortly.

1 Like

I can remove all the pinned versions from requirements.txt, and add a section about how to install using conda!

Not sure what you mean by the “PYTHON_LIBARY env var” issue. Do you mean that we should suggest adding "–swift-python-library " to the “register.py” command in the install instructions, like neuradai does in his medium post? That’s the only PYTHON_LIBRARY env var related thing I see in this thread.

2 Likes

What I did was point PYTHON_LIBRARY to the /home/user/anaconda3/envs/s4tf/lib.
Although I have not had time to check/test any of this out!!!

I think now this should be set too :

/home/user/anaconda3/envs/s4tf/lib/libpython3.6m.so

A few weeks ago I had to set the PYTHON_LIBRARY env var to get py3.7 working. But I suspect --swift-python-library didn’t exist at that point so perhaps my info is out of date.

I am a little confused I have swift notebooks set up except that I have an issue.
To try out my installation s4tf I have cloned from git hub the tutorial directory in which there are several notebooks I have opened two of these

A Swift Tour
and
custom_differentiation
In the first notebook the first code cell works but the second and third fail with a syntax error

see these images

First cell
print(“Hello world!”)
second cell
var myVariable = 42
myVariable = 50
let myConstant = 42
File “”, line 1
var myVariable = 42
Syntax error: invalid syntax

However in the second notebook

first and second cells run without issues

There is something I have missed!!!

Sounds like python? Check that selected kernel is Swift?

2 Likes

Thanks Vova the notebook some how got loaded as Python3 probably some error of mine

Where to find a debugger for swift notebooks!!!. Thanks. I tried with the ipython debugger but it failed on the import syntax also swift uses the lldb debugger.

For installation of Swift 5.0 on Ubuntu 16.04 I did the following.

  1. Install clang:
    $ sudo apt-get install clang
  2. (optional) Import GPG keys:
    $ wget -q -O - https://swift.org/keys/all-keys.asc | sudo gpg --import -
  3. Download, untar and move:
    $ wget https://swift.org/builds/swift-5.0-release/ubuntu1604/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu16.04.tar.gz
    $ sudo tar xzf swift-5.0-RELEASE-ubuntu16.04.tar.gz
    $ mv swift-5.0-RELEASE-ubuntu16.04 /usr/share/swift
  4. Add to path:
    $ echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc
    $ source ~/.bashrc
  5. Test:
    $ swift --version
    or
    $ swift
    and return to shell
    1> :exit

For other versions of Ubuntu, find links on the download page.
source

3 Likes

stiijn
In an earlier post I had the same intentions, however I was advised in a reply not to persist with 16.04 as the releases does not get updated as frequent as the 18.04 releases. When I was looking at this 16.04 was a Jan 1st release and 18.04 was more than a month later. On the basis of this I updated to 18.04.

1 Like

It’s easy to mix them up but the downloads for Swift and S4TF are different packages. :smiley:

The one you can get from Swift.org is for regular Swift, which supports 16.04 just fine. The S4TF builds appear to favor 18.04 (although I guess you could build it yourself for 16.04?).

Hi! I have been studying Tensorflow lite, I found it quite interesting. Especially if you have to use edge devices like raspberry pi 3. However, the code should be written in c++ which is not what I wanted to do. Lately I am quite a lazy guy.

Yesterday I came across into TF lite experiments in Swift. What do you think about? could rPi3 + Swift + TFLite + (hopefully) FastAi be a viable way ?? Thanks

That sounds like a really interesting question to try to answer!.. :slight_smile:

4 Likes

“A year from now it’s gonna be mind-blowing” - Chris Lattner

With MLIR and Swift4TF v1.0, year 2020 is going to be exciting

2 Likes

Just to confirm, are you referring to https://developer.apple.com/swift/resources/? :slight_smile:

I am just getting started with swift