Challenge - 5 Problems
ONNX Export Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
ONNX export output shape verification
Consider the following PyTorch model and ONNX export code. What will be the shape of the output tensor when running the ONNX model with the given input shape?
PyTorch
import torch import torch.nn as nn import onnx class SimpleModel(nn.Module): def __init__(self): super().__init__() self.linear = nn.Linear(10, 5) def forward(self, x): return self.linear(x) model = SimpleModel() model.eval() x = torch.randn(3, 10) # Export to ONNX onnx_path = "simple_model.onnx" torch.onnx.export(model, x, onnx_path, input_names=["input"], output_names=["output"], opset_version=11) # Assume we load and run the ONNX model with input shape (3, 10) # What is the shape of the output tensor?
Attempts:
2 left
💡 Hint
Think about how the linear layer transforms the input shape.
✗ Incorrect
The linear layer transforms input of shape (batch_size, 10) to (batch_size, 5). Since input batch size is 3, output shape is (3, 5).
❓ Model Choice
intermediate1:30remaining
Choosing correct opset version for ONNX export
You want to export a PyTorch model using torch.onnx.export. Which opset_version should you choose to ensure compatibility with most ONNX runtimes and support for common operators?
Attempts:
2 left
💡 Hint
Check the default recommended opset version in PyTorch documentation.
✗ Incorrect
PyTorch recommends opset_version=11 for broad compatibility and support of common operators.
🔧 Debug
advanced2:30remaining
ONNX export error due to dynamic axes
You try to export a PyTorch model to ONNX with dynamic batch size using this code:
torch.onnx.export(model, x, "model.onnx", dynamic_axes={"input": {0: "batch_size"}})
But you get an error about missing output dynamic axes. What is the most likely cause?
Attempts:
2 left
💡 Hint
Dynamic axes must be declared for all tensors that vary in size.
✗ Incorrect
When using dynamic axes, you must specify them for both inputs and outputs if their batch size varies.
❓ Metrics
advanced2:00remaining
Verifying ONNX model correctness with output comparison
After exporting a PyTorch model to ONNX, you want to verify the ONNX model produces the same output as the PyTorch model for the same input. Which metric is best to check this?
Attempts:
2 left
💡 Hint
You want to measure numerical closeness of outputs.
✗ Incorrect
MSE measures the average squared difference between outputs, suitable for regression outputs comparison.
🧠 Conceptual
expert3:00remaining
Understanding ONNX export limitations with control flow
Which of the following statements about exporting PyTorch models with control flow (like loops or conditionals) to ONNX is TRUE?
Attempts:
2 left
💡 Hint
Think about how PyTorch JIT scripting helps ONNX export.
✗ Incorrect
ONNX supports control flow when exporting scripted models, as scripting preserves control flow structure.