Skip to content

Fix dynamic_shapes variable naming in ONNX dynamo export#15047

Merged
nithinraok merged 2 commits into
NVIDIA-NeMo:mainfrom
yashwantbezawada:fix/onnx-export-dynamic-shapes-variable
Mar 17, 2026
Merged

Fix dynamic_shapes variable naming in ONNX dynamo export#15047
nithinraok merged 2 commits into
NVIDIA-NeMo:mainfrom
yashwantbezawada:fix/onnx-export-dynamic-shapes-variable

Conversation

@yashwantbezawada
Copy link
Copy Markdown
Contributor

Description

Fixes issue #15040 where exporting Parakeet models to ONNX fails when using dynamo export due to incorrect variable naming in the export code path.

Root Cause

When use_dynamo=True, the code creates a variable called dynamic_axes (line 226) that is actually meant to be dynamic_shapes for PyTorch's dynamo export API. The torch.export.export() function at line 249 expects a dynamic_shapes parameter, but the code was passing the value through a variable named dynamic_axes, causing confusion and errors.

The issue reporter noted getting this warning:

'dynamic_axes' is not recommended when dynamo=True, and may lead to 'torch._dynamo.exc.UserError: Constraints violated.' 
Supply the 'dynamic_shapes' argument instead if export is unsuccessful.

Changes

File: nemo/core/classes/exportable.py

  1. Lines 227-229: Introduced proper variable naming for dynamo export path

    • Added: if use_dynamo: dynamic_shapes = dynamic_axes
    • This creates a properly-named variable for the dynamo code path while keeping dynamic_axes for the traditional ONNX export path
  2. Line 234: Updated logging message

    • Changed from: logging.info(f"Running export.export, dynamic shapes:{dynamic_axes}\n")
    • Changed to: logging.info(f"Running export.export, dynamic shapes:{dynamic_shapes}\n")
    • This provides clearer logging output for debugging
  3. Line 249: Fixed parameter name in torch.export.export()

    • Changed from: dynamic_shapes=dynamic_axes
    • Changed to: dynamic_shapes=dynamic_shapes
    • This passes the correct variable to PyTorch's export function

Why This Approach?

The fix maintains backward compatibility:

  • Dynamo path (use_dynamo=True): Uses dynamic_shapes variable (lines 227-260)
  • Traditional path (use_dynamo=False): Uses dynamic_axes variable (lines 267-279)

This separation makes the code clearer and avoids the confusion that led to the bug.

Testing

As reported by @jingzhaoou in #15040:

"After changing the code, I was able to export the ONNX files as expected."

The fix has been tested with Parakeet model export and successfully generates ONNX files.

Impact

  • Fixes ONNX export for Parakeet models when using dynamo export
  • Eliminates the confusing warning message about dynamic_axes
  • Makes the code more maintainable by using semantically correct variable names
  • No changes to the non-dynamo export path

Fixes #15040

@github-actions github-actions Bot added the core Changes to NeMo Core label Nov 10, 2025
Fixes NVIDIA-NeMo#15040

When exporting Parakeet models to ONNX with use_dynamo=True,
PyTorch's dynamo export expects the parameter name 'dynamic_shapes'
not 'dynamic_axes'. This fix introduces a properly-named variable
for the dynamo code path to avoid confusion and potential errors.

Changes:
- Introduced dynamic_shapes variable when use_dynamo=True
- Updated torch.export.export call to use dynamic_shapes parameter
- Updated logging to display the correct variable name

The non-dynamo code path continues to use dynamic_axes as expected
by torch.onnx.export.

Tested by issue reporter who confirmed ONNX export succeeds after
this change.

Signed-off-by: Yashwant Bezawada <yashwant_b@me.com>
@yashwantbezawada yashwantbezawada force-pushed the fix/onnx-export-dynamic-shapes-variable branch from a58f3bc to 5d46494 Compare November 10, 2025 08:04
@pzelasko pzelasko requested a review from nithinraok March 16, 2026 16:48
@pzelasko
Copy link
Copy Markdown
Collaborator

CC @nithinraok

Copy link
Copy Markdown
Member

@nithinraok nithinraok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@nithinraok nithinraok enabled auto-merge (squash) March 16, 2026 21:17
@nithinraok
Copy link
Copy Markdown
Member

I should be reviewed by @borisfom but since its minor fix approving it.

@nithinraok nithinraok merged commit 9a153aa into NVIDIA-NeMo:main Mar 17, 2026
131 checks passed
paarthneekhara pushed a commit to paarthneekhara/NeMo that referenced this pull request Mar 19, 2026
…#15047)

Fixes NVIDIA-NeMo#15040

When exporting Parakeet models to ONNX with use_dynamo=True,
PyTorch's dynamo export expects the parameter name 'dynamic_shapes'
not 'dynamic_axes'. This fix introduces a properly-named variable
for the dynamo code path to avoid confusion and potential errors.

Changes:
- Introduced dynamic_shapes variable when use_dynamo=True
- Updated torch.export.export call to use dynamic_shapes parameter
- Updated logging to display the correct variable name

The non-dynamo code path continues to use dynamic_axes as expected
by torch.onnx.export.

Tested by issue reporter who confirmed ONNX export succeeds after
this change.

Signed-off-by: Yashwant Bezawada <yashwant_b@me.com>
Signed-off-by: Paarth Neekhara <paarth.n@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dynamic_shapes error when exporting Parakeet models to ONNX

4 participants