Lesson 13 (2019) discussion and wiki

Yes - in fact, someone has reimplemented lesson 1 from fast.ai by importing PyTorch/fast.ai within Swift.

3 Likes

Thanks, do you mean “linked your installation” when you registered the swift-jupyter kernel?

can we use mac and it’s gpu to develop using swift for tf?

You have to define the + function for the types you’d like to use it with, but there’s no requirement that they be the same type. (Note that the real name for the + function includes the types for the left and right hand sides, and so you’re actually calling different functions depending on the types of your arguments. There’s no one + function.)

3 Likes

All Python objects are imported as the PythonObject type.
Check out the Python interoperability tutorial for more info!

3 Likes

So would this have performance advantages if you are just using Python in Swift?

1 Like

@saeta
FYI: the first time you use TensorFlow, it takes a while to compile.
That may be what’s happening right now

Python isn’t going to be faster if you use it inside swift, no.

3 Likes

I realize you don’t have to say it anymore. So not sure where it gets the python now.

1 Like

Thanks for the pointer!

1 Like

Can you provide a brief explanation on that please :pray:

Python isn’t going to be faster if you use it inside swift, no.

Unfortunately, macOS 10.14 stopped supporting external Nvidia GPUs, and only MacBook Pros from ~2014 or earlier had builtin Nvidia GPUs.

If you have one of those earlier models, CUDA should just work! But you will need to install from source right now since TensorFlow doesn’t ship prebuilt packages with CUDA support due to stability issues.

1 Like

Python is still python. Swift doesn’t compile it to make it faster, it just uses it.

1 Like

When you’re using Python from Swift, you’re using Swift to drive the Python runtime (instead of the Python interpreter driving the Python runtime). As a result, you get all the advantages and disadvantages of the standard Python runtime. (Lots of flexibility, but also the GIL.)

4 Likes

The register.py command tries to cleverly find the python to use, based on what venv or conda environment you’re running it in. There are also some flags that let you specify exactly which python you want (register.py --help should print out some docs).

Edit: If you’re running a standalone swift binary, python is configured a bit differently. One way to do it is to set the PYTHON_LIBRARY env variable to the python so library that you want to use.

7 Likes

is there a long term plan for S4TF to use TensorFlow or the plan is to crate it’s own TF-like library?

Ah, the + function has the names of the types! That makes sense. But, for lack of a better way of putting it, when you do a + b, do we try a.__add__(b), and then b.__radd__(a)?

Today, S4TF builds on top of the standard TensorFlow C++ runtime. But we’re at a very exciting time in machine learning. Sister teams to the S4TF team are working on re-building the TensorFlow runtime, and the MLIR + XLA teams are defining new compilers & ancillary infrastructure. Expect the world to look very different in 6 months, and 12 months.

10 Likes

+ has a lhs (left hand side) and rhs (right hand side) argument, there are no different add or radd functions.

does it mean you have to compile the jupyter notebook code before running the code?