JavaScript™ belongs to Oracle
Deep Learning is all about linalg
JavaScript sucks at linalg
JavaScript no more sucks at linalg
JavaScript even has autodiff now
Quick facts
- Started in 2017 as deeplearn.js
- Rebranded in 2018
- Written in TypeScript
- ~10 developers from Google (Brain)
Official features
- Develop ML in the browser
- Run existing models
- Retrain existing models
Core API
- Copied from Python; naming convention changed
- Eager-only
- A few quirks
- There are API differences
- No
tf.nn
- Semi-manual memory management
- Models must be converted to a "web friendly" format
Tensorflow model formats zoo
- GraphDef = graph + [variable values - 2GB limit]
- Checkpoint = variable values
- Summary (aka Tensorboard) = GraphDef + key-value
- MetaGraph = GraphDef + tags + i/o + Checkpoint
- SavedModel = one or more MetaGraph-s
- ModuleDef (aka Hub) = special SavedModel
- Keras = hdf5 with arch and weights
- 🎉 TensorFlow.js = GraphDef + JSON + sharded weights
Execution modes
- Browser: WebGL backend
- Node.js: libtensorflow backend
- No device pinning/selection
Semi-manual memory management
- There are various JS engines
- There are various GC implementations
- We allocate memory like hungry 🐺
Semi-manual memory management
const y = tf.tidy(() => {
const one = tf.scalar(1);
const a = tf.scalar(2);
const b = a.square();
console.log('numTensors (in tidy): ' + tf.memory().numTensors);
return b.add(one);
});
console.log('numTensors (outside tidy): ' + tf.memory().numTensors);
y.print(); // y = 2 ^ 2 + 1
TensorBuffer
tf.Tensor
is immutable
tf.TensorBuffer
is mutable
- No efficient
set()
Keras API
tf.layers
- do not confuse with Python's
- No CuDNN
- Tensors may leak
- Advanced parameters not supported
Progressive GAN
Installation for Node.js
npm install @tensorflow/tfjs @tensorflow/tfjs-node
or @tensorflow/tfjs-node-gpu
ijavascript
npm install ijavascript-await
- Node.js driver for Jupyter
- Deals with async/await
- Good integration into the notebook
Summary
- Much fun and easy
- Very early days
- PoCs work
- TensorFlow is getting even more complex inside