Skip to content

helios/scheduler: budget interior conversation-anchor splits against checkpoint_extra_work_fraction - #660

Merged
lukealonso merged 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:fix/budgeted-interior-anchor-split
Dec 2, 2026
Merged

lukealonso merged 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:fix/budgeted-interior-anchor-split

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

scheduler_checkpoint_extra_work_fraction in helios/src/scheduler/checkpoints.rs was discontinuous at 0.0 for interior anchors (raw_anchor < prompt_tokens): 0.0 required zero split cost, while nonzero values (default 0.05) pushed raw_anchor unconditionally (split_ns: 0). On small TP4 buckets (Prefill(128)=18 ms vs 512=29 ms), splitting 453 tokens at 450 adds an 18 ms tail (+62%, >12x budget), doubling prefill launches and causing decode-drain bubbles.

What

  • checkpoints.rs (+35 net prod LOC; 0 unsafe, 0 new flags/ABI): Extracted split_overhead_ns and anchor_split_affordable; replaced anchor_split_is_zero_cost with anchor_split_ns; generalized zero_budget_anchor to budgeted_anchor.
  • Budgeted retention: request_anchor_endpoint & checkpoint_selection_uncached retain raw_anchor < prompt_tokens only when split_ns == 0 or extra_spent_ns + split_ns <= allowance(initial_prefill_ns.unwrap_or(whole), fraction) (else prompt_tokens; unknown timings anchor at >0, fall back at 0.0), debiting split_ns (copy_ns: 0).
  • Guards/docs/tests (12 files, +900/-162): Filters Message (end < raw_anchor), preserves charged Anchor cuts across chunks & revoke_unused_anchor_guards(), latches budgeted_anchor, sets 0.50 in #663's forced_anchor_cut_preserves_first_output_wait_clock_without_exempting_service_price, updates docs/tests/check.py. Cores unchanged.

Result

flare run A/B (DeepSeek-V4.1-Flash TP4, gb202-tp4-202612010626, 132,999 KV pages, 0 err), 22cac916834f vs 5d53040e (4x RTX PRO 6000):

Workload (n) Metric Base Cand. Delta
mixed-c32 (n=1) SLO ∥ Out 9.1% ∥ 1,072.8 80.3% ∥ 1,327.0 +71.2 pp ∥ +23.7%
TTFT p50 ∥ Batch 4,577 ms ∥ 9.13 1,920 ms ∥ 17.91 -58.0% ∥ +96.2%
4x6-turn (n=2) TTFT ∥ Prefills 297.4 ms ∥ 48.0 178.8 ms ∥ 30.5 -39.9% ∥ -36.5%
E2E ∥ Wall 394.8 ∥ 2.92 s 459.0 ∥ 2.52 s +16.3% ∥ -13.8%
Burst-8 (n=2) TTFT ∥ Makespan 993.5 ms ∥ 2.72 s 556.7 ms ∥ 2.19 s -44.0% ∥ -19.6%
Agg decode 563.9 701.4 tok/s +24.4%
Controls (n=2/1/1) C=1 short ∥ 27.5K 57.9 ∥ 540.7 ms 44.9 ∥ 543.8 ms -22.3% ∥ +0.6%
C=16 agg dec 1,128.5 1,215.3 tok/s +7.7%

Pre-#656 (571a4471) 4x GB10 (gb10-tp4-202612010243, C=12x4, n=3): TTFT 3,281.7->1,923.8 ms (-41.4%), Out 91.0->98.0 (+7.7%), Prefills 96->60 (-37.5%).
Trade-offs: mixed-c32 per-user p50 93.9->71.0, >250 ms gaps 215->434 (>500 ms 13->11, 0 >1 s); <think>-stripping (4.5K-13.7K) skips Turn-1->2 reuse (--scheduler-checkpoint-extra-work-fraction 0.15 retains it).

Evidence

  • Repro: flare run <model> --gpus 0,1,2,3 --max-concurrency 32 --mtp-draft-tokens 7 --mtp-adaptive-verification --mtp-max-verification-token-budget 128 --mtp-adaptive-verification-alpha 1.0 --scheduler-policy balanced --embedding-table-storage disk --embedding-table-cache-size 84GiB --embedding-table-workers 1 --embedding-table-resident-scales --kv-cache-limit memory --prefix-cache-memory 0; FujitsuPolycom/tokbench d6b74524: python3 -m tokbench run http://127.0.0.1:8002 --scenario mixed-c32 --seed 42 --temperature 0.0 (15s/60s/30s). GB10: --gpus 0 --roce-ring --transfer-streams 16 --memory-limit=-12G --embedding-table-cache-size 4GiB.
  • Archive (d74f8bcb, tree 68a4a374 == pushed 9709d496 on 1fbcc3c9): cargo check --release 0 warn (4 crates); helios 1,281/1,793 (6 template skipped), flare 246, flare-cli 245; pytest 834; ruff==0.12.8; check.py 10/10 TLC, 8/8 obs (594,065), 12/12 aux, 2/2 mutations.
  • Limits: SM120 22cac916 vs 5d53040e; GB10 571a4471; scheduling_sim/kani N/A.

Discord: Dooner

…checkpoint_extra_work_fraction

Why

In helios/src/scheduler/checkpoints.rs, scheduler_checkpoint_extra_work_fraction
behaved discontinuously at zero for interior conversation anchors:

