Skip to content

fix(asr): make DynamicLengthTensor indexing Python 3.10-compatible (#15797)#15932

Open
gauravbyte wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
gauravbyte:fix/15797-py310-streaming-subscript
Open

fix(asr): make DynamicLengthTensor indexing Python 3.10-compatible (#15797)#15932
gauravbyte wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
gauravbyte:fix/15797-py310-streaming-subscript

Conversation

@gauravbyte

Copy link
Copy Markdown

What does this PR do ?

Fixes a SyntaxError on Python 3.10 in nemo/collections/asr/parts/utils/streaming_utils.py.

DynamicLengthTensor.append_no_checks_ indexed a tensor using a PEP 646 starred
expression placed directly inside a subscript:

shifted_indices = shifted_indices[..., *[None for _ in range(len(self.dim_shape))]]

Starred expressions in subscripts only parse on Python 3.11+. NeMo declares
requires-python = ">=3.10" (with a Programming Language :: Python :: 3.10
classifier and black/isort 3.10 targets), so on Python 3.10 importing the module
raised SyntaxError: invalid syntax, which breaks cache-aware streaming inference
(e.g. examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py).

The index tuple is now constructed explicitly:

shifted_indices = shifted_indices[(..., *(None for _ in range(len(self.dim_shape))))]

This uses standard tuple iterable-unpacking (valid since Python 3.5), is semantically
identical to the original indexing, and parses on every supported interpreter.

Fixes #15797

Collection: [ASR]

Changelog

  • Build the trailing-axis index tuple explicitly in DynamicLengthTensor.append_no_checks_
    so it no longer relies on Python 3.11+ starred-subscript syntax.

Usage

Cache-aware streaming inference now imports and runs on Python 3.10:

from nemo.collections.asr.parts.utils.streaming_utils import CacheAwareStreamingAudioBuffer

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

Additional Information

Verification performed locally:

  • Confirmed the original line raises SyntaxError on CPython 3.10; the new line compiles.
  • python -m py_compile passes for the full file on CPython 3.10.
  • Confirmed the expression compiles on CPython 3.10, 3.11, 3.12, 3.13, 3.14, and 3.15.0b3.
  • Verified indexing equivalence with the original for dim_shape lengths 0-3.
  • black, isort, flake8 (.flake8.speech), and pylint (.pylintrc.speech, 10.00/10) all pass.

…VIDIA-NeMo#15797)

`streaming_utils.py` used a PEP 646 starred expression directly inside a
subscript (`x[..., *[None for _ in ...]]`), which only parses on Python
3.11+. On Python 3.10 -- which NeMo officially supports
(`requires-python = ">=3.10"`) -- importing the module raised a
SyntaxError, breaking cache-aware streaming inference.

Build the index tuple explicitly (`x[(..., *(None for _ in ...))]`), which
uses standard tuple iterable-unpacking (valid since 3.5) and is
semantically identical to the original indexing across all dim_shape
lengths. Verified to compile on CPython 3.10 through 3.15.

Fixes NVIDIA-NeMo#15797

Signed-off-by: Gaurav Chaudhari <107786677+gauravbyte@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@gauravbyte

Copy link
Copy Markdown
Author

Hi @nithinraok, could you please review this small fix when you get a chance?

Summary: It resolves #15797nemo/collections/asr/parts/utils/streaming_utils.py used a PEP 646 starred expression directly inside a subscript (x[..., *[None for _ in ...]]), which only parses on Python 3.11+. Since NeMo declares requires-python = ">=3.10", importing the module raised SyntaxError on 3.10 and broke cache-aware streaming inference.

Fix: build the index tuple explicitly — x[(..., *(None for _ in ...))] — which uses standard tuple unpacking (valid since 3.5), is semantically identical, and parses on CPython 3.10–3.15. It's a 1-line change (+3/-1).

Verification: confirmed the old line raises SyntaxError on 3.10 and the new line compiles on 3.10–3.15; py_compile passes for the full file on 3.10; verified indexing equivalence for dim_shape lengths 0–3; black, isort, flake8 (.flake8.speech), and pylint (.pylintrc.speech, 10.00/10) all pass locally. DCO check is green.

Since this is a community fork PR, the NVIDIA-runner CI is gated — could a maintainer kick it off with /ok to test when convenient? Thanks!

gauravbyte and others added 2 commits July 21, 2026 21:03
Signed-off-by: Gaurav Chaudhari <107786677+gauravbyte@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Gaurav Chaudhari <107786677+gauravbyte@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@gauravbyte

Copy link
Copy Markdown
Author

Hi @nithinraok would you be able to review this when you have a moment?

What it fixes (#15797): On Python 3.10, importing streaming_utils.py fails with SyntaxError because it used a PEP 646 starred expression inside a subscript (x[..., *[None for _ in ...]]), which only parses on 3.11+. NeMo declares requires-python = ">=3.10", so this breaks cache-aware streaming inference on 3.10.

The change: build the index tuple explicitly — x[(..., *(None for _ in ...))] — which is standard tuple unpacking, semantically identical, and works on CPython 3.10–3.15. One-line change.

Verified locally: old line raises SyntaxError on 3.10; new line compiles on 3.10–3.15; indexing matches the original.

This is a community fork PR, so NVIDIA-runner CI is gated —could a maintainer trigger /ok to test when convenient? Thanks!

@nithinraok

Copy link
Copy Markdown
Member

/ok to test 66e3b2f

@nithinraok

Copy link
Copy Markdown
Member

@KunalDhawan can you help review and verify this change.

@nithinraok

Copy link
Copy Markdown
Member

Thanks for the PR @gauravbyte

@KunalDhawan KunalDhawan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR and for fixing this, @gauravbyte! This correctly resolves the Python 3.10 SyntaxError from the PEP 646 starred-subscript (which only parses on 3.11+) that was breaking cache-aware streaming import, and the explicit-tuple form is semantically identical. LGTM!

@nithinraok
nithinraok enabled auto-merge (squash) July 21, 2026 21:17
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASR community-request waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python 3.10 not supported for Nemotron-3.5-ASR-Streaming

4 participants