Skip to content

Build a docker image to setup the QNN SDK environment - #3736

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:docker-qnn
Jul 8, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:docker-qnn

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

See https://github.com/k2-fsa/sherpa-onnx/pkgs/container/qnn-sdk

Screenshot 2026-07-08 at 22 23 22

Summary by CodeRabbit

  • New Features
    • Added support for building a QNN SDK Docker image with Android NDK, Python tooling, and QNN utilities preconfigured.
    • Added automated build and test workflows for the QNN SDK container, including manual and branch-based triggers.
  • Bug Fixes
    • Improved environment validation to help catch setup issues before the container is used.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa43408b-cc3f-4405-9f17-aa9cbc15ebb7

📥 Commits

Reviewing files that changed from the base of the PR and between 6a20463 and 7ff90bf.

📒 Files selected for processing (3)
  • .github/scripts/export-qnn/Dockerfile-2.40
  • .github/workflows/qnn-sdk-docker-build.yaml
  • .github/workflows/test-qnn-sdk-docker.yaml

📝 Walkthrough

Walkthrough

Adds a Dockerfile (Dockerfile-2.40) that builds an Ubuntu-based QNN 2.40 SDK environment with Android NDK, Python 3.10 virtualenv, and QNN tool validation, plus two GitHub Actions workflows to build/push the image to GHCR and to test the published image's QNN CLI tools.

Changes

QNN SDK Docker Build and Validation

Layer / File(s) Summary
QNN SDK Dockerfile
.github/scripts/export-qnn/Dockerfile-2.40
Builds Ubuntu 22.04 image, installs Android NDK r29 and QNN toolkit, sets up Python 3.10 venv with pinned dependencies (torch, numpy<2), and validates qnn-onnx-converter, qnn-model-lib-generator, qnn-net-run.
Docker build and push workflow
.github/workflows/qnn-sdk-docker-build.yaml
New workflow builds and pushes qnn-sdk:2.40 image to GHCR via Buildx on push to docker-qnn-2 or manual dispatch, with GitHub Actions caching.
Docker image validation workflow
.github/workflows/test-qnn-sdk-docker.yaml
New workflow runs inside the published qnn-sdk:2.40 container to print environment info and validate QNN CLI tools via --help after sourcing envsetup.sh.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BuildWorkflow as qnn-sdk-docker-build.yaml
  participant GHCR
  participant TestWorkflow as test-qnn-sdk-docker.yaml
  BuildWorkflow->>GHCR: Build and push qnn-sdk:2.40 image
  TestWorkflow->>GHCR: Pull qnn-sdk:2.40 container
  TestWorkflow->>TestWorkflow: Validate QNN CLI tools via --help
Loading

Possibly related PRs

  • k2-fsa/sherpa-onnx#3653: Adds QNN model-export tooling/workflows relying on the same QNN CLI tools and environment setup introduced here.
✨ 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 f8ffa43 into k2-fsa:master Jul 8, 2026
1 check was pending
@csukuangfj
csukuangfj deleted the docker-qnn branch July 8, 2026 14:25

@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 a new Dockerfile (Dockerfile-2.40) to set up an environment with Ubuntu 22.04, Android NDK r29, QNN SDK 2.40, and various Python dependencies. The review feedback identifies critical issues in the Dockerfile's shell execution steps: first, operator precedence pitfalls in Bash chaining (&& and ||) can lead to silent installation failures of both Linux and Python dependencies; second, running check-linux-dependency.sh will fail because package lists were previously deleted, requiring an apt-get update beforehand; and third, there are duplicate dependencies (pyyaml and numpy) in the pip installation layers.

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.

Comment on lines +54 to +56
RUN cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \
&& yes | ${QNN_SDK_ROOT}/bin/check-linux-dependency.sh || true \
&& rm -rf /var/lib/apt/lists/*

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

Bash Operator Precedence & Missing Package Lists\n\nThere are two issues in this step:\n1. Operator Precedence Pitfall: In Bash, && and || have equal precedence and are left-associative. The expression A && B && C || true && D is evaluated as (((A && B && C) || true) && D). If cd or source envsetup.sh fails, the chain A && B && C fails, but the || true evaluates to true, and the shell proceeds to run D (rm -rf ...). This silently ignores failures in sourcing envsetup.sh.\n2. Missing Package Lists: The check-linux-dependency.sh script runs apt-get install under the hood. However, since /var/lib/apt/lists/* was deleted in the previous layer, apt-get will fail to locate packages. Running apt-get update before the script ensures dependencies can be successfully installed.\n\nTo fix both, wrap the dependency check in { ... || true; } and run apt-get update beforehand.

RUN apt-get update && cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \\n    && { yes | ${QNN_SDK_ROOT}/bin/check-linux-dependency.sh || true; } \\n    && rm -rf /var/lib/apt/lists/*

Comment on lines +65 to +102
RUN . /opt/py310/bin/activate && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
mock \
numpy \
opencv-python \
optuna \
packaging \
pandas \
paramiko \
pathlib2 \
pillow \
plotly \
protobuf \
psutil \
pydantic \
pytest \
pyyaml \
rich \
scikit-optimize \
scipy \
six \
tabulate \
typing-extensions \
xlsxwriter \
&& python3 "${QNN_SDK_ROOT}/bin/check-python-dependency" || true \
&& pip install --no-cache-dir \
torch==2.0.0+cpu -f https://download.pytorch.org/whl/torch \
kaldi_native_fbank \
"numpy<2" \
onnx==1.17.0 \
onnxruntime \
soundfile \
librosa \
onnxsim \
sentencepiece \
pyyaml \
&& pip cache purge 2>/dev/null || true

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

Silent Installation Failures & Duplicate Dependencies\n\nThere are two main issues in this block:\n1. Silent Failures due to Operator Precedence: In Bash, && and || have equal precedence and are left-associative. The expression A && B || true && C && D || true is evaluated as ((((A && B) || true) && C) && D) || true. If the first pip install fails, the || true evaluates to true, and the shell proceeds to the second pip install. More critically, if the second pip install (which installs major packages like PyTorch and ONNX) fails, the trailing || true causes the entire RUN instruction to succeed, silently producing a broken Docker image.\n2. Duplicate Dependencies: pyyaml is listed twice (lines 82 and 101). numpy is also listed twice (once as numpy on line 69 and once as \"numpy<2\" on line 94), which causes pip to install the latest numpy first and then downgrade it later.\n\nGrouping the commands with { ... || true; } and cleaning up the duplicates resolves these issues.

RUN . /opt/py310/bin/activate && \\n    pip install --no-cache-dir --upgrade pip && \\n    pip install --no-cache-dir \\n    mock \\n    \"numpy<2\" \\n    opencv-python \\n    optuna \\n    packaging \\n    pandas \\n    paramiko \\n    pathlib2 \\n    pillow \\n    plotly \\n    protobuf \\n    psutil \\n    pydantic \\n    pytest \\n    pyyaml \\n    rich \\n    scikit-optimize \\n    scipy \\n    six \\n    tabulate \\n    typing-extensions \\n    xlsxwriter && \\n    { python3 \"${QNN_SDK_ROOT}/bin/check-python-dependency\" || true; } && \\n    pip install --no-cache-dir \\n    torch==2.0.0+cpu -f https://download.pytorch.org/whl/torch \\n    kaldi_native_fbank \\n    onnx==1.17.0 \\n    onnxruntime \\n    soundfile \\n    librosa \\n    onnxsim \\n    sentencepiece && \\n    { pip cache purge 2>/dev/null || true; }

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant