Convert Hugging Face Transformers to ONNX via Torch, Transformers, or Optimum
AI Impact Summary
The content outlines three distinct pathways to export a Hugging Face Transformer (distilbert-base-uncased-finetuned-sst-2-english) to ONNX: a low-level torch.onnx.export with explicit input_names and dynamic_axes, a mid-level transformers.onnx workflow driven by a model config, and a high-level Optimum Inference path leveraging ORTModelForSequenceClassification via from_pretrained(from_transformers=True). This matters for deployment teams aiming to run inference on ONNX Runtime or cross-platform environments, as it provides flexibility to balance control, automation, and complexity. Key considerations include managing dependencies (torch, transformers[onnx], optimum[onnxruntime]), selecting the appropriate opset (e.g., 13), and understanding how the chosen method affects runtime behavior and maintainability. Businesses can leverage these options to optimize inference performance and portability, but must align on a migration path and ensure compatibility with their deployment stack.
Affected Systems
- Date
- Date not specified
- Change type
- capability
- Severity
- info