S4TF in colab (error)

I went to the Swift github repo, clicked on Usage.md, and clicked on “Open this Swift installation notebook” (https://colab.research.google.com/github/tensorflow/swift/blob/master/notebooks/install_latest_swift.ipynb).

Installation was fine and I got the appropriate output --> using the latest version of Swift. Went back to the same github page and opened the link again and checked that Swift was running fine in the new colab notebook

I used File -> upload to load “00_load_data.ipynb” from the fastai “dev_swift” folder. Checked that runtime type was “Swift” and hardware accelerator was “GPU”.

Running the first cell generated the error:

Kernel is in a bad state. Try restarting the kernel.

Exception in `_process_installs`:

[Errno 17] File exists: '/content/swift-install' -> '/tmp/tmpcapibpcx/swift-install'

I tried running the next notebook "00a_intro_and_float.ipynb"and received the following error running the first cell:

error: <Cell 1>:1:18: error: consecutive statements on a line must be separated by ';'
%install-location $cwd/swift-install
                 ^
                 ;

I didn’t expect the second notebook to run properly since I hadn’t been able to get the load_data notebook to run, but I thought it was an interesting error in the first cell. What are the “consecutive statements” that Swift finds in the first line?

%install-location $cwd/swift-install
3 Likes

Good question!

Swift for TensorFlow v0.3 hasn’t propagated to Colab yet (the process takes a few business days). We expect v0.3 to be available in Colab on Tuesday morning. Until then, new features like %install directives won’t work.

In the meantime, please install swift-jupyter locally (Jeremy’s install guide, instructions from swift-jupyter README). Sorry for the inconvenience!

3 Likes

Note: Colab supports loading any notebook from GitHub, so you don’t need to manually upload notebooks.

Example link: https://colab.sandbox.google.com/github/fastai/fastai_docs/blob/master/dev_swift/00_load_data.ipynb

Not sure if it’ll work out-of-the-box will %install directives though. @marcrasi (swift-jupyter lead) might have some idea.

2 Likes

Seems like the %install-location does not work on Colab. It’s not important for the functioning of the notebook (it just makes it start up a bit faster), so you can fix this problem by deleting the %install-location line. I’ll investigate and fix this eventually.

This is an error that you would get from running an older version of swift-jupyter that doesn’t have %install. You probably accidentally switched to a different VM from the VM you ran the install notebook on. (There are a lot ways this can happen: using a different accelerator type, not unchecking the “reset all runtimes” box in the “warning this is not authored by google” dialog).

There is one additional problem that you will run into after you get around those problems. The fastai notebooks expect to read some dependencies from a copy of the fastai repo on the local filesystem. So you will need to download the fastai repo onto the VM’s local filesystem and move the dependencies into the right place. To do this, execute this code in a python colab:

!git clone https://github.com/fastai/fastai_docs.git
!mv fastai_docs/dev_swift/* /content
4 Likes

+1 on this error, also after I tried not unchecking

So, will wait tuesday. But wondering, if there is a way in colab, where I can check this version ‘Swift for TensorFlow v0.3’ to verify this is the issue?

thanks for making this available on co-lab, saves the huzzle of setting up my own image! :wink:

You could run !/swift/toolchain/usr/bin/swift --version in a Colab python notebook, to get the commit hash of the currently-installed swift. Then you can look that up on https://github.com/apple/swift to see how recent it is. We haven’t been adding release version information into the toolchains, so it won’t tell you “v0.3” though. But it seems like there is a place for a version string that prints out next to the commit hash, and we should set it to our release version, so that it’s easy to tell what release you are on. I’ll keep this in mind for our next release!

2 Likes

seems working now ! thx

You may want to update this to the new location:

!git clone https://github.com/fastai/course-v3.git
!mv course-v3/nbs/swift/* /content

This is not working currently. I have no problem to run swift on colab last few weeks. The /content directory can be share from different colab sessions after I setup the fastai in the /content. I found out the /content directory can not be share from other swift colab session today.

Any one has this problems?

What do you mean under different colab session? Colab file system is ephemeral and changes are not preserved if runtime is recycled which happens after some idle.

I can’t not run these 2 statements under Swift env.

!git clone https://github.com/fastai/fastai_docs.git
!mv fastai_docs/dev_swift/* /content

So I run these 2 statements in fastai setup to create fastai stuff under /content in colab. Then I open the blank_swift_gpu to run the swift notebook with

%install-location $cwd/swift-install
%install ‘.package(path: “$cwd/FastaiNotebook_09_optimizer”)’ FastaiNotebook_09_optimizer

because fastai stuff already installed under /content directory. This session can access /content contains fastai notebook. But I can’t run this setup anymore because the /content can not access after start the swift notebook.

Any way to install fastai notebook to the /content directory under swift env.?

I’m not exactly sure what does “run in fastai setup” mean. If you mean running these commands in python notebook, this should work.
But check that you have same runtime type (GPU) selected in both python setup notebook and swift notebook. Colab uses different VMs for different runtime types, file updates made by python notebook only applied to swift env if you use same VM.

Also, you could use %system command in swift notebook, e.g.:

%system git clone https://github.com/fastai/fastai_docs.git && mv fastai_docs/dev_swift/* /content

However, %system works only in the first cell, and as I remember it should be called before %install.

Thank you for the info. The way I used like

[zaidalyafeai] described
I actually go around that by creating two notebooks one with python(running commands) and the other with swift because they operate on the same environment. Happy to work on it if it is straight forward.

I know what you are saying you are doing. It wasn’t working like you mention but I tried it a couple of days ago and was able to share files between a python and swift notebook again so you may want to try again. Maybe someone corrected something.

This may produce emotions of disbelief but this is what have done.

On my windows laptop I installed ubuntu under VMplayer. I followed Jeremy’s install.
I created a jupyter notebook from the console
I had to create ~/.ssh
I use putty ssh tunnel to add a mapping 192.168.13.129:8888 to localhost:8000
Once sshed I use jupyter notebook list to find the token
Now I could use my browser on windows to access the jupyter notebook as localhost:8000 and enter the token
I used a python notebook to copy the notebooks down to my ubuntu as described above

!git clone https://github.com/fastai/course-v3.git
!mv course-v3/nbs/swift/* /content

Next I started a swift kernel and worked my way through the lesson.
Occasionally I get this

Export

import NotebookExport

let exporter = NotebookExport(Path.cwd/“01a_fastai_layers.ipynb”)

print(exporter.export(usingPrefix: “FastaiNotebook_”))

error: Execution was interrupted, reason: signal SIGSEGV: invalid address (fault address: 0x1d7d6).
The process has been left at the point where it was interrupted, use “thread return -x” to return to the state before expression evaluation.

I re-run the kernel all cells and it works

Export

import NotebookExport

let exporter = NotebookExport(Path.cwd/“01a_fastai_layers.ipynb”)

print(exporter.export(usingPrefix: “FastaiNotebook_”))

success

Has anybody seen anything similar.

I got the error when compiled FastaiNotebook_01a_fastai_layers 01a_fastai_layers.swift and found this file has been modified 13d ago. any one know how to resolve this?

//
[23/26] Compiling FastaiNotebook_01a_fastai_layers 01a_fastai_layers.swift
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:340:27: warning: ‘AllDifferentiableVariables’ is deprecated: ‘AllDifferentiableVariables’ is now equal to ‘Self’ and will be removed
public var variables: AllDifferentiableVariables {
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:241:15: error: type ‘FAAvgPool2D.TangentVector’ does not conform to protocol ‘VectorProtocol’
public struct FAAvgPool2D<Scalar: TensorFlowFloatingPoint>: FALayer {
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:281:15: error: type ‘FAGlobalAvgPool2D.TangentVector’ does not conform to protocol ‘VectorProtocol’
public struct FAGlobalAvgPool2D<Scalar: TensorFlowFloatingPoint>: FALayer {
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:295:1: error: conditional conformance of type ‘Array’ to protocol ‘Layer’ does not imply conformance to inherited protocol ‘Module’
extension Array: Layer where Element: Layer, Element.Input == Element.Output {
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:295:1: note: did you mean to explicitly state the conformance like ‘extension Array: Module where …’?
extension Array: Layer where Element: Layer, Element.Input == Element.Output {
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:341:22: warning: ‘allDifferentiableVariables’ is deprecated: ‘allDifferentiableVariables’ is now equal to ‘self’ and will be removed
get { return allDifferentiableVariables }
^
/content/FastaiNotebook_01a_fastai_layers/Sources/FastaiNotebook_01a_fastai_layers/01a_fastai_layers.swift:342:15: warning: ‘allDifferentiableVariables’ is deprecated: ‘allDifferentiableVariables’ is now equal to ‘self’ and will be removed
set { allDifferentiableVariables = newValue }
///

The notebooks in course v3 are frozen and will only work with S4TF v0.4 (to match the videos), if you’re using a more recent version, you should use the ones in here.

Thank you.

Any google colab setup for this fastai_dev? I can’t apply the colab setup from ‘/fastai/course-v3’ to this github branch fastai_dev.
thank you.