You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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++ TextPrefiller handles this configuration by reading enable_dynamic_shape from the PTE metadata
(extension/llm/runner/llm_runner_helper.cpp:94-129) and passing it as enable_parallel_prefill when constructing TextPrefiller
(extension/llm/runner/llm_runner_helper.cpp:320-324).
TextPrefiller::prefill_chunk() uses this value to select a prefill strategy
that is consistent with the exported graph's input contract and KV-cache state
(extension/llm/runner/text_prefiller.cpp:111-164). The Python runner now
reads 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:
Load the PTE before initializing the base runner and read enable_dynamic_shape,
defaulting to false when the metadata method is not present.
Add enable_dynamic_shape to LlamaRunner and route prompt processing
through a dedicated _prefill_chunk() method.
Preserve the existing full-prompt prefill when dynamic shapes are enabled or
the KV cache is disabled.
For static-shape KV-cache models, invoke the model once per prompt token with
shape [1, 1] and increment input_pos for each invocation.
Regression tests cover static-shape KV-cache prefill, dynamic-shape parallel
prefill, and the non-KV-cache path.
This comment was automatically generated by Dr. CI and updates every 15 minutes.
meta-claBot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Aug 15, 2026
If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.
To add a label, you can comment to pytorchbot, for example @pytorchbot label "release notes: none"
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
CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.community: contributionPRs coming from community (excluding hardware partners)module: examplesIssues related to demos under examples/module: llmIssues related to LLM examples and apps, and to the extensions/llm/ code
3 participants
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.
cc @mergennachin @iseeyuan @lucylq @helunwencser @tarun292 @kimishpatel @jackzhxng @larryliu0820 @cccclai @digantdesai