OnnxBackend#
- class openstef_foundation_models.inference.onnx_backend.OnnxBackend(metadata: CheckpointMetadata, session: InferenceSession) None[source]
Bases:
objectAn
InferenceBackendbacked by ONNX Runtime.The session is built once on construction and reused for every
run()call, so a single backend instance can be shared across an entire backtest. Users may either let the backend build a session from a resolved checkpoint and provider chain, or pass a pre-built session they own.- Parameters:
metadata (
CheckpointMetadata)session (
InferenceSession)
- __init__(metadata: CheckpointMetadata, session: InferenceSession) None[source]
Wrap a pre-built ONNX Runtime session.
Prefer
from_checkpoint()unless you need to own the session lifecycle yourself.- Parameters:
metadata (
CheckpointMetadata) – Metadata describing the checkpoint the session executes.session (
InferenceSession) – A pre-built ONNX Runtime inference session.metadata
session
- classmethod from_checkpoint(checkpoint: ResolvedCheckpoint, providers: Sequence[Annotated[CpuProvider | CudaProvider | TensorRTProvider | CoreMLProvider, FieldInfo(annotation=NoneType, required=True, discriminator='kind')]] | None = None, session_options: SessionOptionsConfig | None = None, *, policy: ProviderPolicy | None = None) Self[source]
Build a backend by loading a checkpoint into a new ONNX Runtime session.
With
providers=Nonethe policy selects a chain from the checkpoint and host; an explicitproviderslist is used as given and policy is ignored. SeeProviderPolicyfor how a chain is chosen and how strictly its realization is enforced.- Parameters:
checkpoint (
ResolvedCheckpoint) – The resolved checkpoint (weights + metadata) to load.providers (
Sequence[CpuProvider|CudaProvider|TensorRTProvider|CoreMLProvider] |None) – Ordered execution providers to try.Nonelets the policy pick a host-appropriate chain from the checkpoint metadata.session_options (
SessionOptionsConfig|None) – Optional ONNX Runtime session options.policy (
ProviderPolicy|None) – Selection policy used whenproviders is None. Defaults toDefaultProviderPolicy.checkpoint
providers
session_options
policy
- Returns:
A backend wrapping the newly built session.
- Return type:
Self
- property metadata: CheckpointMetadata
Metadata describing the checkpoint this backend executes.