[QNN:Bugfix] Raise stack limit for context generation#4570
Merged
Conversation
Qxinyu
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-generatorcommand with gdb and found that it crashes inside the generated QNN model shared library: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_tcontains afloatand anint32_t, so this single local array is roughly:The generated function also contains many other local tensors and metadata arrays. With the default Linux stack limit:
the available stack is only
8192 KB, about8 MiB. This can makeqnn-context-binary-generatorsegfault while composing the graph.After raising the stack limit:
ulimit -s unlimitedthe same
qnn-context-binary-generatorcommand succeeds.This PR raises the Python process stack limit before invoking QNN tools in
npu_convert.py. The QNN subprocesses inherit this limit, soqnn-context-binary-generatorcan 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
Checklist
[Module:Type] Descriptionformatfix: #4567