Lesson 13 (2019) discussion and wiki

You can use S4TF on the command line either to make scripts or to binary programs. Check out additional examples at: GitHub - tensorflow/swift-models: Models and examples built with Swift for TensorFlow

2 Likes

Swift’s functional features are definitely one of the things I really liked about the language when started work with it.

3 Likes

Yes. Think of it as a way to be more declarative (ie. hey, person reading my code, this variable’s value does not change). It makes for more readable code imho.

It also means that if you don’t intend for the value to change and then it does the compiler will let you know :slight_smile:

apache spark , which was built using scala is good at handling big data , likewise , are there any frameworks for bigdata that is supported by swift.

(especially for the poo icon)

No, unless you use type-erasure.

Array is a generic type with one generic type parameter:

// Simplified `Array` declaration.
struct Array<Element> {
  ...
}
// The notation `[X]` is short-hand for `Array<X>`.
let int = 1
let float: Float = 1
[int, int] // inferred to have type `[Int]`
[float, float] // inferred to have type `[Float]`
[float, int] as [Any] // must explicitly type erase to `[Any]`
3 Likes

If you use macOS, Xcode is a great choice and it is maintained by Apple. If you use Linux, CLion might be a great choice, but we have not tested it to make sure it works with Swift for TensorFlow toolchains.

5 Likes

The Fastai Notebooks library can be compiled in Xcode with a few adjustments to the build settings but I’m not sure if it runs okay.

The guy who runs the godbolt/Compiler Explorer website has a great video talking about how a C++ compiler compiles the simplest program:

4 Likes

What if you want to be able to do math on bools (treating them like 0/1)? Would you have to add extensions or is there something in the standard library?

1 Like

Could it ever be possible to debug Swift remotely? Like, if I have a Linux machine with TF and Swift runtime setup but would like to work from my laptop to connect to this remote host? Something similar to a remote interpreter in Python/PyCharm.

Swift for TensorFlow works cross-platform.
You can download a local macOS or Ubuntu 18.04 toolchain here.
See usage instructions here. :slight_smile:

That in keyword is very unintuitive: { arg in arg + 10 } why is arg in arg + 10?

2 Likes

What do the first two lines of code do? Does it compile the entire notebook?
e.g.

%install-location $cwd/swift-install
%install '.package(path: "$cwd/FastaiNotebook_00_load_data")' FastaiNotebook_00_load_data
1 Like

The in keyword is part of Swift’s closure syntax, separating closure arguments from the closure body.
The corresponding code in Python is lambda arg: arg + 10.

3 Likes

Thank you. I will try to experiment with this, this weekend.

Is FastAI forums the best discussion/support mode for S4TF?

Now this is a command to load the packages corresponding to the 00 notebook and its functions.

2 Likes

Although we likely won’t implement anything in this direction anytime soon, you can attach debuggers like GDB and LLDB to remote processes, although it will require a fair bit of work to make this work reliably.

1 Like

They install code exported from the other notebook. Sort of like what Jeremy does in python notebooks. Note: you can install other swift libraries as well. Currently, it has to be executed in the first cell.

3 Likes

Here is a Swift forum thread where they talk about this :slight_smile:

7 Likes