NNEF

class tract.nnef.Nnef[source]

Represent a NNEF context in tract.

NNEF is a neural model interchange format, similar to ONNX but focusing on the needs of an inference engine instead of a training framework.

tract can natively load NNEF models. It can also save models in tract internal format as tract-opl models. tract-opl is a set of proprietary extensions to NNEF allowing serialization of most of the models tract can handle. These extensions can be activated by the with_*() methods.

load(path: str | Path) Model[source]

Load an NNEF model from the file or folder at path.

model = (
    tract.nnef()
    .load("mobilenet_v2_1.0.onnx.nnef.tgz")
    .into_runnable()
)
with_tract_core() Nnef[source]

Enable tract-opl extensions to NNEF to covers tract-core operator set

with_tract_extra() Nnef[source]

Enable tract-extra extensions to NNEF.

with_tract_transformers() Nnef[source]

Enable tract-transformers extensions to NNEF.

with_onnx() Nnef[source]

Enable tract-opl extensions to NNEF to covers (more or) ONNX operator set

with_pulse() Nnef[source]

Enable tract-opl extensions to NNEF for tract pulse operators (for audio streaming)

with_extended_identifier_syntax() Nnef[source]

Enable tract-opl extensions to NNEF for extended identifiers (will support PyTorch 2 path-like ids)

write_model_to_dir(model: Model, path: str | Path) None[source]

Save model as a NNEF directory model in path.

tract tries to stick to strict NNEF even if extensions have been enabled.

write_model_to_tar(model: Model, path: str | Path) None[source]

Save model as a NNEF tar archive in path.

tract tries to stick to strict NNEF even if extensions have been enabled.

write_model_to_tar_gz(model: Model, path: str | Path) None[source]

Save model as a NNEF tar compressed archive in path.

tract tries to stick to strict NNEF even if extensions have been enabled.