Skip to content

Clean up logits processor - #558

Merged
merrymercy merged 5 commits into
mainfrom
clean-logits
Jun 22, 2024
Merged

merrymercy merged 5 commits into
mainfrom
clean-logits

Conversation

@merrymercy

@merrymercy merrymercy commented Jun 22, 2024 •

Copy link
Copy Markdown
Collaborator
  • Add a new class LogitProcessorOutput to organize the output of LogitProcessor.
  • Add a new function add_logprob_return_values to organize the outputs of logprob info

@merrymercy
merrymercy merged commit 303ef88 into main Jun 22, 2024
@merrymercy
merrymercy deleted the clean-logits branch June 22, 2024 07:25
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
michaelzhang-ai added a commit to michaelzhang-ai/sglang that referenced this pull request Feb 26, 2026
PR sgl-project#18242 broadened the `fused_qk_rope_cat_and_cache_mla` code path
from MI350x-only (`_use_aiter_gfx95`) to all HIP platforms
(`_use_aiter`). This causes DeepSeek-V3.2 to produce garbage output on
MI300x (gfx942)—accuracy drops to ~15% on GSM8K (threshold 93%).

The fused kernel works on MI350x but corrupts RoPE on MI300x, confirmed
by both nightly pipelines (ROCm 6.2 run sgl-project#558, ROCm 7.2 run sgl-project#126) where
MI300x DeepSeek-V3.2 tests fail while identical MI350x tests pass.

Restore the original gfx95x-only guards for the three changes from
sgl-project#18242: the duplicate import, the RoPE skip condition, and the fused
kernel dispatch.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
check_free_space() returned "writable" as soon as free space climbed back
above min_free, while _release_write_stop_locked only clears the latch at
min_free * 1.05. In that band the two disagreed: the watchdog said writable,
the next reserve() still refused. Return the latch state instead, so the
margin means what it says and the tier cannot flap between stopped and
writing at the watermark.

Test: test_watchdog_holds_the_latch_inside_the_hysteresis_band -- stop at
min_free/64, still stopped at +1%, released at +10%. Whole file 17 passed;
with test_hicache_file_lru_unit.py and test_hicache_runtime_resize_545.py,
72 passed. ruff (F401,F821,UP037) and codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
os.scandir returns a closable iterator; list() consumed it but left the
directory fd to the garbage collector. The startup scan opens one per shard,
so on a 256-shard directory that is 257 fds waiting on GC. Use the context
manager form. Same 72 tests pass; ruff (F401,F821,UP037) clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
The file backend now writes into 2-hex shard subdirectories, so the
park/unpark roundtrip's page files sit one level below tmp_path and a
top-level iterdir() counted 1 entry instead of 1 + 2*LAYERS. Count files
recursively; the expected number is unchanged.

test_kv_spill_destination_unit.py: 37 passed. ruff (F401,F821,UP037) and
codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
…and the page counters

The sgl-project#121 handover tool reads and writes the same on-disk store the backend
does, so sharding is its contract too. Left alone it would have failed
silently in the worst way: scan_store() listed one directory level, so a
sharded store looks EMPTY to it and a migration reports nothing to do.

- scan_store() now walks the shard subdirectories as well as the directory
  itself, so it sees sharded stores, pre-sharding flat stores, and the mix a
  read-through store legitimately has.
- Migration output goes through a new store_path(), which asks HiCacheFile
  for the shard of a name rather than restating the rule, so the two cannot
  drift. execute_plan() creates each target's own parent instead of only the
  first plan entry's.
- Two integration tests counted pages with a single-level os.listdir of the
  storage directory (test_hicache_spec_file_storage, unified_radix_cache_kl_dsv4);
  both count recursively now. They need a GPU to run -- static fix, not
  executed here.

Tests: test_hicache_migrate.py + test_draft_migrate.py 56 passed; together
with test_kv_spill_destination_unit.py, test_hicache_file_bounds_558.py,
test_hicache_file_lru_unit.py and test_hicache_runtime_resize_545.py, 165
passed. ruff (F401,F821,UP037) clean except one pre-existing UP037 at
hicache_migrate.py:378, which is untouched here and fails on HEAD too;
ruff format clean on the files that were format-clean before; codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
set_limits() could leave the free-space latch set after the watermark it was
raised against was lowered or removed: with min_free back at 0 nothing would
ever clear it, so stats()/capacity_stats() kept reporting write_stopped for a
tier that was writing again. Clear the latch when the watermark goes away, and
reset the probe interval so the next check re-measures against the NEW limits
instead of trusting a verdict about the old ones.

Tests: test_hicache_file_bounds_558.py + test_hicache_file_lru_unit.py +
test_hicache_runtime_resize_545.py, 72 passed. ruff format clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
The migration tool reached into HiCacheFile._shard_of -- a private classmethod
on the backend -- to place its output. Two modules implement the same on-disk
contract, so the rule belongs to neither of them privately: it is now
hicache_storage.page_shard(), which both call. No behaviour change.

Tests: the six CPU files covering the backend, the evictor, the runtime
re-cap, both migration tools and the kvso roundtrip, 165 passed. ruff
(F401,F821,UP037) reports only the pre-existing UP037 in hicache_migrate.py;
codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
Review finding: check_free_space() read _write_stopped and wrote
_last_free_probe outside the evictor lock, while the latch is set and cleared
under it. Two writers could both pass the rate limiter, and a caller could act
on a latch value another thread had just flipped.

The consequence was bounded -- reserve() still runs
_enforce_free_space_locked() under the lock for every admitted page, so that
is the authority and a raced latch costs at most one page reaching a check
that refuses it -- but there is no reason for the state to be unsynchronized.
The rate-limit window and every latch read now happen under the lock, while
the statvfs probe deliberately runs outside it so a slow filesystem cannot
block writers. Which check is authoritative is now stated in both docstrings.

Test: test_watchdog_is_reentrant_safe_under_concurrent_writers -- four threads
interleaving check_disk_space() and set(), joined with a timeout, so a nesting
mistake on the non-reentrant lock hangs the test instead of passing quietly;
it also asserts the accounting stayed within [0, cap] afterwards.

test_hicache_file_bounds_558.py 18 passed; with the evictor, runtime re-cap,
both migration and kvso suites, 166 passed. ruff (F401,F821,UP037), ruff
format and codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
… one

Layout-coverage audit finding: LRUFileEvictor's path_for_stem and
iter_existing defaults describe the pre-sharding flat layout, and nothing said
so at the constructor. HiCacheFile injects both, so no call site is wrong
today -- but a future caller that injects only one, or neither, against a
sharded store gets the quiet failure this task exists to remove: the scan does
not see sharded files, so they are never tracked and never evictable, while
eviction unlinks paths that do not exist. Name the coupling where someone
constructing the evictor will read it. Comment only, no behaviour change.

Tests: 73 passed across the bounds, evictor and runtime re-cap suites. ruff
format and codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 17, 2026
…ambiguity, survive a full disk

STATE OF THE TICKET FIRST, because most of it is already in this tree.
Directory sharding EXISTS: page_shard spreads stems over 256 hex directories
with a 'zz' fallback for synthetic keys, every new write is sharded
(_sharded_path), pre-sharding files keep serving read-through (_existing_path),
and the shard directories are walked by _iter_existing_files. df monitoring
EXISTS too: the LRU evictor carries min_free_bytes, a TTL-throttled statvfs
watchdog (check_free_space) and a pre-write watermark enforcement, driven from
the storage worker loop via check_disk_space.

What was NOT covered is what the sgl-project#706 canonical store makes sharper, and that
is what this commit adds.

1. THE CANONICAL LAYOUT LANDS IN THE SAME SCHEME -- verified, not assumed.
   .part706 and .slots706 derive from the final path, so they inherit its shard
   and never accumulate in the store root (the root is exactly what the sgl-project#558
   incident filled with 11.7M entries), and the TTL sweeper walks the root as
   well as the shards, because a store that predates sharding holds flat
   orphans.

2. MIXED-LAYOUT AMBIGUITY IS NOW REFUSED. _existing_path prefers the sharded
   copy when a stem exists in BOTH layouts, silently -- and the two files can
   differ, because the flat one predates sharding and may predate the current
   key format entirely. That is one content-addressed key resolving to whichever
   file the lookup order finds first. audit_layout() detects it and attach
   raises MixedLayoutError naming the stems, so it is resolved deliberately
   (delete the legacy copies, or run the offline migration) instead of by
   lookup order. Cost: one scandir of a directory that normally holds only
   shard directories.

3. A FULL DISK IS THIS PROTOCOL'S WORST CASE, so it is handled explicitly.
   A page becomes visible by rename after its last byte lands, and the protocol
   ftruncates to FULL WIDTH on creation while writing only one rank's slice --
   so a store can be far closer to full than its file sizes suggest, and the
   failure lands mid-assembly after other stages already spent their IO.
   ensure_space() refuses at the door (cached statvfs, floor via
   SGLANG_HICACHE_CANONICAL_MIN_FREE_BYTES, 0 = today's behaviour). This is
   deliberately NOT the evictor's watermark: that one is disabled entirely
   unless a cap or min-free is configured, which is the DEFAULT, so on a
   default store nothing stood between this protocol and ENOSPC.

API gap found while testing and fixed: write_slice (the KV wrapper) did not
forward space_check to write_extents, so the KV path could not be protected at
all. Caught by the test, not by review.

Tests (hermetic, CUDA_VISIBLE_DEVICES=""), 13 new, 150 in the family:
* test_hicache_sharding_558.py -- sidecars land in the shard and the root stays
  empty; a completed page leaves only the sharded .bin; the sweeper reaps
  orphans in BOTH layouts; the synthetic-stem fallback; a pre-sharding page is
  still found and read byte-for-byte after a restart; a stem in both layouts is
  refused at attach; a clean store audits empty.
* ENOSPC injected at each syscall the protocol uses -- pwrite, the marker
  write, fsync -- because "the disk is full" is three events with different
  amounts of work already spent. In every case NO .bin appears, and after a
  failed marker write the coverage is not claimed, so the next writer treats
  the page as untouched rather than believing slots are present. The page
  completes normally once space returns: a failed write costs the write, not
  the key.
* The floor refuses before anything is created (nothing to reap, no other
  writer's work wasted) and is off by default.

Regression, same env, base c3e9487 vs this commit:
  unit/mem_cache   940 failed / 779 passed -> 940 failed / 907 passed (+128)
  unit/managers      4 failed / 2145 passed -> 4 failed / 2145 passed
One managers run reported 5 failed / 2144 passed; two further runs returned to
4/2145 with a failing-NAME set identical to baseline, so that observation is a
flake in that suite, not a regression from this change. Recorded rather than
dropped.

CAN-FAIL PROOF (mutation applied, suite re-run, reverted):
  R1  the mixed-layout audit never reports a duplicate
      -> test_a_stem_in_both_layouts_is_refused_at_attach, and ONLY that one
  R2  attach ignores the audit's finding
      -> test_a_stem_in_both_layouts_is_refused_at_attach
  R3  the space floor never refuses
      -> test_a_write_below_the_floor_is_refused_before_anything_is_created
  R4  the page is published BEFORE fsync (rename moved one step earlier)
      -> test_no_page_appears_when_fsync_fails,
         test_a_completed_page_leaves_only_the_sharded_bin,
         test_the_page_still_completes_after_the_disk_frees_up
         i.e. the durability ordering is pinned by three independent claims,
         not just by the ENOSPC test that targets it
  R5  the sweeper skips the flat layout
      -> test_the_sweeper_reaps_orphans_in_both_layouts
Restored tree re-verified green after every mutation (13 passed).
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