Fix NeMo RNNT constant-folding overflow - #428
Merged
Merged
Conversation
Use each tensor's dynamic dimension as the Slice end instead of an INT64_MAX sentinel, preventing symbolic shape arithmetic from producing out-of-range constants. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a constant-folding overflow in the NeMo RNNT model graph by removing INT64_MAX Slice end sentinels and instead using each input tensor’s actual dynamic dimension for “slice-to-end” behavior. This prevents symbolic shape inference and subsequent constant folding from materializing out-of-range int64 constants that can trigger OverflowError during cleanup passes.
Changes:
- Replace
Slice(..., ends=INT64_MAX, ...)withSlice(..., ends=_dim(op, x, axis), ...)to preserve slice-to-end semantics safely. - Remove the now-unused
intmaxlocal in the streaming forward path. - Apply this pattern consistently across cache slicing, relative shift slicing, and streaming frame dropping.
Performance Comparison
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SliceINT64_MAX end sentinels with each input tensor's actual dynamic dimensionRoot cause
With onnxscript 0.7.1 / onnx-ir 0.2.1 / onnx 1.22.0 / numpy 2.4.6, the second cleanup pass propagated an INT64_MAX Slice end through symbolic shape arithmetic. It emitted
encoder.layers.0.self_attn.Shape_180as a Constant withvalue_ints=(9223372036854775811,)(INT64_MAX + 4). onnxscript'sFoldConstantsPassthen attemptednp.array(..., dtype=np.int64)and raisedOverflowError: Python int too large to convert to C long.Using the real dimension as the Slice end is semantically exact and avoids treating a sentinel as a concrete shape value.
Validation
pytest src/mobius/models/nemo_rnnt_test.py -q: 11 passedpytest -n auto -m "not integration and not arch_validation" -q: 4685 passed, 334 skipped, 62 xfailedlintrunner --all-files: clean