Skip to content

Fix NeMo RNNT constant-folding overflow - #428

Merged
justinchuby merged 1 commit into
mainfrom
fix/nemo-rnnt-foldconstants-overflow
Jul 25, 2026
Merged

Fix NeMo RNNT constant-folding overflow#428
justinchuby merged 1 commit into
mainfrom
fix/nemo-rnnt-foldconstants-overflow

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • replace NeMo RNNT Slice INT64_MAX end sentinels with each input tensor's actual dynamic dimension
  • prevent symbolic shape inference from deriving out-of-range int64 constants
  • preserve slice-to-end semantics without pinning upstream dependencies

Root 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_180 as a Constant with value_ints=(9223372036854775811,) (INT64_MAX + 4). onnxscript's FoldConstantsPass then attempted np.array(..., dtype=np.int64) and raised OverflowError: 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 passed
  • pytest -n auto -m "not integration and not arch_validation" -q: 4685 passed, 334 skipped, 62 xfailed
  • lintrunner --all-files: clean

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, ...) with Slice(..., ends=_dim(op, x, axis), ...) to preserve slice-to-end semantics safely.
  • Remove the now-unused intmax local in the streaming forward path.
  • Apply this pattern consistently across cache slicing, relative shift slicing, and streaming frame dropping.

@github-actions

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 44bbfe02e71170

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

Copy link
Copy Markdown

Performance Comparison

Comparing 44bbfe02e71170

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 68 68 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 62 62 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 60 60 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 62 62 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 413 413 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@justinchuby
justinchuby merged commit 68fdc67 into main Jul 25, 2026
22 of 24 checks passed
@justinchuby
justinchuby deleted the fix/nemo-rnnt-foldconstants-overflow branch July 25, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants