Skip to content

helios/scheduler: preserve interior anchor for open-reasoning prompts - #66

Draft
FujitsuPolycom wants to merge 1 commit into
mainfrom
fix/helios-preserve-thinking-message-anchor-r2
Draft

FujitsuPolycom wants to merge 1 commit into
mainfrom
fix/helios-preserve-thinking-message-anchor-r2

Conversation

@FujitsuPolycom

Copy link
Copy Markdown
Owner

Why

Commit 4cc6f2fd (#660) budgets every interior conversation anchor (raw_anchor < prompt_tokens) against scheduler_checkpoint_extra_work_fraction (default 0.05), falling back to prompt_tokens whenever splitting prefill at raw_anchor exceeds the request's extra-work allowance.

When a chat template opens a reasoning block after the last complete-message boundary (output.content.start == OutputStart::Reasoning, such as <think>\n on reasoning-enabled Qwen3.8, Nemotron, or DeepSeek models), OpenAI-compatible clients strip reasoning text from subsequent assistant history. Turn k+1 therefore diverges from Turn k inside [raw_anchor, prompt_tokens). Because PrefixCheckpointCache::lookup matches exact published checkpoints across both CONTINUATION_STATE and PAGED_KEY_VALUE cores, falling back to prompt_tokens leaves Turn k with no checkpoint that is a prefix of Turn k+1, collapsing multi-turn prefix reuse and forcing full re-prefill on subsequent turns.

Requests that do not open a reasoning block (OutputStart::Content, OutputStart::RecipientHeader, OutputStart::RecipientFrame, OutputStart::ToolBody, and raw completions) do not have this stripped-suffix divergence: Turn k's prompt-end and terminal checkpoints remain exact prefixes of Turn k+1. Interior-anchor budgeting should therefore remain active for all non-reasoning-open requests (including multi-turn continuations with admission_reused_tokens > 0, preserving #660's non-thinking multi-turn and mixed-workload gains), while retaining raw_anchor specifically when output.content.start == OutputStart::Reasoning under a nonzero extra-work fraction.

What

Net non-test production diff: +28 LOC (+37/-9 across 4 Rust files; zero unsafe, zero CLI, Protobuf, or model-core ABI changes, zero model-name branches). Existing signed cores load and serve unchanged.

  • helios/src/server/runtime.rs (+4/-0 prod), helios/src/server/request.rs (+5/-1 prod), helios/src/scheduler.rs (+5/-0 prod):
    • Added pub preserve_message_anchor: bool to Prompt, RequestSpec, and LiveRequest.
    • Hoisted opens_reasoning (output.as_ref().is_some_and(|out| out.content.start == crate::output::tagged::OutputStart::Reasoning)) in prepare_validated_inference for both grammar_reasoning and Prompt::preserve_message_anchor, and propagated it through Incoming::spec() across initial admission and preemption readmission.
  • helios/src/scheduler/checkpoints.rs (+23/-8 prod):
    • Added one shared predicate RequestScheduler::budget_interior_anchor(&self, request: &LiveRequest) -> bool returning self.policy.checkpoint_extra_work_fraction == 0.0 || !request.preserve_message_anchor, called by request_anchor_endpoint, checkpoint_selection_uncached, and promote_request_anchor so all anchor-selection paths stay consistent.
    • When !self.budget_interior_anchor(request) (fraction > 0.0 and preserve_message_anchor == true): request_anchor_endpoint returns Some(raw_anchor) immediately, checkpoint_selection_uncached enters its existing unbudgeted fallback returning (raw_anchor, 0) without debiting split_ns and clears accounting.budgeted_anchor = None, and promote_request_anchor skips latching budgeted_anchor.
    • Because anchor = raw_anchor < request.prompt_tokens with anchor_split_ns = 0, the distinct prompt-end RetentionRole::Endpoint cut at request.prompt_tokens remains eligible as an optional capture under the request's extra-work allowance (matching pre-#660 exact-prompt replay behavior and bounded by protected_budget under tight snapshot capacity).
    • When self.budget_interior_anchor(request) is true (fraction == 0.0, or preserve_message_anchor == false regardless of admission_reused_tokens): the existing interior-anchor budgeting logic runs unchanged.
  • Documentation and unit tests:
    • Synchronized present-state documentation in docs/scheduling-runtime-design.md, helios/README.md, docs/core-design.md, and docs/cli-design.md (clarifying that budgeted extra-work accounting flare_checkpoint_extra_work_nanoseconds_total covers budgeted interior anchor splits and optional captures while excluding uncharged anchor copies and preserved open-reasoning anchor splits).
    • Added unit tests in helios/src/scheduler/checkpoints.rs and helios/src/server/runtime/phase_tests.rs covering preserved interior anchors at 0.05 (with agreement between request_anchor_endpoint and checkpoint_selection_uncached and stale latches), end-to-end Turn 1 publication (Anchor(896) and Endpoint(1024)) to divergent Turn 2 prefix reuse (admission_reused_tokens == 896 preserved vs 0 unpreserved), strict zero-split fallback at fraction == 0.0, non-preserved continuations with admission_reused_tokens > 0 remaining budgeted identically to #660, OutputStart::Reasoning (true) vs OutputStart::Content, OutputStart::RecipientHeader (ATEM), OutputStart::RecipientFrame (ATEM add_generation_prompt: false and TMLv0), OutputStart::ToolBody (TMLv0), and Protocol::Completions (false), plus readmission preservation across worker.park().

Result

Single-boot-per-arm (Arm A -> Arm B) serving A/B measurements on one NVIDIA GB10 (SM121, 121 GiB unified memory, aarch64) comparing NVIDIA/hyperflare-inference main (07e666e6) against 298d3e68 across three signed local-inference-lab gb10-tp1 cores with identical runtime flags (--gpus 0 --host 127.0.0.1 --port 8051 --scheduler-policy balanced --kv-cache-limit memory --memory-limit=-12G --prefix-cache-memory 0, default scheduler_checkpoint_extra_work_fraction = 0.05, OS page caches dropped before every boot). Rebasing 298d3e68 onto 95050ffb (29968abd) made only behavior-preserving simplifications in production code (folding the duplicate unbudgeted fallback branch in checkpoint_selection_uncached into if raw_anchor < request.prompt_tokens && self.budget_interior_anchor(request) and hoisting opens_reasoning in prepare_validated_inference), plus test and documentation updates. All 6 boots passed GET /v1/models (HTTP 200), 37 * 41 -> 1517 with finite logprobs (0 non-finite), flare_requests_failed_total == 0, and 0 server log errors.

Multi-Turn Prefix Reuse (C=6 x 4 turns, n=2, OpenAI content-only history)

Model (gb10-tp1) Arm Turn 2+ Cache Hit % [T0, T1] Turn 2+ Zero-Hit Misses Output tok/s med [T0, T1] All ∥ Turn 1 ∥ Turn 2+ TTFT p50 (ms) Prefill Tokens (2-trial tot) msg_ckpts ∥ ckpt_caps (anchor/msg/end) prefill Launches ∥ work_budget Skips
Qwen3.8-27B-FLARE (nvidia/Qwen3.8-27B-NVFP4) 07e666e6 (base) 56.61% [51.28, 61.94] 9 / 36 42.70 [37.81, 47.60] 3,140.5 ∥ 6,659.6 ∥ 2,465.7 112,517 24 ∥ 48 / 11 / 60 103 ∥ 30
298d3e68 (fix) 83.78% [83.82, 83.75] (+27.17 pp) 0 / 36 52.34 [48.45, 56.23] (+22.6%) 2,078.4 ∥ 8,199.9 ∥ 1,772.9 (-28.1%) 66,148 (-41.2%) 48 ∥ 48 / 0 / 96 96 ∥ 35
NVIDIA-Nemotron-3.5-Bolt-74B-A9B-24GB-FLARE 07e666e6 (base) 74.07% [74.96, 73.19] 0 / 36 42.25 [40.47, 44.02] 5,475.9 ∥ 8,976.9 ∥ 4,231.3 86,256 35 ∥ 48 / 21 / 61 90 ∥ 44
298d3e68 (fix) 83.81% [83.82, 83.80] (+9.74 pp) 0 / 36 43.19 [41.38, 44.99] (+2.2%) 4,966.9 ∥ 9,250.8 ∥ 4,571.5 (+8.0%) 68,925 (-20.1%) 60 ∥ 48 / 12 / 96 229 ∥ 25
Qwen3.8-Flash-Next-FLARE 07e666e6 (base) 52.16% [48.38, 55.93] 14 / 36 42.09 [38.37, 45.81] 3,828.3 ∥ 5,828.0 ∥ 2,218.2 121,336 18 ∥ 48 / 2 / 64 87 ∥ 42
298d3e68 (fix) 83.94% [83.97, 83.90] (+31.78 pp) 0 / 36 51.17 [50.89, 51.46] (+21.6%) 1,910.9 ∥ 7,540.4 ∥ 1,744.7 (-21.3%) 66,652 (-45.1%) 48 ∥ 48 / 0 / 96 96 ∥ 46

Warm-Catalog Concurrent Cold-Prefill Burst on Qwen3.8-27B-FLARE (4 decoders ~1.7K->160 + 2 staggered heavy cold prefills, n=2)

Arm Decode ITL p99 med [T0, T1] (ms) Peak Burst Gap med ∥ max (ms) Per-Trial Peak Gaps (ms) >500ms ∥ >1s Stalls Heavy 0 ∥ 1 TTFT med (ms) Makespan med (s) prefill Launches ∥ msg_ckpts
07e666e6 (base) 469.2 [469.7, 468.8] 984.4 ∥ 1,234.7 [1,234.7, 734.2] 6 ∥ 1 21,835 ∥ 21,952 23.84 103 ∥ 5
298d3e68 (fix) 374.0 [425.3, 322.6] (-20.3%) 1,009.5 ∥ 1,521.3 [1,521.3, 497.6] 6 ∥ 5 20,410 ∥ 22,295 24.35 108 ∥ 12

Trade-offs and Scope

  • Retaining the interior message anchor on open-reasoning turns adds one short tail prefill on Turn 1 (raising Turn 1 TTFT p50 from 5.83–8.98 s to 7.54–9.25 s), which is repaid across Turns 2–4 with -20.1% to -45.1% fewer total prefill tokens, 0 / 108 Turn 2+ zero-hit misses across all three models (+9.74 pp to +31.78 pp Turn 2+ cache hit), and +2.2% to +22.6% higher multi-turn output throughput. On NVIDIA-Nemotron-3.5-Bolt-74B-A9B-24GB-FLARE (max_active = 4), retaining all interior anchors under C = 6 queueing increased Turn 2–4 prefill launches (90 -> 229) and Turn 2+ median TTFT (+8.0%) while still reducing all-turn median TTFT (-9.3%) and total prefill tokens (-20.1%).
  • Because preserved open-reasoning turns keep anchor = raw_anchor < prompt_tokens with anchor_split_ns = 0, checkpoint_selection_uncached retains the distinct prompt-end RetentionRole::Endpoint snapshot at prompt_tokens whenever its snapshot copy fits the request's extra-work allowance (ckpt_caps end rose from 60/61/64 to 96 across 48 turns in the 3-model GB10 runs, i.e., one prompt-end snapshot plus one terminal snapshot per turn). This preserves pre-#660 exact-prompt replay / retry behavior and remains bounded by protected_budget (prompt_tokens - raw_anchor) under tight snapshot capacity, without displacing earlier Message cuts (which are evaluated ahead of prompt-end Endpoint).
  • On Qwen3.8-27B-FLARE warm-catalog prefill_burst, 298d3e68 reduced median decode ITL p99 by -20.3% (469.2 -> 374.0 ms) and restored complete message-checkpoint capture (5 -> 12), with 0 >500 ms stalls in Trial 1 (497.6 ms peak vs 734.2 ms base) and one Trial 0 chunk spike (1,521.3 ms peak, 5 >1 s decoder gaps vs 1,234.7 ms / 1 on base).
  • All non-reasoning-open requests (OutputStart::Content, OutputStart::RecipientHeader, OutputStart::RecipientFrame, OutputStart::ToolBody, and raw completions), including multi-turn continuations with admission_reused_tokens > 0, remain budgeted identically to #660.
  • Operators setting --scheduler-checkpoint-extra-work-fraction 0.0 retain strict zero-split fallback even for open-reasoning requests.

Evidence

All software checks ran on clean git archive 29968abd88068a91c25a5d3fb350bc05dca228a3 (tree 230f195d39248f08043dba84d5cb4354fac13c35; git merge-tree --write-tree 95050ffb 29968abd produced 230f195d39248f08043dba84d5cb4354fac13c35 with 0 conflicts):

  • Release compile checks (rustc 1.100.0, x86_64): RUSTFLAGS="-D warnings -A deprecated" cargo check --locked --release --tests passed with 0 warnings across all six crates (eos, selene --features test-support, selene-manager --features test-support, helios --features runtime-core,server, flare, and flare-cli).
  • Release Rust test suites (cargo test --locked --release, FLARE_TEST_TEMPLATE_DIR populated via tests/frontend/prepare_templates.py):
    • eos: 12 passed, 0 failed.
    • selene --features test-support: 553 passed (552 lib + 1 integration), 0 failed.
    • helios --features runtime-core,server: 1,901 passed (1,839 lib + 62 integration, including all 4 new/expanded unit tests), 0 failed (47 lib + 37 integration checkpoint-gated ignored).
    • flare: 255 passed (247 lib + 8 integration), 0 failed (4 ignored).
    • flare-cli -- --test-threads=1: 245 passed (219 lib + 26 integration), 0 failed (3 ignored).
  • Fault-mutation checks (scratch archive copies restored and verified byte-identical by SHA-256):
    • Mutation A: forcing budget_interior_anchor to true in helios/src/scheduler/checkpoints.rs failed both preserved_message_anchor_reuses_interior_prefix_across_divergent_turn_two (rc=101) and preserved_message_anchor_retains_interior_boundary_and_respects_zero_fraction (rc=101).
    • Mutation B: widening == OutputStart::Reasoning back to != OutputStart::Content in helios/src/server/request.rs failed prepare_inference_sets_preserve_message_anchor_and_preserves_across_readmission on OutputStart::RecipientHeader (rc=101).
  • Python boundary & hook tests (pytest): tests/preparation/test_core_boundary.py and tests/test_design_review_hook.py — 22 passed, 0 failed (1.39 s).
  • TLA+ lifecycle verification & mutations (python3 verification/helios-lifecycle/check.py --mutations --jobs 6): All 8 TLA+ models (Lifecycle, RankProtocol, DispatchRing, OffloadTransfer, CacheOwnership, Speculation, ResponseLifecycle, CheckpointReservation), observed Rust trace conformance, and all source/model mutation guards (including dropped multi-chunk budgeted-anchor fallback in helios/src/scheduler/checkpoints.rs) passed.
  • Live 3-model GB10 A/B reproducer and artifacts (flare aarch64 release binaries built from clean git archive, measured prior to the rebase onto 95050ffb and behavior-preserving cleanups):
    • Binaries: Arm A (07e666e6, SHA-256 eccdaa0fcdae7cc0acbd60643a7420492b9a7b3509b1ca6600ab4ec0db0c7273) vs Arm B (298d3e68, SHA-256 8892aa6f0f2e1abe04f858ecbf49ff79a3e46d6eaa695517020f3c536778355b).
    • Cores & server launch (single-boot-per-arm on one NVIDIA GB10, SM121, 121 GiB unified RAM, plain local NVMe ext4, sync && echo 3 > /proc/sys/vm/drop_caches before each boot): local-inference-lab/{Qwen3.8-27B-FLARE,NVIDIA-Nemotron-3.5-Bolt-74B-A9B-24GB-FLARE,Qwen3.8-Flash-Next-FLARE} at revision="gb10" launched via:
      flare run <core>/model.safetensors \
        --gpus 0 --host 127.0.0.1 --port 8051 --trust-store <trust.toml> \
        --scheduler-policy balanced --kv-cache-limit memory --memory-limit=-12G \
        --prefix-cache-memory 0
    • Multi-turn workload (C=6 x 4 turns, n=2 repeats per arm, 48 requests/arm): Streaming OpenAI /v1/chat/completions client (stream=true, temperature=0, max_tokens=64) running 6 concurrent 4-turn conversations that append only assistant content (stripping reasoning_content) between turns (Turn 1 prompts 3,199–3,383 tokens growing to 5,492–5,773 tokens by Turn 4), capturing Prometheus /metrics deltas around each repeat.
    • Warm-catalog prefill_burst workload (Qwen3.8-27B-FLARE, n=2 repeats per arm): Catalog warmup exercising 128..4096 prefill buckets, followed by 4 concurrent streaming decoders (1,667–1,714 prompt tokens, max_tokens=160, temperature=0) overlapped with 2 staggered cold heavy prefills (18,731–18,738 and 24,985–25,013 prompt tokens, stream=true, temperature=0), recording per-decoder ITL p99, peak gap, >500 ms / >1 s stalls, heavy TTFT, makespan, and /metrics deltas.

Limitations

  • Chat templates that inject a self-closed empty reasoning suffix when enable_thinking=false (such as <think>\n\n</think>\n\n, which resolves to OutputStart::Content because the template closes the reasoning block before generation starts) are not distinguished by OutputStart and remain budgeted with preserve_message_anchor = false.
  • scripts/scheduling_sim/ and cargo kani do not model checkpoint anchor selection and are not applicable.
  • Live hardware A/B measurements in this PR cover single-GPU gb10-tp1 (SM121) reasoning-enabled cores measured on 07e666e6 vs 298d3e68 (prior to rebasing onto 95050ffb and applying the two behavior-preserving production cleanups in checkpoint_selection_uncached and prepare_validated_inference); SM120 TP4 DeepSeek-V4.1-Flash non-thinking workloads were not re-benchmarked here because preserve_message_anchor evaluates to false on OutputStart::Content requests and leaves their #660 code path unchanged (verified by the non_preserved_continuation_with_reused_prefix_still_budgets_interior_anchor unit test).

Discord: Dooner

Why

Commit 4cc6f2f budgets every interior conversation anchor
(`raw_anchor < prompt_tokens`) against `scheduler_checkpoint_extra_work_fraction`
(default 0.05), falling back to `prompt_tokens` whenever splitting prefill at
`raw_anchor` exceeds the request's extra-work allowance.

When a chat template opens a reasoning block after the last complete-message
boundary (`output.content.start == OutputStart::Reasoning`, such as `<think>\n`
on reasoning-enabled Qwen, Nemotron, or DeepSeek models), OpenAI-compatible
clients strip reasoning text from subsequent assistant history. Turn k+1
therefore diverges from Turn k inside `[raw_anchor, prompt_tokens)`. Because
`PrefixCheckpointCache::lookup` matches exact published checkpoints across all
core types, falling back to `prompt_tokens` leaves Turn k with no checkpoint
that is a prefix of Turn k+1 and forces full re-prefill on subsequent turns.

Requests that do not open a reasoning block (`OutputStart::Content`,
`OutputStart::RecipientHeader`, `OutputStart::RecipientFrame`,
`OutputStart::ToolBody`, and raw completions) do not suffer this stripped-suffix
divergence: Turn k's prompt-end and terminal checkpoints remain exact prefixes
of Turn k+1. Interior-anchor budgeting should therefore remain active for all
non-reasoning-open requests (including multi-turn continuations with
`admission_reused_tokens > 0`), while retaining `raw_anchor` specifically when
`output.content.start == OutputStart::Reasoning` under a nonzero extra-work
fraction.

What

- Added `pub preserve_message_anchor: bool` to `Prompt`
  (`helios/src/server/runtime.rs`), `RequestSpec`, and `LiveRequest`
  (`helios/src/scheduler.rs`), populated in `prepare_validated_inference`
  (`helios/src/server/request.rs`) from a hoisted `opens_reasoning` check
  (`output.as_ref().is_some_and(|out| out.content.start == OutputStart::Reasoning)`)
  and propagated across admission and preemption readmission via
  `Incoming::spec`.
