Skip to content

feat: add check_env - #645

Merged
Ying1123 merged 1 commit into
sgl-project:mainfrom
zhyncs:check-env
Jul 18, 2024
Merged

Ying1123 merged 1 commit into
sgl-project:mainfrom
zhyncs:check-env

Conversation

@zhyncs

@zhyncs zhyncs commented Jul 18, 2024

Copy link
Copy Markdown
Contributor

Motivation

as titled cc @merrymercy @Ying1123 @hnyls2002

python3 -m sglang.check_env
Python: 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0]
CUDA available: True
GPU 0: NVIDIA A100-SXM4-80GB
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.2, V12.2.140
CUDA Driver Version: 535.54.03
PyTorch: 2.3.0+cu121
sglang: 0.1.21
flashinfer: 0.0.9+cu121torch2.3
aiohttp: 3.9.5
fastapi: 0.111.0
hf_transfer: 0.1.6
huggingface_hub: 0.23.4
interegular: 0.3.3
packaging: 24.1
pillow: Module Not Found
psutil: 6.0.0
pydantic: 2.8.2
rpyc: 6.0.0
uvicorn: 0.30.1
uvloop: 0.19.0
zmq: 26.0.3
vllm: 0.5.1
openai: 1.35.13
anthropic: 0.31.1
NVIDIA Topology:
	GPU0	NIC0	NIC1	NIC2	NIC3	NIC4	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	SYS	SYS	SYS	PXB	NODE	32-63,96-127	1		N/A
NIC0	SYS	 X 	NODE	NODE	SYS	SYS
NIC1	SYS	NODE	 X 	NODE	SYS	SYS
NIC2	SYS	NODE	NODE	 X 	SYS	SYS
NIC3	PXB	SYS	SYS	SYS	 X 	NODE
NIC4	NODE	SYS	SYS	SYS	NODE	 X

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

NIC Legend:

  NIC0: mlx5_bond_0
  NIC1: mlx5_bond_1
  NIC2: mlx5_bond_2
  NIC3: mlx5_bond_3
  NIC4: mlx5_bond_4

Modification

as titled

Checklist

  1. Ensure pre-commit or other linting tools are used to fix potential lint issues.
  2. Confirm that modifications are covered by complete unit tests. If not, please add more unit tests for correctness.
  3. Modify documentation as needed, such as docstrings or example tutorials.

@Ying1123
Ying1123 merged commit d93388d into sgl-project:main Jul 18, 2024
@zhyncs
zhyncs deleted the check-env branch July 18, 2024 04:40
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu added a commit to efschu/htsglang that referenced this pull request Aug 7, 2026
Two production wedges on 2026-08-07, both PrefixLensRankDivergence, both
on boots reporting `impl=UnifiedRadixCache hybrid_ssm=True
hierarchical=True` under `--hicache-write-policy write_through`:

  12:15   rank 0 [2047]    rank 1/2 [10238]     roomy rank SHORTER
  13:26   rank 0 [22014]   rank 1/2 [19967]     roomy rank LONGER

The 13:26 gap is exactly 2047 tokens, one chunked_prefill_size chunk.

sgl-project#639 made `host_avail` replicated in write_backup, which turned
`host_avail < kv_tokens` into a rank-uniform branch. What it did not make
uniform is what happens inside that branch. `evict_host` selects victims
from `evictable_host_leaves`, and `_is_host_leaf` gates candidacy on
`node.evicted` -- a rank-sized DEVICE pool (190400/143840/143906). So the
ranks delete different nodes (`_evict_host_leaf` ->
`_remove_leaf_from_parent`, a tree edit) and some cover `needed` while
others do not (`evicted < needed` -> no backup, and under write_through an
un-backed-up node is deleted at its next device eviction while a
backed-up one is demoted and stays matchable).

Those are the two specimens, opposite directions, one branch: a rank that
keeps old prefixes its peers dropped, and a rank that drops a new prefix
its peers kept.

A floor repairs an ADMISSION, not a SELECTION -- no arithmetic on a
published scalar makes two ranks pick the same nodes out of two different
candidate sets. So under an active floor the backup path no longer evicts
and refuses uniformly instead. HiRadixCache carries the same defect at its
own evict_host retry and is fixed with it, because #616g's load-back fix
already spent a boot sitting in the class deployment never built.

Second half: the floor is published at the top of the iteration and read
at the end of it, so it counted as free every slot the iteration's own
backups had already taken. Admissions are now charged against it
(`uniform_host_admitted_since_floor`, reset by the publisher). The ledger
is rank-uniform by construction and sufficient: live availability is at
least `avail_at_publish - admitted` and `avail_at_publish >= floor`.

COST, deliberate: this is the base component's only host-eviction trigger
when enable_storage is False, so on an uneven rig a saturated host tier
stops recycling and the host hit rate decays. Throughput traded for
correctness; recovering it needs a group-agreed victim list, which is a
scheduler-side design.

NOT closed, named in the tests and left to their own tickets: the backup
VERDICT can still diverge when a write fails under an active floor (now
logged, once per floor, instead of silently editing the tree); the
prefetch_host evict_host calls (hiradix 1930, unified 2270) are unguarded
but dead on this config (hicache_storage_backend=None); _evict_backuped,
_detach_backuped and _drop_subtree_no_host carry no floor either.

Tests, all CPU-only, CUDA_VISIBLE_DEVICES=99:
  test_uniform_host_evict_floor_645.py  base 7 failed/6 passed -> 13 passed
    Drives the REAL write_backup of BOTH classes, closing the "cannot be
    driven hermetically" gap the sgl-project#639 suite left on HiRadixCache. The
    ledger test carries its own can-fail proof (restoring the pre-sgl-project#645
    arithmetic brings the divergence back).
  test/registered/unit/distributed/     2633 passed, 12 skipped, 0 failed
  test/registered/unit/mem_cache/       937 failed/708 passed on BOTH base
    and branch, 899 failing test names identical -> no regression
    (pre-existing CPU-environment failures)
  ruff 91 errors on base and branch alike; black and codespell clean
  Pre-existing and unrelated: test_collective_family_siblings_610.py
    PrefillAdmissionBudgetTest, 2 failures, identical at base
efschu added a commit to efschu/htsglang that referenced this pull request Aug 7, 2026
…nder a uniform floor

Production runs UnifiedRadixCache, not HiRadixCache (both sgl-project#645 crash logs:
impl=UnifiedRadixCache, zero HiRadixCache references), so the fix lands in
both classes. sgl-project#639's floor made the host-availability compare rank-uniform,
but evict_host still picked victims via _is_host_leaf, which gates on a
rank-sized device pool: uniform trigger, rank-local action. Both observed
crash directions fall out of that one call -- victim divergence (13:26,
rank 0 longer by exactly one 2047 chunk) and evicted<needed divergence
(12:15, rank 0 shorter). An admission ledger additionally fixes the stale
floor snapshot: the precheck read a value published at iteration top and
counted slots this iteration's own backups had already taken.

Falsifier reproduces both directions in one iteration: base 7 failed /
6 passed -> 13 passed. Full distributed suite 2633 passed, 12 skipped.
mem_cache failure set byte-identical to base (937 failed both sides, 899
failing names identical). Behavioural neutrality pinned with the floor
unset. Named but not closed: the one-node refusal residual (needs a
group-agreed verdict, i.e. a collective) and the throughput cost -- this
is the base component's only host-eviction trigger without a storage
backend, so a saturated host tier on an uneven rig stops recycling.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…s the ledger the host had

ROOT. evict_from_tree_cache gates the eviction on
uniform_avail_for_evict(...) < num_tokens. That reads
tree_cache.uniform_avail_floor, published ONCE per iteration
(scheduler.py:4142-4144) as the group MIN of available_size(). Allocations made
later in the same iteration were never charged against it, so late in an
iteration the number is stale-OPTIMISTIC: with floor >= num_tokens the eviction
is SKIPPED entirely, the alloc then fails against the live pool, and the raise
reports a tree full of evictable tokens nothing ever asked for.

Not a new class -- the HOST sibling already had this fixed. Its own comment
states the reasoning: "a stale floor over-admits ... charging admissions against
the floor removes the staleness without a second collective". The DEVICE sibling
never got the ledger. This adds it, mirroring sgl-project#645 exactly:
uniform_admitted_since_floor, charged on the success path of alloc_token_slots,
reset by the scheduler in the same call that publishes the next floor so it
never outlives the number it corrects.

Sufficient, by sgl-project#645's argument: live availability is at least
avail_at_publish - admitted, and avail_at_publish >= floor, so a request
clearing floor - admitted fits the real pool. Rank-uniform by construction:
num_tokens comes from the replicated batch, so every rank charges the same
amount at the same allocation and the predicate stays identical across ranks --
the #616g invariant this must not break, pinned by a test.

fundable_extend_tokens reads the same predicate, so admission inherits the
correction for free.

OVERLAP VERDICT vs sgl-project#701(a), checked in code rather than assumed: NOT one
defect, on the available evidence.
 * evictable and protected are DISJOINT by construction -- inc_lock_ref moves
   tokens out of evictable_size_ into protected_size_ (radix_cache.py:605-606)
   and dec_lock_ref moves them back (:622-623). So a reported evictable count
   never includes protected-prefix pages.
 * The only specimen present in any accessible log is 66039 (available=273 +
   full_evictable=65766, 512 requested). Its "Full LRU list evictable size:
   65766" matches full_evictable_size EXACTLY. That sanity check is an
   independent traversal of the eviction list, and divergence is precisely what
   it exists to detect -- so this specimen's evictable was genuinely reachable,
   refuting the paper-evictable hypothesis for it. It is also the specimen sgl-project#681
   already diagnosed (mamba tombstone leaf) and paid in MambaRadixCache.
   evict_full.
 * The "167k evictable" specimen is NOT in any log I can reach, so its
   decomposition into mamba-recoverable vs paper-only cannot be done and is not
   inferred. If F4-r4's 1f594e7 instrument catches a recurrence, its
   skipped-vs-ran line decides it directly.
So the staleness defect is proven STRUCTURALLY (the host/device asymmetry) and
fixed with a can-fail falsifier; it is not claimed as the cause of a specimen
whose instrument output does not exist.

One self-inflicted defect caught by the suite: getattr(tree_cache,
"uniform_admitted_since_floor", 0) yields a Mock on an unconfigured double, and
int(Mock()) is 1, not 0 -- silently shaving a token off the floor and breaking
test_a_published_floor_is_returned (499 != 500). Guarded by an isinstance check,
with the reason recorded. Third appearance of the sgl-project#624 stub-drift class. The
host sibling carries the identical latent exposure and is left untouched here to
keep the blast radius small; worth a follow-up.

Tests: 7, red first, including the can-fail proof that an uncharged stale floor
really does skip. managers 2113 passed / 0 failed. mem_cache is 944 failed /
772 passed both before and after this change -- a large PRE-EXISTING red suite,
verified by patch round-trip on the clean tree (945/2870 baseline across
managers+mem_cache without the new file). ruff clean on all three files,
compared against HEAD.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…s the ledger the host had

ROOT. evict_from_tree_cache gates the eviction on
uniform_avail_for_evict(...) < num_tokens. That reads
tree_cache.uniform_avail_floor, published ONCE per iteration
(scheduler.py:4142-4144) as the group MIN of available_size(). Allocations made
later in the same iteration were never charged against it, so late in an
iteration the number is stale-OPTIMISTIC: with floor >= num_tokens the eviction
is SKIPPED entirely, the alloc then fails against the live pool, and the raise
reports a tree full of evictable tokens nothing ever asked for.

Not a new class -- the HOST sibling already had this fixed. Its own comment
states the reasoning: "a stale floor over-admits ... charging admissions against
the floor removes the staleness without a second collective". The DEVICE sibling
never got the ledger. This adds it, mirroring sgl-project#645 exactly:
uniform_admitted_since_floor, charged on the success path of alloc_token_slots,
reset by the scheduler in the same call that publishes the next floor so it
never outlives the number it corrects.

Sufficient, by sgl-project#645's argument: live availability is at least
avail_at_publish - admitted, and avail_at_publish >= floor, so a request
clearing floor - admitted fits the real pool. Rank-uniform by construction:
num_tokens comes from the replicated batch, so every rank charges the same
amount at the same allocation and the predicate stays identical across ranks --
the #616g invariant this must not break, pinned by a test.

fundable_extend_tokens reads the same predicate, so admission inherits the
correction for free.

