Skip to content

Export nemotron-speech-streaming-en-0.6b to QNN - #3725

Merged
csukuangfj merged 6 commits into
k2-fsa:masterfrom
csukuangfj:export-nemotron-streaming-qnn
Jul 7, 2026
Merged

csukuangfj merged 6 commits into
k2-fsa:masterfrom
csukuangfj:export-nemotron-streaming-qnn

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

C++ runtime will be added in a separate pull request.

You can find the exported models at

(search for streaming in the above two pages)

Summary by CodeRabbit

  • New Features

    • Added support for exporting a new streaming speech model to QNN artifacts.
    • Introduced automated workflows to generate model builds across multiple chunk sizes and target devices.
    • Added tooling to export ONNX components and run streaming inference checks for the model.
  • Bug Fixes

    • Improved export compatibility for streaming model graphs and cached-state handling.
    • Added validation steps to help catch issues during model conversion and packaging.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds an end-to-end pipeline for exporting the nemotron-speech-streaming-en-0.6b NeMo model to ONNX and quantizing it to QNN. It includes a patched ONNX export wrapper, a streaming ONNX inference test script, a shell launcher, a build matrix generator, and a new GitHub Actions workflow.

Changes

Nemotron speech streaming QNN export

Layer / File(s) Summary
Encoder patching and ONNX export wrappers
scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/wrapper.py
Monkey-patches ConformerEncoder forward/streaming post-process for ONNX/QNN compatibility and defines EncoderWrapper, DecoderWrapper, JoinerWrapper plus main() to export encoder.onnx, decoder.onnx, joiner.onnx (opset 13).
Shell launcher for export
scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/run.sh
Installs Python dependencies and runs wrapper.py with configurable chunk-size-ms and model-id.
ONNX streaming inference test script
scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/test_onnx.py
Loads exported ONNX models, computes fbank features, runs streaming encoder/decoder/joiner inference with cached states, decodes tokens, and optionally dumps debug tensors.
Build matrix generator
.github/scripts/export-qnn/generate_nemotron_speech_streaming.py
Defines a Config dataclass and builds a JSON matrix over SoCs, chunk sizes, and model names (excluding SM8350).
CI workflow for ONNX export and QNN quantization
.github/workflows/export-nemotron-speech-streaming-en-0.6b-qnn.yaml
Adds onnx, generate_build_matrix, and qnn jobs to export ONNX, build the SoC matrix, quantize/convert to QNN, package artifacts, and publish releases.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Push
  participant OnnxJob
  participant GenerateMatrixJob
  participant QnnJob
  participant Release

  Push->>OnnxJob: trigger workflow, run.sh exports ONNX
  OnnxJob->>OnnxJob: test_onnx.py validates encoder/decoder/joiner
  OnnxJob->>Release: upload per-chunk-size ONNX artifact
  Push->>GenerateMatrixJob: run generate_nemotron_speech_streaming.py
  GenerateMatrixJob->>QnnJob: expose SoC/chunk-size build matrix
  QnnJob->>OnnxJob: download matching ONNX artifact
  QnnJob->>QnnJob: convert/quantize via qnn-onnx-converter, build context binaries
  QnnJob->>Release: package tarballs, publish release artifacts
Loading

Related PRs: None identified.

Suggested labels: ci, export, qnn, nemo

Suggested reviewers: csukuangfj

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: exporting nemotron-speech-streaming-en-0.6b to QNN.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@csukuangfj
csukuangfj merged commit d310532 into k2-fsa:master Jul 7, 2026
1 check was pending
@csukuangfj
csukuangfj deleted the export-nemotron-streaming-qnn branch July 7, 2026 06:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/run.sh`:
- Line 29: Quote the shell variables in the wrapper.py invocation to prevent
word splitting and globbing; update the run.sh command that passes chunk_size_ms
and model_id so both arguments are wrapped in quotes when used in the python3
./wrapper.py call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb410d9b-6b5e-42af-b360-6178033bef2e

📥 Commits

Reviewing files that changed from the base of the PR and between 5f1153b and 4ed5859.

📒 Files selected for processing (5)
  • .github/scripts/export-qnn/generate_nemotron_speech_streaming.py
  • .github/workflows/export-nemotron-speech-streaming-en-0.6b-qnn.yaml
  • scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/run.sh
  • scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/test_onnx.py
  • scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/wrapper.py

model_id="$2"
fi

python3 ./wrapper.py --chunk-size-ms $chunk_size_ms --model-id $model_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Quote $chunk_size_ms and $model_id to avoid globbing/word-splitting.

🔧 Proposed fix
-python3 ./wrapper.py --chunk-size-ms $chunk_size_ms --model-id $model_id
+python3 ./wrapper.py --chunk-size-ms "$chunk_size_ms" --model-id "$model_id"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
python3 ./wrapper.py --chunk-size-ms $chunk_size_ms --model-id $model_id
python3 ./wrapper.py --chunk-size-ms "$chunk_size_ms" --model-id "$model_id"
🧰 Tools
🪛 Shellcheck (0.11.0)

[info] 29-29: Double quote to prevent globbing and word splitting.

(SC2086)


[info] 29-29: Double quote to prevent globbing and word splitting.

(SC2086)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemo/qnn/nemotron-speech-streaming-en-0.6b/run.sh` at line 29, Quote
the shell variables in the wrapper.py invocation to prevent word splitting and
globbing; update the run.sh command that passes chunk_size_ms and model_id so
both arguments are wrapped in quotes when used in the python3 ./wrapper.py call.

Source: Linters/SAST tools

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces scripts and wrappers to export and test the nemotron-speech-streaming-en-0.6b model for Qualcomm QNN. Key changes include a configuration generator for GitHub Actions, a test script using ONNX Runtime, and a wrapper that monkey-patches NeMo's ConformerEncoder to ensure QNN compatibility. The review feedback highlights several critical issues: a potential ModuleNotFoundError due to missing import paths, a crash when chunk_size_ms is 80, potential parsing failures with whitespace tokens, and inefficient array upcasting to float64. Additionally, minor shell scripting improvements are suggested to prevent globbing and word-splitting issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


import json

from device_info import soc_info_dict

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The script imports device_info directly, but device_info.py is located in scripts/qnn/device_info.py, which is not in the Python search path when running this script. This will cause a ModuleNotFoundError when executed. Please add the scripts/qnn directory to sys.path before importing.

Suggested change
from device_info import soc_info_dict
import sys
from pathlib import Path
# Add scripts/qnn to sys.path so we can import device_info
sys.path.append(str(Path(__file__).resolve().parents[3] / "scripts" / "qnn"))
from device_info import soc_info_dict

Comment on lines +227 to +229
for line in f:
t, idx = line.split()
id2token[int(idx)] = t

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using line.split() to parse tokens.txt will fail with a ValueError if any token is a space or empty string (which is common in SentencePiece/BPE vocabularies), because split() ignores leading/trailing whitespace and splits on any whitespace. Using rsplit(" ", 1) is much more robust.

Suggested change
for line in f:
t, idx = line.split()
id2token[int(idx)] = t
for line in f:
parts = line.rstrip("\r\n").rsplit(" ", 1)
if len(parts) == 2:
t, idx = parts
id2token[int(idx)] = t


window_size = chunk_size + pre_encode_cache_size

window_shift = chunk_size

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

If chunk_size_ms is 80, chunk_size becomes 0. This sets window_shift to 0, which will cause test_onnx.py to crash with ValueError: range() arg 3 must not be zero. Ensuring window_shift is at least 1 prevents this crash.

Suggested change
window_shift = chunk_size
window_shift = max(1, chunk_size)

)
sample_rate = 16000

tail_padding = np.zeros(sample_rate * 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Creating tail_padding without specifying dtype defaults to float64. When concatenated with audio (which is float32), it upcasts the entire array to float64. This is inefficient and can cause type mismatch issues with the ONNX model which expects float32 inputs.

Suggested change
tail_padding = np.zeros(sample_rate * 1)
tail_padding = np.zeros(sample_rate * 1, dtype=np.float32)

set -ex

pip install \
nemo_toolkit['asr'] \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Unquoted package names with extras like nemo_toolkit['asr'] can cause shell expansion/globbing errors in some shells (such as zsh). It is safer to quote the package name.

Suggested change
nemo_toolkit['asr'] \
"nemo_toolkit[asr]" \

model_id="$2"
fi

python3 ./wrapper.py --chunk-size-ms $chunk_size_ms --model-id $model_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It is a best practice to quote variables in bash scripts to prevent word splitting and globbing issues.

Suggested change
python3 ./wrapper.py --chunk-size-ms $chunk_size_ms --model-id $model_id
python3 ./wrapper.py --chunk-size-ms "$chunk_size_ms" --model-id "$model_id"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant