Fix PPL VLM last-position scoring: rewind-free incremental teacher forcing - #19
Open
amd-genmingz wants to merge 1 commit into
Open
Conversation
The last-position-only branch in compute_sample_nll scored PPL targets with rewind_to + append_tokens. On gemma4 multimodal + amdgpu EP with past_present_share_buffer=false, the per-layer KV-cache branch does not maintain the sequence-length bookkeeping across a rewind, so the pre-allocated present.* tensor shape disagrees with the EP-computed shape and the native layer fatally aborts (0xC0000409). Replace it with a single generator doing incremental teacher forcing: prefill the prompt once (vision encoder + image features computed a single time), then append_tokens the true previous target token per step and read the final-position logits. Only append_tokens is used (never generate_next_token), so no sampled token is inserted and rewind_to is never called. This keeps the expensive prefill at O(1) instead of O(target_len) and is mathematically equivalent to the all-position path. Also fix an argparse help string (%% escaping and en-dash) in the CLI section.
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
compute_sample_nllintests/PPL/perplexity_vlm.pyto score targets withoutrewind_to.prompt once, then
append_tokensthe true previous target token perstep and read the final-position logits.
generate_next_tokenis nevercalled, so no sampled token is inserted into the sequence.
Why
The previous last-position path relied on
rewind_to+append_tokenstorecover per-position logits. On
gemma4multimodal + amdgpu EP withpast_present_share_buffer=false, the OGA per-layer KV-cache branch doesnot maintain the sequence-length bookkeeping (
shape_[2]) across a rewind.After a rewind, OGA's pre-allocated
present.*shape disagrees with theEP-computed shape (e.g.
{1,8,277,256}vs{1,8,296,256}), and the nativelayer fatally aborts with
0xC0000409(STATUS_STACK_BUFFER_OVERRUN).What changed
rewind_tocalls from the last-position branch.each target position costs a single incremental decode step. Cost goes from
O(target_len) full prefills back to O(1) prefill + O(target_len) cheap
single-token decodes.
if) branch is unchanged; models that emit full[B, T, V]logits still take the single-pass fast path.target_ids/target_nll/top1_ids/ topk) areunchanged, so downstream
compare_vlm_ep_cpu.pyis unaffected.%%escaping and en-dash normalization).Correctness
set_inputs(prompt), final-position logits =P(? | prompt)=prediction for
target[0].append_tokens([target[j-1]]), final-position logits =P(? | prompt + target[:j])= prediction fortarget[j].all-position path (same set of target-position NLLs).