Skip to content

Fuse top_k and top_k in the sampler - #1457

Merged
merrymercy merged 4 commits into
mainfrom
pr-fix-sampler
Sep 18, 2024
Merged

merrymercy merged 4 commits into
mainfrom
pr-fix-sampler

Conversation

@merrymercy

Copy link
Copy Markdown
Collaborator

This can reduce the memory usage and make it faster.

@merrymercy
merrymercy merged commit 7f24ea9 into main Sep 18, 2024
@merrymercy
merrymercy deleted the pr-fix-sampler branch September 18, 2024 11:35
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
… zeroing -- the pool is unmapped right after

Boot weg2xsn212 (WEG2-FLIP-TIMELINE): sleep-kv stage 877 ms, of which P's
'flush: zeroed 18 KV data buffers' (~10 GB memset under SGLANG_FLUSH_ZERO_KV)
took ~0.8 s and the pause 19 ms -- zeroing pages the pause then discards.
Scheduler.flush_cache(zero_kv=None) keeps the env law; the Weg-2 sleep leg
passes zero_kv=False.  The mamba/req_to_token resets still run on mapped
pages before the pause; the wake-side restore keeps its zeroing.
Tests: dormant_hold_1445 (+1) + hold_refetch_1456 + seam_defer_1450: passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
… the wake restore

Boot weg2xsn213: the sleep leg's flush no longer zeroed (sgl-project#1457), but the
sleep-kv stage stayed at 861 ms -- PP0 waited 793 ms in the group fence
for PP1/PP2, which were still zeroing 8/6 KV buffers from the QUIESCE
witness (/flush_cache with the default flush, reduced over every rank).
Every flush on a Weg-2 rank outside _weg2_wake_restore_pools precedes a
pause; _flush_zero_kv_wanted answers False there (explicit zero_kv wins,
the env law holds elsewhere; the wake restore zeroes itself).
Tests: dormant_hold_1445 (+cases) + hold_refetch_1456: passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
… rank -- CTRL-RECV at intake, SLEEP-CHUNK pause, GROUP-FENCE join

Boot weg2xsn214: the sleep-kv stage stays at ~860 ms although no rank
zeroes any more (sgl-project#1457/b) -- PP0 joins the KV-release fence after 789 ms
waiting for PP1/PP2, whose second-granular logs only say ':28'.  Every
Weg-2 control request (FlushCache / Release / Resume) now logs its arrival
per rank with t=%.3f, and the pause and fence lines carry t= too, so the
next boot names the wait (chain forwarding, the row-chain gate, or the
handler itself).
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 2, 2026
… + mamba envelope zeroed as int64 (SGLANG_WEG2_ZERO_WIDE)

Every D wake of N5m/N5p/N5q: 'WEG2-WAKE-INVARIANT kv_cache pools re-zeroed
after resume ... in 85-95 ms' on TP0 (5090) and 169-189 ms on TP1/TP2
(3080), before flip done (wake_kv_dc). The ratio is the cards' bandwidth
ratio, so the work is device-bound -- but ~8-10 GB per rank at ~100 / ~46
GB/s is a few percent of what the cards write; sgl-project#1457 measured the same fill
on P at ~10 GB in ~0.8 s. The zeros are zero_() over fp8 KV buffers (32 on
D: 16 full-attention layers x K/V) and the uint8 mamba envelope (raw):
an element-wise fill at one byte per element. P's current wake restore
zeroes in 4-7 ms.

- zero_wide_(t): a contiguous buffer is zeroed through an int64 (else
  int32) view of its own bytes -- identical bytes, 8x fewer elements; a
  strided, odd-sized or misaligned one keeps the plain zero_() and is
  counted. zero_kv_data_buffers (safe_zero_rows unchanged) and the mamba
  envelope use it.
- Marker: 'flush: zeroed N KV data buffers (...) wide= narrow= bytes= ms='
  (synced). narrow>0 on D would name a strided layout this does not reach.
- SGLANG_WEG2_ZERO_WIDE=0 = the per-dtype zero_() everywhere.
- Not removed: the zeros are load-bearing (fresh-boot invariant on remapped
  pages that held the other group's bytes; fp8 0x7f/0xff are NaN; the DFLASH
  solo pool reads zero-KV holes by design).
- The L15 bounded scrub (_l15_flush_zero_kv_bounded) is l15-lead's and is
  untouched; it can call zero_wide_ the same way.

Gate (20 flush/reset_state/zero/wake-restore files): base 5 failed (all in
the new test) + 1 pre-existing collection error, change 291 passed + the
same error.
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