Skip to content

Support Deepseek MoE Model - #689

Merged
hnyls2002 merged 1 commit into
mainfrom
deepseek
Jul 21, 2024
Merged

hnyls2002 merged 1 commit into
mainfrom
deepseek

Conversation

@hnyls2002

Copy link
Copy Markdown
Collaborator

No description provided.

@hnyls2002
hnyls2002 merged commit eedc12e into main Jul 21, 2024
@hnyls2002
hnyls2002 deleted the deepseek branch July 21, 2024 10:09
@Ying1123 Ying1123 mentioned this pull request Aug 2, 2024
15 of 29 tasks
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
cen121212 pushed a commit to cen121212/sglang that referenced this pull request Nov 10, 2025
* Update test_utils.py

* Update test_utils.py

* Update test_utils.py
cherryblo added a commit to cherryblo/sglang-project that referenced this pull request Jul 2, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
… it by default

THIS REVERSES THE CONCLUSION OF 7b706e8, WHICH WAS MEASURED WRONG.

That commit reported "SGLANG_FLIP_SEAM_CHUNK_MIB=16 buys nothing under load,
default stays 0" from two boots labelled chunk-OFF and chunk-16. The
chunk-OFF boot was not off. The operator's captured environment
(evidence-662-F4/restore_r2_env.txt:79) has carried
SGLANG_FLIP_SEAM_CHUNK_MIB=8 all along, so the comparison was 8 against 16 --
two values that sit ABOVE the arena commit-chunk floor, where the knob's own
comment already predicted no difference ("B=32 returns EXACTLY the B=16
numbers because the 16 MiB commit chunk's floor binds there"). I measured the
gap the documentation told me was empty and reported it as the answer to a
different question.

Caught by reading the worker's /proc environ after the restore rather than
trusting the boot recipe -- the instrument, not the intention.

THE REAL MEASUREMENT. Three boots of 7b706e8, same argv, same
4x25625-token load, one variable, compared at matched live-slot counts:

  staging reserved per rank      chunk 0            chunk 16        delta
  PP0  131 / ~25.7k slots    1438.25 / 1510.21  1061.53 / 1133.43  -377 (-26%)
  PP1  131 / ~25.7k slots    1229.24 / 1301.20   959.67 / 1031.58  -270 (-22%)
  PP2  131 / ~25.7k slots    1870.46 / 1942.42  1654.92 / 1726.83  -216 (-12%)

A CONSTANT OFFSET, NOT A SLOPE: the same absolute saving at 131 and at 25765
live slots. That is what makes it worth a default -- margin the seam gets
back at every size, not only when it is already comfortable. Corridor law
warnings over the same load fell 6 (chunk 0) -> 3 (chunk 16), and 216-377 MiB
is the same order as the margin the 06:47:48 wedge was short by (PP1 missed
by 293).

THE DEFAULT MOVES 0 -> 8, not 0 -> 16. 8 -> 16 is the comparison that really
does measure nothing (slopes 0.00195 vs 0.00206 MiB/slot, intercepts within
3%), so 8 buys the whole shrink at half the chunk -- and it is the value this
rig has been running by hand, which means the default now matches proven
practice instead of trailing it.

WHAT THIS MEANS BEYOND THIS RIG. The shipped 16-block row-blocking default
was UNREACHABLE in every fresh deployment: `_effective_row_blocks` returns 1
when the arena cannot do span ops, and with no commit chunk it cannot. The
machinery has been inert since it landed, everywhere except boots whose
operator set the env by hand.

TESTS: 2 new cases pinning the default and requiring its measurement table to
travel with it (a default whose provenance is not written down gets reverted
by the next reader of the old "defaults to 0" comment), 8 in that file, 1005
across corridor / phase / purity / seam / margin / kv_backing / memory_pool /
vmm. One unrelated pre-existing failure in test_swa_unittest.py needs a real
accelerator and fails identically on the untouched tree.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
… it by default

THIS REVERSES THE CONCLUSION OF 7b706e8, WHICH WAS MEASURED WRONG.

That commit reported "SGLANG_FLIP_SEAM_CHUNK_MIB=16 buys nothing under load,
default stays 0" from two boots labelled chunk-OFF and chunk-16. The
chunk-OFF boot was not off. The operator's captured environment
(evidence-662-F4/restore_r2_env.txt:79) has carried
SGLANG_FLIP_SEAM_CHUNK_MIB=8 all along, so the comparison was 8 against 16 --
two values that sit ABOVE the arena commit-chunk floor, where the knob's own
comment already predicted no difference ("B=32 returns EXACTLY the B=16
numbers because the 16 MiB commit chunk's floor binds there"). I measured the
gap the documentation told me was empty and reported it as the answer to a
different question.

Caught by reading the worker's /proc environ after the restore rather than
trusting the boot recipe -- the instrument, not the intention.

THE REAL MEASUREMENT. Three boots of 7b706e8, same argv, same
4x25625-token load, one variable, compared at matched live-slot counts:

  staging reserved per rank      chunk 0            chunk 16        delta
  PP0  131 / ~25.7k slots    1438.25 / 1510.21  1061.53 / 1133.43  -377 (-26%)
  PP1  131 / ~25.7k slots    1229.24 / 1301.20   959.67 / 1031.58  -270 (-22%)
  PP2  131 / ~25.7k slots    1870.46 / 1942.42  1654.92 / 1726.83  -216 (-12%)

A CONSTANT OFFSET, NOT A SLOPE: the same absolute saving at 131 and at 25765
live slots. That is what makes it worth a default -- margin the seam gets
back at every size, not only when it is already comfortable. Corridor law
warnings over the same load fell 6 (chunk 0) -> 3 (chunk 16), and 216-377 MiB
is the same order as the margin the 06:47:48 wedge was short by (PP1 missed
by 293).

THE DEFAULT MOVES 0 -> 8, not 0 -> 16. 8 -> 16 is the comparison that really
does measure nothing (slopes 0.00195 vs 0.00206 MiB/slot, intercepts within
3%), so 8 buys the whole shrink at half the chunk -- and it is the value this
rig has been running by hand, which means the default now matches proven
practice instead of trailing it.

WHAT THIS MEANS BEYOND THIS RIG. The shipped 16-block row-blocking default
was UNREACHABLE in every fresh deployment: `_effective_row_blocks` returns 1
when the arena cannot do span ops, and with no commit chunk it cannot. The
machinery has been inert since it landed, everywhere except boots whose
operator set the env by hand.

TESTS: 2 new cases pinning the default and requiring its measurement table to
travel with it (a default whose provenance is not written down gets reverted
by the next reader of the old "defaults to 0" comment), 8 in that file, 1005
across corridor / phase / purity / seam / margin / kv_backing / memory_pool /
vmm. One unrelated pre-existing failure in test_swa_unittest.py needs a real
accelerator and fails identically on the untouched tree.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…, and the cut moves again

THE TERMS. `fixed_overhead_mib` and `transient_mib` were still the sgl-project#485
reference bench's, measured on a different checkpoint.
`residency_terms_from_flight` reads both by pid, provenance-stamped, with the
same refuse-on-absence separation the draft term uses.

FIXED OVERHEAD IS SETTLED BY THE BOOT MARKS: what is resident at
`boot_complete` and is not weights, not the KV pool and not the draft runner --
CUDA context, NCCL init, attention workspace, graph capture, boot tail.
Measured 1610 / 1222 / 1198 MiB.

THE TRANSIENT IS NOT SETTLED, AND THE READER SAYS SO. The serving marks give
the draw over the window they cover: 742 / 440 / 584 MiB over 996 s. Law 31's
worst measured state is 1989-3148 MiB on a 22-minute soak, and a gate fed the
gentler number admitted cuts metal then broke the corridor on, twice. So the
reader returns `observed_transient_mib` with its sample count and window and
hard-codes `covers_worst_load_state=False` -- nothing in the marks proves the
window was a soak. The caller charges `max(observed, worst known)`, so the sgl-project#485
soak value survives as a floor and the gate cannot get cheaper by looking at a
shorter window. That is asserted, not just documented.

THE REFUSAL FIRED ON REAL DATA WHILE THIS WAS BEING WRITTEN. Reading
/spinning/flight_605 without a boot id hit an in-flight boot (pid 3505168, no
`boot_complete` yet) and raised instead of differencing an unfinished boot into
a confident overhead. That is the sgl-project#606 lesson doing its job on live input
rather than in a fixture.

THE CALIBRATION ACCEPTANCE HOLDS: with the measured overhead charged, the
RUNNING configuration still prices feasible (624865 tokens at its own seam
fixed point).

AND THE CUT MOVES AGAIN, WHICH IS THE ANSWER TO THE QUESTION ASKED:

    uncalibrated                       [30,17,17]
    + draft term, seam one-shot        [31,16,17]
    + draft term, seam fixed point     [30,17,17]
    + overhead and transient (this)    [31,16,17]

So [30,17,17] does NOT survive the third calibration. Chasing that oscillation
is what produced the finding that matters:

THE THREE CUTS ARE A TIE, ON BOTH OBJECTIVES. Under full calibration
[30,17,17], [31,16,17] and [29,18,17] score the IDENTICAL KV floor (851960)
and the IDENTICAL makespan (1.0804 s), because stage 2 is the bottleneck on
both in all three and stage 2 is the same in all three. The solver was
returning a deterministic tie-break, not a preference, and reporting either
vector as "the answer" would have implied a distinction the objective cannot
make.

**The load-bearing change is stage 2: 16 -> 17 layers.** The stage0/stage1
split is free. TICKET_602_METAL.md recommends 31,16,17 only because it leaves
the largest margin on stage 1 (0.9221 s against a 1.0804 s bottleneck), and
says plainly that preserving `...,17` is what preserves the result.

Fully calibrated, both cuts at their own seam fixed point:

    incumbent [28,20,16]   624865 tokens
    solved    [31,16,17]   851960 tokens   +227095  (+36.3 %)

WHAT IS STILL NOT CALIBRATED, and it is why the ticket makes the absolute
number a DIAGNOSTIC rather than a gate: `nonlayer_weight_mib` (embedding on
stage 0, lm_head on stage 2) and `state_mib` (the GDN/mamba state pool) are
both still ZERO, and against the recorder the model's per-stage weight total is
short by 1.63x / 1.43x / 1.90x -- the ratio being highest on the LAST stage is
the signature of the missing lm_head. The measured floor will land materially
below 851960 and the boot must not fail for it.

TESTS. Red-first: 7 of 13 fail against d9ed47b; 13 green now. Covered:
overhead differenced from the boot marks; the observed transient as peak over
boot_complete; provenance including the sample count; the reader refusing to
call a short window a worst case; absence raising on no marks, on a boot with
no serving marks, and on a boot with no boot_complete; the running config still
feasible; charging the overhead lowering the floor; the WORST load state being
charged rather than the observed one; and the solve converging, beating the
shipping cut on equal terms and covering all 64 layers.

NO REGRESSIONS: test/registered/unit/planner 2542 passed (2529 before, +13 =
exactly the new cases), 2 failed -- the same pre-existing
test_rejected_evidence_pins pair. Hermetic throughout
(CUDA_VISIBLE_DEVICES="").

TICKET_602_METAL.md added: one boot, one flag, hard acceptance on the corridor,
the arming floor and a rising world MIN; the absolute floor recorded as a
diagnostic; and an explicit scheduling constraint against F4-r4's sgl-project#689 window,
because re-cutting moves per-stage arena and seam geometry -- the quantities his
peer-fit and arena-occupant measurements are about.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…n retraction disproved

Live at 15:00:41:

    seam staging asked the corridor guard for 5 MiB (tp_to_pp): ok=False,
    spendable now 1677 MiB against a need of 1682 MiB. The binding rank's
    inactive-layout arena is the occupant this ask exists to reclaim.

That last sentence is false and I wrote it. 0263713 retracted the premise --
arena_fixed_bytes is the tp_to_pp leg's FUTURE commit cost, not memory held
idle, and rung 3 already releases the real tail after every refill -- and fixed
the label in the staging census. It did not fix this second copy of the same
claim in the guard-ask line, so the receipt kept pointing the next reader at a
reclaim that does not exist. Fixing one of two copies is how a corrected
finding comes back.

Replaced with what ok=False actually means here: under must_reclaim the verdict
is the measured DELTA, so a False says the ladder released nothing and every
registered provider is dry -- which is what the co-reported KV rung line
(current=147456 rows, floor=359770, slack=0) independently shows.

Receipt-only. Committed, NOT deployed: the sgl-project#694 soak is running on de92bb6
and a wording fix does not justify interrupting it.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
… dry run, and the vouch

The notes were written at 3c984ad and had gone stale in three ways.

Chain: 18 commits at e21e87f -> 22 at 5939d0e. Added sgl-project#697
(8fb86ef), sgl-project#441 (5e0fa1e), sgl-project#524 (5939d0e) and the revision-1 docs
commit. Runtime-touching is now 8 of 22, and sgl-project#441 is recorded as NOT runtime
despite its ticket -- it adds a handover script and one test guard.

Target: integration/r2 has moved a73a0d8 -> a157bf1, so the dry run was
re-run rather than carried over. Still zero conflicts. Scope shrank with the
target's advance: 115 -> 109 commits, 129 -> 124 files, +22731 -> +22196.
Merged-tree tests: managers 2093 passed / 0 failed; planner plus the three new
test files 2594 passed / 2 failed. Those 2 are PpWithSpecEvidenceTest in
test_rejected_evidence_pins.py and were re-verified as pre-existing by
aborting the merge and running that file on clean a157bf1 -- same 2 failed,
2 passed. The chain introduces no new failure. Because the target tip moved,
this was re-checked instead of quoting revision 1's finding.

Holds: sgl-project#690 (e21e87f) and sgl-project#697 (8fb86ef) are in F4-r4's bundle, so
revision 1's objection to landing sgl-project#690 ahead of the sgl-project#694 soak is spent; both
lift to group 1 on his boot commit. sgl-project#524 (5939d0e) joins the hold list --
desk-verified only, never on metal, A/B window-gated. sgl-project#685 (5301b94) stays
held on the unmade R' decision.

Vouch (new section 5): the four F4-r4 cherry-picks are byte-identical to the
originals by git patch-id --stable -- f630947/c41645c8c9,
7c58aba/ce6035884d, f1f31d2/658ea3ac11, de92bb6/84b0171fa6 -- so
preferring the originals is free and the only real risk is double attribution.
1073702 is excluded: patch-id 8595e66885ac matches nothing here, it is
diagnostic scaffolding and not mine to vouch for.

Section 6 records that 5af1531 (sgl-project#696) and c738ef5 (sgl-project#689) are F4-r4's
line, not this branch, and are listed only because they lift holds; sgl-project#696 is
what was DoSing the lanes.

Docs only. No merge performed; the dry-run worktree was removed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…t and load

A static window is wrong in both directions -- too short at high load (the
backlog never clears) and too long at low load (decodes wait behind an empty
prefill window). planner/phase_window.py solves it.

## The amortization argument

Over a cycle C = T_p + T_d + flips*F the work arriving in C must clear in C, so
T_p = rho_p*C, T_d = rho_d*C and:

  stability floor   C >= flips*F / (1 - rho)
  latency ceiling   C <= (budget - F) / rho_d

The floor is where the backlog stops growing however the windows are split; the
ceiling is the wait a request meets arriving just after the prefill window
shuts. Flip overhead is flips*F/C, which FALLS as the cycle lengthens, so
throughput always wants a longer window and THE ECONOMIC CHOICE IS THE LARGEST
ADMISSIBLE CYCLE, floored by stability. Not a midpoint, and not a constant.

## The sharpest result, and it reprices sgl-project#690

The two constraints move in OPPOSITE directions with F: the floor rises as
flips*F while the ceiling falls as -F/rho_d. A dearer flip does not merely add
an overhead line -- IT CLOSES THE FEASIBLE BAND FROM BOTH ENDS, and past some F
the band shuts entirely: no window length works, at any split.

On this rig with a 10 s TTFT budget:

   F=2.0 rho=0.30 -> cycle 53.3 s, overhead  7.5%
   F=2.0 rho=0.50 -> cycle 32.0 s, overhead 12.5%
   F=3.0 rho=0.50 -> cycle 28.0 s, overhead 21.4%
   F=4.2 rho=0.50 -> cycle 23.2 s, overhead 36.2%
   any F, rho=0.80 -> REFUSED, floor above ceiling

So at rho=0.8 this rig is already refused at every measured flip cost. Halving
the flip cost does not halve an overhead; it REOPENS CONFIGURATIONS THAT ARE
CURRENTLY IMPOSSIBLE, which is a far stronger argument for sgl-project#690 than "2-4 s is
slow".

## Two refusals, because a policy that quietly does the impossible is worse

- THE SEAM MUST BE ABLE TO ARM. If the layout's free column no longer clears its
  arming floor there is no flip to schedule at any window length. This composes
  directly with sgl-project#707's closed form and the n0 <= 51 depth bound it implies, and
  is checked BEFORE any arithmetic.
- THE DECODE WINDOW MUST BE WORTH ENTERING. Batch formation (sgl-project#689) collapses
  toward size 1 below a queue threshold, so flipping early buys a fraction of
  the decode rate for a full flip cost. That is a floor on the cycle,
  C >= q/(lambda*rho_p), and AT LIGHT LOAD IT BINDS INSTEAD OF STABILITY --
  exactly the regime where a static window over-flips.

## Discipline

Every quantity injected; the rig's figures are calibration data in the test. A
foreign profile (flip 0.05 s, rho 0.8, 2 s budget, 50 arrivals/s) pins the
generality and lands at under 2% overhead, showing the policy is about the
RATIO of flip cost to cycle rather than about this rig.

225 tests green, hermetic (CUDA_VISIBLE_DEVICES=""), ruff + codespell clean.

test_phase_window_677.py (13): the window as a function of flip cost rather
than a constant; the floor diverging toward saturation and refusing rho>=1 as a
capacity problem; the band closing from both ends; a dear flip under load
admitting NO window; the economic choice being the ceiling; overhead falling
with cycle length; halving the flip cost worth more than an overhead line; the
batch floor and the case where it binds instead of stability; the seam refusal;
a pure-prefill regime with no ceiling; a foreign profile; malformed inputs.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 17, 2026
… is not the bug

MEASURED: a TEN-token prompt waited 31.64 s to first token. Sampled every 2 s
across the whole wait -- 0 running, 1 queued, mamba_available 3 (never zero,
0/16 samples), KV hundreds of thousands free -- while the policy logged
"BOTH BLOCKED ... 0 req resident, 22 tok pending". An 8-arm run put every TTFT
between 11.87 s and 62.65 s with NOT ONE arm under 3 s, so this is the serving
floor rather than an outlier.

THE CANDIDATE I CARRIED IN IS DEAD. I suspected the message's pending count and
the simulation's disagreed. They cannot: _idle_locked_inputs receives ONE
pending_tokens argument and passes the SAME value to both _layout_admits calls,
and the policy message prints the same figure. No denominator divergence exists.

AND THE SIMULATION IS CORRECT. Replaying _layout_admits with exactly the
measured numbers returns pp=True / tp=False, so _idle_locked_inputs would have
returned (nothing_can_run=True, target_can_admit=True) and the policy would have
ARMED THE FLIP. The refusal is therefore not a bad rule; the values the
simulation reads in-process differ from what /metrics reports, and no amount of
external sampling can show which -- I already spent a measurement window
proving that. The terms have to be printed where they are computed.

So this commit adds the instrument, not a fix. One line, on the refusal branch
only (both layouts declined), rate limited to 5 s because the state persists
for tens of seconds and healthy rounds must stay silent. It names every term the
verdict was computed from: phase, running_bs, pending_tokens, both layout
verdicts, post_evict_rows, allocator availability, mamba slots, chunk size --
and reports an accessor that RAISES as "RAISED <type>" rather than silently
becoming 0, since a raising probe is one of the two ways slots can read zero.

Tests, hermetic (CUDA_VISIBLE_DEVICES=""):
  test_pp_admits_the_measured_idle_state ..... the complaint in one assertion
  test_tp_correctly_refuses_the_same_state ... counterweight: tp MUST refuse,
      else nothing_can_run is false and the refusal would be correct
  test_the_pair_would_have_armed_the_flip .... (True, True) on the real state
  starved pool / no state slot / no pending work still refuse -- the refusal
      must stay reachable for its genuine causes
  test_double_refusal_prints_every_term
  test_silent_when_the_target_can_admit ...... CAN-FAIL: a diagnostic that
      narrates healthy rounds is noise, and noise is how a signal gets filtered
  -> 8 passed; 118 passed + 7 subtests across 713 + 708 + 701 + 677 + 689 +
     flip-runtime. ruff clean in the changed region.

ADJACENCY, named not absorbed (sgl-project#689 window formation, sgl-project#677 window economics):
both suites are in the run above and pass. This touches neither -- it adds no
branch to the arming decision and changes no input to it.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 17, 2026
…e rules outrank it

Wiring for 59592d6, plus both review findings, plus three precedences the
EXISTING TESTS taught me -- which is the substance of this commit.

FINDING 1, THE TP MIRROR. The tp branch pulled unconditionally on pend>0, so
after an EXHAUSTED release the next TP evaluation would pull straight back and
decode would lose the layout before serving anything: the C2 defect with the
phases swapped, degenerating under both-sides load to max_hold PP rounds, ~0 TP
rounds and TWO seams per cycle -- strictly worse than the timer it replaced.
The pull now yields to a RUNNING decode batch for MIN_DECODE_ROUNDS (2: the
minimum that means "did not preempt mid-batch"), bounded so it cannot become a
new starvation of the prefill side. The degenerate cycle is pinned by test, not
by hope: release at the bound, then assert the pull does NOT come straight back.

FINDING 2, THE COUNTER LIFECYCLE. hold_rounds_so_far was caller-maintained.
next_hold_rounds() is now a pure function resetting on EITHER boundary -- phase
change or pending reaching 0 -- and the defect it prevents is pinned directly:
a stale counter of 8 carried across a phase change releases the very first hold
of the next episode, i.e. the C2 fix evaporates for the arrival that needed it.

FINDING 3, THE REASONS REACH THE LOG. The gate returns its verdict as the
decision's reason, so it travels the same path BOTH BLOCKED already does -- that
is how the boot's acceptance gets read.

THE THREE PRECEDENCES, each taught by a test I broke:
  * sgl-project#688 idle-locked outranks it, exactly as it outranks sgl-project#689 formation:
    holding a layout that can build NOTHING is waiting inside a layout that
    cannot serve.
  * The DRAINED exit outranks it on sgl-project#669's economics: a residual ABOVE one
    chunk stays (which this hold wants anyway), but a SUB-CHUNK residual is
    finishing regardless and holding for it spends a ~2.6 s seam to save a
    fraction of a chunk. sgl-project#669 moved anti-pinning to the starvation cap
    precisely so the drain could exit.
  * The DECODE STARVATION CAP outranks it absolutely. That SLO is the system's
    guarantee that PP can never pin the server; this lever's round bound is
    only a secondary backstop. Vetoing the cap would put a local timer above a
    global guarantee and reintroduce the pinning it prevents.

AND THE GATE IS PP_TO_TP ONLY, as sgl-project#689's is. My first wiring vetoed EVERY arm,
including the idle return leg -- 11 tests red -- because the rules arm for
reasons this lever cannot see. It may only convert the one arm that contradicts
it. Recorded because three exemptions is a shape: if a fourth appears, invert to
an allowlist rather than adding it.

Tests: 22 passed + 17 subtests in the lever file; 221 passed + 24 subtests
across phase-policy, idle-locked-arm, window-formation, admission-intake, 708
and flip-runtime. ruff clean.
vstone-w added a commit to vstone-w/sglang that referenced this pull request Aug 20, 2026
The official sgl-kernel-npu (PR sgl-project#689 merged) registers the compressor op
under torch.ops.npu, not torch.ops.custom.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant