Skip to content

generate, mtp: near the context's end the spec window and its drafts stay inside it - #1700

Closed
midagedev wants to merge 1 commit into
Niko1221:mainfrom
midagedev:spec-window-context-end
Closed

midagedev wants to merge 1 commit into
Niko1221:mainfrom
midagedev:spec-window-context-end

Conversation

@midagedev

Copy link
Copy Markdown
Contributor

Summary

strata generate --spec S fails near the end of the context. The admission checks prompt + max_new <= max_context, but the loop still opens a full window there. So a request that fits ends with "ran out of context" (rc 2) and prints nothing. Near the end, MtpDrafter::draft can also draft into cell max_cells, past the page table.

What changed

  • src/program/generate.cpp: a window takes only the rows that fit, min(spec, max_context - p). The lookup chain stays inside them.
  • src/core/mtp.cpp: a draft round caps its steps at max_cells - (p + a). Serve calls the same drafter, so it gets the cap too. The cap binds only at the end of the context.

Extra Notes

  • CUDA 13.3 on Linux, RTX A6000, Qwen3.8-Flash-Next UD-Q4_K_XL, fb58e0db against this branch:
    • 4094-token prompt, --max-context 4096 --max-new 2 --spec 4: before, rc 2 and no output. After, rc 0 and 2 tokens.
    • 4084-token prompt, --max-new 12 --spec 5 --suffix-draft 0 --mtp, with a probe print: before, a round drafts into cell 4096 (max_cells 4096), then rc 2. After, its last cell is 4095, and the run ends with rc 0 and 12 tokens.
    • 512-token prompt, --max-new 64 --spec 4 --mtp, CPU share off: the same 64 tokens from both builds, twice each.
  • Not built: HIP and SYCL. The SYCL copies have the same lines. I can port the fix there.
  • I used Claude Code to find this and draft the change. I ran the tests myself.

…stay inside it

The admission checks prompt + max_new <= max_context, but the spec loop
opened every window at S_mtp rows, so a request that fits ended with
"ran out of context" (rc 2) once p + S passed the end, and printed
nothing. The window now takes only the rows the context still holds.
MtpDrafter::draft wrote draft j at cell p + a + j for every step, past
max_cells near the end, where the page table has no entry; it now drafts
only the cells that exist. Far from the end nothing changes.
@Niko1221

Copy link
Copy Markdown
Owner

Reproduced on our box: a 4094-token prompt with --max-context 4096 --max-new 2 --spec 4 gives rc 2 'ran out of context' before the fix and rc 0 after. Ported with your authorship. Serve is not affected for plain requests (its admission stops earlier), the MTP cell cap still applies there.

@Niko1221 Niko1221 closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants