Skip to content

Refactor decoding logprob and add completion_tokens_wo_jump_forward - #189

Merged
comaniac merged 3 commits into
mainfrom
cody/usage
Feb 15, 2024
Merged

comaniac merged 3 commits into
mainfrom
cody/usage

Conversation

@comaniac

@comaniac comaniac commented Feb 14, 2024 •

Copy link
Copy Markdown
Contributor
  • Introduce return_text_in_logprobs to GenerateReqInput, so that even /generate could return token logprob in (text, logprob) format instead of (token id, logprob).
  • Fix a bug in OpenAI completion.
  • Introduce completion_tokens_wo_jump_forward to metric.

@comaniac comaniac changed the title Add completion_tokens_wo_jump_forward Refactor decoding logprob and add completion_tokens_wo_jump_forward Feb 14, 2024
@comaniac
comaniac merged commit 63ba630 into main Feb 15, 2024
@comaniac

Copy link
Copy Markdown
Contributor Author

I merged this first for some further testing. Feel free to comment if you see any issue and I'll fix them ASAP.

@comaniac
comaniac deleted the cody/usage branch February 15, 2024 18:54
vschandramourya pushed a commit to vschandramourya/sglang that referenced this pull request Feb 3, 2026
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 7, 2026
…est gaps

Adversarial audit found one real BUG + test-depth/coverage gaps.

* B1 (BUG, fixed) — the SESSION_END handler ran
  `await kv_scheduler.handle()` UNGUARDED before the F5 PUT.
  handle() only wraps its own fetch_state/build_paper_state, NOT
  decide()/_dispatch_*; a downstream policy/dispatch error therefore
  propagated out of the handler and SKIPPED the PUT {ENDED} — sglang
  would never learn the program ended.  My docstring falsely claimed
  handle() "swallows its own downstream errors."  Fix: wrap step 2
  in try/except (log + continue); the F5 state-transition + PUT is
  the contract, the migrate is best-effort on top.  New stage C2
  (RED before the fix) pins it.
* G2 (gap) — new stage B3: the p_hat ENDED carve-out fires on EVERY
  event (it changed a core scoring path).  Drives a MEMORY_PRESSURE
  event against a leftover ENDED-held unit → workload-prior p_hat +
  top-k demote candidate.  Guards the cross-event blast radius.
* G1 (gap, resolved by removal) — dropped the reframed E0/E1 "live
  unit is kept by the scorer" narrative.  It's a non-scenario for
  SESSION_END (a live program's units are never in p's D_t) and the
  absolute keep-vs-demote threshold is value-rule calibration, not
  sgl-project#187.  F0 now states the real survival mechanism: D_t EXCLUSION
  (holders ⊋ {p}), which is also why sgl-project#187 cannot over-evict.
* G3 (coverage honesty) — README previously cited integration_stress
  as the SESSION_END regression; it has ZERO SESSION_END references.
  Corrected to state plainly there is no e2e for the migrate (the
  wire is covered by T20/T33; the decision is daemon-pure here).
  Tracked: sgl-project#191 (e2e flavor), sgl-project#189 (TOOL_CALL session_tail vs
  exclusive, pre-existing N2), sgl-project#190 (tracker ENDED GC, pre-existing
  N3).

verify/t187: 12 stages (10 + B3 + C2), all green.  Regression:
T41 (17) / kv_scheduler_value_rule (19) / T40 all green.
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 7, 2026
…e is right)

Resolves the sgl-project#187-audit discrepancy: the code's `_units_for_session`
uses the EXCLUSIVE form (holders == {p}) for TOOL_CALL_START/END,
while DESIGN §7's `session_tail` was defined INCLUSIVE (p ∈ holders).
User decision: the CODE is correct — fix DESIGN to match.

