Tensorflow Lite in Faasm
Tensorflow Lite is well suited to runninginference tasks in a resource-constrained serverless context.
It is written in C/C++ hence we can build Tensorflow Lite to WebAssembly using thestandard Faasm toolchain.
Faasm currently only supports the C/C++ API, but building the Python API usingFaasm's Python support should be possible and on the to-do list.
Compiling TensorFlow Lite to WebAssembly
To do this, make sure you've checked out this project and updated all the git submodules,then, from the Faasm CLI:
- inv libs.tflite
The build output ends up at third-party/tensorflow/tensorflow/lite/tools/make/gen
.
Building a C/C++ function with TF Lite
A function implementing image classification is includedin the examples. This is based on theexample in the TF Lite repo.The data and model for the example are stored in this repo.
To run the example function, you need to run a local Faasm cluster (as described in the README),then:
- # Upload files and state
- inv data.tf-upload data.tf-state
- # Upload the function (takes a few seconds)
- inv upload tf image
- # Invoke
- inv invoke tf image
Eigen Fork
To support WASM simd instructions I've hacked about with Eigen on afork. It seems to work but isn't welltested.
TF Lite will be compiled against the version of Eigen downloaded as part of its 3rd partydeps, so if you need to change it and rebuild you'll need to run:
- cd third-party/tensorflow/tensorflow/lite/tools/make
- rm -r downloads/eigen/
- ./download_dependencies.sh