Overview
The ONNX support module enables seamless conversion between Neurenix models and the ONNX (Open Neural Network Exchange) format, allowing you to leverage models across different machine learning frameworks and deployment platforms.ONNXConverter Class
TheONNXConverter class provides the core functionality for importing and exporting models.
Initialization
Supported Operations
The converter supports the following ONNX operations: Layers:Conv→ Conv2dGemm,MatMul→ LinearBatchNormalization→ BatchNorm2dMaxPool→ MaxPool2dAveragePool→ AvgPool2d
Relu,Sigmoid,Tanh,LeakyReluDropout
Add,Mul,Sub,Div(tensor operations)Reshape,Transpose,FlattenReduceMean,ReduceSum
Exporting Models to ONNX
Basic Export
Export a Neurenix model to ONNX format:Export with Dynamic Axes
Support variable batch sizes and sequence lengths:Advanced Export Options
Importing Models from ONNX
Basic Import
Load an ONNX model into Neurenix:Import with Device Selection
Using the Converter Class
Complete Workflow Example
Here’s a complete example of training, exporting, and re-importing:Troubleshooting
Installation Requirements
ONNX export and import require additional dependencies:Common Issues
Unsupported Operations: If you encounter unsupported operations:FLOAT(fp32)DOUBLE(fp64)INT32INT64
Best Practices
- Test Before Deployment: Always verify the exported model produces the same outputs as the original
- Use Dynamic Axes: Enable flexibility in production environments with variable input sizes
- Specify Opset Version: Use the latest stable opset version supported by your deployment platform
- Model Validation: Run the ONNX checker after export to catch potential issues early
- Document Input/Output Shapes: Keep track of expected tensor shapes for deployment
Integration with Deployment Platforms
ONNX models can be deployed on:- ONNX Runtime: High-performance inference engine
- TensorRT: NVIDIA’s optimized inference engine
- CoreML: Apple’s ML framework
- Windows ML: Microsoft’s ML platform
- Edge Devices: Mobile and embedded systems