Skip to content

[QNN:Bugfix] Raise stack limit for context generation#4570

Merged
Qxinyu merged 1 commit into
alibaba:masterfrom
LudovicoYIN:llm-qnn-raise-stack
Jul 1, 2026
Merged

[QNN:Bugfix] Raise stack limit for context generation#4570
Qxinyu merged 1 commit into
alibaba:masterfrom
LudovicoYIN:llm-qnn-raise-stack

Conversation

@LudovicoYIN

Copy link
Copy Markdown
Contributor

Description

When converting Qwen3/Qwen3.5 4B LLM models to QNN context binaries on v73, the conversion may fail at the last large graph, which appears to include the lm_head part.

We debugged the failed qnn-context-binary-generator command with gdb and found that it crashes inside the generated QNN model shared library:

SIGSEGV in QnnModel_composeGraphs() from libgraph1_37.so

The generated C++ for the final graph contains very large local stack arrays for lm_head quantization metadata, for example:

Qnn_ScaleOffset_t tensor__lm_lm_head_Linear_bias_axis_scale_offset[] = { ... };

In our case, this array had about 151,936 entries. Qnn_ScaleOffset_t contains a float and an int32_t, so this single local array is roughly:

151,936 * 8 bytes = 1,215,488 bytes ~= 1.16 MiB

The generated function also contains many other local tensors and metadata arrays. With the default Linux stack limit:

ulimit -s
# 8192

the available stack is only 8192 KB, about 8 MiB. This can make qnn-context-binary-generator segfault while composing the graph.

After raising the stack limit:

ulimit -s unlimited

the same qnn-context-binary-generator command succeeds.

This PR raises the Python process stack limit before invoking QNN tools in npu_convert.py. The QNN subprocesses inherit this limit, so qnn-context-binary-generator can compose the large graph successfully.

No QNN graph options are changed in this PR.

Tested with Qwen3-4B QNN conversion on v73 using QNN SDK 2.42.

Module

QNN

Type

  • Bugfix

Checklist

  • Commit message follows [Module:Type] Description format
  • Code compiles without errors
  • Tested on relevant platform(s)
  • No unrelated format or style changes included

fix: #4567

@Qxinyu
Qxinyu merged commit 0bff03c into alibaba:master Jul 1, 2026
9 checks passed
@LudovicoYIN
LudovicoYIN deleted the llm-qnn-raise-stack branch July 1, 2026 07:57
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.

[LLM][QNN] QNN context binary generation fails at final lm_head graph on v73 for Qwen3/Qwen3.5 4B

2 participants