- Added one shared predicate `RequestScheduler::budget_interior_anchor` in
  `helios/src/scheduler/checkpoints.rs` returning
  `self.policy.checkpoint_extra_work_fraction == 0.0 || !request.preserve_message_anchor`,
  consumed by `request_anchor_endpoint`, `checkpoint_selection_uncached`, and
  `promote_request_anchor`.
  - When `!budget_interior_anchor(request)` (`fraction > 0.0` and
    `preserve_message_anchor == true`), `request_anchor_endpoint` returns
    `Some(raw_anchor)` immediately, `checkpoint_selection_uncached` enters the
    existing unbudgeted fallback returning `(raw_anchor, 0)` without debiting
    `split_ns` and clearing `accounting.budgeted_anchor = None`, and
    `promote_request_anchor` skips latching `budgeted_anchor`. Retaining
    `raw_anchor < prompt_tokens` with `anchor_split_ns = 0` keeps the distinct
    prompt-end `RetentionRole::Endpoint` snapshot at `prompt_tokens` eligible
    under the request's extra-work allowance (bounded by `protected_budget`,
    matching pre-4cc6f2fd exact-prompt replay behavior).
  - When `budget_interior_anchor(request)` is true (`fraction == 0.0`, or
    `preserve_message_anchor == false`), the existing interior-anchor budgeting
    logic runs unchanged, including when `admission_reused_tokens > 0`.
- Synchronized present-state documentation (`docs/scheduling-runtime-design.md`,
  `helios/README.md`, `docs/core-design.md`, `docs/cli-design.md`) and added
  unit tests in `helios/src/scheduler/checkpoints.rs` and
  `helios/src/server/runtime/phase_tests.rs` covering preserved interior anchors
  at 0.05, end-to-end Turn 1 publication to divergent Turn 2 prefix reuse
  (`896` vs `0` reused tokens), strict zero-fraction fallback, non-preserved
  continuations with reused prefixes, `OutputStart::Reasoning` vs
  `OutputStart::Content`, `OutputStart::RecipientHeader`,
  `OutputStart::RecipientFrame` (ATEM and TMLv0), `OutputStart::ToolBody`, and
  raw completions preparation, plus readmission propagation. No CLI, Protobuf,
  model-core ABI, or `unsafe` changes; existing signed cores load and serve
  unchanged.

Result

Restores Turn k -> k+1 exact message-anchor prefix reuse for open-reasoning
conversations under the default `scheduler_checkpoint_extra_work_fraction =
0.05` while keeping interior-anchor split budgeting active for
`OutputStart::Content`, `OutputStart::RecipientHeader`,
`OutputStart::RecipientFrame`, `OutputStart::ToolBody`, and raw completions,
and preserving strict zero-split opt-out at `fraction == 0.0`.

Evidence

Verified on clean `git archive` via release `cargo check` and `cargo test`
across `eos`, `selene`, `selene-manager`, `helios`
(`--features runtime-core,server`), `flare`, and `flare-cli`, TLA+ lifecycle
models and mutation verification (`verification/helios-lifecycle/check.py
--mutations`), core-boundary and design-review hook pytest suites, and scratch
fault-mutation checks reverting `budget_interior_anchor` and widening the
`OutputStart::Reasoning` predicate. Live 3-model GB10 `flare run` A/B results
comparing `07e666e6` against `298d3e68` (prior to rebasing onto `95050ffb` and
applying behavior-preserving cleanups that fold the duplicate fallback branch in
`checkpoint_selection_uncached` and hoist `opens_reasoning` in
`prepare_validated_inference`) are reported in the PR description.

Limitations: chat templates that inject a self-closed empty reasoning suffix
when `enable_thinking=false` (such as `<think>\n\n</think>\n\n`, which
resolves to `OutputStart::Content`) remain budgeted with
`preserve_message_anchor = false`; `scripts/scheduling_sim` and `cargo kani` do
not model checkpoint anchor selection.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
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