unilab.training.onnx_export¶
ONNX export and onnxruntime numeric verification helpers for play entrypoints.
Functions
|
Export |
|
Compare PyTorch and ONNX Runtime outputs on identical inputs. |
- unilab.training.onnx_export.export_policy_onnx(export_module, onnx_path, export_inputs, *, input_names, output_names=None, opset_version=17)[source]¶
Export
export_moduletoonnx_pathand print the artifact path.- Parameters:
export_module (
Module) – Module traced bytorch.onnx.export.onnx_path (
str) – Destination file path for the exported graph.export_inputs (
tuple[Tensor,...]) – Positional example inputs matchinginput_names.input_names (
list[str]) – ONNX input names, aligned positionally withexport_inputs.output_names (
list[str] |None) – ONNX output names; defaults to["action"].opset_version (
int) – ONNX opset version; defaults to 17.
- Return type:
- unilab.training.onnx_export.verify_policy_onnx(export_module, onnx_path, verify_inputs, *, input_names, max_diff_tol=0.0001)[source]¶
Compare PyTorch and ONNX Runtime outputs on identical inputs.
Runs
export_moduleand the exported graph atonnx_pathonverify_inputs, prints the max/mean absolute difference, and prints a warning when the max difference exceedsmax_diff_tol.- Parameters:
export_module (
Module) – Module that was exported toonnx_path. Tuple outputs are compared on their first element.onnx_path (
str) – Exported ONNX graph to verify.verify_inputs (
tuple[Tensor,...]) – Positional inputs matchinginput_names.input_names (
list[str]) – ONNX input names, aligned positionally withverify_inputs.max_diff_tol (
float) – Absolute max-difference tolerance before warning.
- Return type:
- Returns:
(max_diff, mean_diff)between PyTorch and ONNX Runtime outputs.