Skip to main content

bindings of sonos/tract rust NN inference enging for python

Project description

tract-python

Project Archived: tract now maintains it's own Python package here.

License: MIT PyPI version CI

tract inference engine bindings in Python via FFI. It support Neural Network inference from NNEF or ONNX.

Why

No need to compile tract or have cargo installed, fast install.

tract-cli is very feature-full but reloading a model each time you wish to do an inference is computationaly costy and slow.

Think onnxruntime except it support NNEF, and it is based on tract.

Install

Install using pip:

pip install tract_python

Usage

import tract_python

print(tract_python.TRACT_VERSION)
# "X.X.X"

tract_model = tract_python.TractModel.load_from_path(
  # This parameter can be an ONNX or NNEF filepath (in case of NNEF it can be a dir or a tgz)
  './tests/assets/test_simple_nnef/' # simple graph that mul input by 2
)
# .run take as argument names the name of input nodes in your neural network
results = tract_model.run(input_0=np.arange(6).reshape(1, 2, 3).astype(np.float32))
print(results)
#{'output_0': array([[[ 0.,  2.,  4.],
#       [ 6.,  8., 10.]]], dtype=float32)}

Status

This project is maintained with latest tract version.

Scope

Our personnal usecase is to be able to run +10M inferences with 'tract' engine. So loading/running NNEF or ONNX is sufficient.

We would be happy to support some others tract-cli features:

  • computing: number of FMA operations
  • computing: profiling infos

(Thought it would be better to extract from tract-cli a tract-profile crate first in original repo to avoid code duplicate) We do not have the bandwith to do more and welcome any contributor that would wish to add more features.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tract_python-0.2.12.tar.gz (21.8 kB view hashes)

Uploaded Source

Built Distributions

tract_python-0.2.12-py3-none-win_amd64.whl (5.4 MB view hashes)

Uploaded Python 3 Windows x86-64

tract_python-0.2.12-py3-none-manylinux_2_35_x86_64.whl (7.9 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.35+ x86-64

tract_python-0.2.12-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.5 MB view hashes)

Uploaded Python 3 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page