Repository navigation
Add warmup to SRT server - #146
Merged
Merged
Conversation
timethink
pushed a commit
to timethink/sglang
that referenced
this pull request
Mar 9, 2025
XiaobingSuper
pushed a commit
to XiaobingSuper/sglang
that referenced
this pull request
Jan 23, 2026
…per-layer *.alpha) (sgl-project#146)
vschandramourya
pushed a commit
to vschandramourya/sglang
that referenced
this pull request
Feb 3, 2026
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
rucnyz
added a commit
to rucnyz/sglang
that referenced
this pull request
Jun 2, 2026
T33 rewrote the daemon's value-rule API surface (_value signature,
Action assignments shape, state-JSON consumption layer). t7's 3300
LoC of verify + regression_probe tests the pre-round-9 contract:
_value(u, tier, state) → now _value(u, next_residence, state)
Action.assignments=[(id,Tier)] → now [(id, add_tiers, remove_tiers)]
state['tier_usage'] → removed in T17; state['pool_usage']
nested per-subpool
POST /aginfer/migrate payload → T20 residence-set shape
Running verify.py against current daemon fails at first stub state
JSON with KeyError: 'pool_usage'.
Plan: a full rewrite is its own task (sgl-project#146 created, est. 1-2 days).
The rewrite shouldn't be force-fit into the cleanup queue. README
banner updated to make the stale status loud. verify.py +
regression_probe.py kept as the behavioural-spec reference for the
rewrite (the BEHAVIOUR being verified — tier ordering, ACTING-floor
clamping, shared-aware aggregation, top-k regret — is unchanged by
T33; only the type signatures changed).
verify/README.md row 7 marks STALE.
rucnyz
added a commit
to rucnyz/sglang
that referenced
this pull request
Jun 2, 2026
Same situation as verify/t7 (commit 1d0bf0e): 1569 LoC of verify + regression_probe.py tests pre-round-9 API (u.tier single field; state['tier_usage'] flat; admission_controller's _hbm_occ as Dict[Tier, float]). T33 replaced all three. Running fails on first stub with KeyError: 'pool_usage'. G9 (theta mismatch) noted in the old OPEN WORK is closed by DESIGN round-9 GET/PUT /aginfer/thresholds broadcast — tracked under T22 in PLAN §3. The admission_controller rewrite shares fixtures with the kv_scheduler_value_rule rewrite (same SchedulerState construction helpers, same residence-set Action assertions); both folded into task sgl-project#146 as one piece.
rucnyz
added a commit
to rucnyz/sglang
that referenced
this pull request
Jun 2, 2026
Shared entry point for every deployment-bug-class daemon halt. Pre-
req for all later fail-fast work (T22 thresholds, T34 multi-axis DP,
T23+T37 APPLY_FAILED, HASH_COLLISION); those landers will convert
their bug-class halts to fatal(...) instead of inventing per-site
dump logic.
Implementation: dev/aginfer/daemon/_fatal.py
fatal(reason, **context):
1. Resolves data dir via $AGINFER_DATA_DIR (default
<sglang>/dev/aginfer/data).
2. Writes <data_dir>/forensic/<reason>_<ns_ts>_<pid>.json with
{reason, timestamp_unix/iso, pid, traceback, context}.
- traceback uses format_stack() when no exception is in flight,
so assert-style halts (joint_decide_infeasible, bytes_at) get
a real call site, not an empty trace.
- context is recursively JSON-coerced: dataclasses.asdict for
dataclasses, .value for Enums, model_dump() for pydantic,
repr(...) as the final fallback so unserialisable fields
(live sockets, etc.) do NOT abort the dump.
3. Logs CRITICAL: 'FATAL reason=<r> forensic_file=<p> pid=<pid>'.
4. sys.exit(1).
Never raises. If the data dir is unwritable the helper logs the
full payload in the message instead and still exits 1.
Call sites converted in this commit (the deployment-bug-list members
that already had raise ValueError + the new checks). In
dev/aginfer/daemon/kv_scheduler.py:
- _flatten_per_rank empty list → 'per_rank_empty'
- cross-rank subpool key mismatch → 'subpool_key_mismatch_across_ranks'
- unsupported_tree_cache reported → 'unsupported_tree_cache'
- missing top-level state field → 'missing_state_field' (NEW)
- per-link peak_bw_bps <= 0 → 'peak_bw_bps_non_positive' (NEW)
The deferred call sites (joint_decide_infeasible, bytes_at, hash_-
collision, daemon_attach_lost) land with the features that introduce
them — T34, T23+T37, etc.
Verification: dev/aginfer/verify/t43/verify.py — 9 stages all GREEN
on first pass. Each fatal-path stage subprocess-runs the trigger and
inspects (exit==1, forensic file present at the expected path,
CRITICAL log line names the file, payload contract keys, traceback
captures the call-site frames, repr-fallback for unserialisable
context).
TDD: verify probe was written FIRST and confirmed RED (no _fatal.py
module) before the helper landed. Stage 8 'happy-path sanity (no
fatal)' guards against the new checks bleeding into the green path.
Known stale-test side effect (documented in README RESULTS): the new
missing_state_field guard tightens build_paper_state's entry
contract. Two pre-T17 stub-state probes (kv_scheduler_value_rule,
admission_controller/regression_probe.py) now fatal() at the first
call instead of raising KeyError. Those probes were already broken
relative to T17 — fixing them is task sgl-project#146 scope, not T43's.
Log: verify/t43/results/20260531_t43_initial_pass.log
rucnyz
added a commit
to rucnyz/sglang
that referenced
this pull request
Jun 2, 2026
Post-T36-audit cleanup. Pre-cleanup there were TWO dispatch paths
in KvScheduler._dispatch_migrate — the outbound enqueue (post-T36)
and a legacy sync POST fallback (pre-T36) that was 'preserved for
unit tests not yet migrated'. Maintaining two implementations was
real debt: the dual path doubled the surface area for any change,
and 30 LoC of dead production code lingered.
The pre-cleanup A/B comparison test (using --use-outbound flag)
already produced the head-to-head data we wanted; logs are kept in
verify/t36/results/20260601_t36_compare_run{A_pre,B_post}.log.
With those data on disk we no longer need the flag.
Removed:
daemon/kv_scheduler.py:
- _dispatch_migrate sync POST fallback (~50 LoC of httpx POST
+ response parsing + _record_skips)
- _record_skips method (was a sync-path helper; production no
longer reads sync skipped[]; tests no longer need it)
- http_client / _client / _owns_client constructor param and
fields (no longer dispatch HTTP from this class)
- ensure_client() and aclose() methods (httpx now lives on
the OutboundQueue worker instead)
- import httpx (no longer needed)
daemon/main.py:
- --use-outbound CLI flag (the temporary A/B benchmark knob).
Outbound is now unconditional.
Added contract:
daemon/kv_scheduler.py:
- _dispatch_migrate raises RuntimeError if self.outbound is
None. Production main.py always wires it; tests that
construct KvScheduler directly and call _dispatch_migrate
must pass outbound=OutboundQueue(...).
daemon/event_router.py:
- _apply_failed_handler now ALSO emits a structured
'aginfer_metric event=apply_failed endpoint=... reason=...
action_id=...' line so operators retain a per-event grep
target. Pre-cleanup this signal came from the sync-path
'migrate_skipped' log line that's now gone.
Verify updates (all green):
verify/t36 8/8: A6 trimmed text 'no sync POST' (vacuously true)
verify/t42 20/20: stage B4 rewritten to assert dispatch raises
when outbound is missing (was: '_record_skips no longer
bumps counter' — that contract is now structurally true)
verify/t23_t37 7/7: stage A4 rewritten to capture the new
'event=apply_failed' structured-metric line (was: '_record_
skips MUST NOT bump counter' — also structurally true now);
_build_test_daemon_app now uses production
attach_apply_failed_handler instead of an inline replica
T20 / verify uses sglang and stays untouched (its httpx POSTs are
direct to sglang, not through the daemon's outbound queue).
verify/kv_scheduler_value_rule's regression_probe still references
removed methods (sched.aclose / ensure_client) but that module is
already in sgl-project#146 (stale pre-T17 schema); cleaning it up belongs in
that task.
Logs:
verify/t36/results/20260601_t36_cleanup_pass.log (8/8)
verify/t42/results/20260601_t42_post_cleanup_pass.log (20/20)
verify/t23_t37_apply_failed/results/20260601_t23_t37_post_cleanup_pass.log (7/7)
verify/t36/results/20260601_t36_compare_run{A_pre,B_post}.log
— the A/B benchmark data is preserved on disk so the comparison
can be re-read without re-running
rucnyz
added a commit
to rucnyz/sglang
that referenced
this pull request
Jun 2, 2026
…contract
Legacy 3300-LoC verify+regression_probe targeted the pre-round-9
surface (single Tier per assignment, flat tier_usage dict) and
hadn't passed since T17/T33 landed. Archived under `legacy/` as
behavioral-spec reference; do not delete.
New verify (~700 LoC, 19 stages) pins the post-T33 contract:
A. Schema adapter (build_paper_state)
A0 pool_usage[tier].subpools[sp] → TierUsage
A1 multi-rank per_rank flatten (sum + hash-dedupe)
A2 unknown tier label skipped + logged once
A3 missing required field → fatal(missing_state_field)
A4 partial-zero h_max → fatal(holding_cost_non_positive)
B. Paper §4 decision-set per EventKind
B0 6 kinds × correct D_t (shared / tail / both / empty)
B1 MEMORY_PRESSURE top-k by ascending regret (lowest first)
C. Program-aware λ + p_hat
C0 ACTING program → λ clamped to [1/30, 1/1] both saturating
C1 PAUSED program also inherits ACTING-floor (R2-M1)
C2 alive holder → p_hat=1.0; all-ENDED → hits/age proxy
D. Action / dispatch (post-T33 + post-T36)
D0 Action.assignments is 3-tuple (uid, add_tiers, remove_tiers);
add ∩ remove = ∅
D1 assignments_to_wire → {hash, add_tiers, remove_tiers, action_id}
envelope; action_id unique per item
D2 _dispatch_migrate without outbound → RuntimeError (no silent drop)
D3 _dispatch_migrate routes through OutboundQueue.enqueue_migrate
E. Robustness
E0 /aginfer/state fetch raises → handler bows out, no migrate
E1 LLM_PREFILL empty D_t → no decide(), no migrate
E2 policy declines → no migrate enqueued
F. Idempotence + latency
F0 same state → same Action across 3 repeated decides
F1 decide(1k units) mean+3σ < 25 ms (5 trials)
A3 and A4 spawn subprocesses to exercise fatal() (which calls
os._exit(1)). Closes sgl-project#146.
efschu
added a commit
to efschu/htsglang
that referenced
this pull request
Jul 21, 2026
…er-card) for virtual rigs Predicts the heterogeneous efficiency gap (a virtual 5090 vs 3080) from each card's TDP + compute + membw + uneven-DCP compute-share, BEFORE any run — the energy sibling of the existing throughput roofline. roofline.py: roofline_energy() reuses the throughput roofline for the shared lockstep wall time (1/tok_s, with discounts) and its per-rank byte/FLOP terms; P_op = idle + (TDP-idle) x util, idle = 10% TDP, util = eff x activity/max (decode ~ membw util, prefill ~ FLOPS util) — the pace-setter runs at eff, a faster co-rank that finishes early and waits draws less. Interconnect discount is deliberately NOT folded into util (collective waits lengthen the token time, not the busy power). Co-located ranks aggregate onto one board. New CardEnergy / RooflineEnergyEstimate carry planner-estimate provenance. feasibility.py: attach result.roofline_energy (guarded, degrades to None). webui.py: estimated per-card table under the roofline (same raw-J/tok + wpw(rel) layout as the measured panel, ESTIMATE-tagged amber, honoring the kWh price for estimated ct/1M). Tests (test_roofline_energy.py, +11): per-card J sums to total; hetero gap (5090 wpw > 3080 wpw); util bounded [idle,TDP]; provenance rejected by the measured results store; co-located-rank aggregation. Planner suite 195 -> 206. Calibration vs measured sgl-project#146 (TP=3 5090+2x3080): rig-total watts within ~2% (prefill 614 vs 626 W; decode 831 vs 817 W), the bottleneck 3080 within ~10%, the RTX 5090's absolute watts ~29% high — the fixed idle-FRACTION of TDP over-charges idle on a very-high-TDP card a memory-bound op never loads. That constant (IDLE_FRACTION_OF_TDP) is the one flagged for future calibration; the predicted efficiency RANKING (wpw gap) is directionally correct.
efschu
added a commit
to efschu/htsglang
that referenced
this pull request
Jul 21, 2026
…power anchors) Reusable, frontend-triggerable backend that MEASURES real per-card board power (NVML nvmlDeviceGetPowerUsage) in three states — idle (context alive, no kernel), sustained membw kernel (decode-relevant), sustained GEMM (prefill-relevant) — one card at a time, each isolated in its own CUDA_VISIBLE_DEVICES=<uuid> subprocess. Every watt is attributed to the PHYSICAL card by NVML UUID (torch cuda:0 != NVML idx 0). Busy cards are skipped via nvidia-smi --query-compute-apps; we only ever touch our own subprocesses. Reuses energy.PowerSampler + uneven_perf's bench kernels. Persists a MEASURED artifact (provenance=measured), keyed by UUID + arch, re-runnable. roofline.py's energy estimate now consumes it as an OVERRIDE: a card with a measured entry (matched by UUID, or arch on a live rig) uses its real idle/membw/gemm anchors instead of IDLE_FRACTION_OF_TDP*TDP + a TDP-scaled ceiling; unmeasured/virtual cards keep the heuristic. The IDLE_FRACTION_OF_TDP constant stays ONLY as that fallback. Measured on this rig (5090 sm120 + 2x3080 sm86): idle 47.8/73.2/72.5 W, membw 434/303/290 W, gemm 576/319/319 W. Re-running the sgl-project#148 calibration vs measured sgl-project#146 (FP8-27B TP3): mean |per-card watt error| 17.0% -> 9.6%, and the 5090 decode over-charge +32% -> +0.5% (the measured membw anchor replaces the too-high TDP ceiling). Residual: the util model still slightly under-drives the non-bottleneck 3080s (~10-15%), an honest wall-time-model limit, not an anchor error. Frontend button wiring (trigger + display) is intentionally NOT here — a later webui.py bundle calls measure_all_cards() and renders the table. Tests: test_power_calibration.py (14) — parse/aggregate/persist round-trip, measured-overrides-heuristic by UUID and by arch, unmeasured fallback, manual-source hermeticity, hetero ranking preserved. Full planner suite green (266 passed). GPU-measurement path guarded so import needs no GPU.
efschu
added a commit
to efschu/htsglang
that referenced
this pull request
Jul 22, 2026
…er-card) for virtual rigs Predicts the heterogeneous efficiency gap (a virtual 5090 vs 3080) from each card's TDP + compute + membw + uneven-DCP compute-share, BEFORE any run — the energy sibling of the existing throughput roofline. roofline.py: roofline_energy() reuses the throughput roofline for the shared lockstep wall time (1/tok_s, with discounts) and its per-rank byte/FLOP terms; P_op = idle + (TDP-idle) x util, idle = 10% TDP, util = eff x activity/max (decode ~ membw util, prefill ~ FLOPS util) — the pace-setter runs at eff, a faster co-rank that finishes early and waits draws less. Interconnect discount is deliberately NOT folded into util (collective waits lengthen the token time, not the busy power). Co-located ranks aggregate onto one board. New CardEnergy / RooflineEnergyEstimate carry planner-estimate provenance. feasibility.py: attach result.roofline_energy (guarded, degrades to None). webui.py: estimated per-card table under the roofline (same raw-J/tok + wpw(rel) layout as the measured panel, ESTIMATE-tagged amber, honoring the kWh price for estimated ct/1M). Tests (test_roofline_energy.py, +11): per-card J sums to total; hetero gap (5090 wpw > 3080 wpw); util bounded [idle,TDP]; provenance rejected by the measured results store; co-located-rank aggregation. Planner suite 195 -> 206. Calibration vs measured sgl-project#146 (TP=3 5090+2x3080): rig-total watts within ~2% (prefill 614 vs 626 W; decode 831 vs 817 W), the bottleneck 3080 within ~10%, the RTX 5090's absolute watts ~29% high — the fixed idle-FRACTION of TDP over-charges idle on a very-high-TDP card a memory-bound op never loads. That constant (IDLE_FRACTION_OF_TDP) is the one flagged for future calibration; the predicted efficiency RANKING (wpw gap) is directionally correct.
efschu
added a commit
to efschu/htsglang
that referenced
this pull request
Jul 22, 2026
…power anchors) Reusable, frontend-triggerable backend that MEASURES real per-card board power (NVML nvmlDeviceGetPowerUsage) in three states — idle (context alive, no kernel), sustained membw kernel (decode-relevant), sustained GEMM (prefill-relevant) — one card at a time, each isolated in its own CUDA_VISIBLE_DEVICES=<uuid> subprocess. Every watt is attributed to the PHYSICAL card by NVML UUID (torch cuda:0 != NVML idx 0). Busy cards are skipped via nvidia-smi --query-compute-apps; we only ever touch our own subprocesses. Reuses energy.PowerSampler + uneven_perf's bench kernels. Persists a MEASURED artifact (provenance=measured), keyed by UUID + arch, re-runnable. roofline.py's energy estimate now consumes it as an OVERRIDE: a card with a measured entry (matched by UUID, or arch on a live rig) uses its real idle/membw/gemm anchors instead of IDLE_FRACTION_OF_TDP*TDP + a TDP-scaled ceiling; unmeasured/virtual cards keep the heuristic. The IDLE_FRACTION_OF_TDP constant stays ONLY as that fallback. Measured on this rig (5090 sm120 + 2x3080 sm86): idle 47.8/73.2/72.5 W, membw 434/303/290 W, gemm 576/319/319 W. Re-running the sgl-project#148 calibration vs measured sgl-project#146 (FP8-27B TP3): mean |per-card watt error| 17.0% -> 9.6%, and the 5090 decode over-charge +32% -> +0.5% (the measured membw anchor replaces the too-high TDP ceiling). Residual: the util model still slightly under-drives the non-bottleneck 3080s (~10-15%), an honest wall-time-model limit, not an anchor error. Frontend button wiring (trigger + display) is intentionally NOT here — a later webui.py bundle calls measure_all_cards() and renders the table. Tests: test_power_calibration.py (14) — parse/aggregate/persist round-trip, measured-overrides-heuristic by UUID and by arch, unmeasured fallback, manual-source hermeticity, hetero ranking preserved. Full planner suite green (266 passed). GPU-measurement path guarded so import needs no GPU.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now the first request after the SRT is launched is extremely slow. This is because when the first time running the model forward, the backend needs to allocate intermediate memory, build kernels, etc. Thus, this PR adds a warmup process after the server is ready, just like other serving frameworks do.