Rationale: a TOOL_CALL is a PER-PROGRAM event, so it nominates only
p's PRIVATE units (the ones whose value changed when p went idle).  A
SHARED platform/tool_def prefix's value did NOT change because one of
its many holders went tool-bound — the others still need it — so it
must not be a demote candidate on one program's tool call.  Shared-
prefix residence is driven by SESSION_ARRIVAL (preload) +
MEMORY_PRESSURE (global top-k).  Outcomes are identical either way
(a shared unit's multi-holder p_hat=1.0 keeps it), but exclusive is
the cleaner semantics AND keeps the SUB_DISPATCH union
(`_units_for_session + _shared_prefix_units`) disjoint — inclusive
would double-list the caller's shared units.

* DESIGN §7: `session_tail` redefined to the exclusive predicate
  (`session_ids == {sid}`) with the per-program rationale; TOOL_CALL /
  SUB_DISPATCH table rows clarified (disjoint union).
* kv_scheduler `_units_for_session` docstring: cites the sgl-project#189
  reconciliation.
* verify/kv_scheduler_value_rule B0b (new): pins TOOL_CALL excludes a
  shared prefix the caller holds AND the SUB_DISPATCH D_t is a
  duplicate-free disjoint LIST (b0 set()s dups away; B0b catches them).

Doc + test only — no behavior change (code was already exclusive).
Regression: value_rule (20) + t187 green.
efschu pushed a commit to efschu/htsglang that referenced this pull request Jul 26, 2026
…G_FP8_FUSED_GEMV off-switch

The sgl-project#179 fused kernel fires only for block-scaled fp8, so on the very card the
dequant fallback exists for it was never compiled: the 4B checkpoint on the
2080 Ti is compressed-tensors strategy=channel (read from its safetensors
headers: 128 fp8 2-D weights, every scale (N,1)). A w8a8 config that misses the
sm89 floor is routed to CompressedTensorsW8A16Fp8, so that scheme's dequant
branch -- plus Fp8LinearMethod.use_dequant -- are the two sites wired here.

Kernel delta to the block variant: the scale depends on n only, so it leaves the
k loop (one vector load onto the accumulator instead of a scale tile per k step);
no block geometry, hence no ragged decline; tiles (32, 64) instead of (64, 128).
Same raw-byte e4m3 decode, fp32 accumulator, tl.dot with BLOCK_M padded to 16,
and the same M<=8 decode cut.

The N>=K guard is NOT inherited -- measured, not assumed. On the real 4B mix
every shape wins, wide ones included (worst 1.22x); keeping the guard would cost
4.44x -> 3.58x on a 3080 and 4.52x -> 2.18x time-weighted. The block variant's
guard exists because a long-K weight there pays a scale-tile load per k step as
well as starved occupancy; this loop is only load, decode, dot.

SGLANG_FP8_FUSED_GEMV=0 disables BOTH variants for same-session A/B. It rides on
fp8_needs_dequant_fallback() and can only subtract from it, never add.

Also recorded: the mathematically simpler post-loop scale measured 2.7x slower
on the 2080 Ti, and the TTGIR falsified the layout explanation for it -- the
inverted ranking is an artifact of that card being locked at a 300 MHz SM clock
(6.0 TFLOP/s vs a 3080's 58.2, while memory ran at 45%: a 4.4x bias against a
compute-heavy kernel). The clean formulation ships on the healthy cards' verdict.

Tests: 24/24 on sm86 (RTX 3080) and sm75 (RTX 2080 Ti), 4/4 CPU subset.
Raw-byte e4m3 decode pinned bit-exact; fp32 error band rather than equality
against the old path (fused 0.00141 vs materialise 0.01325); both wired memory
layouts asserted bit-identical; purity and non-mutation checked.
Microbench (bf16, count-weighted over the 4B mix): 4.44x on RTX 3080, 2.34x on
RTX 5090. End to end on the 2080 Ti the wiring fires (176 Triton artifacts),
output is coherent in all three content classes with 0 degenerate, and the
off-switch works; its throughput A/B (0.87 vs 2.69 tok/s) measures the clock
fault, not the kernel, and the owed sm75 number stays open on hardware grounds.
Full detail and raw-data paths in INTEGRATION_R3_VALIDATION.md.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
…probe

Fused per-channel fp8 dequant-GEMV for small-batch decode, merged BEFORE sgl-project#192
(feat/deterministic-fp8-sm8x) as planned -- sgl-project#192 arms the W8A16 dequant lane
that sgl-project#189's kernel then serves, so this order puts the kernel in place first
and lets sgl-project#192's conflict resolution see it.

Semantic pre-check: the only file this shares with the tip is
INTEGRATION_R3_VALIDATION.md (the record itself). No source overlap with
anything merged this window.

# Conflicts:
#	INTEGRATION_R3_VALIDATION.md
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
…r3-probe

SGLANG_DETERMINISTIC_FP8_GEMM, merged after sgl-project#189 as planned.

Semantic pre-check (the one pair the plan flagged), fp8.py and
compressed_tensors_w8a16_fp8.py:
* fp8.py -- sgl-project#189 at 54/1070, sgl-project#192 at 64/483/1197. Disjoint bodies; only the
  import block is adjacent.
* compressed_tensors_w8a16_fp8.py -- genuine textual overlap at the import
  block (line 15): sgl-project#189 inserts the fp8_dequant_gemv import, sgl-project#192 rewrites the
  adjacent fp8_utils single-line import into a two-symbol one. Resolved by
  keeping BOTH; the additions are independent symbols.
Semantically the two compose rather than collide: sgl-project#192 sets use_marlin=False on
sm80..88 and routes those cards INTO the W8A16 dequant lane, and sgl-project#189 supplies
that lane's small-batch GEMV. sgl-project#189's kernel is single-program-per-output-tile
with a sequential k-loop and no atomics or split-K, so it is run-to-run
bit-stable and does not undermine what sgl-project#192 promises.

CONSEQUENCE, carried from the desk analysis and NOT yet discharged: sgl-project#189 is
more accurate than the materialisation it replaces, so it changes values on
this lane. sgl-project#192's solo byte-baseline is therefore invalidated and the
integrated SGLANG_DETERMINISTIC_FP8_GEMM run is re-baselined in this window's
validation section, not compared against the old numbers.
SGLANG_FP8_FUSED_GEMV=0 separates the two effects in-build.

# Conflicts:
#	INTEGRATION_R3_VALIDATION.md
#	python/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a16_fp8.py
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
Records merges 2-10 with per-step semantic pre-checks, the sgl-project#189 x sgl-project#192 conflict
resolution and its per-card verification, the two deliberately skipped branches
(sgl-project#143 Gate 4 never measured, sgl-project#119 needs a 122B A/B that did not fit), and the
failure-set diff: 36 pre-existing failures at 9b142ce -> 11 at the merge tip,
no new ones, with the 25-case test_pool_configurator red repaired by sgl-project#96.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
…onclusive by construction

Closing boots on the merge tip all green: the 27B uneven-DCP MTP working arm
(max_total 98328, identical to the Phase-1 reference), arm E with the HTCCL
device transport (one extension built for arch 8.6 AND 12.0, 3/3 byte-identical),
and the SGLANG_DETERMINISTIC_FP8_GEMM boot (4/4 byte-identical).

sgl-project#192 re-baselined after sgl-project#189 as owed: M=256, 300 iters on one 3080, flag-on arm
0/300 both with the fused GEMV active and with SGLANG_FP8_FUSED_GEMV=0, against
a marlin control that is nondeterministic in both builds.

A1/A2 complete the six-field link matrix. A strictly even TP=3 is not
expressible for Llama and --rank-tp-ratio 1,1,1 is now rejected outright, so A1
uses the explicit 3,3,2.

SPLIT-BALANCE: the premise is confirmed (capacity installs [2,3,3], giving the
fast 5090 the fewest tokens) and the mechanism demonstrably works (perf split
doubles the 5090's KV rows and raises its power draw 5.5%), but there is no
throughput effect above the noise -- round_rate mean +0.67%, sd 1.74%, 4/2 sign
split. The load-bearing finding is methodological: both arms produced DIFFERENT
output text at all six points, so tok/s cannot be compared between them at all
and the A/B cannot resolve a <=3% effect by construction. KV cost is zero here
only because the hybrid mamba cap binds before the KV split does.
Chosen-David pushed a commit to Chosen-David/sglang that referenced this pull request Oct 9, 2026
linhu-nv added a commit to linhu-nv/sglang that referenced this pull request Nov 26, 2026
With --enable-linker-mla-dedup, start_layer_wise_loading checked that all
TP ranks agreed on the load plan before looking at the queue, so every
scheduler step, decode included, paid an all_gather_object over the TP
group even when there was nothing to load. Whether a load is queued
depends only on the transfers, so every rank sees the same empty queue;
return early and only run the check when a load is actually queued.

The check itself now compares the plan digest with a single CPU int64
all-reduce (MIN over [v, -v]) instead of pickling digests through
all_gather_object. The mismatch handling is unchanged.

On B200 TP4 DeepSeek-V4.1 the check ran on every scheduler step at about
5 ms per call under rank skew. With KVCR sgl-project#189 and this change, GPU-hit
TTFT (16K prompt) is 81-83 ms vs 84 ms before; the Mooncake linker on the
same tree measures 79-81 ms.
linhu-nv added a commit to linhu-nv/sglang that referenced this pull request Dec 3, 2026
With --enable-linker-mla-dedup, start_layer_wise_loading checked that all
TP ranks agreed on the load plan before looking at the queue, so every
scheduler step, decode included, paid an all_gather_object over the TP
group even when there was nothing to load. Whether a load is queued
depends only on the transfers, so every rank sees the same empty queue;
return early and only run the check when a load is actually queued.

The check itself now compares the plan digest with a single CPU int64
all-reduce (MIN over [v, -v]) instead of pickling digests through
all_gather_object. The mismatch handling is unchanged.

On B200 TP4 DeepSeek-V4.1 the check ran on every scheduler step at about
5 ms per call under rank skew. With KVCR sgl-project#189 and this change, GPU-hit
TTFT (16K prompt) is 81-83 ms vs 84 ms before; the Mooncake linker on the
same tree measures 79-81 ms.
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