Fix Qwen3.5 static-shape prefill (#18832) - #21873
Open
yenhao-huang wants to merge 1 commit into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21873
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
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.
Summary
Fixes #18832
The Python native Llama runner always sent the complete prompt in a single
prefill invocation. This fails for static-shape KV-cache PTEs whose token input
is fixed to shape
[1, 1].The C++
TextPrefillerhandles this configuration by readingenable_dynamic_shapefrom the PTE metadata(
extension/llm/runner/llm_runner_helper.cpp:94-129) and passing it asenable_parallel_prefillwhen constructingTextPrefiller(
extension/llm/runner/llm_runner_helper.cpp:320-324).TextPrefiller::prefill_chunk()uses this value to select a prefill strategythat is consistent with the exported graph's input contract and KV-cache state
(
extension/llm/runner/text_prefiller.cpp:111-164). The Python runner nowreads the contract during initialization
(
examples/models/llama/runner/native.py:38-52) and applies it at prefill time(
examples/models/llama/runner/generation.py:94-136).The Python runner changes are:
enable_dynamic_shape,defaulting to
falsewhen the metadata method is not present.enable_dynamic_shapetoLlamaRunnerand route prompt processingthrough a dedicated
_prefill_chunk()method.the KV cache is disabled.
shape
[1, 1]and incrementinput_posfor each invocation.Regression tests cover static-shape KV-cache prefill, dynamic-shape parallel
prefill, and the non-KV-cache path.
Test plan
Run lintrunner on the affected files:
Result:
No lint issuesRun the focused generation regression tests:
PYTHONPATH="$PWD/src" python -m pytest -q \ examples/models/llama/tests/test_generation.pyResult:
3 passedRun the Qwen3.5 static-shape PTE end to end with the KV cache enabled:
env -u PYTHONPATH OMP_NUM_THREADS=8 timeout 300 \ /data/executorch_venv_18832_fixed/bin/python -m \ executorch.examples.models.llama.runner.native \ --model qwen3_5_0_8b \ --pte /data/executorch-issues/18832/outputs/qwen3_5_0_8b_fp32.pte \ --tokenizer /models/Qwen-Qwen3.5-0.8B/tokenizer.json \ --tokenizer_config /models/Qwen-Qwen3.5-0.8B/tokenizer_config.json \ --prompt $'<|im_start|>user\nHello<|im_end|>\n<|im_start|>assistant\n' \ --params examples/models/qwen3_5/config/0_8b_config.json \ --max_len 128 \ -kv \ --temperature 0.3Result: Generated a response successfully without the input-shape error.