Skip to content

Commit 9a153aa

Browse files
Fix dynamic_shapes variable naming in ONNX dynamo export (#15047)
Fixes #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>
1 parent f767ae5 commit 9a153aa

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

nemo/core/classes/exportable.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,14 @@ def _export(
224224
# dynamic axis is a mapping from input/output_name => list of "dynamic" indices
225225
if dynamic_axes is None:
226226
dynamic_axes = self.dynamic_shapes_for_export(use_dynamo)
227+
# When using dynamo export, use dynamic_shapes instead of dynamic_axes
228+
if use_dynamo:
229+
dynamic_shapes = dynamic_axes
227230
if use_dynamo:
228231
typecheck.enable_wrapping(enabled=False)
229232
# https://github.com/pytorch/pytorch/issues/126339
230233
with monkeypatched(torch.nn.RNNBase, "flatten_parameters", lambda *args: None):
231-
logging.info(f"Running export.export, dynamic shapes:{dynamic_axes}\n")
234+
logging.info(f"Running export.export, dynamic shapes:{dynamic_shapes}\n")
232235

233236
# We have to use different types of arguments for dynamo_export to achieve
234237
# same external weights behaviour as onnx.export :
@@ -243,7 +246,7 @@ def _export(
243246
self,
244247
tuple(input_list),
245248
kwargs=input_dict,
246-
dynamic_shapes=dynamic_axes,
249+
dynamic_shapes=dynamic_shapes,
247250
strict=False,
248251
)
249252
ex_model = ex_model.run_decompositions()

0 commit comments

Comments
 (0)