Shortcuts

ExportOutputSerializer

class torch.onnx.ExportOutputSerializer(*args, **kwargs)

Protocol for serializing an ONNX graph into a specific format (e.g. Protobuf). Note that this is an advanced usage scenario.

serialize(export_output, destination)[source]

Protocol method that must be implemented for serialization.

Parameters
  • export_output (ExportOutput) – Represents the in-memory exported ONNX model

  • destination (BufferedIOBase) – A binary IO stream or pre-allocated buffer into which the serialized model should be written.

Example

A simple serializer that writes the exported onnx.ModelProto in Protobuf format to destination:

class ProtobufExportOutputSerializer:
    def serialize(
        self, export_output: ExportOutput, destination: io.BufferedIOBase
    ) -> None:
        destination.write(export_output.model_proto.SerializeToString())

torch.onnx.dynamo_export(...).save(
    destination="exported_model.onnx",
    serializer=ProtobufExportOutputSerializer(),
)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources