fix(asr): make DynamicLengthTensor indexing Python 3.10-compatible (#15797)#15932
fix(asr): make DynamicLengthTensor indexing Python 3.10-compatible (#15797)#15932gauravbyte wants to merge 4 commits into
Conversation
…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>
|
Hi @nithinraok, could you please review this small fix when you get a chance? Summary: It resolves #15797 — Fix: build the index tuple explicitly — Verification: confirmed the old line raises Since this is a community fork PR, the NVIDIA-runner CI is gated — could a maintainer kick it off with |
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>
|
Hi @nithinraok would you be able to review this when you have a moment? What it fixes (#15797): On Python 3.10, importing The change: build the index tuple explicitly — Verified locally: old line raises This is a community fork PR, so NVIDIA-runner CI is gated —could a maintainer trigger |
|
/ok to test 66e3b2f |
|
@KunalDhawan can you help review and verify this change. |
|
Thanks for the PR @gauravbyte |
KunalDhawan
left a comment
There was a problem hiding this comment.
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!
What does this PR do ?
Fixes a
SyntaxErroron Python 3.10 innemo/collections/asr/parts/utils/streaming_utils.py.DynamicLengthTensor.append_no_checks_indexed a tensor using a PEP 646 starredexpression placed directly inside a subscript:
Starred expressions in subscripts only parse on Python 3.11+. NeMo declares
requires-python = ">=3.10"(with aProgramming Language :: Python :: 3.10classifier 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:
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
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:
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:
Additional Information
Verification performed locally:
SyntaxErroron CPython 3.10; the new line compiles.python -m py_compilepasses for the full file on CPython 3.10.dim_shapelengths 0-3..flake8.speech), and pylint (.pylintrc.speech, 10.00/10) all pass.