Repository navigation
helios/scheduler: cache per-lane powered survival curves across candidate pricing - #693
Conversation
|
A case file has been opened for 693. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe core optimization is mathematically exact, low-risk, and well-placed in the model-agnostic Helios scheduling layer: caching per-slot powered survival curves across
Walkthrough
Merge Risk: Low · up to
|
a9f7dd7 to
000a6ac
Compare
|
@flare-autobot Addressed all review findings in
Re-verified on
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeCommit
Walkthrough
Merge Risk: Low · up to
|
…date pricing Fixes NVIDIA#547 Based on the diagnosis, patch design, and bounded-evaluation tests by @shieldstar (Discord: shieldstarx) in NVIDIA#547. Why: During a single `RequestScheduler::candidates` or `RequestScheduler::acceptance_probe` pass, request state and speculative forecasts remain immutable (`&self`), yet candidate pricing previously rebuilt each decoding lane's powered survival curve (`powered_curve`) on every priced shape: waiting maintenance steps (`Init`, `Restore`, `Snapshot`, `Vision`) called `lane_value` per decoding lane across every continuation shape and rebuilt separate `curve` and `mixed_curve` locals in `next_progress` for each maintenance batch capacity; `mixed_candidates` rebuilt each decoding lane's curve on every mixed shape; `acceptance_probe` built optimistic curves separately in `packed_round_candidates` and `mixed_candidates`; non-speculative `Decode` pricing built unused curves for 1-token lanes; and `powered_curve`, `prefix_lengths_with_values`, and `host_prefix_ranking` evaluated `f64::powf(p, alpha)` even at the default exponent `adaptive_verification_alpha == 1.0`. In NVIDIA#547, `pow@@GLIBC_2.29` appeared at 5.48% of samples on the `flare-model` worker thread while serving DeepSeek-V4.1-Flash with MTP at `alpha == 1.0` on a GB300 host; as noted in NVIDIA#547, that sample came from a stripped binary on a downstream tree without a call graph, so it does not separate `powered_curve` from other `powf` call sites. Caching each slot's powered survival curve for the duration of a pricing pass and short-circuiting unit widths and unit exponents deduplicates these evaluations without altering any candidate score or scheduling decision. What changed: - Added `CurveCache` in `helios/src/scheduler/policy.rs`, wrapping `[Option<Vec<f64>>; REQUEST_LANES]` with an `optimistic: bool` mode tag checked by `debug_assert_eq!` so ordinary and optimistic survival curves cannot mix in one cache. - Allocated one ordinary `CurveCache` in `RequestScheduler::candidates` and threaded `&mut CurveCache` through `mixed_candidates_with_curves`, `packed_round_candidates_with_curves`, `add_candidate`, `continuation_candidate`, `prerequisite_value`, and `next_progress` (replacing `next_progress`'s separate `curve` and `mixed_curve` locals, and allocating a per-call cache in test helper `phase_plan`). - Replaced uncached `lane_value`, `lane_value_within`, and `lane_value_for_tokens` with `prefill_lane_value` for prefill-only callers, `cached_expected_tokens` (taking `optimistic: bool` and `&mut CurveCache`, returning `f64::from(tokens != 0)` when `tokens <= 1`), `cached_lane_value`, `cached_lane_value_within`, and `cached_lane_value_for_tokens_within` (retaining `#[cfg(test)] lane_value_for_tokens_within` for existing tests and `expected_speculative_tokens` for submitted-step accounting in `helios/src/scheduler.rs` and `resize_prefill`). - Updated `RequestScheduler::acceptance_probe` in `helios/src/scheduler/learning.rs` to allocate one optimistic `CurveCache::new(true)` and share it across `packed_round_candidates_with_curves` and `mixed_candidates_with_curves`; gated standalone `mixed_candidates`, `packed_round_candidates`, and `optimistic_tokens` under `#[cfg(test)]`. - In `helios/src/scheduler/rounds.rs`, short-circuited `width <= 1` in `proposal_forecast_tokens` (used by `expected_speculative_tokens` and `#[cfg(test)] optimistic_tokens`) and `limit <= 1` in `packed_round_candidates_with_curves`, and added the `alpha == 1.0` fast path to `powered_curve` (avoiding a second `Vec<f64>` allocation), `prefix_lengths_with_values`, and `host_prefix_ranking`. - Added a test-only thread-local `CURVE_EVALUATIONS` counter in `helios/src/scheduler/rounds.rs` and four unit tests in `helios/src/scheduler/policy_tests.rs` checking evaluation bounds (including `candidates`, ordinary and optimistic `mixed_candidates`, optimistic `packed_round_candidates`, and `acceptance_probe`) and bit-identical lane values, candidate scores, and plans against uncached `speculative_curve` + `powf(alpha)` at `alpha = 1.0` and `0.6`. Claimed result: Behavior-preserving curve-evaluation deduplication refactor. Within a `candidates()` pass (ordinary mode) or an `acceptance_probe()` pass (optimistic mode), powered survival curve evaluations are bounded to at most one per eligible lane priced for speculative decoding (active decoding lanes and non-terminal prompt-endpoint `Snapshot` lanes resuming into `Decode`) whose speculative width exceeds 1, and zero for non-speculative `Decode` passes and 1-token lanes, while preserving bit-identical lane values, candidate scores, and scheduling decisions for finite survival probabilities in `[0.0, 1.0]`. Outside `candidates()` and `acceptance_probe()`, `select_plan()` still evaluates per-lane curves in `lane_values()` (`service_rates` in `helios/src/scheduler/service.rs` and `coalescing_prefill_log_bonus` in `helios/src/scheduler/policy.rs`) and on `resize_prefill` (`helios/src/scheduler/policy.rs`). No standalone GPU serving latency or throughput improvement is claimed. Supporting evidence and limitations (Linux x86_64 CPU, rebased on `origin/main` `f705086b`): - `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server` (with frontend templates prepared via `tests/frontend/prepare_templates.py`): 1918 library and 62 integration tests passed, 0 failed (86 ignored: 49 lib, 37 integration), plus the 4 new scheduler tests passed in debug mode with `CurveCache` `debug_assert_eq!` enabled. - `cargo clippy --locked --manifest-path helios/Cargo.toml --features runtime-core,server --lib --tests`: 0 warnings on modified scheduler code. - `cargo test --locked --release --manifest-path flare/Cargo.toml`: 247 library and 8 integration tests passed, 0 failed (4 ignored). - `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: 224 unit and 26 integration tests passed, 0 failed (3 ignored). - Scheduling simulator (`pytest` over `tests/test_scheduling_sim.py`, `test_scheduling_oracle.py`, `test_scheduling_utility.py`, `test_scheduling_continuation.py`, `test_scheduling_timing.py`, `test_scheduling_learning_policy.py`, `test_scheduling_learning_run.py`, and `test_scheduling_learning_experiments.py`): 837 passed, 0 failed. - Formal lifecycle verification (`python3 verification/helios-lifecycle/check.py`, TLC2 2.19): all TLA+ models, all 9 Rust trace-conformance suites, and all 12 guard tests passed. - Limitations: no standalone GPU serving benchmark on an exported core was run, no checked-in CPU microbenchmark harness is included, and Kani sequential proofs were not run (`cargo-kani` is not installed on the test host; existing Kani harnesses do not cover `helios/src/scheduler/`). Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com> Signed-off-by: Luke Alonso <lalonso@gmail.com> Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
000a6ac to
ddf3be8
Compare
Why: Upstream `main` (`be4092d7`) introduced per-lane survival-curve caching (`CurveCache` and `prefill_lane_value`, #693) and core-parameter admission validation (`plan_admission_with_core_parameters` without an explicit definition slice, #621), conflicting with this branch in `policy.rs`, `policy_tests.rs`, and `runtime.rs`. Separately, in `PrefillCostModel::fit` (`helios/src/scheduler/cost.rs`), treating `pos_u_max == 0.0` as `wide_or_full_positive` caused a `GraphKind::Mixed` model that had observed only `zero_fill` (`work == 0`) samples to emit `constant_nanos = Some(decode_ns)`, under-pricing full-chunk prefills and inflating `service_rates` until a positive-fill step ran. What changed: - `helios/src/scheduler/cost.rs`, `docs/scheduling-runtime-design.md`: removed `pos_u_max == 0.0` from `wide_or_full_positive` so a `zero_fill`-only model never emits `constant_nanos`; added `PrefillPredictor::has_positive_fill()`; returned `0` (unmeasured) from `PrefillPredictor::predict(work > 0, _)` and `full_chunk_affine()` when `pos_u_max <= 0.0`; gated `with_borrowed_context_slope` on `pos_u_max > 0.0`; retained positive `decode_ns` in `Estimate::nanos` from `PrefillCostModel::observe` when only `zero_fill` samples exist; and added unit coverage in `cost.rs` and `policy_tests.rs`. - `helios/src/scheduler/{policy.rs,policy_tests.rs}`: resolved conflicts against #693 by threading `curves: &mut CurveCache` through `add_candidate`'s `eval_mixed` and `mixed_candidates_with_curves`'s `score_decoders`, switching prefill scoring to `prefill_lane_value`, gating oversized unmeasured-prefill pruning on `!has_positive_fill()`, and retaining both test suites. - `helios/src/server/runtime.rs`: resolved the #621 admission-plan conflict in `begin_pool_lookup` using `incoming.spec(false)` with the two-argument `plan_admission_with_core_parameters` signature. Claimed benefit and result: PR #729 merges cleanly onto `origin/main` (`be4092d7`) while preserving #693's per-lane `CurveCache` reuse across `GraphKind::Mixed` candidates, and a `zero_fill`-only `GraphKind::Mixed` entry accurately prices decode-only steps (`work == 0`) without under-pricing positive-fill chunks or inflating prefill `service_rates` (verified by `zero_fill_only_mixed_model_does_not_inflate_prefill_service_rates` and `mixed_cost_model_tracks_zero_fill_partial_fill_deep_context_and_peer_slope`). Supporting evidence: - `python3 verification/helios-lifecycle/check.py --mutations`: 10/10 TLA+ models passed, 623,976 observed Rust transitions verified (3,865 against `Lifecycle.tla`, 431 against `AsyncTransfer.tla`), and 60/60 mutations detected (19 TLA+, 41 Rust). - Rust release test suites: `helios --lib` 1,966 passed (49 ignored; 6 HF template tests require `prepare_templates.py` downloads), `helios --test '*'` 59 passed (39 checkpoint-gated ignored; 3 Gemma template tests require downloads), `flare` 255 passed (4 ignored), `flare-cli` 254 passed (3 ignored), and 4/4 live SM120 GPU KV codec tests on idle GPU 5. - Python pytest (`CUDA_VISIBLE_DEVICES=3 FLARE_RUN_CUDA_TESTS=1`): 1,120 passed (`tests/test_scheduling_*.py`, `tests/test_design_review_hook.py`, `tests/cli`, `tests/direct/test_scheduler.py`, `tests/test_kv_codec.py`). - Unrun locally: `cargo-kani` (running in CI) and the 9 HF chat-template tests requiring `prepare_templates.py` downloads. Design-Signed-Off-By: Antigravity (Gemini 3.1 Pro); design-review=2e5b Signed-off-by: Luke Alonso <lalonso@gmail.com>
Fixes #547
Based on the diagnosis, patch design, and bounded-evaluation tests by @shieldstar (Discord:
shieldstarx) in #547.Why
During a single
RequestScheduler::candidatesorRequestScheduler::acceptance_probepass, request state and speculative forecasts remain immutable (&self), yet candidate pricing previously rebuilt each decoding lane's powered survival curve (powered_curve) on every priced shape:Init,Restore,Snapshot,Vision) evaluatedlane_valuefor every decoding lane across every continuation shape incontinuation_candidate, andnext_progressbuilt separatecurveandmixed_curvelocals for each maintenance batch capacity.mixed_candidatesrebuilt each decoding lane's curve on every mixed shape inmixed_catalog, andacceptance_probebuilt optimistic curves separately inpacked_round_candidatesandmixed_candidates.Decodepricing built curves for 1-token lanes even though a lane of width 0 or 1 always has expected tokens equal tof64::from(tokens != 0).powered_curve,prefix_lengths_with_values, andhost_prefix_rankingevaluatedf64::powf(p, alpha)for every survival entry even at the defaultadaptive_verification_alpha == 1.0, where finite survival probabilities in[0.0, 1.0]satisfyp.powf(1.0) == p.In #547,
pow@@GLIBC_2.29appeared at 5.48% of samples on theflare-modelworker thread while serving DeepSeek-V4.1-Flash with MTP atalpha == 1.0on a GB300 host. As noted in #547, that sample came from a stripped binary on a downstream tree without a call graph, so it does not separatepowered_curvefrom the scheduler's otherpowfcall sites. Becausecandidatesandacceptance_probeborrow&selfwithout mutating slot or forecast state, each slot's powered survival curve can be computed once per pricing pass and reused across all priced shapes without changing any candidate score or scheduling decision.What changed
CurveCachestruct inhelios/src/scheduler/policy.rswrapping[Option<Vec<f64>>; REQUEST_LANES]and anoptimistic: boolmode tag checked bydebug_assert_eq!so ordinary and optimistic curves cannot mix in one cache.CurveCacheinRequestScheduler::candidatesand threaded&mut CurveCachethroughmixed_candidates_with_curves,packed_round_candidates_with_curves,add_candidate,continuation_candidate,prerequisite_value, andnext_progress(replacingnext_progress's separatecurveandmixed_curvelocals, and allocating a per-call cache in test helperphase_plan).lane_value,lane_value_within, andlane_value_for_tokenswithprefill_lane_value(for prefill-only callers),cached_expected_tokens(takingoptimistic: booland&mut CurveCache, returningf64::from(tokens != 0)whentokens <= 1),cached_lane_value,cached_lane_value_within, andcached_lane_value_for_tokens_within, while retaining#[cfg(test)] lane_value_for_tokens_withinfor existing unit tests andexpected_speculative_tokensfor submitted-step accounting (helios/src/scheduler.rs) andresize_prefill.RequestScheduler::acceptance_probeinhelios/src/scheduler/learning.rsto allocate one optimisticCurveCache::new(true)shared acrosspacked_round_candidates_with_curvesandmixed_candidates_with_curves, and gated standalonemixed_candidates,packed_round_candidates, andoptimistic_tokensunder#[cfg(test)].helios/src/scheduler/rounds.rs:width <= 1inproposal_forecast_tokens(used byexpected_speculative_tokensand#[cfg(test)] optimistic_tokens) andlimit <= 1inpacked_round_candidates_with_curves.adaptive_verification_alpha == 1.0fast path topowered_curve(avoiding a redundantVec<f64>allocation),prefix_lengths_with_values, andhost_prefix_ranking.CURVE_EVALUATIONScounter inhelios/src/scheduler/rounds.rsand four unit tests inhelios/src/scheduler/policy_tests.rs.Claimed result
Behavior-preserving curve-evaluation deduplication refactor. Within a
candidates()pass (ordinary mode) or anacceptance_probe()pass (optimistic mode), powered survival curve evaluations are bounded to at most one per eligible lane priced for speculative decoding (active decoding lanes and non-terminal prompt-endpointSnapshotlanes resuming intoDecode) whose speculative width exceeds 1, and zero for non-speculativeDecodepasses and 1-token lanes, while preserving bit-identical lane values, candidate scores, and scheduling decisions for finite survival probabilities in[0.0, 1.0].Scope note: outside
candidates()andacceptance_probe(),select_plan()still evaluates per-lane curves inlane_values()(service_ratesinhelios/src/scheduler/service.rsandcoalescing_prefill_log_bonusinhelios/src/scheduler/policy.rs) and onresize_prefill(helios/src/scheduler/policy.rs). No standalone GPU serving latency or throughput improvement is claimed from this change.Supporting evidence and limitations
Verified on head
ddf3be86overorigin/main(f705086b) on Linux x86_64 CPU:cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server(with frontend templates prepared viatests/frontend/prepare_templates.py): 1918 library and 62 integration tests passed, 0 failed (86 ignored: 49 lib, 37 integration), including:waiting_init_prices_each_decoding_lane_curve_once_per_candidate_passmixed_candidates_price_each_decoding_lane_curve_once_per_call(ordinary and optimistic)decode_only_candidate_pass_builds_no_forecast_curvecached_lane_pricing_matches_uncached_for_unit_and_fractional_alpha(checks bit-identicalscore.to_bits()parity against uncachedspeculative_curve+powf(alpha)andoptimistic_tokensatalpha = 1.0andalpha = 0.6, covering widths 0, 1, 2, 4, 8, a 1-remaining-token lane, waitingInit, ordinary and optimisticMixed, packedSpeculative, shared optimisticCurveCachereuse inacceptance_probe, tie-breaking between identical decoding lanes, and selectedplan()winners)cargo test --locked --manifest-path helios/Cargo.toml --lib ...): 4 passed, 0 failed withCurveCachedebug_assert_eq!enabled.cargo clippy --locked --manifest-path helios/Cargo.toml --features runtime-core,server --lib --tests: 0 warnings on modified scheduler code.cargo test --locked --release --manifest-path flare/Cargo.toml: 247 library and 8 integration tests passed, 0 failed (4 ignored).cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 224 unit and 26 integration tests passed, 0 failed (3 ignored).pytestovertests/test_scheduling_sim.py,tests/test_scheduling_oracle.py,tests/test_scheduling_utility.py,tests/test_scheduling_continuation.py,tests/test_scheduling_timing.py,tests/test_scheduling_learning_policy.py,tests/test_scheduling_learning_run.py, andtests/test_scheduling_learning_experiments.py: 837 passed, 0 failed.python3 verification/helios-lifecycle/check.py(TLC2 2.19): all TLA+ models, all 9 Rust trace-conformance suites, and all 12 guard tests passed.cargo-kaniis not installed on the test host (existing Kani harnesses do not coverhelios/src/scheduler/).Discord: jcartu