Repository navigation
Fix Qwen3.5 static-shape prefill (#18832) - #21873
yenhao-huang wants to merge 8 commits into
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
|
|
Thanks for the PR, @yenhao-huang. Re-running CI tests |
|
@claude review this PR. |
|
Claude finished @digantdesai's task in 1m 5s —— View job Summary: The fix is correct. It matches the C++ Detailed reviewPR Review: #21873SummaryThe Python native Llama runner now reads Code Quality
RecommendationApprove. The simplification above is optional. |
digantdesai
left a comment
There was a problem hiding this comment.
can we fix c issues, LGTM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @digantdesai, all review feedback addressed and ready to merge. Thanks! |
|
Thanks for the ping @yenhao-huang. Could you update the branch and give a ping? |
|
@nil-is-all Branch updated. Thanks. |
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.
cc @mergennachin @iseeyuan @lucylq @helunwencser @tarun292 @kimishpatel @jackzhxng @larryliu0820 @cccclai @digantdesai