Runtime, Runnable and State¶
Runtime¶
- tract.runtime.runtime_for_name(name: str)[source]¶
Look up a runtime by name and return a
Runtimeinstance.Available runtimes depend on the build and the platform:
"default"for CPU,"metal"on Apple Silicon Macs,"cuda"on systems with NVIDIA GPUs.
- class tract.runtime.Runtime(ptr)[source]¶
A hardware/software backend that can execute a
Model.Calling
Model.into_runnable()implicitly uses the default CPU runtime. To run on a GPU, obtain aRuntimeviaruntime_for_name()—"metal"on Apple Silicon Macs,"cuda"on NVIDIA systems — then callprepare()to produce aRunnableoptimized for that backend.
Runnable¶
- class tract.runnable.Runnable(ptr)[source]¶
A model that has been fully optimized and is ready to perform computation.
This is the final stage of the model pipeline. A
Runnableis obtained either by callingModel.into_runnable()(CPU default) or by passing aModeltoRuntime.prepare()for GPU-accelerated execution. Once obtained, callrun()with numpy arrays orTensorinstances to perform inference.- run(inputs: List[Tensor | ndarray]) List[Tensor][source]¶
Runs the model over the provided input list, and returns the model outputs.
State¶
- class tract.state.State(ptr)[source]¶
Mutable execution state for stateful (typically streaming) models.
Stateful models maintain internal buffers between calls to
run()(e.g. recurrent networks, pulsed convolutions). AStateis created byRunnable.spawn_state()and can be called repeatedly with successive input chunks. Usefreeze()to snapshot the state for later reuse.- run(inputs: List[Tensor | ndarray]) List[Tensor][source]¶
Runs the model over the provided input list, and returns the model outputs.
- freeze() FrozenState[source]¶
Freeze the state into an immutable
FrozenStatesnapshot.