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
{{ message }}
Repository navigation
Commit 0768f8d
Browse filesBrowse the repository at this point in the historyBrowse files
perf(qwen3_5 cuda): keep the prompt-end cache entry one token before the prompt's end
A chat prompt ends in the generation prompt, <think> and a newline (token
198). When the next request sends that turn back without its reasoning, its
history renders an empty reasoning block, <think> and two newlines (token
271), so the entry kept for the whole prompt differs from the next prompt in
its last token and does not match: the follow-up is prefilled from the last
shorter entry or from scratch. Both prefix caches now keep a prompt's entry
at len(prompt) - 1 (engine.entry_end; a one-token prompt keeps its whole
prompt): the one-stream cache (two entries, one GPU and both ranks of two)
and the concurrent PrefixCache (KEEP entries, private copies). An identical
prompt sent again now resumes with one token to prefill; a prompt that
extends the whole last prompt prefills one token more; stats["cached"]
reports the entry's length.
prefill, prefill_tp and prefill_state take keep_at and also return the
state after prompt[:keep_at] and the drafter's snapshot there. The spans
do not change and no forward is added: the chunk that holds the point runs
each GDN chain as two launches, rows [0, cut) then [cut, W). The chain
kernel steps one row at a time on fp32 state that it loads and stores as
fp32, so the two launches give one launch's output rows and final state;
the prompt's own state, last logits and first token keep their bits. The
state between the launches, the conv rows before the cut and the key/value
rows below it are the state a prefill of the first keep_at tokens commits
(prefill bits do not depend on chunking). The kept state takes the prompt
state's key/value buffers after the last chunk, so a buffer grown past the
point is never held twice. The drafter's taps start where its window
reaches back from the kept point; it absorbs the chunk's rows before the
cut, is snapshotted, then absorbs the rest. Two ranks add no collective.
Tests: tests/cuda/test_qwen27_prompt_end_cache.py (a cut chunk against one
launch; keep_at against none, one and several spans; the kept state
against a fresh prefill of the prefix; the next turn, a resumed prefill,
longer and repeated prompts resumed against fresh prefills, greedy and
sampled; buffers grown inside the cut chunk; the drafter's taps; the
engine and the concurrent decoder end to end against the serial
reference), tests/test_qwen27_prompt_end_cache_host.py (both caches'
entries and resumes with stand-ins, both ranks of two; prefill_state's
spans, cuts and drafter calls with a stand-in chunk; the prefill on
row-wise CPU stand-ins for the kernels). tests/cuda/test_qwen27_multi.py:
a prompt extending a finished reply now resumes one token earlier. Not yet
run on a GPU.
(cherry picked from commit 9b2021a)
"""Commit the rest of the prompt into ``st``, handing ``keep(p, state, drafter context)`` the state after each stop (``keep_at``: ``prefill_state``'s)."""
"""Commit the prompt and sample the first token; resuming a kept ``state`` gives a fresh prefill's bits (``keep_at`` adds a third item: the state after prompt[:keep_at] and the drafter's snapshot there)."""
"""Both ranks prefill, from a kept ``state`` with a fresh prefill's bits; rank 0 shares the first token (``keep_at``: a third item, as ``decode.prefill``'s; the split chains are each rank's own)."""
"""A cached state: attention rows below ``pos`` viewed in place (commits only write past a stream's ``pos``), DeltaNet states copied (decoding replays them in place)."""
"""Commit ``tokens`` at [st.pos, st.pos + W) into ``st``, replacing its list entries, never writing through them (``every``: all rows' final normed states)."""
59
+
last: bool=True, every: bool=False, cut: int=0):
60
+
"""Commit ``tokens`` at [st.pos, st.pos + W) into ``st`` without writing through its entries (``every``: all rows' final normed states; ``cut``: also the state after the first ``cut`` rows, the GDN chains run as two launches with one launch's bits)."""
60
61
61
62
c=w.config
62
63
pg=prefill_glueifw.fast_prefillelseprefill_bf16# FP8 inputs only where every projection is 4-bit g64
63
64
W=int(tokens.shape[0])
65
+
ifnot0<=cut<W:
66
+
raiseValueError(f"cut {cut} is not inside a chunk of {W} rows")
0 commit comments