How to Set Up Jupyter Notebooks for S4TF on Docker


(James Thompson) #1

Hey, everyone!

I just wanted to briefly share my excitement for fastai and S4TF. It goes without saying that I’m already a huge fan of fastai–the teaching philosophy really resonates with me. I was already extremely excited to be attending the 2019 Deep Learning Pt. II course, but hearing the news at TF dev summit had me cheering! I was at WWDC when the open sourcing of Swift was announced (equal excitement). I truly think Swift is an amazing language. And that is coming from an objective place. I regularly have to go back and forth between Swift, Obj-C, C and C++ for work, and I have to say, I feel so much more productive with Swift. I’ve had colleagues independently say the same thing. I’m super optimistic to say the least!

Anyways, I thought I’d share the medium post I just made about getting going with swift-jupyter on Docker (feedback is more than welcome of course). It was the cleanest way I found to try stuff out on my compute rig. I’m also working on some other guides on getting going via other methods including Xcode. I’m also looking at other ways of contributing back but need to reel myself back into PyTorch and fastai stuff a bit. I still have a lot of cool stuff to learn w.r.t. deep learning. :smile:

Cheers!


#2

This is really cool! :slight_smile: Thx for sharing. Really nice, detailed write up.

I’m like on my 0.75 day of learning Swift and so far enjoying the experience a lot :slight_smile:


(Walter Wiggins) #3

I just wrote up my experience setting up S4TF + Jupyter on Ubuntu 18.04 without Docker, posted on Medium. Then saw this thread and thought I’d share it here.


(Christian Werner) #4

Eager to get into it, too.

I wonder (and maybe I missed this): is it possible to play around with swift4tf on a MacBook Pro with Xcode but obviously no Nvidia GPU?
Can you also do the python imports in this setup?

Or should I go via jupyter?

Sorry for the noob question,
C


(Brennan Saeta) #5

There are a lot of ways to get started with Swift for TensorFlow, and no NVidia GPUs required! :slight_smile: Check out the README which includes instructions for how to get started. Google Colaboratory lets you get started right in your web browser, which is super fast. But if you’d like to run things locally, check out the local installation instructions right below.

All the best,
-Brennan


(Christian Werner) #6

Thanks! Not sure how I missed that :pensive:


(Brennan Saeta) #7

:slight_smile: No worries!


(Dan Zheng) #8

Hi Walt,

Thanks for documenting your setup experience on Medium! I noticed this blurb at the bottom:

Could you please share more info about your errors? We’re definitely interested in fixing them.


(Christian Werner) #9

@dan-zheng hope you don’t mind me jumping in with a question re python interop.

Is there a way to use a specific python version on the system (I.e. installed via pyenv)?


(Brennan Saeta) #10

I believe you can use:

PythonLibrary.useVersion(2, 7)

to set a specific Python version. Is that what you’re looking for?


(Dan Zheng) #11

Yes - I’m sorry that this is currently undocumented.

If you have a path to the libpythonX.x.so shared library for the desired Python environment you want to use, set the PYTHON_LIBRARY environment variable to it.

# Example.
export PYTHON_LIBRARY="~/anaconda3/lib/libpython3.7m.so"
# Then, try running your Swift program again.

Here’s a Gist explaining this and other Python details. I’ll document this more formally when I get a chance.


(Walter Wiggins) #12

This Gist got me on the right track. It took some experimentation to sort everything out, but I finally got there…at least for Swift-Jupyter…

These are the steps for my conda env setup and registration of the Swift-Jupyter kernel.

$ conda create -n s4tf python==3.6
$ conda activate s4tf
(s4tf) $ conda install jupyter numpy matplotlib
(s4tf) $ python register.py --sys-prefix --swift-toolchain ~/Applications/swift-tensorflow --swift-python-library ~/miniconda3/envs/s4tf/lib/libpython3.6m.so

After these steps, I was able to run the tutorial Jupyter notebooks without any errors.

Out of curiosity, I next tried to set the PYTHON_LIBRARY environment variable, to then run the Swift REPL and play around with Python interop… This was the result.

I’m pretty content to use Swift-Jupyter for now, but would appreciate any suggestions you might have as to how this might be remedied for future use of the Swift REPL.


Swift for TensorFlow
(Dan Zheng) #13

Is it the case that setting PYTHON_LIBRARY fixes Jupyter but not the REPL? If so, that’s a bit unexpected to me.

Could you please try export PYTHON_LOADER_LOGGING=1 as well?

You should be able to see some debug output like this, that should help illuminate things.


(Walter Wiggins) #14

Exporting PYTHON_LOADER_LOGGING=1 didn’t seem to change anything. No additional debug output was printed. It seems like the REPL isn’t seeing my environment variables for some reason.


(Christian Werner) #15

Thanks.

I will check it out!