OVERLAP VERDICT vs sgl-project#701(a), checked in code rather than assumed: NOT one
defect, on the available evidence.
 * evictable and protected are DISJOINT by construction -- inc_lock_ref moves
   tokens out of evictable_size_ into protected_size_ (radix_cache.py:605-606)
   and dec_lock_ref moves them back (:622-623). So a reported evictable count
   never includes protected-prefix pages.
 * The only specimen present in any accessible log is 66039 (available=273 +
   full_evictable=65766, 512 requested). Its "Full LRU list evictable size:
   65766" matches full_evictable_size EXACTLY. That sanity check is an
   independent traversal of the eviction list, and divergence is precisely what
   it exists to detect -- so this specimen's evictable was genuinely reachable,
   refuting the paper-evictable hypothesis for it. It is also the specimen sgl-project#681
   already diagnosed (mamba tombstone leaf) and paid in MambaRadixCache.
   evict_full.
 * The "167k evictable" specimen is NOT in any log I can reach, so its
   decomposition into mamba-recoverable vs paper-only cannot be done and is not
   inferred. If F4-r4's 1f594e7 instrument catches a recurrence, its
   skipped-vs-ran line decides it directly.
So the staleness defect is proven STRUCTURALLY (the host/device asymmetry) and
fixed with a can-fail falsifier; it is not claimed as the cause of a specimen
whose instrument output does not exist.

One self-inflicted defect caught by the suite: getattr(tree_cache,
"uniform_admitted_since_floor", 0) yields a Mock on an unconfigured double, and
int(Mock()) is 1, not 0 -- silently shaving a token off the floor and breaking
test_a_published_floor_is_returned (499 != 500). Guarded by an isinstance check,
with the reason recorded. Third appearance of the sgl-project#624 stub-drift class. The
host sibling carries the identical latent exposure and is left untouched here to
keep the blast radius small; worth a follow-up.

Tests: 7, red first, including the can-fail proof that an uncharged stale floor
really does skip. managers 2113 passed / 0 failed. mem_cache is 944 failed /
772 passed both before and after this change -- a large PRE-EXISTING red suite,
verified by patch round-trip on the clean tree (945/2870 baseline across
managers+mem_cache without the new file). ruff clean on all three files,
compared against HEAD.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…ling included

Third appearance of the stub-drift class earns the consolidation now.

