Skip to content

add openai error handler with retry and logger - #148

Merged
Ying1123 merged 5 commits into
mainfrom
openai_error_handler
Feb 6, 2024
Merged

Ying1123 merged 5 commits into
mainfrom
openai_error_handler

Conversation

@ChuyueSun

Copy link
Copy Markdown
Contributor

@ChuyueSun
ChuyueSun requested a review from Ying1123 February 6, 2024 03:32
Comment thread python/sglang/backend/openai.py Resolved
Comment thread python/sglang/backend/openai.py Resolved
Comment thread python/sglang/backend/openai.py Resolved
@Ying1123
Ying1123 merged commit e2bf732 into main Feb 6, 2024
@Ying1123
Ying1123 deleted the openai_error_handler branch February 6, 2024 04:38
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
sgl-project#148 deliverable.  T33 (commit 076d831) + T20 (commit 12728cd)
should have closed the daemon→sglang migrate loop end-to-end.  Smoke
run shows the wire-format gap IS closed (daemon emits new payload,
sglang accepts), but the FIRST combined add+remove action crashes
the scheduler:

  daemon: kv_decide outcome=dispatched action_n=4
          migrate_post status=exception
          (then all subsequent state fetches: ConnectError)
  sglang: ValueError: pool memory leak detected!
          [full] total=65536, available=60254, evictable=5293, ...
          (scheduler subprocess died)

Root cause: T20's apply_aginfer_migrations applies adds first
(write_backup, ASYNC — enqueues D→H copy + records pending lock
in ongoing_write_through) then removes (_evict_component DEVICE +
_cascade_evict, SYNC).  The device buffer is freed while the
background copy is still reading it.  sglang's new
invariant_checker tripwire catches the categories-no-longer-
disjoint state and crashes the scheduler.

Why T20's verify (10 stages PASS) didn't catch it: no stage
exercises the combined add+remove in ONE action.  Stage 1 only
adds DRAM.  Stage 2 starts from [HBM, DRAM] so the write_backup
already completed.  Stage 3 is full DROP (no add).  The canonical
{HBM} → {DRAM} transition that ours_greedy emits routinely is
the missing case.

Created task sgl-project#157 to fix the impl + add a Stage 11 to verify/t20
that drives the bug (RED-first per the TDD process).

verify/e2e_smoke/ is the new home for end-to-end sanity checks of
this kind — runs that exercise the full daemon→sglang chain and
catch issues no single per-Tn verify covers.  README documents
the repro recipe.  Raw daemon + sglang logs under results/.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 21, 2026
…+ FP8-27B TP=3 validation

Reusable measurement module (energy.py): boots a serving config with CUDA
graphs ON, drives a batch-bucket sweep (bs 1/4/16) under two workloads (code +
prose, temp 0), measures prefill/decode tok/s, and integrates NVML board power
per-phase (prefill window vs decode window) -> J/token. Ingests measured rows
(provenance "measured") that pass the results_store guard; the dashboard now
prefers measured over the roofline estimate.

Energy detail:
- Whole-rig energy = SUM of all GPUs' NVML board power (GPU-only; EXCLUDES
  CPU/RAM/PSU losses -- NOT wall-socket power; labelled as such everywhere).
- PER-CARD breakdown from each card's OWN integrated power (never total/N),
  plus per-card compute-share from the uneven-TP ratio (torch->NVML mapped by
  UUID, avoiding the device-order trap). Surfaces the measured compute-share
  vs power-share divergence.
- kWh/1M-token = J/token / 3.6, derived at render time (not stored).
- Cost layer: a ct/kWh price input drives ct-per-1M-token for prefill/decode
  (per workload + per card + total). Shared JS helpers (kwhToCt / jPerTokToCt
  Per1M / kwhBandToCt) so sgl-project#147 (HiCache kWh-saved -> money saved band) and sgl-project#148
  (virtual-rig estimate -> cost) plug into the same conversion.

Schema: ResultEntry gains `workload` + `per_card_energy`.

Validated on Qwen3.6-27B-FP8, TP=3 uneven-DCP (rank-tp-ratio 28591,16464,16464
-> 8:4:4 vision-head split), kv fp8_e4m3, CUDA graphs ON, on the live
5090+2x3080 rig (no P2P). Measured decode: 40 tok/s @bs1 .. 427 tok/s @bs16;
code ~= prose decode (base decode is content-independent, as expected). The
roofline decode estimate for this config was ~25 tok/s @bs1 (interconnect
discount x0.341) vs measured 40 -> the no-P2P/3-card discount is ~1.6x too
harsh but same order of magnitude. Per-card @bs16: RTX 5090 carries 46% of the
compute yet draws the LEAST power (~222 W) while each 27%-share 3080 draws
~240 W -- the Blackwell card is the efficient workhorse; the Ampere 3080s cost
disproportionate energy per unit work. Cost @30 ct/kWh (code): decode 13.7
ct/1M @bs16 .. 147 ct/1M @bs1; prefill ~2-4 ct/1M.

Tests: test_energy.py (per-card integration, ingest-guard, kWh derivation,
launch shape) -- 8 new; full planner suite green (128).
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
…+ FP8-27B TP=3 validation

Reusable measurement module (energy.py): boots a serving config with CUDA
graphs ON, drives a batch-bucket sweep (bs 1/4/16) under two workloads (code +
prose, temp 0), measures prefill/decode tok/s, and integrates NVML board power
per-phase (prefill window vs decode window) -> J/token. Ingests measured rows
(provenance "measured") that pass the results_store guard; the dashboard now
prefers measured over the roofline estimate.

Energy detail:
- Whole-rig energy = SUM of all GPUs' NVML board power (GPU-only; EXCLUDES
  CPU/RAM/PSU losses -- NOT wall-socket power; labelled as such everywhere).
- PER-CARD breakdown from each card's OWN integrated power (never total/N),
  plus per-card compute-share from the uneven-TP ratio (torch->NVML mapped by
  UUID, avoiding the device-order trap). Surfaces the measured compute-share
  vs power-share divergence.
- kWh/1M-token = J/token / 3.6, derived at render time (not stored).
- Cost layer: a ct/kWh price input drives ct-per-1M-token for prefill/decode
  (per workload + per card + total). Shared JS helpers (kwhToCt / jPerTokToCt
  Per1M / kwhBandToCt) so sgl-project#147 (HiCache kWh-saved -> money saved band) and sgl-project#148
  (virtual-rig estimate -> cost) plug into the same conversion.

Schema: ResultEntry gains `workload` + `per_card_energy`.

Validated on Qwen3.6-27B-FP8, TP=3 uneven-DCP (rank-tp-ratio 28591,16464,16464
-> 8:4:4 vision-head split), kv fp8_e4m3, CUDA graphs ON, on the live
5090+2x3080 rig (no P2P). Measured decode: 40 tok/s @bs1 .. 427 tok/s @bs16;
code ~= prose decode (base decode is content-independent, as expected). The
roofline decode estimate for this config was ~25 tok/s @bs1 (interconnect
discount x0.341) vs measured 40 -> the no-P2P/3-card discount is ~1.6x too
harsh but same order of magnitude. Per-card @bs16: RTX 5090 carries 46% of the
compute yet draws the LEAST power (~222 W) while each 27%-share 3080 draws
~240 W -- the Blackwell card is the efficient workhorse; the Ampere 3080s cost
disproportionate energy per unit work. Cost @30 ct/kWh (code): decode 13.7
ct/1M @bs16 .. 147 ct/1M @bs1; prefill ~2-4 ct/1M.

Tests: test_energy.py (per-card integration, ingest-guard, kWh derivation,
launch shape) -- 8 new; full planner suite green (128).
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants