this repo is a python package. running it as a script will define and export various neural network graphs to various formats.
these neural networks are not trained models and are somewhat arbitary in architecture. thus, absolute performance numbers are not meaningful. but they should provide a sense of the relative presence/performance of various operators between formats and runtimes.
nn.Module
s defined in pytorch are exported to:
- torchscript (
.ts
) usingtorch.jit
- -> ONNX (
.onnx
) via torchscript usingtorch.onnx
- -> tensorflow SavedModel (
.tf
) via ONNX usingonnx-tf
- -> tflite (
.tflite
) via SavedModel usingtensorflow.lite
- -> tflite (
- -> tensorflow SavedModel (
- -> ONNX (
- TOSA (
.tosa
) usingtorch-mlir
(torch-mlir needs rosetta, but tensorflow and pytorch nightly seem unable to coexist on rosetta)
# NOTE the env names matter
TODO: create just one conda env, script to install
CONDA_SUBDIR=osx-64 conda create -n zoo-tf -c conda-forge python pip fire tensorflow
conda activate zoo-tf
conda config --env --set subdir osx-64
pip install tensorflow-probability onnx-tf
CONDA_SUBDIR=osx-64 conda create -n zoo -c conda-forge python pip fire
conda activate zoo
conda config --env --set subdir osx-64
pip install --pre torch-mlir -f https://github.com/llvm/torch-mlir/releases --extra-index-url https://download.pytorch.org/whl/nightly/cpu
pip install tvm
cd embedded_model_zoo
pip install -e .
python -m zoo
may need this workaround:
python -m zoo --log_level=DEBUG
to see errors
define new nn.Module
subclasses in zoo/models/*.py
, using the @register
decorator. If adding new files under models/
, be sure to import them from models/__init__.py
- tflite and TOSA conversion often choke on
unsqueeze
ops (which torchscript seems to use when indexing withNone
e.g.x[...,None]
to add a new final dimension to a tensor). workaround is to usereshape
in pytorch code instead.