Both floor correctors read a per-iteration ledger off the tree cache: the
DEVICE one in uniform_avail_for_evict (sgl-project#694) and the HOST one in
uniform_host_avail_for_backup (sgl-project#645). Real caches declare the attribute on
BasePrefixCache with a 0 default; a test double usually does not, and
int(Mock()) is 1, not 0 -- so an unconfigured stand-in silently shaved one
token off whichever floor it fed.

Measured on both: 499 != 500 against the device ledger
(test_a_published_floor_is_returned), and reproduced against the host ledger by
a new test that leaves uniform_host_admitted_since_floor unconfigured. The host
exposure was real, not theoretical.

Rather than a second isinstance check that would drift from the first, both
sites now go through _ledger_tokens, whose docstring IS the named list the
audit asked for -- there is no separate registry doc to add them to, and a
helper both callers must use is a stronger guarantee than a list someone has to
remember to read. bool is excluded deliberately: it is an int subclass, so a
truthy flag landing there would charge 1 token for exactly the reason a Mock
did.

Tests: 5 more, red first -- the host case failed with the identical 499 != 500
signature before the fix, which is the can-fail proof that the sibling shared
the defect rather than being fixed by coincidence.

managers + the sgl-project#645 host suite + the sgl-project#694 suite: 2131 passed, 0 failed. ruff
clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 22, 2026
…ount the refusals

A staging host tier is small on purpose, and nothing at runtime bounded what
write-through put into it. The tier itself did, by running out -- which is not
a bound but two silent failures. The read consumer starves: a prefetch takes
its landing slot from mem_pool_host.alloc() BEFORE issuing the storage read, so
a tier full of undrained write-through pages makes it evict, retry, truncate
and abandon; a correct miss, invisible to every capacity metric and visible
only as latency. And the write refusal itself is silent: write_backup learns
about exhaustion by reading a None back out of an allocation that already
happened, then -- with no rank-uniform floor published -- takes evict_host(), a
RANK-LOCAL tree edit, which is the sgl-project#645 divergence.

NOT sgl-project#720's ReadBufferPool. Its acquire() (read_buffer_pool.py:99-105) answers
exhaustion by allocating a fresh UNCOUNTED pinned buffer, deliberately:
"stalling the prefetch worker to save memory would trade a bounded spike for an
unbounded latency". Right for a prefetch worker, and precisely wrong for a
write path under a RAM budget -- the footprint that overflow re-inflates is the
one --hicache-host-role staging exists to cap. StagingWriteRing never
allocates; its only outcomes are admitted and refused-and-counted.

THE RESIDENCY IS TWO-PHASE, and only one phase is refusable. write_backup
allocates the host slots; write_backup_storage calls node.protect_host() and
the protection drops only at the backup ack (ongoing_backup.pop ->
release_host). The bandwidth-delay product that planner/hicache_staging sizes
the tier from is the SECOND phase, so a ring spanning only the device->host
copy would claim a bound it does not have. Phase one is admit(), taken before
any allocation, where a refusal is actionable. Phase two is occupy(), which
cannot be refused -- the page is already resident, so refusing would free
nothing and merely hide the drain queue from the next admission.

Phase two is keyed by the STORAGE OPERATION, not the node, and that is not
cosmetic: in UnifiedRadixCache one write-through ack fans out into several
storage backups after a node split, each with its own id, and lock_node is by
then no longer among publish_nodes. A node-keyed charge would be stranded
there -- and a leak shrinks the ring permanently, a strictly worse failure than
the overshoot it protects against. So the node-keyed charge is retired at
exactly one site (_finish_write_through_ack) before the hand-off.

CAPACITY WITHOUT A NEW NUMBER. The read consumer is already bounded at runtime
by cache_controller.prefetch_capacity_limit = int(0.5 * mem_pool_host.size).
Both consumers share one tier, so the write bound is that number's complement.
The module introduces no constant of its own and does not become a second
sizing authority beside the planner (sgl-project#584/sgl-project#785). Built after
_symmetrize_prefetch_capacity(), so the bound derives from the group-agreed
number: a rank-dependent admission bound on this path is the sgl-project#645 defect.

No hysteresis, deliberately: a refused backup is not lost work (the node stays
in the tree and the next insert offers it again), so there is no thrash cost
for a watermark to damp, and a resume fraction would be an invented number.

Wired into both cache classes that have a construction site -- HiRadixCache
(registry.py:115) and UnifiedRadixCache (registry.py:191). HiMambaRadixCache
has none, stated at registry.py:108-109.

Default unchanged: the ring is built only under --hicache-host-role staging.
Under retention -- the default -- the attribute is None and every call site is
one `is None` test. The diff is purely additive.

Tests: test/registered/unit/mem_cache/test_staging_write_ring_810.py, 33 cases,
hermetic (CUDA_VISIBLE_DEVICES=""). Both real write_backup implementations are
driven UNBOUND over a fixture, in both directions: a ring with room admits
exactly as before, a full ring refuses, and a refusal is shown never to reach
evict_host and never to call cache_controller.write. The drain edges are driven
through the real write_backup_storage and the real
_drain_storage_control_queues_impl.

Mutants, 15, all confirmed dying:
  hiradix admit gate inert                     -> 4 failed
  hiradix abort on failed write removed        -> 1 failed
  hiradix abort on floor refusal removed       -> 1 failed
  hiradix drain-phase occupy removed           -> 2 failed
  hiradix release at D2H ack removed           -> 1 failed
  hiradix release at backup ack removed        -> 1 failed
  hiradix release on forced detach removed     -> 1 failed
  unified admit gate inert                     -> 2 failed
  unified abort on failed write removed        -> 1 failed
  unified drain-phase occupy removed           -> 1 failed
  unified release at backup ack removed        -> 1 failed
  unified release at D2H ack removed           -> 1 failed
  role gate removed (retention gets a ring)    -> 2 failed
  capacity is the whole tier, not the complement -> 2 failed
  exhaustion allocates instead of refusing     -> 8 failed
Source green again at 33 passed.

"unified release at D2H ack removed" SURVIVED the first battery at 32/32 green:
that call edge was untested. The test it now dies on
(UnifiedDrainPhaseTest.test_the_two_phases_do_not_double_count_one_page) was
added for it. Without the mutant round a leak edge would have shipped unchecked.

ruff/black/codespell clean on the new files; the modified files carry 372 ruff
findings before and after this change, i.e. none in these hunks.
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