Skip to content

feat: restore linear-state slots in base step_for_schedule_overlap. - #2295

Draft
yingxudeng wants to merge 3 commits into
xLLM-AI:preview/glm-5.3-flashfrom
yingxudeng:bugfix/vlm-linear-state-restore-on-overlap
Draft

feat: restore linear-state slots in base step_for_schedule_overlap.#2295
yingxudeng wants to merge 3 commits into
xLLM-AI:preview/glm-5.3-flashfrom
yingxudeng:bugfix/vlm-linear-state-restore-on-overlap

Conversation

@yingxudeng

Copy link
Copy Markdown
Collaborator

Description

Related Issues

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactor
  • Documentation
  • Test
  • Build or CI

Pull Request Checklist

Thank you for contributing to xLLM. Before requesting review, please make sure the following items are complete.

PR Title and Commit Messages

  • The PR title and each commit message follow the xLLM commit format: <type>: <subject>.

Allowed types: feat, bugfix, docs, test, refactor, chore, style, revert, perf, model, build, release.
The subject should use clear English, start with a verb, include at least 4 words, and end with ..

Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit or an equivalent command.
  • I have installed the hooks with pre-commit install.
  • I have run pre-commit run --all-files and fixed any reported issues.

If you are unsure how to set up pre-commit, see the pre-commit documentation.

Self Review

  • I have self-reviewed the code according to .agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.
  • I have rebased this PR onto the latest main branch.

Build and Test Coverage

  • Tests have been added or updated as needed.
  • CUDA: python setup.py build test has passed on a CUDA machine.
  • NPU: python setup.py build test has passed on an NPU machine.
  • MLU: python setup.py build test has passed on an MLU machine.

Reviewer Notes

VLMWorkerImpl does not override step_for_schedule_overlap, so the base
version was used when a VLM backend ran with enable_schedule_overlap and
enable_prefix_cache both on. The base version only invoked step() and
skipped the linear-state slot restore, while prepare_work_before_execute
already gated its own restore on !enable_schedule_overlap(). The net
effect was that every chunked-prefill boundary read a stale recurrent
slot on VLM frontends (e.g. GLM-5.3-Flash), which produced non-
deterministic accuracy regressions with symptoms matching KV / linear
state cross-request contamination.

Move the restore into the base step_for_schedule_overlap and gate it by
owns_recurrent_cache so speculative/MTP outer workers -- which own no
kv_caches_ -- fall through unchanged. LLMWorkerImpl keeps its override
because it also drops the default-stream sync via
execute_no_sync_on_stream, which is an LLM-only optimization.

Verified on GLM-5.3-Flash 45L with a 5x5 rigorous GSM8K run
(serial batch=1, temperature=0, MAX_CHUNK_TOKENS=128):

  Group             run1 run2 run3 run4 run5   mean
  ---------------   ---- ---- ---- ---- ----   ----
  prefix OFF        0.9  0.9  0.9  1.0  0.9    0.92
  prefix ON (fix)   0.9  1.0  0.9  1.0  0.8    0.92
  prefix ON (pre)   0.4  0.7  0.9  0.8  0.6    0.68

Cache hits confirmed unchanged (input_tokens_cache_read=512 per request).
… ordering.

Extract has_linear_attention_layers + owns_recurrent_cache + restore_linear_state_slots into
WorkerImpl::try_restore_linear_state_slots and replace both callsites (base
step_for_schedule_overlap and prepare_work_before_execute_on_stream) so the invariants stay in
sync. Widen the compute_stream_ StreamGuard in the base overlap path to cover both the restore
and the following step() so a future pooled compute_stream_ cannot desync chunk-boundary
restores from the forward. Change step_for_schedule_overlap signature from const ForwardInput&
to ForwardInput& (base + LLMWorkerImpl override) so the write-through of
linear_state_validity_mask is honest instead of const_cast. Turn the compute_stream_ nullptr
check into a CHECK so a future regression cannot silently revert to the stale-slot bug.
…event.

Base step_for_schedule_overlap only enters compute_stream_ when the model has linear-attention
layers, so dense frontends inherit the historical stream selection unchanged. Inside the guard,
wait on input.metadata_ready_event before restore or step() so the prepare_stream_ H2D copies
are observable on compute_stream_ regardless of which stream published them. Mirror the same
has_linear_attention_layers gate in LLMWorkerImpl::step_for_schedule_overlap. Update the MLU
overlap test helper to take ForwardInput& so it matches the tightened base signature.
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.

1 participant