- At 0.0, an interior message boundary (raw_anchor < request.prompt_tokens,
  such as prompt_tokens - 3 before a chat template's assistant header) is kept
  only when splitting prefill there adds zero predicted work, falling back to
  request.prompt_tokens otherwise.
- At any nonzero fraction, including the 0.05 default needed by
  allocate_terminal_capture() so multi-turn chats retain post-decode prefix
  checkpoints, the scheduler unconditionally pushed raw_anchor with split_ns: 0
  and uncharged split cost.

On tensor-parallel catalogs where fixed weight-read latency dominates small
prefill buckets (for example, Prefill(128) = 18 ms versus Prefill(512) = 29 ms
on 4x RTX PRO 6000 SM120 TP4), splitting a 453-token prompt at 450 adds an
18 ms 3-token tail (+62% prefill work, more than 12x the 5% budget), doubles
prefill launches per turn, creates decode-drain bubbles, and leaves the split
uncharged in the joint checkpoint budget ledger.

What

- helios/src/scheduler/checkpoints.rs (+95/-60, +35 net non-test production LOC;
  zero unsafe, zero CLI, Protobuf, or model-core ABI changes):
  - Extracted shared helpers split_overhead_ns(...) -> Option<u64> and
    anchor_split_affordable(budget_base, split_ns, spent_ns, fraction) -> bool,
    replaced anchor_split_is_zero_cost with anchor_split_ns(...) ->
    Option<(u64, u64)>, and generalized zero_budget_anchor to
    budgeted_anchor: Option<(usize, usize, usize)> for all fractions >= 0.0.
  - Unified both request_anchor_endpoint and checkpoint_selection_uncached on
    anchor_split_affordable so interior raw_anchor < request.prompt_tokens is
    retained only when split_ns == 0 or extra_spent_ns + split_ns <=
    allowance(initial_prefill_ns.unwrap_or(whole), fraction) (reducing
    identically to split_ns == 0 at fraction == 0.0); otherwise prompt_tokens
    serves as Anchor. Unknown prefill timings preserve best-effort interior
    anchoring under nonzero fractions and prompt-end fallback at 0.0.
  - Charged retained interior anchor split_ns to Cut.split_ns and
    accounting.reserved_ns (debiting extra_spent_ns and
    flare_checkpoint_extra_work_nanoseconds_total on commit, matching
    docs/api.md) while keeping the single anchor snapshot copy uncharged
    (copy_ns: 0), preserving reserved_ns + extra_spent_ns <=
    allowance(initial_prefill_ns, fraction) and sharing allowance headroom with
    earlier optional Message and distinct Endpoint cuts.
  - Filtered optional earlier Message candidates by end < raw_anchor, preserved
    unreached charged Anchor cuts across intermediate multi-chunk steps and
    revoke_unused_anchor_guards() (anchor_guard.is_some() || extra_spent_ns > 0
    || cut.split_ns > 0), and enabled O(1) budgeted_anchor latching in
    promote_request_anchor for all fractions >= 0.0.
- Synchronized present-state documentation (helios/README.md,
  docs/cli-design.md, docs/core-design.md, docs/scheduling-runtime-design.md),
  updated the verification/helios-lifecycle/check.py mutation target and
  checkpoint_lifecycle_tests.rs names, deduplicated permissive test fixture
  setup across tests.rs and boundary_tests.rs, and added unit tests covering
  default 0.05 short-turn fallback, long-prompt retention, anchor-guard
  revocation, Anchor-only multi-chunk split-cost conservation, zero-split
  retention when extra_spent_ns > available, C=16 single-launch batching, and
  request_anchor_endpoint vs checkpoint_selection agreement under spent budget
  and missing/stale latches. Existing signed cores load and serve unchanged.

Result

Zero-re-export flare run A/B measurements (--scheduler-policy balanced, default
0.05, DeepSeek-V4.1-Flash TP4, 132,999 KV pages, 0 errors) on predecessor
commit 22cac91 (identical cold-request anchor-budgeting math) vs 5d53040
on 4x RTX PRO 6000 (SM120 TP4):

- mixed-c32 (C=32): SLO pass rate 9.1% -> 80.3% (+71.2 pp, 8.8x), output
  throughput 1,072.8 -> 1,327.0 tok/s (+23.7%), TTFT p50 4,577 -> 1,920 ms
  (-58.0%), mean decode batch 9.13 -> 17.91 (+96.2%).
- 4x6-turn (22.0K): TTFT p50 297.4 -> 178.8 ms (-39.9%), prefill rounds
  48.0 -> 30.5 (-36.5%), E2E throughput 394.8 -> 459.0 tok/s (+16.3%), wall
  time 2.92 -> 2.52 s (-13.8%).
- Burst-8: burst TTFT p50 993.5 -> 556.7 ms (-44.0%), agg decode 563.9 ->
  701.4 tok/s (+24.4%), makespan 2.72 -> 2.19 s (-19.6%).
- Controls: C=1 short TTFT 57.9 -> 44.9 ms (-22.3%), C=1 32K TTFT 540.7 ->
  543.8 ms (+0.6%), C=16 agg decode 1,128.5 -> 1,215.3 tok/s (+7.7%).
- Pre-NVIDIA#656 (571a447, 0 checkpoints.rs edits to 5d53040) 4x DGX Spark GB10
  C=12x4: TTFT p50 3,281.7 -> 1,923.8 ms (-41.4%), output 91.0 -> 98.0 tok/s
  (+7.7%), prefills 96 -> 60 (-37.5%).
- Trade-offs: higher mixed-c32 concurrency lowers per-user p50 (93.9 -> 71.0
  tok/s) and raises >250 ms gaps (215 -> 434; >500 ms 13 -> 11, 0 >1 s);
  clients stripping <think> blocks on single-chunk 4.5K-13.7K prompts skip
  Turn-1->2 reuse (--scheduler-checkpoint-extra-work-fraction 0.15 retains
  them), and retained interior anchors share allowance headroom with optional
  Message/Endpoint cuts and report split_ns in
  flare_checkpoint_extra_work_nanoseconds_total.

Evidence

Verified on a clean git archive of this commit atop 1fbcc3c via release
cargo check and cargo test (helios --features server and
--features runtime-core,server, flare, flare-cli, heliopause), pytest
(core boundary and scheduling suites), ruff 0.12.8, TLA+ lifecycle models plus
Rust trace conformance (verification/helios-lifecycle/check.py), and
checkpoints.rs mutation verification (check.py --mutations).

Limitations: live flare run A/B benchmarks ran on predecessor commit
22cac91 (identical cold-request anchor-budgeting math; only the
request_anchor_endpoint fallback consistency helper plus docs/test cleanup
changed since) and pre-NVIDIA#656 571a447 on GB10; gated Hugging Face
chat-template tests require FLARE_TEST_TEMPLATE_DIR; scripts/scheduling_sim
and kani are N/A (neither models checkpoint/anchor budgeting).

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
@flare-autobot flare-autobot added area:scheduling Request scheduling, fairness, batching, and speculative-width selection. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. labels Dec 1, 2026
@FujitsuPolycom
FujitsuPolycom marked this pull request as ready for review December 1, 2026 20:45
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 660.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added the triage:review Proposed change needs code review; this does not imply merge readiness. label Dec 1, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The core scheduler change in helios/src/scheduler/checkpoints.rs is lean, well-motivated, and well-tested, backed by strong 4× RTX PRO 6000 A/B results on 22cac916834f. However, generalizing the anchor check from 0.0 to arbitrary fractions left two anchor-decision sites using different budget bases and spent-work rules, and helios/README.md now contradicts the new contract.

  • Blockers: 0 · Should fix: 2 · Subtract/Simplify: 3 · Nits: 3
Walkthrough
  • helios/src/scheduler/checkpoints.rs (:28, 430-442, 444-517, 524-650, 864-886): Replaced anchor_split_is_zero_cost() -> bool with anchor_split_ns(...) -> Option<(u64, u64)>; renamed zero_budget_anchor → budgeted_anchor; generalized interior anchor budgeting to all fractions >= 0.0; charges anchor_split_ns to Cut.split_ns/reserved_ns (copy_ns: 0); preserves unreached charged Anchor cuts across multi-chunk steps and revoke_unused_anchor_guards(); latches budgeted_anchor in promote_request_anchor.
  • helios/src/scheduler/checkpoints.rs (:1530-4655): Updated anchor-split budgeting assertions and added four isolated end-to-end tests (default 0.05 SM120-like catalogs, guard revocation preservation, C=16 single-launch prefill batching, multi-chunk charged-anchor preservation, split_ns == 0 retention when extra_spent_ns > available).
  • helios/src/scheduler/{boundary_tests.rs, checkpoint_lifecycle_tests.rs, policy_tests.rs, tests.rs, vision_window_tests.rs} & helios/src/server/runtime/phase_tests.rs: Opted synthetic flat-cost/high-overhead fixtures out of 0.05 (1.0/0.2/0.1); aligned phase_tests.rs:1540 to prefill_chunk_size so it stays on default 0.05.
  • docs/{cli,core,scheduling-runtime}-design.md (not opened) & verification/helios-lifecycle/check.py: Documented budgeted interior anchor retention and split charging (copy uncharged); updated the budgeted_anchor mutation target in check.py:674-675.
Merge Risk: Medium · up to 22cac91
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@FujitsuPolycom
FujitsuPolycom force-pushed the fix/budgeted-interior-anchor-split branch from 22cac91 to cf744df Compare December 1, 2026 21:57
@FujitsuPolycom

Copy link
Copy Markdown
Contributor Author

Addressed all review items in squashed commit cf744dffef8d (tree 0a77b1c0) (atop 5d53040e, 0 conflicts vs a3c80e19):

  • Should Fix 1 (unify anchor affordability): Extracted anchor_split_affordable (helios/src/scheduler/checkpoints.rs:96), wired both request_anchor_endpoint (:534) and checkpoint_selection_uncached (:620) to pass initial_prefill_ns.unwrap_or(whole) and extra_spent_ns, and added request_anchor_endpoint_matches_selection_with_spent_budget_and_no_latch (:4685).
  • Should Fix 2 (helios/README.md): Updated helios/README.md:372-385 to match the budgeted interior-anchor retention, split-charging, and uncharged-copy contract.
  • Simplify 1 (split-overhead helper): Extracted split_overhead_ns (checkpoints.rs:434) shared by anchor_split_ns (:457) and the optional-candidate loop (:718).
  • Simplify 2 (test fixture helper): Extracted STANDARD_PREFILL_CAPACITIES and permissive_checkpoint_costs in helios/src/scheduler/tests.rs:161-184, reused at tests.rs:3330 and boundary_tests.rs:74,427,559.
  • Simplify 3 (doc deduplication): Tightened docs/scheduling-runtime-design.md:614-623 to a concise summary with a cross-reference to core-design.md#exact-endpoint-capture.
  • Nits 1-3: Pinned assert_eq!(unknown.cuts[0].endpoint, 896) (checkpoints.rs:1677); documented flare_checkpoint_extra_work_nanoseconds_total, budget sharing, and scripts/scheduling_sim/kani N/A in the PR body; renamed stale zero-budget test/mutation strings (checkpoint_lifecycle_tests.rs:309,369,445,494, verification/helios-lifecycle/check.py:673-676).
  • Verification (clean git archive cf744dffef8d (tree 0a77b1c0)): RUSTFLAGS="-D warnings" cargo check --release 0 warnings (helios, flare, flare-cli, heliopause); cargo test --release passed (helios server 1,269 / runtime-core,server 1,780 excl. 6 gated FLARE_TEST_TEMPLATE_DIR, flare 238, flare-cli 239); pytest 832; ruff==0.12.8 0 err; check.py 10/10 TLC + 8/8 Observed (594,065 edges) + 12/12 aux + 2/2 checkpoints.rs mutations killed.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

cf744df cleanly resolves both Should Fix items, all three Subtract / Simplify suggestions, and all three Nits from the prior review (22cac91), keeping the production diff tight (+95/-60, +35 net production LOC in helios/src/scheduler/checkpoints.rs, zero unsafe, zero new flags/ABI). Anchor-split affordability is now shared by request_anchor_endpoint and checkpoint_selection_uncached, all four doc sites agree, and verification spans unit/contract tests, TLA+/Observed lifecycle conformance, mutation testing, and served 4× RTX PRO 6000 A/B workloads.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 3 · Nits: 2
Walkthrough
  • helios/src/scheduler/checkpoints.rs (:28,96-98,434-467,469-547,554-728,883-912): zero_budget_anchor → budgeted_anchor; extracted anchor_split_affordable, split_overhead_ns, anchor_split_ns; both request_anchor_endpoint (:534-539) and checkpoint_selection_uncached (:618-629) now gate on split_ns == 0 || extra_spent_ns + split_ns <= allowance(initial_prefill_ns.unwrap_or(whole), fraction); retained interior anchor split_ns charged to reserved_ns/extra_spent_ns/checkpoint_extra_work_ns with copy_ns: 0; charged unreached Anchor cuts preserved across multi-chunk steps and revoke_unused_anchor_guards() (:563-576); earlier Message cuts filtered by end < raw_anchor (:677); latching generalized in promote_request_anchor (:893-903).
  • Same file (:1556-4771): updated anchor-split budget assertions plus six isolated end-to-end tests — default 0.05 SM120-like catalogs, guard revocation, C=16 single-launch prefill batching, multi-chunk charged-anchor preservation, split_ns == 0 retention when extra_spent_ns > available, and unlatched request_anchor_endpoint vs. checkpoint_selection agreement (:4203-4771).
  • helios/src/scheduler/{tests.rs,boundary_tests.rs,checkpoint_lifecycle_tests.rs,policy_tests.rs,vision_window_tests.rs} & helios/src/server/runtime/phase_tests.rs: added STANDARD_PREFILL_CAPACITIES and permissive_checkpoint_costs (tests.rs:161-184) for synthetic flat-cost fixtures; phase_tests.rs:1542-1546 aligned to prefill_chunk_size to stay on default 0.05; stale zero_budget lifecycle names/messages renamed.
  • docs/{core,cli,scheduling-runtime}-design.md (not opened), helios/README.md, verification/helios-lifecycle/check.py: normative + summary docs synchronized for budgeted interior-anchor retention, split charging, uncharged anchor copy, and unknown-cost behavior; budgeted_anchor mutation target updated in check.py:673-676.
Merge Risk: Medium · up to cf744df
  • Default-path behavior shift (0.05): Interior conversation-anchor retention changes under the shipped default checkpoint_extra_work_fraction = 0.05 — falls back to the zero-split prompt end when an interior split exceeds the extra-work allowance, and charges retained interior splits against the shared allowance (anchor snapshot copy stays uncharged). Trade-offs (mixed-c32 per-user p50 93.9 -> 71.0 tok/s at higher concurrency, >250 ms gap count 215 -> 434, <think>-stripping clients on single-chunk 4.5K–13.7K prompts) are explicitly measured and disclosed.
  • Clean concurrency and hot-path footprint: RequestScheduler mutates via &mut self with a per-plan RefCell<Option<SelectionCache>> (:11-19,138-141,414-432); promote_request_anchor latches budgeted_anchor for O(1) decode fast paths (STRIDE_RUNS == 0); no new locks, wire/ABI changes, or model core re-exports.
  • Expected rebase with open helios: retain measured snapshot cost after expiry and discover unmeasured cost once #655: Open Ready-To-Merge helios: retain measured snapshot cost after expiry and discover unmeasured cost once #655 touches checkpoint_selection_uncached (fresh_duration → measured_duration at :666,1000,1067) and the same four docs; changes are orthogonal and rebase cleanly in either order.
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
Optional cleanups (non-blocking): 3 subtract/simplify · 2 nits

Subtract / Simplify

  1. Remove unreachable configure_policy(0.5) block (checkpoints.rs:4363-4368): default_fraction_anchor_guard_revocation_preserves_charged_anchor_split sets checkpoint_extra_work_fraction: 0.5 then immediately overwrites it with 0.279 at :4375-4380 after only measure(...) calls — no admission or selection in between. Deleting :4363-4368 drops 6 dead lines with no behavior change.
  2. Optional — extract a shared stepped_costs test helper (:4369-4372,4510-4513,4625-4628,4688-4691): four new tests repeat the identical [(128, 100), (256, 110), (512, 200)] prefill loop with only the Snapshot duration varying; a small fn stepped_costs(scheduler: &mut RequestScheduler, snapshot_ns: u64) beside linear_costs (:1151) would deduplicate them.
  3. Optional — trim helios/README.md:374-386 to delegate normative detail: docs/scheduling-runtime-design.md:614-621 summarizes the rule and delegates to docs/core-design.md#exact-endpoint-capture, while the README restates the full normative clauses right before its existing link at :390. A 2–3 sentence summary reduces future doc-drift surface.

Nits

  • Doc line wrap: docs/cli-design.md:699,708 and docs/core-design.md:1457 run ~93–130 columns inside ~85-column wrapped paragraphs.
  • Latch readability: if budgeted_anchor: Option<(usize, usize, usize)> (checkpoints.rs:28) is touched again, a helper method or named struct (BudgetedAnchor) would avoid open-coding the 3-tuple match at :477-482 and :637-640.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@FujitsuPolycom
FujitsuPolycom force-pushed the fix/budgeted-interior-anchor-split branch from cf744df to 9709d49 Compare December 2, 2026 00:22
FujitsuPolycom added a commit to FujitsuPolycom/flare-local-inference that referenced this pull request Dec 2, 2026
…ced streams

Why

To keep decode cadence responsive without mixed prefill-decode graphs, Helios
interleaves smaller prepared prefill chunks with normal decode steps under the
default balanced policy (PolicyConfig::decode_age_price = 0.1 value/ms^2,
specified in docs/scheduling-theory.md and docs/scheduling-runtime-design.md).
On prepared cores whose TERMINAL_PREFILL catalog covers capacities above the
smallest chunk (for example, 256..=16384 alongside PREFILL 128..=16384), long
cold prompts contending with active decoding streams still cause multi-second
decode stalls for three reasons:

1. Cold-discovery lockout: prompts up to max_terminal measure TerminalPrefill(c)
   while leaving smaller non-terminal Prefill(c) unmeasured; add_candidate and
   continuation_candidate skip unmeasured capacities other than natural_fit, and
   funded refresh only revisits measured keys.
2. Monolithic-tail lockout: prefill_requires_terminal_completion_from excludes
   non-terminal Prefill whenever remaining tokens fit within max_terminal,
   forcing any remaining tail up to max_terminal into one TerminalPrefill step.
3. Two-frame prefill pipelining: prefill_step_requires_feedback lets consecutive
   non-terminal Prefill steps fill both transport frames ahead of active
   age-priced decoders and updated output ages.

Pricing unmeasured smaller prefill capacities from already-measured GPU
durations, allowing non-terminal Prefill chunks below max_terminal while active
age-priced streams exist, and requiring feedback between non-terminal chunks
lets ValueRate choose latency-bounded chunks by default under balanced without
new CLI flags, hardcoded capacities, duration ceilings, or per-model branches.

What

Net non-test production change: +319 LOC (+397/-78) across 4 Rust scheduler
files (11 files total, +1,949/-106; zero new CLI/config flags, zero unsafe,
zero hardcoded capacities, zero model-name branches, zero Protobuf or ABI
changes):

- Interpolated GPU-measured prefill estimates and discovery origin
  (helios/src/scheduler/cost.rs, policy.rs): added
  ActionCosts::interpolated_prefill_duration, deriving positive durations
  strictly from measured GPU timings (same-capacity sibling first, else linear
  interpolation between nearest smaller peer or fastest Decode/Speculative/Resume
  floor and nearest strictly larger peer, with order-independent same-kind
  precedence and ScoredPrefill isolation). When age_price > 0.0, unmeasured
  pure-prefill capacities <= nat_fit compete by ValueRate in add_candidate and
  continuation_candidate (excluding oversized padded shapes > nat_fit). In
  select_plan() and phase_plan(), unmeasured interpolated winners return
  PlanOrigin::Discovery directly (preventing displacement by stale refresh
  probes and preventing unmeasured interpolated durations from entering
  PlanOrigin::AcceptanceStart), drain on first run as TimingOrigin::Discovery,
  and record real GPU timings. Solo prefill (age_price == 0.0), service_rates,
  and checkpoint planning are unchanged.
- Chunkable non-terminal Prefill, resize capping, and hot-path caching
  (helios/src/scheduler.rs, policy.rs, service.rs): tightened
  resolve_prefill_kind_from so deferred_prefill never selects non-terminal-
  catalog shapes when needs_terminal is false; updated resize_prefill to select
  from terminal_prefill_catalog whenever request.deferred_prefill is active and
  cap age-priced non-terminal prefill growth at candidate.capacity; added
  prefill_must_complete_terminally_from and
  prefill_requires_terminal_completion_for_age; cached terminal_prefill_window
  and hoisted per-slot prefill planning state across capacities/continuations;
  kept the token_rate == 0.0 non-terminal Prefill fallback in service_rates.
- Active-stream feedback barrier (helios/src/scheduler.rs):
  prefill_step_requires_feedback drains between non-terminal Prefill steps when
  an active Decode/Resume (decode_age_price > 0.0) or terminal-cleanup
  (terminal_age_price > 0.0) stream exists, preserving two-frame pipelining for
  solo prefill and --scheduler-policy throughput (decode_age_price = 0.0).
- Added a GB10 simulator workload (scripts/scheduling_sim/workloads.py), unit
  and mutation-coverage regression tests, updated the deferred-prefill source
  mutation pattern in verification/helios-lifecycle/check.py, and reconciled
  present-state documentation (docs/scheduling-runtime-design.md,
  docs/scheduling-theory.md, helios/README.md). Existing signed cores load and
  serve unchanged.

Result

Live zero-re-export flare run A/B measurements with stock --scheduler-policy
balanced (0.1) and --scheduler-policy throughput (0.0) (zero new CLI flags,
DeepSeek-V4.1-Flash signed cores, zero errors, zero non-finite logprobs):

- 4x RTX PRO 6000 (SM120 TP4, signed core gb202-tp4-202612010626, flare run
  --gpus 0,1,2,3 --max-concurrency 32 --mtp-draft-tokens 7
  --mtp-adaptive-verification --mtp-max-verification-token-budget 128
  --mtp-adaptive-verification-alpha 1.0 --scheduler-policy balanced
  --embedding-table-storage disk --embedding-table-cache-size 84GiB
  --embedding-table-workers 1 --embedding-table-resident-scales
  --kv-cache-limit memory --prefix-cache-memory 0):
  - Standalone pre-NVIDIA#663 (5d53040 vs fdb10bb): on 4 active decoders + staggered
    14K+32K+64K prefills (T_50C, n=2), peak decode gap drops 331.9 -> 260.3 ms
    (-21.6%), mean max gap drops 279.7 -> 246.1 ms (-12.0%), and mean TPOT drops
    6.10 -> 5.55 ms (-9.0%) for +1.8% makespan (3.164 -> 3.221 s). On tokbench
    mixed-c32 (FujitsuPolycom/tokbench d6b74524, C=32, seed 42, temperature 0.0,
    warmup 15s + measure 60s + drain 30s, n=1), >250 ms stalls drop 215 -> 78
    (-63.7%), gap p99 drops 237.2 -> 188.6 ms (-20.5%), and per-user p50 rises
    93.9 -> 99.2 tok/s (+5.7%) for -2.0% output (1,072.8 -> 1,050.8 tok/s). Solo
    27.5K TTFT stays within +0.7% (540.7 -> 544.2 ms, n=1); solo C=1 short (464
    tok, n=2) Trial 0 matches base (58.91 vs 58.58 ms; Trial 1 189.2 ms jitter).
  - Post-NVIDIA#663 stacked SM120 A/B (a3c80e1 base vs NVIDIA#663 vs NVIDIA#660+NVIDIA#661+NVIDIA#663,
    mixed-c32, n=1): standalone NVIDIA#663 raises mixed-c32 gap p99 from 227.3 to
    286.0 ms and >250 ms stalls from 206 to 431; stacking NVIDIA#661 eliminates that
    regression, cutting gap p99 by -29.0% (286.0 -> 203.1 ms, -10.6% below
    pre-NVIDIA#663 base) and >250 ms stalls by -78.9% vs NVIDIA#663 (431 -> 91, -55.8% below
    pre-NVIDIA#663 base) while sustaining 97.8% SLO and 1,354.9 tok/s output.
- 4x DGX Spark GB10 (SM121 TP4, signed core gb10-tp4-202612010243, pre-NVIDIA#656
  571a447, n=3 trials, 12 decoders + 3x19.5K prompts): >1 s decode stalls drop
  24 -> 0 (-100%), p99 ITL drops 1,670 -> 713 ms (-57.3%), max burst gap drops
  1,699 -> 725 ms (-57.4%), trading +2.8% heavy TTFT p50 and -1.3% decode output.
- 4x RTX PRO 6000 throughput control (pre-NVIDIA#656 571a447, --scheduler-policy
  throughput, n=2 across 3 workloads): prefill launches are bit-identical
  (28/24/19) and makespan stays within +0.3% (3.64 vs 3.65 s).
- Host planning & calibrated simulation: 25-bucket dense-catalog plan() is
  4.70x-8.65x faster than base 571a447 (55.8-196.0 us mean). All 21 existing
  workloads remain bit-identical under Python UtilityScheduler.

Evidence

Verified on a clean git archive of this commit atop 1fbcc3c (post-NVIDIA#663 main)
via release cargo check (-D warnings) and cargo test (helios --features server
and --features runtime-core,server, flare, flare-cli, and heliopause), pytest
(core boundary and scheduling suites), ruff 0.12.8 lint, throttled
scripts/scheduling_sim/learning.py smoke and screen presets (known, ttl,
retained-refresh), and TLA+ lifecycle models, Rust trace conformance, and full
source/model mutation testing (verification/helios-lifecycle/check.py
--mutations). Standalone SM120 hardware A/B ran on direct pre-NVIDIA#663 predecessor
fdb10bb (atop 5d53040) and stacked post-NVIDIA#663 SM120 A/B ran on 82f68ea8
(NVIDIA#660+NVIDIA#661+NVIDIA#663 atop a3c80e1), both prior to the resize_prefill
deferred_prefill guard, select_plan() PlanOrigin::Discovery guard, doc sync,
and rebase onto 1fbcc3c.

Limitations: live flare run A/B benchmarks were not re-executed on this exact
rebased SHA atop 1fbcc3c; gated Hugging Face chat-template tests require
FLARE_TEST_TEMPLATE_DIR with gated repo credentials; cargo-kani was not run
because completion-vector and StateView validators are unchanged.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
FujitsuPolycom added a commit to FujitsuPolycom/flare-local-inference that referenced this pull request Dec 2, 2026
…l swap

Why

Under concurrent mixed prefill and decode load (multiple long cold prompts
competing alongside active decoders), prefill valuation in
helios/src/scheduler/policy.rs and scripts/scheduling_sim/utility.py has two
structural defects:

1. Scalar min_i(rem_i) collapse: clamping the decode-batch coalescing horizon
   and expected speculative output across active decoders to min_i(rem_i)
   collapses coalescing credit whenever one active decoder nears completion.
2. Multi-chunk prefill lockstep: ServicePrice::observe credits each
   intermediate prefill chunk, dropping the executing prompt's normalized
   price below untouched peers so long prompts advance in lockstep instead of
   completing sequentially and freeing KV pages.

Averaging bounded per-decoder remaining budgets across active decoders prevents
single-stream collapse without inflating credit past the cohort's remaining
output. Recording planned normalized-entitlement swaps among competing
multi-chunk prefills at submission, projecting queued swaps across depth-2
pipelines, and applying the exchange only at validated completion conserves
aggregate prefill entitlement relative to active decoders while preserving
completion-only accounting and rejection safety.

What

- Helios scheduler (helios/src/scheduler.rs, helios/src/scheduler/policy.rs,
  helios/src/scheduler/service.rs, helios/src/scheduler/utility.rs; +263/-39,
  +224 net non-test Rust production LOC; zero CLI, config, decode, ABI, unsafe,
  or lock changes):
  - Replaced scalar min_i(rem_i) in coalescing_prefill_log_bonus with the
    cohort mean across all active decoders for both speculative expected output
    and the coalescing horizon (bounded by coalescing_horizon_tokens and each
    prefiller's post-prefill output budget).
  - Added ServicePrice::{log_normalized_share, swap_normalized_share},
    best_prefill_chunk, stack-allocated heavy_prefill_donors (zero heap Vec
    allocations), projected_services, and Submission::prefill_share_swap.
  - Multi-chunk pairing activates only when active non-terminal decoders exist
    (excluding retiring Snapshot requests), token_fairness > 0,
    decode_age_price > 0 (inactive under --scheduler-policy throughput), and at
    least two non-terminal, non-prompt_logprobs prefills exceed
    prefill_chunk_size (including deferred TerminalPrefill chunks). Single-chunk
    prefills (remaining <= prefill_chunk_size) are excluded even when the
    highest-throughput chunk c_max is smaller than prefill_chunk_size.
  - Submission records any non-self (recipient, donor) handle pair computed
    from projected prices without mutating stored prices. Depth-2 projection
    (projected_services) applies pending swaps before projecting queued frames.
    observe_service executes swap_normalized_share only after
    observed_duration_ns returns Some, verifying non-error status, positive
    useful_tokens on the recipient, and matching live request handles.
- Python scheduling simulator (scripts/scheduling_sim/utility.py; +105/-7):
  mirrored cohort-mean coalescing and weighted-conserving multi-chunk share
  exchange (ranking and swapping log_price to conserve aggregate sum q_i across
  unequal weights, gated on reference is not None, age_price > 0,
  rate_history == "service", and remaining_prefill > max_prefill_cap, using
  log-space urgency to avoid overflow on tiny durations, and validating
  duration_ms and committed rows before mutating prices or clearing donors).
- Documentation and tests (+127/-35 docs; +784/-0 Rust tests; +245/-0 Python
  tests): placed canonical specification and linear-aging preemption limits in
  docs/scheduling-utility.md, reconciled docs/scheduling-runtime-design.md,
  docs/scheduling-theory.md, and helios/README.md, and added unit tests
  covering packed/unpacked speculative cohort-mean, zero-fairness/throughput
  opt-out, prompt_logprobs exclusion, single-chunk exclusion below
  prefill_chunk_size, arrival-wait aging and tie-breakers, completion-only
  depth-2 pipelining, error/zero-timing invariance, Mixed prefill swaps, and
  weighted Python conservation.

Result

Measured incrementally atop post-NVIDIA#663 main (1fbcc3c):
- All 21 standard simulator workloads in scripts/scheduling_sim/workloads.py
  under both standard and mixed catalogs and both balanced and throughput
  policies show zero regressions (0/21 changed).
- --scheduler-policy throughput (decode_age_price == 0) is byte-for-byte
  unchanged by share swaps across all tested workloads.
- Under balanced policy on concurrent multi-chunk workloads alongside active
  decoders (standard catalog): 2 decoders + 2x16k shifts heavy TTFTs from
  [593.1, 678.4] ms to [383.9, 857.2] ms (first -35.3%, mean 320.1 -> 312.5 ms,
  max_output_gap_ms unchanged at 217.3 ms, output_tok_s -1.9%, decode_age_area
  +6.2%); 4 decoders + 4x16k shifts heavy TTFTs from [1436.0..1637.3] ms to
  [788.0, 970.6, 1968.6, 2200.6] ms (first -45.1%, mean 773.5 -> 744.7 ms,
  max_output_gap_ms 213.0 -> 226.6 ms, output_tok_s -2.4%, decode_age_area
  +7.9%). On mixed catalog: 2 decoders + 2x16k shifts mean TTFT -17.2% (first
  -36.9%, gap unchanged 145.0 ms, out -1.8%); 4 decoders + 4x16k shifts mean
  TTFT -21.1% (first -57.4%, gap unchanged 114.7 ms, out -1.5%). Live
  SM120/SM121 flare run GPU A/B is pending before upstream review.

Evidence

Verified on clean git archive (tree d0c622a) atop 1fbcc3c:
- Merge-tree: 0 conflicts vs upstream/main (1fbcc3c), NVIDIA#660 (9709d49),
  NVIDIA#661 (c588d61), NVIDIA#665 (c5b3923), and composed main + NVIDIA#660 + NVIDIA#665.
- Rust builds & tests: RUSTFLAGS="-D warnings" cargo check --locked --release
  across helios, flare, flare-cli, and heliopause passed with 0 warnings;
  helios --features server --lib 1,284 passed; helios --features
  runtime-core,server --lib 1,796 passed (excl. 6 FLARE_TEST_TEMPLATE_DIR
  tests); flare --lib 246 passed; flare-cli 245 passed (0 failed).
- Python & simulator: pytest (test_core_boundary.py + test_scheduling*.py) 838
  passed; ruff==0.12.8 0 issues; full 21-workload sweep under balanced and
  throughput (standard + mixed catalogs).
- Formal & mutations: 10/10 standalone Java TLC configs, 8/8 observed Rust
  TLA+ traces (594,065 transitions, 0 errors), 12/12 aux tests, 26/26 check.py
  Rust lifecycle mutations + 13/13 TLA+ model mutations + 1/1 DispatchRing
  SlotReuseSafe observed-edge check KILLED (0 survivors), plus 13/13 reachable
  custom Rust PR mutations and 12/12 custom Python PR mutations KILLED.
- Limits: live SM120/SM121 flare run GPU A/B is pending; learning.py --preset
  validate and cargo-kani were not run because their covered code is unchanged.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
FujitsuPolycom added a commit to FujitsuPolycom/flare-local-inference that referenced this pull request Dec 2, 2026
Why

In Helios's prepared-graph scheduler (`helios/src/scheduler/policy.rs`),
the per-prefill-token decode-batch coalescing bonus
(`coalescing_prefill_log_bonus`) prices the steady-state throughput gain
unlocked when queued prefills join an under-batched active decode cohort
over a bounded output-token horizon (`coalescing_horizon_tokens`, default
64.0). Previously, `coalescing_prefill_log_bonus` reduced all active
decoders' remaining output budgets to a single scalar minimum
(`peer_budget = peer_budget.min(rem)`), and the Python reference scheduler
(`scripts/scheduling_sim/utility.py`) used the same scalar minimum for the
coalescing horizon. Under heterogeneous mixed serving, any single active
decoder within one token of its output limit (`rem = 1`) collapsed both the
speculative per-round expected output (`mean_out`) and the coalescing
horizon to 1 token for the entire cohort, eliminating over 98% of the
coalescing incentive even when all other active decoders had large remaining
budgets.

Averaging per-decoder clamped budgets across the active cohort preserves
accurate continuation value when individual requests approach completion
while still shrinking smoothly as the cohort as a whole approaches its
output limit.

What

- In `helios/src/scheduler/policy.rs::coalescing_prefill_log_bonus` (+11/-10
  lines, +1 net Rust production LOC; function visibility unchanged):
  - Replace the scalar minimum `peer_budget` with a bounded per-decoder
    remaining-budget array (`decoder_rems`), where each `rem` is an active
    decoder's remaining output tokens.
  - Compute speculative per-round expected output (`mean_out`) by clamping
    `expected_at(width)` (speculative expected accepted tokens per round,
    evaluated at `eff_width` in the packed branch and `width` in the
    unpacked branch) to each active decoder's `rem` and averaging across
    `decoder_rems[..decoder_count]`.
  - Compute each prefiller's coalescing `horizon` by clamping each active
    decoder's `rem` to `min(coalescing_horizon_tokens, post_prefill)`
    (where `post_prefill` is the prefiller's remaining output budget after
    its first generated token) and averaging across
    `decoder_rems[..decoder_count]`.
- In `scripts/scheduling_sim/utility.py` (+2/-6, -4 net Python LOC): replace
  `peer_budget = min(v.output_budget for v in decoders)` in the coalescing
  horizon calculation with the cohort mean across active decoders, matching
  Helios and the existing cohort-mean `mean_out` in `best_decode_rate`.
- In `docs/scheduling-runtime-design.md`: update the coalescing horizon
  specification to reflect cohort-averaged per-decoder clamping.
- In `helios/src/scheduler/policy_tests.rs` and
  `tests/test_scheduling_utility.py`: add unit tests covering pure Decode,
  packed and full-width Speculative cohorts with a near-EOS (`rem = 1`)
  decoder alongside a long decoder, single-decoder equivalence, and
  zero-decoder / single-token-prefill no-op invariants.

Result

- Single-decoder cohorts and homogeneous-budget cohorts produce identical
  values to the prior minimum formula.
- Mixed cohorts with one near-EOS decoder (`rem = 1`) and one long decoder
  (`rem = 100`) retain a 32.5-token coalescing horizon instead of collapsing
  to 1 token.
- Measured on `DeepSeek-V4.1-Flash` (`tokbench v0.3.0`, seed 42, temp 0,
  base `1fbcc3c990b5`) on 4x NVIDIA RTX PRO 6000 Blackwell (SM120, TP4):
  - Solo `long-context-mixed` (1-rep): +1.8% output (655.4 -> 667.3 tok/s),
    stalled >250ms 28.1% -> 26.3%, -4.0% TTFT p50 (1,510 -> 1,449 ms),
    +2.8 pp SLO (89.8% -> 92.6%).
  - Solo `mixed-c32` (2-rep medians): -0.4% output (1,281.7 -> 1,276.8
    tok/s), TTFT p50 1,425.3 -> 1,390.2 ms (-2.5%), stalled >250ms 11.29%
    -> 11.49%, SLO 93.0% -> 91.1%.
  - Solo `cold-heavy-mix` (1-rep): -3.7% output (541.8 -> 521.8 tok/s),
    -9.0 pp SLO (88.1% -> 79.1%). Default-ON trade-off: keeping coalescing
    active near EOS pulls competing 150K-250K cold prefills ahead of
    decoders without chunk shrinking, raising `agentic_multiturn` TTFT p99
    from 3,323 to 5,144 ms.
  - Combined stack atop open PRs NVIDIA#660, NVIDIA#661, and NVIDIA#665 (attributed to that
    composed stack):
    - `mixed-c32` (2-rep medians): +1.4% output (1,374.6 -> 1,394.2 tok/s),
      overall TTFT p50 1,001.0 -> 921.8 ms (-7.9%), stalled >250ms 4.82% ->
      4.34% (-10.0% rel; spread [3.45%, 5.23%] vs [4.77%, 4.88%]), SLO
      96.5% -> 97.1% (+0.6 pp). Trial-2 (1-trial rep): 233 -> 120 stalls,
      Gap p99 230.2 -> 183.0 ms, `agentic_multiturn` TTFT p50 845 -> 681 ms
      vs `heavy_prefill` 3,239 -> 7,551 ms.
    - `long-context-mixed` (1-rep): output 707.8 -> 692.1 tok/s (-2.2%),
      stalled >250ms 6.0% -> 4.0% (141 -> 94 stalls), SLO 94.1% -> 92.9%.
    - `cold-heavy-mix` (1-rep): output 579.1 -> 574.0 tok/s (-0.9%), stalls
      567 -> 672, cache hit 48.1% -> 52.8% (+4.7 pp).
- Measured on 4x NVIDIA DGX Spark GB10 (SM121, TP4, RoCEv2, signed core
  `gb10-tp4-202612010547`, combined stack atop NVIDIA#660+NVIDIA#661+NVIDIA#665):
  - `mixed-c8` (2-rep medians): output 128.4 -> 129.4 tok/s (+0.8%), TTFT
    p50 1,181 -> 1,118 ms (-5.3%), stalled >250ms 41.8% -> 38.0%, SLO 79.0%
    -> 81.7% (+2.7 pp).
  - `agentic-coding` C=8 (1-rep): output 137.1 -> 135.0 tok/s (-1.5%), TTFT
    p50 1,024 -> 877 ms (-14.4%), Gap p99 1,354 -> 725 ms (-46.5%), >1s
    stalls 35 -> 12 (-65.7%), stalled >250ms 45.4% -> 34.5%, SLO 81.8% ->
    85.7% (+3.9 pp), cache hit 74.6% -> 76.4%.

Evidence

Verified on clean `git archive` of tree `40596880cc64`:
- Rust (`RUSTFLAGS="-D warnings"`): `cargo check --locked --release` across
  `eos`, `selene`, `selene-manager`, `helios` (`runtime-core,server`),
  `flare`, `flare-cli` and `helios` tests -> 0 warnings.
- `cargo test --locked --release`: `helios --features server --lib` (1,283
  passed, 15 ignored), `helios --features runtime-core,server --lib` (1,795
  passed, 47 ignored), `flare --lib` (246 passed, 4 ignored), `flare-cli`
  (245 passed, 3 ignored).
- Python (`pytest`): 853 passed across `tests/preparation/test_core_boundary.py`,
  `tests/test_scheduling*.py`, and `tests/test_design_review_hook.py`.
- Scheduling simulator (`scripts/scheduling_sim`, 21 workloads x {std, mixed}
  x {balanced, throughput}): 84/84 identical traces vs `1fbcc3c9`, 0
  regressions.
- Cohort-mean mutation checks: reverting packed `mean_out`, Rust `horizon`,
  and Python `utility.py` `horizon` back to `.min()` fails tests (3/3
  reachable sites killed; the `!saw_packed` fallback branch in `policy.rs`
  is structurally unreachable because `ActionCosts::duration(Speculative, b, w)`
  queries `packed = b * w != 0` which `packed_round_shapes()` always yields).
- Formal lifecycle verification (`verification/helios-lifecycle/check.py`):
  10/10 TLA+ configs, 8/8 observed Rust traces (594,065 edges) + negative
  `DispatchRing SlotReuseSafe` check, 12/12 aux tests, 13/13 TLA+ model
  mutations, and 26/26 Rust lifecycle mutations killed.
- `git merge-tree --write-tree`: clean against `1fbcc3c9`, NVIDIA#660 (`9709d496`),
  NVIDIA#661 (`c588d610`), and NVIDIA#665 (`c5b39236`).
- Hardware binaries were built from unpushed local build trees `df9a8ebd`
  (solo) and `dbbf65df` (stack) whose `helios/src/scheduler/policy.rs` is
  byte-identical to this commit. SM120 `flare run` flags:
  `--scheduler-policy balanced --max-concurrency 32 --mtp-draft-tokens 7
  --mtp-adaptive-verification --mtp-max-verification-token-budget 128
  --mtp-adaptive-verification-alpha 1.0 --embedding-table-cache-size 84GiB
  --kv-cache-limit memory --prefix-cache-memory 0`. External client harness
  (`tokbench`): `python3 -m tokbench run --url http://127.0.0.1:8002
  --scenario <mixed-c32|long-context-mixed|cold-heavy-mix> -c <32|20|32>
  --warmup <15|15|20> --duration <75|90|120> --drain <20|30|45>
  --repeats <2|1|1> --seed 42 --temperature 0`. Standalone GB10, other GPUs,
  and other model recipes were not benchmarked.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
@lukealonso
lukealonso merged commit 4cc6f2f into NVIDIA:main Dec 2, 2026
3 checks passed
FujitsuPolycom added a commit to FujitsuPolycom/flare-local-inference that referenced this pull request Dec 2, 2026
Why

In Helios's prepared-graph scheduler (`helios/src/scheduler/policy.rs`),
the per-prefill-token decode-batch coalescing bonus
(`coalescing_prefill_log_bonus`) prices the steady-state throughput gain
unlocked when queued prefills join an under-batched active decode cohort
over a bounded cohort-mean output horizon (`coalescing_horizon_tokens`,
default 64.0). Previously, `coalescing_prefill_log_bonus` reduced all
active decoders' remaining output budgets to a single scalar minimum
(`peer_budget = peer_budget.min(rem)`), and the Python reference scheduler
(`scripts/scheduling_sim/utility.py`) used the same scalar minimum for the
coalescing horizon (while already averaging per-decoder expected output
`mean_out` across active decoders in `best_decode_rate`). Under
heterogeneous mixed serving, any single active decoder within one token of
its output limit (`rem = 1`) collapsed both Rust's speculative per-round
expected output (`mean_out`) and both implementations' coalescing `horizon`
to 1 token for the entire cohort, eliminating over 98% of the coalescing
incentive even when all other active decoders had large remaining budgets.

Averaging per-decoder clamped budgets across the active cohort repairs the
Rust-to-simulator `mean_out` parity gap and extends cohort averaging to the
coalescing `horizon`, preserving continuation value when individual requests
approach completion while still shrinking smoothly as the cohort approaches
its output limit.

What

- In `helios/src/scheduler/policy.rs::coalescing_prefill_log_bonus`
  (+16/-18 lines, -2 net Rust production LOC; visibility unchanged):
  - Replace the scalar minimum `peer_budget` with a bounded per-decoder
    remaining-budget array (`decoder_rems`), where each `rem` is an active
    decoder's remaining output tokens clamped by KV sequence headroom
    (`max_sequence_tokens - scheduled_consumed`).
  - Extract local helper `mean_capped(rems: &[usize], cap: f64) -> f64`,
    hoist `expected_at(eff_width)` and `expected_at(width as f64)` out of
    the per-decoder loop, and delete provably dead `.max(1.0)` clamps and
    the unreachable `if horizon > 0.0` branch while keeping the
    `per_token.is_finite() && per_token > 0.0` guard.
  - Compute speculative per-round expected output (`mean_out`, parity with
    `utility.py`) and each prefiller's coalescing `horizon` (clamped to
    `min(coalescing_horizon_tokens, post_prefill)`, where `post_prefill` is
    the prefiller's remaining output budget after its first generated token)
    via `mean_capped`.
- In `scripts/scheduling_sim/utility.py` (+2/-6, -4 net Python production
  LOC): replace `peer_budget = min(v.output_budget for v in decoders)` in
  the coalescing horizon calculation with the cohort mean across active
  decoders, matching Helios and `best_decode_rate`'s existing cohort-mean
  `mean_out`.
- In `docs/scheduling-runtime-design.md`: update the coalescing horizon
  specification to describe the bounded cohort-mean decode horizon and
  per-decoder clamped cohort averaging.
- In `helios/src/scheduler/policy_tests.rs` and
  `tests/test_scheduling_utility.py`: add unit tests covering `[1, 100]`
  and `n=3` `[1, 20, 100]` heterogeneous cohorts, Rust-specific KV-headroom
  clamping, packed and unpacked speculative cohorts (reusing
  `super::rounds::forecast_tokens`), single-decoder equivalence, zero-bonus
  invariants, and an end-to-end `scripts/scheduling_sim` heterogeneous-budget
  test (`max_new_tokens < 64`) under `balanced` (`age_price = 0.1`).

Result

- Single-decoder and homogeneous-budget cohorts produce identical values to
  the prior minimum formula; a `[1, 100]` cohort retains a 32.5-token
  horizon instead of collapsing to 1 token.
- End-to-end `scripts/scheduling_sim` (`catalog()`, `balanced`,
  `age_price = 0.1`, cohort-mean vs prior `min(rem, ph)` horizon):
  - Non-speculative (`short0` `max_new_tokens=8` + 3 long decoders + 4
    queued 4K prefills): makespan 7,779.0 -> 7,734.0 ms (-45.0 ms), mean
    prefill TTFT 266.8 -> 201.0 ms (-24.6%), max prefill TTFT 373.0 ->
    327.0 ms (-12.3%), max output gap 226.0 -> 182.0 ms (-19.5%).
  - Speculative (`short0` `max_new_tokens=32` + 3 long decoders + 5 queued
    4K prefills): makespan 1,912.0 -> 1,878.0 ms (-34.0 ms), mean prefill
    TTFT 293.6 -> 266.4 ms (-9.3%), max prefill TTFT 468.0 -> 432.0 ms
    (-7.7%), max output gap 278.0 -> 212.0 ms (-23.7%).
- Measured on `DeepSeek-V4.1-Flash` (`FujitsuPolycom/tokbench`, seed 42,
  temp 0, base `1fbcc3c990b5`) on 4x RTX PRO 6000 Blackwell (SM120, TP4)
  and 4x DGX Spark GB10 (SM121, TP4, `gb10-tp4-202612010547`):
  - Solo on `1fbcc3c9`: `long-context-mixed` (1-rep) +1.8% output (655.4 ->
    667.3 tok/s), stalls 28.1% -> 26.3%, SLO 89.8% -> 92.6%; `mixed-c32`
    (2-rep) output 1,281.7 -> 1,276.8 tok/s, TTFT p50 1,425 -> 1,390 ms,
    stalls 11.29% -> 11.49%, SLO 93.0% -> 91.1%; `cold-heavy-mix` (1-rep)
    regresses output 541.8 -> 521.8 tok/s (-3.7%) and SLO 88.1% -> 79.1%
    (-9.0 pp, `agentic_multiturn` TTFT p99 3,323 -> 5,144 ms) because
    keeping coalescing active near EOS pulls 150K-250K cold prefills ahead
    of decoders without `NVIDIA#661` chunk shrinking.
  - Atop `NVIDIA#661` (`3d868f84`, primary stall reduction from `NVIDIA#661`):
    `mixed-c32` (2-rep med) output 1,254 -> 1,261 tok/s, stalls 6.65% ->
    5.95%, TTFT p50 1,479 -> 1,439 ms, SLO 89.4% -> 90.5%;
    `long-context-mixed` (1-rep) stalls 16.4% -> 9.8% while SLO dropped
    89.3% -> 82.1% (-7.2 pp); `cold-heavy-mix` (1-rep) output 545.6 ->
    547.8 tok/s, stalls 56.3% -> 55.7%, SLO 81.6% -> 79.8%.
  - Composed 4-PR stack (`NVIDIA#660 + NVIDIA#661 + NVIDIA#665`, where prefix-cache hit-rate
    gains come from `NVIDIA#665` and primary stall cuts from `NVIDIA#661`): SM120
    `mixed-c32` (2-rep) output 1,374.6 -> 1,394.2 tok/s (+1.4%), stalls
    4.82% -> 4.34%, TTFT p50 1,001 -> 922 ms (-7.9%), SLO 96.5% -> 97.1%;
    GB10 `mixed-c8` (2-rep) stalls 41.8% -> 38.0%, TTFT p50 1,181 -> 1,118
    ms, SLO 79.0% -> 81.7%; GB10 `agentic-coding` C=8 (1-rep) stalls 45.4%
    -> 34.5%, TTFT p50 1,024 -> 877 ms, SLO 81.8% -> 85.7%.

Evidence

Verified on clean `git archive` of tree `fe2b8739991e`:
- Rust (`RUSTFLAGS="-D warnings"`): `cargo check --locked --release` across
  `eos`, `selene`, `selene-manager`, `helios` (`runtime-core,server --tests`),
  `flare`, `flare-cli` -> 0 warnings.
- `cargo test --locked --release`: `eos` (12 passed), `selene --features
  test-support` (553 passed), `selene-manager --features test-support`
  (426 passed, 1 ignored), `helios --features server --lib` (1,283 passed,
  15 ignored), `helios --features runtime-core,server --lib` (1,795 passed,
  47 ignored), `flare --lib` (246 passed, 4 ignored), `flare-cli` (245
  passed, 3 ignored).
- Python: `ruff==0.12.8` passed on modified Python files; `pytest` passed
  (854 passed across `tests/preparation/test_core_boundary.py`,
  `tests/test_scheduling*.py`, and `tests/test_design_review_hook.py`,
  including `test_coalescing_heterogeneous_budget_end_to_end_balanced`).
- Fault mutation checks (scratch copies): reverting `scripts/scheduling_sim/
  utility.py` `horizon` to `min(ph, min(output_budget))` failed both
  `test_coalescing_heterogeneous_budget_end_to_end_balanced` and
  `test_coalescing_horizon_averages_active_decoder_budgets`; reverting
  `helios/src/scheduler/policy.rs::mean_capped` to `.min()` failed both
  Rust coalescing unit tests (`2/2` killed).
- `git merge-tree --write-tree`: clean (`rc=0`) against `main` (`4cc6f2fd`),
  `2acc3f3a`, `NVIDIA#660` (`9709d496`), `NVIDIA#661` (`3d868f84`), and `NVIDIA#665`
  (`c5b39236`).
- Hardware binaries were built from earlier equivalent trees `df9a8ebd`
  (solo), `38130855` (on `NVIDIA#661`), and `dbbf65df` (stack) before the
  semantics-preserving `mean_capped` / hoist refactor; final rebase onto
  `main` after `NVIDIA#661` lands and CI/A/B confirmation on the rebased head
  remain pending. Standalone GB10, other GPUs, and other recipes were not
  benchmarked.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
lukealonso pushed a commit that referenced this pull request Dec 2, 2026
Why

In Helios's prepared-graph scheduler (`helios/src/scheduler/policy.rs`),
the per-prefill-token decode-batch coalescing bonus
(`coalescing_prefill_log_bonus`) prices the steady-state throughput gain
unlocked when queued prefills join an under-batched active decode cohort
over a bounded cohort-mean output horizon (`coalescing_horizon_tokens`,
default 64.0). Previously, `coalescing_prefill_log_bonus` reduced all
active decoders' remaining output budgets to a single scalar minimum
(`peer_budget = peer_budget.min(rem)`), and the Python reference scheduler
(`scripts/scheduling_sim/utility.py`) used the same scalar minimum for the
coalescing horizon (while already averaging per-decoder expected output
`mean_out` across active decoders in `best_decode_rate`). Under
heterogeneous mixed serving, any single active decoder within one token of
its output limit (`rem = 1`) collapsed both Rust's speculative per-round
expected output (`mean_out`) and both implementations' coalescing `horizon`
to 1 token for the entire cohort, eliminating over 98% of the coalescing
incentive even when all other active decoders had large remaining budgets.

Averaging per-decoder clamped budgets across the active cohort repairs the
Rust-to-simulator `mean_out` parity gap and extends cohort averaging to the
coalescing `horizon`, preserving continuation value when individual requests
approach completion while still shrinking smoothly as the cohort approaches
its output limit.

What

- In `helios/src/scheduler/policy.rs::coalescing_prefill_log_bonus`
  (+16/-18 lines, -2 net Rust production LOC; visibility unchanged):
  - Replace the scalar minimum `peer_budget` with a bounded per-decoder
    remaining-budget array (`decoder_rems`), where each `rem` is an active
    decoder's remaining output tokens clamped by KV sequence headroom
    (`max_sequence_tokens - scheduled_consumed`).
  - Extract local helper `mean_capped(rems: &[usize], cap: f64) -> f64`,
    hoist `expected_at(eff_width)` and `expected_at(width as f64)` out of
    the per-decoder loop, and delete provably dead `.max(1.0)` clamps and
    the unreachable `if horizon > 0.0` branch while keeping the
    `per_token.is_finite() && per_token > 0.0` guard.
  - Compute speculative per-round expected output (`mean_out`, parity with
    `utility.py`) and each prefiller's coalescing `horizon` (clamped to
    `min(coalescing_horizon_tokens, post_prefill)`, where `post_prefill` is
    the prefiller's remaining output budget after its first generated token)
    via `mean_capped`.
- In `scripts/scheduling_sim/utility.py` (+2/-6, -4 net Python production
  LOC): replace `peer_budget = min(v.output_budget for v in decoders)` in
  the coalescing horizon calculation with the cohort mean across active
  decoders, matching Helios and `best_decode_rate`'s existing cohort-mean
  `mean_out`.
- In `docs/scheduling-runtime-design.md`: update the coalescing horizon
  specification to describe the bounded cohort-mean decode horizon and
  per-decoder clamped cohort averaging.
- In `helios/src/scheduler/policy_tests.rs` and
  `tests/test_scheduling_utility.py`: add unit tests covering `[1, 100]`
  and `n=3` `[1, 20, 100]` heterogeneous cohorts, Rust-specific KV-headroom
  clamping, packed and unpacked speculative cohorts (reusing
  `super::rounds::forecast_tokens`), single-decoder equivalence, zero-bonus
  invariants, and an end-to-end `scripts/scheduling_sim` heterogeneous-budget
  test (`max_new_tokens < 64`) under `balanced` (`age_price = 0.1`).

Result

- Single-decoder and homogeneous-budget cohorts produce identical values to
  the prior minimum formula; a `[1, 100]` cohort retains a 32.5-token
  horizon instead of collapsing to 1 token.
- End-to-end `scripts/scheduling_sim` (`catalog()`, `balanced`,
  `age_price = 0.1`, cohort-mean vs prior `min(rem, ph)` horizon):
  - Non-speculative (`short0` `max_new_tokens=8` + 3 long decoders + 4
    queued 4K prefills): makespan 7,779.0 -> 7,734.0 ms (-45.0 ms), mean
    prefill TTFT 266.8 -> 201.0 ms (-24.6%), max prefill TTFT 373.0 ->
    327.0 ms (-12.3%), max output gap 226.0 -> 182.0 ms (-19.5%).
  - Speculative (`short0` `max_new_tokens=32` + 3 long decoders + 5 queued
    4K prefills): makespan 1,912.0 -> 1,878.0 ms (-34.0 ms), mean prefill
    TTFT 293.6 -> 266.4 ms (-9.3%), max prefill TTFT 468.0 -> 432.0 ms
    (-7.7%), max output gap 278.0 -> 212.0 ms (-23.7%).
- Measured on `DeepSeek-V4.1-Flash` (`FujitsuPolycom/tokbench`, seed 42,
  temp 0, base `1fbcc3c990b5`) on 4x RTX PRO 6000 Blackwell (SM120, TP4)
  and 4x DGX Spark GB10 (SM121, TP4, `gb10-tp4-202612010547`):
  - Solo on `1fbcc3c9`: `long-context-mixed` (1-rep) +1.8% output (655.4 ->
    667.3 tok/s), stalls 28.1% -> 26.3%, SLO 89.8% -> 92.6%; `mixed-c32`
    (2-rep) output 1,281.7 -> 1,276.8 tok/s, TTFT p50 1,425 -> 1,390 ms,
    stalls 11.29% -> 11.49%, SLO 93.0% -> 91.1%; `cold-heavy-mix` (1-rep)
    regresses output 541.8 -> 521.8 tok/s (-3.7%) and SLO 88.1% -> 79.1%
    (-9.0 pp, `agentic_multiturn` TTFT p99 3,323 -> 5,144 ms) because
    keeping coalescing active near EOS pulls 150K-250K cold prefills ahead
    of decoders without `#661` chunk shrinking.
  - Atop `#661` (`3d868f84`, primary stall reduction from `#661`):
    `mixed-c32` (2-rep med) output 1,254 -> 1,261 tok/s, stalls 6.65% ->
    5.95%, TTFT p50 1,479 -> 1,439 ms, SLO 89.4% -> 90.5%;
    `long-context-mixed` (1-rep) stalls 16.4% -> 9.8% while SLO dropped
    89.3% -> 82.1% (-7.2 pp); `cold-heavy-mix` (1-rep) output 545.6 ->
    547.8 tok/s, stalls 56.3% -> 55.7%, SLO 81.6% -> 79.8%.
  - Composed 4-PR stack (`#660 + #661 + #665`, where prefix-cache hit-rate
    gains come from `#665` and primary stall cuts from `#661`): SM120
    `mixed-c32` (2-rep) output 1,374.6 -> 1,394.2 tok/s (+1.4%), stalls
    4.82% -> 4.34%, TTFT p50 1,001 -> 922 ms (-7.9%), SLO 96.5% -> 97.1%;
    GB10 `mixed-c8` (2-rep) stalls 41.8% -> 38.0%, TTFT p50 1,181 -> 1,118
    ms, SLO 79.0% -> 81.7%; GB10 `agentic-coding` C=8 (1-rep) stalls 45.4%
    -> 34.5%, TTFT p50 1,024 -> 877 ms, SLO 81.8% -> 85.7%.

Evidence

Verified on clean `git archive` of tree `fe2b8739991e`:
- Rust (`RUSTFLAGS="-D warnings"`): `cargo check --locked --release` across
  `eos`, `selene`, `selene-manager`, `helios` (`runtime-core,server --tests`),
  `flare`, `flare-cli` -> 0 warnings.
- `cargo test --locked --release`: `eos` (12 passed), `selene --features
  test-support` (553 passed), `selene-manager --features test-support`
  (426 passed, 1 ignored), `helios --features server --lib` (1,283 passed,
  15 ignored), `helios --features runtime-core,server --lib` (1,795 passed,
  47 ignored), `flare --lib` (246 passed, 4 ignored), `flare-cli` (245
  passed, 3 ignored).
- Python: `ruff==0.12.8` passed on modified Python files; `pytest` passed
  (854 passed across `tests/preparation/test_core_boundary.py`,
  `tests/test_scheduling*.py`, and `tests/test_design_review_hook.py`,
  including `test_coalescing_heterogeneous_budget_end_to_end_balanced`).
- Fault mutation checks (scratch copies): reverting `scripts/scheduling_sim/
  utility.py` `horizon` to `min(ph, min(output_budget))` failed both
  `test_coalescing_heterogeneous_budget_end_to_end_balanced` and
  `test_coalescing_horizon_averages_active_decoder_budgets`; reverting
  `helios/src/scheduler/policy.rs::mean_capped` to `.min()` failed both
  Rust coalescing unit tests (`2/2` killed).
- `git merge-tree --write-tree`: clean (`rc=0`) against `main` (`4cc6f2fd`),
  `2acc3f3a`, `#660` (`9709d496`), `#661` (`3d868f84`), and `#665`
  (`c5b39236`).
- Hardware binaries were built from earlier equivalent trees `df9a8ebd`
  (solo), `38130855` (on `#661`), and `dbbf65df` (stack) before the
  semantics-preserving `mean_capped` / hoist refactor; final rebase onto
  `main` after `#661` lands and CI/A/B confirmation on the rebased head
  remain pending. Standalone GB10, other GPUs, and other recipes were not
  benchmarked.

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

area:scheduling Request scheduling, fairness, batching, and speculative-width selection. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants