Skip to content

Improve performance when running with full parallel - #394

Merged
hnyls2002 merged 1 commit into
mainfrom
fix-schedule
Apr 25, 2024
Merged

hnyls2002 merged 1 commit into
mainfrom
fix-schedule

Conversation

@hnyls2002

Copy link
Copy Markdown
Collaborator

Why this PR?

  • Before this PR, llm_judge benchmark with parallel=64, latency=90.094, cache_hit_rate = 24%
  • After this PR, llm_judge benchmark with parallel=64, latency=53.705s, cache_hit_rate = 74%

What does this PR do?

When the priority of the waiting queue is fixed, e.g. LPM (Longest Prefix Match), the SRT should only accept a prefix of the waiting queue.

This is because we don't want the requests with lower priority to come into the prefill phase which will lead to the eviction of the previously cached prefix.

@hnyls2002
hnyls2002 merged commit 9216b10 into main Apr 25, 2024
@hnyls2002
hnyls2002 deleted the fix-schedule branch April 25, 2024 09:29
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 2, 2026
Desk design only, no cards (CUDA_VISIBLE_DEVICES=99), no implementation.

Verdict: sgl-project#407 is not a new abstraction, it is a NODE layer plus a
reconciliation. The edge half — what does it cost to move a byte from here
to there — already exists FOUR times with four readers and four absent-value
rules: cost_model.PairMatrix (#348b, UUID-keyed), barlink_path_rates.
PathProfile (sgl-project#279, affine per route), offload_movement.PeerPathCapability
(sgl-project#286, CUDA-ordinal-keyed) and card_probe h2d/d2h (sgl-project#271). E2 and E3 both want
the effective BAR1 aperture from p2p_readiness/capability_matrix.json and only
E2 has a loader. What exists nowhere is the node layer, and in its place the
tree carries four disjoint tier vocabularies (PARK_TARGETS sgl-project#286;
LOCAL_DESTINATION/SUPPORTED_PARK_BACKENDS sgl-project#224; StorageMedium telemetry;
HiCache choices=). Expert offload, the largest byte mover in the fork, is in
none of them: its tier is device="cpu" + .pin_memory() written out five times.

Two shipped contradictions the design bends around, both stated up front:

C1 — two opposite total orders over one axis. sgl-project#224's destinations_error makes
'local' first a hard validation law ("a remote tier is a tier BELOW local,
never above it"); sgl-project#286's ladder puts peer_vram ABOVE host_ram. Resolved by
making the order a shortest path over a STAGING GRAPH: 'local first' is
recovered as reachability (the only edge out of a device tier toward a blob
tier runs through host), peer_vram is recovered because vram->vram is a direct
edge. Neither consumer's shipped behaviour changes.

C2 — the one existing tier ledger is positionally keyed. CapacityLedger keys
peer-VRAM budgets by CUDA ordinal; AUDIT_331 calls that SCOPED and legitimate
until it crosses a process boundary, which is exactly what sgl-project#305 §6 ("one
ledger, no second accounting") asks for. On this rig the 5090 is CUDA ordinal
0 and NVML index 1, so the failure is silent card-swapping.

Honesty correction on three numbers the brief assumed measured: the peer-VRAM
1-3 us posted-write class is an explicit ASSUMPTION (EVAL_p2p §"Tragende
Annahmen"), NVMe latency does not exist in the tree in any unit, and host DRAM
38 GB/s is derived from an ASSUMED DDR4-3200 peak (the VM hides SPD). They
ship as ESTIMATE/ABSENT under #348b's measured-or-named rule. Everything else
in the inventory is sourced: 5090 32607 MiB / 3080 20480 MiB, membw 1558/723
GB/s, BAR1 256 MiB nominal but 96 MiB contiguous with 1.13-1.34x vs NCCL at
20 KiB-16 MiB, H2D 6.4/13/13 GB/s gen4 x4/x8/x8, NVMe 1.8 GB/s cold (ARC rows
excluded), rig-2 2.07-2.83 GB/s with 1.47 us at 8 B and ~89/202 us serving
collectives.

Consumer survey, eight consumers read in their target-selection code:
sgl-project#77/sgl-project#123 expert offload MECHANICAL for the UUID-vector half (it revives sgl-project#394's
merged-but-starved link-proportional sharding, 145 -> 86 ms/token, 1.69x) and
REBUILD for a third rung (two dicts, binary resident|spill, UVA aliasing);
HiCache MECHANICAL for backends, ladder EXCLUDED (it is the type signature of
every controller method, not configuration); sgl-project#224 MECHANICAL for the list,
REBUILD for the ordering law, victim half untouched; sgl-project#89 MECHANICAL-PLUS
(needs a persistence class or a tmpfs --hibernate-dir is a silent regression,
and a driver-free arg-parse-time query); sgl-project#305 NO MIGRATION, it is the awaited
mechanism; sgl-project#286 MECHANICAL and the donor — lift _select_target and
CapacityLedger rather than write new ones; sgl-project#389 and sgl-project#306 greenfield.

Cut plan, no big bang: 1 registry + read-only enumeration + GateRow dashboard
row (S); 2 publish the rank->card-UUID vector without a collective so sgl-project#394
comes alive (S, the only cut whose yield is already measured); 3 sgl-project#224 consumes
it (S-M); 4 CapacityLedger becomes a view of registry/ledger.py, keys widen to
TierId (M); 5-9 expert offload, hibernate, sgl-project#305 transitions, HiCache backends,
NVMe/sgl-project#306 declaration. Exclusions with hard reasons only: the HiCache ladder,
GDN state (DEVICE_BOUND_ONLY admission, a refusal not an omission), cross-rig
GPU-to-GPU (driver guard, sgl-project#280 closed in userspace), compute placement (sgl-project#302).

Measurement plan names six gaps, five of them S, three of them new arms in the
existing comm-suite which today has no BAR1, storage or host-DRAM arm.

codespell clean; ruff not applicable (documentation only).
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…r plus a reconciliation, not a new abstraction — edge costs already exist FOUR times (PairMatrix #348b, PathProfile sgl-project#279, PeerPathCapability sgl-project#286 on CUDA ordinals, card_probe sgl-project#271) with four absent-value rules and no reconciler, while four disjoint tier vocabularies coexist and the largest byte mover (expert offload) is in none of them; honesty corrections shipped as ESTIMATE/ABSENT (peer-VRAM us-class is an assumption, NVMe latency unmeasured in any unit, DRAM derived from assumed DDR4-3200); contradictions resolved in design: local-first vs peer-vram-above-host becomes shortest-path reachability over a staging graph (neither consumer changes), the positionally-keyed CapacityLedger named as the silent-card-swap hazard at process boundaries; TenantState frozen (client-visible enum mixing tiers into policy) with orthogonal resident_tier; cut plan S-first with cut 2 = publish rank->UUID vector WITHOUT a collective — revives sgl-project#394, the only cut with measured yield (1.69x) (sgl-project#407)
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
… consumers yet

Charter: every memory you have access to must be a level cache, a spill target
or an offload target depending on volatility -- disk, RAM, VRAM, local as well
as remote. Today four disjoint tier vocabularies coexist (sgl-project#286's PARK_TARGETS,
sgl-project#224's destination chain, StorageMedium telemetry, HiCache's choices= list) and
the largest byte mover in the fork, expert offload, is in none of them. This is
the node layer they can share. The edge layer (what a byte costs between two
places) is NOT re-implemented: planner.cost_model keeps it.

python/sglang/srt/memtier/, six modules, no consumer touched, no write outside
a test's temp directory:

* tiers.py -- TierId grammar (UUID or a named absence of one; a bare CUDA
  ordinal is refused at the door, naming C2: on this rig the 5090 is CUDA 0 and
  NVML 1, so a positional key silently swaps cards across a process boundary),
  the record, and the volatility law. Admission is a REFUSAL, not a ranking: a
  registry that only ordered tiers by cost would happily offer the GDN pool a
  remote tier, and recurrent state that made a lossy round trip is a
  correctness failure. Two enums, tier-side and payload-side, mapped by one
  table -- which is what makes the falsifier expressible.
* profile.py + profiles/rig1.json -- the measured numbers as DATA for exactly
  one machine, every rate carrying the probe it came off. Device tiers bind
  from card-MODEL templates when a live card is enumerated, so no UUID is
  hardcoded and an unprofiled model gets live capacity with ABSENT caps rather
  than a roofline (#348b D4 one layer down). Overlay merges by tier id.
* registry.py -- enumerate (blocked tiers included; omission is how a spill
  target silently becomes a different spill target), filter by volatility,
  object class, bandwidth floor, capability property and capacity, and a NAMED
  refusal for every tier that did not make the list. The ordering key is public
  so cut 3 can swap in the staging-graph path cost visibly.
* reservations.py -- one ledger, no second accounting (DESIGN_305 §6). A tier
  reservation is a named post in the sgl-project#260/sgl-project#400 Posten sense; VramLedgerHook
  forwards device tiers into registry/ledger.py so the corridor, lease and
  invariant stay where they are.
* probe.py -- DESIGN_407 §4's M1-M8 as records, every arm declared and every
  arm refusing. apply_outcome is the only writer of a measured cap.

The three honesty corrections ship as the design demanded: host DRAM bandwidth
is an ESTIMATE (its 51.2 GB/s reference peak is an ASSUMED DDR4-3200 figure --
dmidecode is empty under this VM), the peer-VRAM "1-3 us posted write" class is
ABSENT because it is an assumption and not a probe, and NVMe latency is ABSENT
because it does not exist in this tree in any unit. M1 also records the harness
it CANNOT use: barlink has no send/recv, so the BAR1 ladder needs p2p_readiness.

Deviations from the design, all recorded in its new §8: aperture is a Rate not
an Optional[int] (an int cannot say why it is missing); vram:unenumerated@<host>
added to the grammar so rig-2's cards are declared-and-blocked rather than
invented; no staging graph and no GET route (both cut 3 / a consumer).

Tests: 82 hermetic cases in test/registered/unit/memtier/, base-a-test-cpu, no
driver and no network -- 28 records/registry, 22 profile, 14 reservations, 18
probe. All green. collect_local_facts is executed for real against /proc/meminfo
and statvfs, and VramLedgerHook is driven against a real ReservationStore in a
temp directory, so neither path is desk-written.

Can-fail proof, 12 mutations, each turning exactly its guard red: EXPENSIVE_OK
admitting persistence; a CUDA ordinal accepted as a card key; the provenance
rank dropped from the ordering key (an estimate 21x faster than a measurement
then wins); an absent bandwidth read as zero; an unknown headroom read as
unlimited; an unnamed ledger post; a profile rate with no source; a roofline
substituted for an unprofiled card; a failed probe delivering its value; an
estimate entering through a probe; a measurement silently overwritten; blocked
tiers omitted from the enumeration.

ruff / codespell / black / isort clean; mypy clean on the package. The
test_module_state_ratchet failure on this branch is pre-existing
(layers/moe/utils.py _barlink_overlap_announced) and untouched here.

Desk work, no cards (CUDA_VISIBLE_DEVICES=99). Next: cut 2, publish the
rank -> card-UUID vector so sgl-project#394's merged link-proportional sharding comes
alive -- the only cut in the plan whose yield is already measured (145 -> 86
ms/token on the cold tier, 1.69x).
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
Broadcasting SIGUSR2 across a matched process set to flush a sgl-project#390 dump killed
the frontend process, which never installs the handler (no MoE layers there, so
no collector) and therefore takes the signal's fatal default. The scheduler
ranks went down with it before flushing.

The sgl-project#390 signal trigger is installed PER-PROCESS. "The server" is not one
process, and a signal with a fatal default must never be aimed at a set on the
assumption that a handler exists everywhere.

Both measured boots switched to SGLANG_EXPERT_STATS_INTERVAL_SEC, which needs no
signal at all.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…host memory

The wall measured on 2026-08-02: delegating a cold expert on a disjoint expert
shard loses it, because each rank's cold pool lived in that process's private
anonymous pages and a peer could not address it. All three pools were already
host DRAM in the same machine, so this is a MAPPING change, not a new tier --
the bytes stay where they are, one copy, and a peer maps the owner's segment
and DMAs the row over its OWN PCIe link, which is what makes apportioning by
link bandwidth mean anything.

cold_tier_shm.py provides the primitive: a named POSIX segment per (instance,
rank, layer, param), a ColdTierLayout identity-keyed by the owner's card UUID
and PCI BDF (sgl-project#397 -- a rank index is a launch artifact and cannot identify a
card across a process boundary), a manifest published as a file (the same
collective-free channel registry.rank_cards uses) and read LAZILY at first
fetch, long after load, so it can never become a barrier inside the weight-load
loop.

Torn mappings fail loudly, which is the property the whole mechanism rests on.
Every segment carries magic, format version, instance id, owner rank, row
count, row bytes and a digest of the layout that produced it; a reader
validates all of it before returning a byte. The header is sealed LAST, so
"mapped but half-written" is refused rather than read. Peers are mapped once
per process, and cudaHostRegister pins the mapping so the local DMA engine can
source from it (falls back to pageable with a warning, never to silence).

17 hermetic tests, real mmap over real files, no CUDA. Falsifier arms for every
way a mapping can tear: leftover segment from a previous launch (the dangerous
one -- it reads perfectly), wrong format, manifest/segment digest disagreement,
truncation, unsealed read, unknown expert id. Two committed can-fail arms,
including one that shows the stale bytes ARE perfectly readable without the
instance check, which is the entire argument for the header.

Also surfaced: /dev/shm is 63 GiB here while the cold tier peaks around 88 GiB.
The pages are RAM either way -- it is the tmpfs size cap, not a shortage -- so
create_owned_segment refuses early and names the remount rather than failing
mid-load.

Slice 2 (fetch-path wiring) and the GPU proof follow. 221 passed / 34 skipped.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…t survive a restart

/dev/shm was remounted 63 -> 96 GiB on 2026-08-02 so the ~88 GiB cold tier
fits (verified: 96 G total, 93 G free, running segments untouched). That
remount is not restart-persistent: a container restart puts the cap back, and
the failure would land mid-load rather than at launch.

cold_tier_shm.preflight() is the one-liner for a window preflight, and
ANALYSE_393 section 11.6 makes running it a step rather than an assumption.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…ping, wall named

Decision: the peer mapping stays PROT_READ. The OS write protection is the
foundation of the torn-mapping guarantee, and relaxing it for a friendlier
constructor would reintroduce the silent shared-buffer corruption surface the
header design removes.

The intended API hits a hard wall, named rather than quietly routed around:
torch.UntypedStorage.from_buffer rejects the mapping as called ("Buffer size
too small (0 instead of at least 1 bytes)") AND copies, which at a multi-GiB
cold tier defeats the point of sharing. So peer_row_tensor uses
torch.frombuffer, zero-copy over the read-only mapping.

PyTorch warns it does not model non-writable tensors and that one "can write to
the underlying buffer". The kernel disagrees and the kernel enforces: a write
through the view takes SIGSEGV, verified in a forked child (signal 11) and
committed as a test, because a silent write there would corrupt ANOTHER RANK's
expert weights.

Executing it caught a live defect: ctypes.from_buffer() refuses a PROT_READ
mapping, so cudaHostRegister was silently failing to pin every peer segment.
The address now comes from the same torch view.

Zero-copy is proved by aliasing (a byte the owner writes afterwards is visible
through the view), not by pointer arithmetic that a copy could accidentally
satisfy.

Capturable path: targets equivalent registration, no soft exclusion where there
is no hard boundary. The named SGLANG_MOE_OFFLOAD_CUDA_GRAPH refusal stays
until the GPU-window gate is green -- capture with a registered peer segment
replaying byte-identically against eager (sgl-project#52/sgl-project#53 family). It falls to a
passing test, not to finished code.

223 passed / 34 skipped. Decisions recorded in ANALYSE_393 section 11.7.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…as a measurement artefact

club-3090 suite, script unmodified and uncopied, on the equal-shard arm:
narrative 7.10 wall / 7.15 decode tok/s, code 7.15 / 7.21, TTFT ~920 ms.
Footnotes state plainly that link-proportional sharding is NOT active and why,
so the run cannot be read as an A/B.

The useful number is CV 1.0-1.4 % at 800-1000 generated tokens against ~5 % on
a 96-token probe in the same boot: measurement LENGTH set the earlier noise
floor, not the rig. The later proof window measures at bench length.

Per-rank H2D over 17.8 TiB of bench traffic sharpens the target: the x4 rank is
the clock at 1.40x the mean (858 s vs 559 s ideal), so 1.54x is recoverable on
the transfer term -- above the short probe's 1.36x, still well below the 1.69x
that assumed an equal-thirds split this configuration never had. 1.54x on the
transfer term is what the proof window is judged against.

Hit rate on the larger sample: 0.812 activation grain, 0.620 unique grain,
5.8x WASTE's 0.14, within a point of the short-probe row -- which is itself the
finding that it is stable across prompt shape.

Cards released: all three at 0 MiB, no orphaned processes, gpu-arb holder
removed and a window published for sgl-project#424.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
/root/v4flash_club3090_bench_footnotes.txt was still the unfilled template I
wrote before the window and it contradicted what happened: footnote 3 claimed
"Link-proportional cold-expert shards ACTIVE (sgl-project#394)", which is the opposite of
the truth -- the proportional arm cannot serve this model and the bench ran on
the equal distribution (measured 42.1 / 28.9 / 29.0 %). Three placeholders
(<MODEL>, <AB_EVIDENCE_LINE>, <SPEC_STATE>) were never filled.

Rewritten from the boot log rather than from memory:

* sgl-project#394 stated NOT ACTIVE, with the reason (disjoint expert ranges mean a
  delegated cold expert is absent, not relocated) and the fact that the arm is
  refused at boot.
* no A/B delta claimed, since there is no second arm; replaced by the measured
  opportunity -- x4 rank the clock at 1.40x the mean, 1.54x recoverable on the
  transfer term, with the note that the equal split was already 42/29/29 and
  never the 33/33/33 the older 1.69x assumed.
* speculative decoding OFF, evidenced by speculative_algorithm=None at launch.
* quant verified against the load log: IQ3_XXS, not Q3_K_XL. Served id recorded
  as the checkpoint path, because --served-model-name was not set.

Gated: no placeholders, no absolute paths / host / port / token leaks, no
false "active" claim, codespell clean. The same evidence citations added to the
two markdown copies so all three agree, and the battery-dir copy refreshed.

The file now reads correctly without any report standing next to it.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…dings, detectors vendored

Completes the audit with the two detectors that a consumer count cannot
replace, and commits them so the sweep is reproducible against a later tip.

Calibration now PASSES on both known cases, each against its pre-fix tree:

  sgl-project#197 (asymmetric gate) -- Detector C fires at ef6f8bc^ on
  models/qwen3_vl.py:1280/1288, keyed on three facts it derived itself: the
  gate docstring names "embed_tokens/lm_head", embed_tokens branches on
  gguf_dense_vocab() before its assignment, lm_head does not. Correct
  negative at HEAD. Worth stating plainly: the Detector A/D sweep committed
  in a800960 would NOT have found sgl-project#197 -- consumer counting sees absent
  wiring, never partial wiring.

  sgl-project#394 (always-default + degenerate derivation) -- Detector B classifies the
  cold_shard chain TEST-ONLY at d71e713, and B2 flags the nameplate-only
  derivation. Both correct-negative at HEAD.

Two refinements were only discovered by calibrating, and both are the
difference between finding the case and missing it:
  - B must propagate forwarding taint. A site passing foo=foo proves nothing
    when foo is the enclosing function's own always-default parameter. The
    untainted version printed WIRED for sgl-project#394.
  - B2 must strip docstrings. resolve_host_shard_ratio scored
    "has-measured-source" purely because its prose says "measured" while
    every actual source was an NVML nameplate query.

New findings:
  F8 presplit_expert_offload_after_repack(cold_shard=) is TEST-ONLY. The
     GGUF door got wired by a2b21c2; the fp8/GPTQ/AWQ presplit door did
     not, so sgl-project#394 is live for GGUF MoE only -- while the merge message says
     both halves take their layout from ONE plan object.
  F9 PathProfile.transport_hint: four production construction sites, none
     passes it, yet it is read on the actuation path, which therefore always
     gets None.

Coverage gaps are now stated in the document rather than left implicit. The
largest: Detector C was calibrated but NEVER SWEPT -- the all-envs run did
not finish, so sgl-project#197-shape partial-wiring defects remain essentially
unaudited at HEAD. That is the obvious next slice; the detector exists and
is calibrated, it just needs to run. Also unverified: planner/ (936 raw
rows, mostly **kwargs), and one open question on
PathProfile.saturation_threshold (no writer anywhere, permanently 1.0).

Test results:
  scripts/dev/audit_421/{detA_flags_envs,detD_module_reachability}.py were
  desk-edited (path parameterisation, lint) and then RE-RUN against the
  worktree: both reproduce their original output exactly (detD: 1 module at
  100% unreferenced = runtime_draft.py; detA: 1 DEAD + 16 TEST-ONLY of 165).
  The pins from a800960 are unchanged and still 8 passed.
  ruff check + ruff format + codespell clean on all touched files.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…n instead of trusting it

Follow-up to the shared-box arbitration warning. The cold-tier tests create
real segments with real mmaps, and the one path on which that stops being
hermetic is the module default -- ``/dev/shm``, a live shared resource other
sessions measure against. The autouse fixture already redirected it; now it
ASSERTS the redirection took, and asserts on the way out that no
``sgl-cold-*`` segment was left in the real ``/dev/shm``. A test added later
without the fixture, or a rename of SGLANG_MOE_COLD_TIER_SHM_DIR, fails here
rather than in somebody else's tmpfs budget.

Investigated the reported arbitration leak; this slice is not its source.
strace -f over the complete tests/moe_offload/ run (openat, creat, mkdir,
utimensat, unlink) records ZERO operations on /tmp/gpu-card-*.lock or
/spinning/gpu-arb/*. The only three matching lines are read-only opens of
/tmp/pytest-of-root/pytest-659/test_every_lock_carries_its_ow0/locks/
gpu-card-{0,1}.lock -- pytest's own tmp_path retention sweep walking another
test's fixture tree. Findings for the systematic task:

* /spinning/gpu-arb/holder advances with no test of this worktree running
  (mtime 1785682535 -> 1785682583 -> 1785682595, sampled idle).
* arb-reaper.sh:20-29 (two instances live, PIDs 193445/269212) touches
  $ARB/holder on every pass while any /tmp/gpu-card-*.lock exists, and
  RECREATES it as a regular file when absent. That reproduces the 0-byte
  holder without any test, and it is why the holder mtime appears to track
  whatever run happens to be in progress.
* A leaked ``battery_heartbeat`` loop (PID 2428539) from
  test_every_lock_carries_its_ow0 is still running, sed -i-ing .../info inside
  a pytest tmpdir -- a different task's un-torn-down subprocess, and the
  reason that stale lock tree keeps looking alive.

No debris of this slice to remove: /dev/shm carries zero sgl-cold-* entries,
and the current /tmp/gpu-card-*.lock files were not created by these runs, so
they are left alone rather than raced against the reaper.

tests/moe_offload/: 254 passed, 34 skipped. ruff + codespell clean.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…PUTE placement via --rank-moe-ratio link (planner solve over the measured provenance chain, resident mass fixed, launcher-resolved ranges) — slice 3 of the sgl-project#394 chain; proof arm ARM3 specced
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
… (#task de-sync port)

Device-side remap replaces topk_ids.tolist() under capture; scratch admission
bound tightened to worst_case_unique_spill; sgl-project#394 delegation seam clamped with
device-resident breach counter (OffloadCaptureBreach). Default eager path
unchanged. 63 new tests, four executed can-fail arms. GPU boot proof (capture/
replay/UVA/perf arms) pending — scripts/dev/443_graph_proof/.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
Desk analysis, no build. docs/dev/ANALYSE_CPU_EXPERT_LANE.md. Scope is the
LOCAL CPU (98 GB, no swap); DESIGN_453's remote CPU lane on rig 2 is a
different vehicle and is not re-derived.

MECHANICAL CUT. The CPU lane replaces the FETCH in the existing
expert_offload path: instead of H2D-copying an expert's weights into a resident
slot, the CPU computes on the pinned host shard and only activations cross.
For the two local vehicles, shapes read from the shipped configs: Qwen3.5-35B-
A3B one expert is 6.29 MB against 8 KB of activations per token, the 122B is
18.87 MB against 12 KB -- roughly 800:1 in the lane's favour in decode. The
transfer wall really does disappear; what replaces it is a compute question.

PRICE ANCHOR, MEASURED rather than cited (hermetic torch CPU GEMM on the real
expert shapes, 16 threads, no card):

  Qwen3.5-35B-A3B  fp32: 0.268 ms/expert @1 tok (23.5 GFLOP/s), 0.338 @8,
                         0.932 @64 (432 GFLOP/s)
  Qwen3.5-122B-A10B fp32: 1.005 / 1.011 / 3.185 ms

FINDING 1, the most important line in the document: HALF PRECISION ON THIS CPU
IS A 400x CLIFF -- ~1.0 GFLOP/s for bf16 AND fp16 against 23-432 for fp32
(torch falls back to a scalar path). A CPU expert lane computing in the model's
native bf16 is not slow, it is impossible: 6.3 ms for one expert-token. The
lane's numeric format is therefore the feasibility question, not an
implementation detail -- a number that would have sunk a naive build after the
fact and costs 20 seconds to learn beforehand.

FINDING 2, the crossover runs the right way: against an H2D fetch at an assumed
~10 GB/s (all-PHB rig; the one unmeasured term, flagged as such), fp32 CPU
breaks even at ~40 tokens/expert on the 35B and >64 on the 122B. Per-expert
token counts are tiny in decode and ~64 in prefill, so this is a DECODE-ONLY
lane -- ~2.3x in decode, losing in prefill where sgl-project#254's expert-major waves
already win. That reproduces ANALYSE_393's ~2.00x on local shapes.

THE RAM WALL decides the local vehicle: fp32 masters would need 129 GB (35B) or
464 GB (122B) against 98 GB with no swap. Neither fits, so a local lane must
dequantise per event from GPTQ-Int4 into a small fp32 tile -- cost UNMEASURED,
and it must fit inside the 0.36 ms/expert-token of headroom the 2.3x buys. That
is the probe.

HONEST COSTS. Numerics land in the ~1e-2 class the fork already ACCEPTED for
GPTQ/AWQ-marlin offload (byte-identity is off the table), so the lane is lossy
and belongs after byte-identical wins under the quality-last rule. Scheduling:
the only overlap that pays is CPU and GPU on DISJOINT expert sets of the SAME
layer, making a layer cost max(GPU_hot, CPU_cold) rather than the sum -- any
other arrangement serialises and 40 layers x 0.268 ms would eat the whole win.
That is a starting constraint, not a later optimisation.

GRAPH COMPATIBILITY, per the standing requirement: "breaks capturable" is
rejected as an end state, and the route is sgl-project#462's breakable route, which this
tree already built -- the graph addresses SLOTS and the eager phase publishes
them before replay, so the CPU lane is an eager segment between captured
segments writing a fixed-shape, graph-addressed result buffer with the captured
grouped-GEMM masked over those rows. Start state is "graphs with an existing
break", not "no graphs"; what is new is the fixed-shape buffer and the mask,
both hermetically testable.

PER-VEHICLE PRICING, kept separate, and the summary is uncomfortable: DSV4F-
GGUF is transfer-wall dominated so the upside is largest, but its natural
format is an integer kernel that does not exist in this tree; Qwen3.5-35B-A3B
has only 0-28 % residual margin after sgl-project#394 and is the vehicle the rig runs. The
vehicle with the margin has the expensive build; the vehicle with the cheap
build has little margin left.

VERDICT: PROBE FIRST. Two of three terms are now measured; the third decides
everything -- how long GPTQ-Int4 -> fp32 dequant of one expert takes on this
CPU. Hermetic, no GPU, minutes. Anti-fooling named: measure on a COLD tile and
report the thread count, since a lane competing with the serving process will
not get 16 cores and an idle-box rate is an upper bound.

CROSSING QUESTION WITH P6, asked and answered rather than excluded: both want
eager time inside a captured decode step, but they touch different layers and
different resources, so there is no correctness conflict. The composition rule
is that whichever probe runs SECOND must measure with the first one ARMED, or
its margin is measured against a floor that will not exist in production. Both
funnel through the same sgl-project#462 graph discipline, which argues for doing that dock
properly once rather than twice.

codespell: clean.
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