yobx.torch.in_transformers.exporter#
Provides YobxOnnxExporter, a subclass of
transformers.exporters.OnnxExporter that replaces the default
torch.onnx.export / onnxscript backend with the yobx converter.
This lets callers use the standard transformers exporter API while benefiting from yobx’s graph-builder optimisations and operator coverage.
Usage:
from transformers.exporters import OnnxConfig
from yobx.torch.in_transformers import YobxOnnxExporter
exporter = YobxOnnxExporter()
artifact = exporter.export(model, sample_inputs, config=OnnxConfig(dynamic=True))
# artifact is an ExportArtifact – save it, inspect the proto, etc.
artifact.save("model.onnx")
- class yobx.torch.in_transformers.exporter.YobxOnnxExporter(target_opset: int | None = None, **kwargs: Any)[source]#
Subclass of
transformers.exporters.OnnxExporterthat converts aPreTrainedModelto ONNX using the yobx graph builder instead of the defaulttorch.onnx.export/ onnxscript pipeline.When
transformersis not installed, instantiating this class raisesImportError.The interface is identical to the upstream exporter:
from transformers.exporters import OnnxConfig from yobx.torch.in_transformers import YobxOnnxExporter exporter = YobxOnnxExporter() artifact = exporter.export(model, inputs, config=OnnxConfig(dynamic=True)) artifact.save("model.onnx")
Extra keyword arguments passed to the constructor are forwarded verbatim to
yobx.torch.to_onnx()during export (e.g.options,dispatcher,export_modules_as_functions, …).- Parameters:
target_opset – ONNX opset version to target. Overrides the value carried by
config.opset_versionwhen both are supplied.kwargs – extra keyword arguments forwarded verbatim to
yobx.torch.to_onnx().
- export(model: PreTrainedModel, sample_inputs: MutableMapping[str, Any], config: 'OnnxConfig' | Dict[str, Any]) ExportArtifact[source]#
Exports model to ONNX using the yobx converter.
Applies the same transformers-side preprocessing as
transformers.exporters.DynamoExporter(label stripping, output-flag patching, dynamic-shape inference) and then feeds the resultingtorch.export.ExportedProgramtoyobx.torch.to_onnx().- Parameters:
model – the
PreTrainedModelto export.sample_inputs – forward kwargs — what you would pass to
model(**sample_inputs). Labels and loss-related keys must not be present (seetransformers.exporters.DynamoExporter).config – an
OnnxConfig(or a plaindictthat will be converted to one) controlling dynamic shapes, output path, opset version, etc.
- Returns:
ExportArtifactwrapping the exported ONNX proto.