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 todestination
: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(), )