Skip to content

remove assertion in triton attention and add an unit test - #1385

Merged
merrymercy merged 3 commits into
sgl-project:mainfrom
ByronHsu:byhsu/follow-up-non-2
Sep 11, 2024
Merged

merrymercy merged 3 commits into
sgl-project:mainfrom
ByronHsu:byhsu/follow-up-non-2

Conversation

@ByronHsu

@ByronHsu ByronHsu commented Sep 11, 2024 •

Copy link
Copy Markdown
Collaborator

Motivation

Resolve #1359 in order to support all non 2^n attention use cases.

Modifications

  1. Remove assertion in attention
  2. Add unit tests for decode, extend and prefill attention. Note that decode and extend are only tested for not erroring out instead of correctness. We need a follow up for correctness compared with torch implementation.

Test

Successfully run on 3 models regarding 3 issues

  1. Support Phi3 mini and medium #1299
$ python3 -m sglang.bench_latency --model microsoft/Phi-3-medium-4k-instruct --output-len 128 --trust-remote-code --attention-backend triton

Init nccl begin.
Load weight begin. avail mem=78.66 GB
INFO 09-11 04:04:30 weight_utils.py:236] Using model weights format ['*.safetensors']
Loading safetensors checkpoint shards:   0% Completed | 0/6 [00:00<?, ?it/s]
Loading safetensors checkpoint shards:  17% Completed | 1/6 [00:00<00:04,  1.10it/s]
Loading safetensors checkpoint shards:  33% Completed | 2/6 [00:01<00:03,  1.24it/s]
Loading safetensors checkpoint shards:  50% Completed | 3/6 [00:02<00:02,  1.18it/s]
Loading safetensors checkpoint shards:  67% Completed | 4/6 [00:03<00:01,  1.13it/s]
Loading safetensors checkpoint shards:  83% Completed | 5/6 [00:04<00:00,  1.08it/s]
Loading safetensors checkpoint shards: 100% Completed | 6/6 [00:05<00:00,  1.06it/s]
Loading safetensors checkpoint shards: 100% Completed | 6/6 [00:05<00:00,  1.10it/s]

Load weight end. type=Phi3ForCausalLM, dtype=torch.bfloat16, avail mem=52.50 GB
Memory pool end. avail mem=9.31 GB
max_total_num_tokens=225766
Warmup ...
Prefill. latency: 1.24759 s, throughput:    820.78 token/s
Decode.  latency: 0.03711 s, throughput:     26.95 token/s
Decode.  latency: 0.02068 s, throughput:     48.36 token/s
Decode.  latency: 0.02067 s, throughput:     48.37 token/s
Decode.  latency: 0.02060 s, throughput:     48.55 token/s
Decode.  median latency: 0.02068 s, median throughput:     48.37 token/s
Total. latency:  1.347 s, throughput:    763.38 token/s
Benchmark ...
Prefill. latency: 0.08270 s, throughput:  12382.60 token/s
Decode.  latency: 0.02173 s, throughput:     46.02 token/s
Decode.  latency: 0.02061 s, throughput:     48.52 token/s
Decode.  latency: 0.02070 s, throughput:     48.30 token/s
Decode.  latency: 0.02064 s, throughput:     48.45 token/s
Decode.  latency: 0.02097 s, throughput:     47.69 token/s
Decode.  median latency: 0.02027 s, median throughput:     49.33 token/s
Total. latency:  2.615 s, throughput:    440.60 token/s
  1. [Bug] head_dim 96 not supported #1159

$ python3 -m sglang.bench_latency --model vonjack/Phi-3-mini-4k-instruct-LLaMAfied  --output-len 128 --trust-remote-code --attention-backend triton

max_total_num_tokens=169367
Warmup ...
Prefill. latency: 2.15460 s, throughput:    475.26 token/s
Decode.  latency: 1.52448 s, throughput:      0.66 token/s
Decode.  latency: 0.02624 s, throughput:     38.11 token/s
Decode.  latency: 0.01949 s, throughput:     51.31 token/s
Decode.  latency: 0.01732 s, throughput:     57.73 token/s
Decode.  median latency: 0.02286 s, median throughput:     43.74 token/s
Total. latency:  3.742 s, throughput:    274.71 token/s
Benchmark ...
Prefill. latency: 0.02857 s, throughput:  35840.08 token/s
Decode.  latency: 0.02151 s, throughput:     46.48 token/s
Decode.  latency: 0.01859 s, throughput:     53.78 token/s
Decode.  latency: 0.01494 s, throughput:     66.94 token/s
Decode.  latency: 0.01057 s, throughput:     94.58 token/s
Decode.  latency: 0.01036 s, throughput:     96.55 token/s
Decode.  median latency: 0.01625 s, median throughput:     61.55 token/s
Total. latency:  2.835 s, throughput:    406.32 token/s
  1. [Bug] Failure to Dispatch Head Dimension 80 in sglang with Specific Configurations #1109
$ python3 -m sglang.bench_latency --model stabilityai/stablelm-3b-4e1t --output-len 128 --trust-remote-code --attention-backend triton

Init nccl begin.
Load weight begin. avail mem=78.66 GB
INFO 09-11 04:03:41 weight_utils.py:236] Using model weights format ['*.safetensors']
INFO 09-11 04:03:42 weight_utils.py:280] No model.safetensors.index.json found in remote.
Loading safetensors checkpoint shards:   0% Completed | 0/1 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 100% Completed | 1/1 [00:00<00:00,  1.02it/s]
Loading safetensors checkpoint shards: 100% Completed | 1/1 [00:00<00:00,  1.02it/s]

Load weight end. type=StableLmForCausalLM, dtype=torch.bfloat16, avail mem=73.29 GB
Memory pool end. avail mem=9.35 GB
max_total_num_tokens=209225
Warmup ...
Prefill. latency: 0.96427 s, throughput:   1061.94 token/s
Decode.  latency: 0.08962 s, throughput:     11.16 token/s
Decode.  latency: 0.01486 s, throughput:     67.29 token/s
Decode.  latency: 0.01477 s, throughput:     67.69 token/s
Decode.  latency: 0.01456 s, throughput:     68.69 token/s
Decode.  median latency: 0.01482 s, median throughput:     67.49 token/s
Total. latency:  1.098 s, throughput:    936.17 token/s
Benchmark ...
Prefill. latency: 0.02249 s, throughput:  45525.51 token/s
Decode.  latency: 0.01480 s, throughput:     67.55 token/s
Decode.  latency: 0.01457 s, throughput:     68.64 token/s
Decode.  latency: 0.01479 s, throughput:     67.63 token/s
Decode.  latency: 0.01463 s, throughput:     68.37 token/s
Decode.  latency: 0.01452 s, throughput:     68.87 token/s
Decode.  median latency: 0.01438 s, median throughput:     69.53 token/s
Total. latency:  1.874 s, throughput:    614.77 token/s

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

@merrymercy
merrymercy merged commit 8c0efa5 into sgl-project:main Sep 11, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
b_start_loc = torch.arange(0, total_tokens, seq_len, device="cuda")
b_seq_len = torch.full((B,), seq_len, device="cuda")

decode_attention_fwd(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you miss the results checking part in this case?

efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… loop, not just the price

Step 1 (45477c1) wired the cap through PRICING ONLY: the host ledger
charged `lanes_priced` while `weight_updater.py`'s lane loop still pinned a
buffer for every lane it owned, unconditionally. A ledger that charges LESS
than the runtime actually pins funds a boot that then dies at the host --
sgl-project#1358's under-charge reproduced in the other direction, and a violation of
host-schwelle-nie-uebertreten. The WEG2-XCHG-LANES-CONCURRENT-CAVEAT line
said so as `runtime_enforcement=NOT_WIRED`; this commit is what makes it
say the opposite truthfully.

THE PRIMITIVE: `weight_exchange_transport.LanePermit`, a boot-wide POSIX
counting semaphore, opened (never created) by a rank -- the identical
NEVER-O_CREAT rule `SemSet` already gives, for the identical reason: the
launcher creates it with O_EXCL after unlinking
(`weight_exchange_region.create_lane_permit_semaphore`, named
`/weg2-xchg-<boot>-lanes-permit`, deliberately inside the existing
REGION_PREFIX namespace so the launch-time residue sweep
(`sweep_xchg_semaphores`) cleans it up exactly as it already does the other
36 names -- no second teardown path to build or forget). Sized to
`lanes_priced`, the SAME number the ledger just charged with, never a
second count.

THE WIRING: `weight_updater.py`'s lane loop (inside
`_weg2_xchg_bounce_leg`) acquires the permit RIGHT BEFORE each lane's
`bx.run_bounce_leg(...)` call and releases it in a `finally` RIGHT AFTER --
deliberately outside the per-tag drain wait (`rv.wait_drained`), because
that wait is for a peer's unrelated progress and holding a permit across it
would tie up a boot-wide slot while idle, making the cap less effective
than the number it charges for. `run_bounce_leg`'s OWN `finally` already
closes (unpins) its `LayerBounce` on every exit path before returning or
raising, so by the time the wrapping `finally` releases the permit the
memory is guaranteed already freed -- the buffer is freed BEFORE the next
acquire can succeed, never after. The permit object itself is created only
when `terms.lanes_concurrent > 0` (the SAME field the ledger priced with),
so the unset/default path opens no semaphore and performs the zero extra
syscalls the flag has always promised.

BOUNDED WAIT, NAMED REFUSAL: `LanePermit.acquire` reuses
`Weg2XchgGateTimeout` (W69) -- the exact class this rig's own history
already uses for "a bounded semaphore wait exceeded its budget"
(oncard rows, slot pairs, gates) -- rather than minting a new code for the
same shape, and rather than ever waiting unboundedly: a permit that can
never be granted means the boot's own accounting of who holds one has
already diverged from reality, and that is a fact about THIS boot, never a
reason to hang. Default budget 120s, the same fence CrossSlotRendezvous
already uses.

Tests, appended to test_weg2_xchg_lanes_concurrent_1385.py (36 total now):
  TheLanePermitPrimitive       -- REAL POSIX IPC, not a mock: create/open/
    acquire/release/unlink round trip; refuse permits<1; a rank can never
    create the name by opening it (ENOENT, matching SemSet's own rule); a
    bounded timeout that is neither instant nor unbounded, named W69, and
    the SAME semaphore grants again once released
  test_at_most_N_permits_are_ever_held_at_once -- M1, THE CORE MUTANT
    GUARD: 6 real threads, 2 real permits, a real shared counter. MANUALLY
    VERIFIED: making `LanePermit.acquire` a no-op makes this test measure
    peak concurrency 6 against a 2-permit budget and fail immediately;
    restored after (diff empty)
  RuntimeEnforcementIsWiredCorrectly -- source-order proof (the same style
    test_weg2_bounce_perlane_1358.py already uses for this exact class of
    claim, because a full multi-rank GPU boot is not available to a
    hermetic desk test) that acquire precedes run_bounce_leg precedes
    release, that acquire is itself gated on `_lane_permit_active`, and
    that release lives in a `finally`. MANUALLY VERIFIED: forcing
    `_lane_permit_active = False` fails all four of these immediately;
    restored after (diff empty)
  TheLauncherPricesTheOnlyPermitCount -- the launcher creates the
    semaphore with `bounce_terms_for_ranks.lanes_priced`, never `n_lanes`
    or a second count, only when `_lanes_concurrent > 0`, and the name
    shares REGION_PREFIX so the existing sweep covers it
  Updated the two tests that asserted `runtime_enforcement=NOT_WIRED` to
    assert `=WIRED` and that the old EMITTED string no longer coexists

36/36 green; the wider bounce/lane/ledger/region/transport/shadow
neighbourhood (test_weg2_xchg_bounce_1332/perlane/depth-flag/-formkey_1358,
widest_layer_census_1332b, store_priced_x_1317,
xchg_bounce_execution_smoke_1273, xchg_bounce_phases_1330,
lane_coverage_1348, xchg_diagonal_lane_1334, lane_lockstep_1374,
shadow_execution_smoke_1329, xchg_card_uuid_map_1335, xchg_region_1273,
xchg_shadow_1273, xchg_transport_1273): 559/560 green, the one red
(test_prepare_and_teardown_round_trip_the_region_and_the_sems) reproduces
identically on the unmodified HEAD (verified by temporarily reverting only
weight_exchange_region.py to HEAD's copy and rerunning) -- pre-existing,
untouched by this diff (a pure 71-line addition ahead of
`unlink_semaphores`). ruff clean. No /dev/shm residue left by the test run
(unique per-test boot nonces, unlinked in `finally`).

STILL NOT BOOT-PROVEN, and the caveat line says so: the sgl-project#1358 3-way
measurement (tmpfs holders, cgroup d_shmem, host-slot lines) has not run on
the metal. What is proven at the desk: the semaphore primitive genuinely
bounds concurrency (real threads, real IPC) and the product code genuinely
acquires/releases it around exactly one lane's buffer lifetime, in the
right order, gated the right way. What a boot with
`--xchg-lanes-concurrent 2` must still confirm on xsn31's own checkpoint:
that the real host peak actually falls from 15.75 GiB toward 6.75 GiB
rather than merely reporting that it does.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…11b's cushion breach

Wand 11b (sgl-project#1377) is the open host blocker for the goal-question boot: the
bounce prices 5 measured lanes x 3.00 GiB + 0.75 GiB staging = 15.75 GiB on
xsn31/3's own checkpoint (front.log:111 xchg_bounce=15.75, front.log:106
lanes=5 source=measured), and the sleep-leg cushion floor (1.50 GiB) latches
at 0.20 (W98 Weg2HostRateLatched) because that growth ate the room. sgl-project#1370
made the bounce PRICED HONESTLY; it did not make it SMALLER.

ONE SOURCE, the --xchg-bounce-depth shape (48adc00) reused rather than a
second publication path: `BounceTerms.lanes_concurrent` (0 = "not stated",
byte-identical -- the same convention `max_tag_bytes` already uses two
fields over) caps how many of `n_lanes` price at once through a new
`lanes_priced` property; `total_bytes` reads that property instead of
`n_lanes` directly. The field rides `_TERM_FIELDS`, so P, D and the host
ledger recompute the identical capped total from the published inputs,
never a second formula. `checkpoint_census.widest_layer_terms` and
`launcher.choose_host_ledger` / `xchg_bounce_terms_for_arm` pass it through
unchanged; `main()` resolves the CLI value exactly once
(`xchg_bounce.resolve_lanes_concurrent`) and hands the same resolved int to
both the ranks' publication call and the ledger's own call, so the two
sides cannot disagree about which values are refused.

REFUSAL, NOT SILENT DEGRADATION: `--xchg-lanes-concurrent 0` (or negative)
is refused (W103 Weg2XchgLanesConcurrentInvalid) rather than folded into
the same 0 sentinel BounceTerms uses for "unset" -- collapsing them would
run every lane concurrently while the argv says the opposite. W103 is the
next free number after a tree-wide census (`grep -rhoE 'W[0-9]+'` tops out
at W102); W52/W53/W54/W56/W58 are a documented collision class (sgl-project#1265/sgl-project#1306)
of guessed digits, so this one is taken from the census.

NAMED AND COUNTED, NEVER SILENT: `WEG2-XCHG-LANES-CONCURRENT
lanes_concurrent= lanes_total= lanes_priced= serialised=` is appended to the
arm's own line list (appended, not inserted, so lines[0..2]'s existing
positional readers are untouched) so a boot can put a number beside the
flip-time cost of serialising the lanes this cap does not price.

THE COMPUTED EFFECT, on xsn31/3's own geometry (largest tag 2907 MiB, 128
MiB slots -> 24 slots/lane -> 3072 MiB/lane, 0.75 GiB staging, 5 measured
lanes): concurrent=2 charges 2 x 3.00 + 0.75 = 6.75 GiB (a 9.00 GiB
reduction from the measured 15.75); concurrent=1 charges 3.75 GiB (12.00
GiB reduction). Against xsn31/3's own cushion_min=0.20 (floor 1.50):
0.20 - (-9.00) = 9.20 >= 1.50 at concurrent=2, and 0.20 - (-12.00) = 12.20
>= 1.50 at concurrent=1 -- the invariant holds with wide margin either way,
using the boot record's own linear-tracking method (6.99 -> 0.20 explained
by the +7.96 GiB bounce growth). NOTE: depth (1 vs 2) changes NOTHING on
this checkpoint -- Option 1's tag-need (23 slots + 1 shadow = 24) dominates
the depth floor (2 or 3) at both depth=1 and depth=2, so the entire saving
here comes from lanes_concurrent alone, not from --xchg-bounce-depth.

HONESTY GATE, NAMED HERE NOT BUILT: this commit wires the cap through
PRICING only. `weight_updater.py`'s per-rank leg driver still allocates a
buffer for every lane it owns unconditionally -- no cross-process
concurrency permit exists yet, so a real boot's tmpfs usage may still
reach `lanes_total`'s worth even though the ledger now charges
`lanes_priced`. A WEG2-XCHG-LANES-CONCURRENT-CAVEAT line names this
explicitly whenever a cap actually serialises lanes, pointing at the same
3-way measurement (sgl-project#1358: tmpfs holders, cgroup d_shmem, host-slot lines)
that must confirm the real peak before this ARM number is trusted.

Tests: test_weg2_xchg_lanes_concurrent_1385.py, 23 cases (hermetic,
CUDA_VISIBLE_DEVICES=""), covering the default byte-identical path, the cap
actually shrinking the charge (the mutant guard for the OOM direction --
manually verified: reverting `lanes_priced` to `n_lanes` in `total_bytes`
fails 3 tests immediately, restored after), refusal for N<1, the W103
census-not-guess check, the named/counted log line (source and execution
smoke through a real fake checkpoint), and the one-source property (single
`resolve_lanes_concurrent(` call in `main`, both call sites take the same
resolved value). test_weg2_widest_layer_census_1332b.py's line-count
assertion updated 3->4 for the new appended line (positional indices
unchanged). 193 tests green across the full bounce/lane/ledger neighbour
suite plus the new file; ruff clean.

Default is byte-identical: lanes_concurrent=0 is the "not stated" sentinel,
`lanes_priced` returns `n_lanes` unchanged, and no existing caller passes
the new keyword.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
… loop, not just the price

Step 1 (45477c1) wired the cap through PRICING ONLY: the host ledger
charged `lanes_priced` while `weight_updater.py`'s lane loop still pinned a
buffer for every lane it owned, unconditionally. A ledger that charges LESS
than the runtime actually pins funds a boot that then dies at the host --
sgl-project#1358's under-charge reproduced in the other direction, and a violation of
host-schwelle-nie-uebertreten. The WEG2-XCHG-LANES-CONCURRENT-CAVEAT line
said so as `runtime_enforcement=NOT_WIRED`; this commit is what makes it
say the opposite truthfully.

THE PRIMITIVE: `weight_exchange_transport.LanePermit`, a boot-wide POSIX
counting semaphore, opened (never created) by a rank -- the identical
NEVER-O_CREAT rule `SemSet` already gives, for the identical reason: the
launcher creates it with O_EXCL after unlinking
(`weight_exchange_region.create_lane_permit_semaphore`, named
`/weg2-xchg-<boot>-lanes-permit`, deliberately inside the existing
REGION_PREFIX namespace so the launch-time residue sweep
(`sweep_xchg_semaphores`) cleans it up exactly as it already does the other
36 names -- no second teardown path to build or forget). Sized to
`lanes_priced`, the SAME number the ledger just charged with, never a
second count.

THE WIRING: `weight_updater.py`'s lane loop (inside
`_weg2_xchg_bounce_leg`) acquires the permit RIGHT BEFORE each lane's
`bx.run_bounce_leg(...)` call and releases it in a `finally` RIGHT AFTER --
deliberately outside the per-tag drain wait (`rv.wait_drained`), because
that wait is for a peer's unrelated progress and holding a permit across it
would tie up a boot-wide slot while idle, making the cap less effective
than the number it charges for. `run_bounce_leg`'s OWN `finally` already
closes (unpins) its `LayerBounce` on every exit path before returning or
raising, so by the time the wrapping `finally` releases the permit the
memory is guaranteed already freed -- the buffer is freed BEFORE the next
acquire can succeed, never after. The permit object itself is created only
when `terms.lanes_concurrent > 0` (the SAME field the ledger priced with),
so the unset/default path opens no semaphore and performs the zero extra
syscalls the flag has always promised.

BOUNDED WAIT, NAMED REFUSAL: `LanePermit.acquire` reuses
`Weg2XchgGateTimeout` (W69) -- the exact class this rig's own history
already uses for "a bounded semaphore wait exceeded its budget"
(oncard rows, slot pairs, gates) -- rather than minting a new code for the
same shape, and rather than ever waiting unboundedly: a permit that can
never be granted means the boot's own accounting of who holds one has
already diverged from reality, and that is a fact about THIS boot, never a
reason to hang. Default budget 120s, the same fence CrossSlotRendezvous
already uses.

Tests, appended to test_weg2_xchg_lanes_concurrent_1385.py (36 total now):
  TheLanePermitPrimitive       -- REAL POSIX IPC, not a mock: create/open/
    acquire/release/unlink round trip; refuse permits<1; a rank can never
    create the name by opening it (ENOENT, matching SemSet's own rule); a
    bounded timeout that is neither instant nor unbounded, named W69, and
    the SAME semaphore grants again once released
  test_at_most_N_permits_are_ever_held_at_once -- M1, THE CORE MUTANT
    GUARD: 6 real threads, 2 real permits, a real shared counter. MANUALLY
    VERIFIED: making `LanePermit.acquire` a no-op makes this test measure
    peak concurrency 6 against a 2-permit budget and fail immediately;
    restored after (diff empty)
  RuntimeEnforcementIsWiredCorrectly -- source-order proof (the same style
    test_weg2_bounce_perlane_1358.py already uses for this exact class of
    claim, because a full multi-rank GPU boot is not available to a
    hermetic desk test) that acquire precedes run_bounce_leg precedes
    release, that acquire is itself gated on `_lane_permit_active`, and
    that release lives in a `finally`. MANUALLY VERIFIED: forcing
    `_lane_permit_active = False` fails all four of these immediately;
    restored after (diff empty)
  TheLauncherPricesTheOnlyPermitCount -- the launcher creates the
    semaphore with `bounce_terms_for_ranks.lanes_priced`, never `n_lanes`
    or a second count, only when `_lanes_concurrent > 0`, and the name
    shares REGION_PREFIX so the existing sweep covers it
  Updated the two tests that asserted `runtime_enforcement=NOT_WIRED` to
    assert `=WIRED` and that the old EMITTED string no longer coexists

36/36 green; the wider bounce/lane/ledger/region/transport/shadow
neighbourhood (test_weg2_xchg_bounce_1332/perlane/depth-flag/-formkey_1358,
widest_layer_census_1332b, store_priced_x_1317,
xchg_bounce_execution_smoke_1273, xchg_bounce_phases_1330,
lane_coverage_1348, xchg_diagonal_lane_1334, lane_lockstep_1374,
shadow_execution_smoke_1329, xchg_card_uuid_map_1335, xchg_region_1273,
xchg_shadow_1273, xchg_transport_1273): 559/560 green, the one red
(test_prepare_and_teardown_round_trip_the_region_and_the_sems) reproduces
identically on the unmodified HEAD (verified by temporarily reverting only
weight_exchange_region.py to HEAD's copy and rerunning) -- pre-existing,
untouched by this diff (a pure 71-line addition ahead of
`unlink_semaphores`). ruff clean. No /dev/shm residue left by the test run
(unique per-test boot nonces, unlinked in `finally`).

STILL NOT BOOT-PROVEN, and the caveat line says so: the sgl-project#1358 3-way
measurement (tmpfs holders, cgroup d_shmem, host-slot lines) has not run on
the metal. What is proven at the desk: the semaphore primitive genuinely
bounds concurrency (real threads, real IPC) and the product code genuinely
acquires/releases it around exactly one lane's buffer lifetime, in the
right order, gated the right way. What a boot with
`--xchg-lanes-concurrent 2` must still confirm on xsn31's own checkpoint:
that the real host peak actually falls from 15.75 GiB toward 6.75 GiB
rather than merely reporting that it does.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…dger priced

WAND, TRACED AND CLOSED: xsn31/4 (--xchg-lanes-concurrent 2) measured the
lane-concurrency cap working PERFECTLY (2 files, never 5 or more -- two
independent instruments, a 0.2s filesystem poller and the lane's own
WEG2-XCHG-HOST-SLOT lines, deckungsgleich) while each file was 18,151,770,624
B (16.905 GiB) against a priced 3,221,225,472 B (3.00 GiB) -- 5.6x over.
Cushion latched (0.19 GiB < 1.50 GiB floor) 4 seconds after flip start.

ROOT CAUSE, TRACED TO THE BYTE. `weight_exchange_bounce.run_bounce_leg` read
`leg_geometry(terms)` for the per-band SIZE unconditionally -- the PRE-sgl-project#1374
"Amendment 2" pair, where one band equals one WHOLE LAYER
(widest_layer_bytes=756,323,776 B on this checkpoint) -- while separately
reading `terms.lane_slots` (Option 1's band COUNT, 24, sized by
`xchg_bounce.tag_slots` under the assumption that a band is
`terms.slot_bytes` wide, 128 MiB) for the band count. Multiplying a count
sized for 128-MiB bands by the widest-LAYER size:
756,323,776 x 24 = 18,151,770,624 -- EXACT, to the byte, against both
measurements. Two mechanisms from the SAME sgl-project#1374 "Option 1" day, never
reconciled: the slot COUNT changed when Option 1 landed, the slot SIZE it
multiplies did not.

DIRECTION, VERIFIED TWICE ON FRESH METAL (xsn31/4 with concurrent=2,
xsn31/5 with concurrent=1): "Allokator folgt der Preisformel". Re-pricing
the ledger on the real, uneven-PP-stage tag size (the other option) was
never live -- P's `--pp-stage-ratio 39,13,12` makes some tags carry many
multiples of one layer, so an honest price would make the ARM number true
and the boot impossible. xsn31/5 independently confirmed the cap itself is
flawless (never more than one file, all boot) while the per-file size
stayed at the bug's 16.905 GiB, because that boot ran the allocator this
commit fixes, not the fix.

NOT FACHLICH NOETIG, VERIFIED RATHER THAN ASSUMED: "whole tag in one
buffer" (Option 1's own promise: a deposit completes without its collector)
is a claim about the BUFFER'S TOTAL CAPACITY (`lane_slots` bands must cover
the whole tag so nothing wraps mid-tag), never about writing it as one
contiguous blob. `weight_exchange_transport.batch_descs` already slices any
unit across as many slot-sized bands as it takes -- this is what already
lets `lm_head` (4x a layer) band across the pre-sgl-project#1374 slot size without
complaint. The small-scale execution test below moves real bytes through
512-byte bands (not through anything layer-sized) and gets every
destination row exactly right, `bands > 1`, `verdict=MATCH`: the layered
form loses nothing.

THE FIX: `weight_exchange_bounce.leg_slot_bytes(terms)` -- the ONE producer
`run_bounce_leg` now reads for the per-band size. Option 1 active
(`terms.max_tag_bytes > 0`): returns `terms.slot_bytes` (the SAME 128 MiB
oncard unit `BounceTerms.lane_buffer_bytes` already multiplies by
`terms.lane_slots` to get the priced total), so
`leg_slot_bytes(terms) * terms.lane_slots == terms.lane_buffer_bytes` BY
CONSTRUCTION -- never a third number. Option 1 absent: `leg_geometry`'s
pre-sgl-project#1374 pair, byte-identical (that function and its own pinned tests,
test_the_leg_geometry_comes_from_the_arm_term_not_from_this_module and the
whole non-Option-1 execution-smoke suite, are untouched).

A second, NECESSARY change: `refuse_if_plan_exceeds_slot`'s AMENDMENT-2
check ("a layer must be assembled complete in ONE slot") is now SKIPPED
under Option 1 -- not removed, SKIPPED, because its premise (slot_bytes ==
widest_layer_bytes, so a layer always fit trivially) is false the moment
`slot_bytes` becomes the 128 MiB oncard unit, and calling it unchanged
would refuse every Option-1 boot on its first layer. The equivalent
protection under Option 1 already existed and is unchanged: the in-loop
`bands >= slots` refusal (W68 Weg2XchgPlanDisagree), graded against the
SAME `slots` the buffer is actually built with.

NAMED, NOT FIXED (out of scope for this commit): `_compare_band`'s shadow
slot address (`bounce.slot_address(int(depth))`) is correct only in the
pre-Option-1 geometry (`slots = depth + 1`, so index `depth` is the one
extra slot); under Option 1 (`slots = lane_slots = 24`) the reserved shadow
slot is actually at index `lane_slots - 1`, not `depth`. This is a
pre-existing, LATENT defect -- unaffected by this commit either way, and
not yet exercised on any boot (xsn31/4's own INJECT lines all read
`verdict=NO-COMPARE pieces=0`: the flip died before a single comparison
ran). Commented in place; a future seat must reconcile it before trusting
`mode=shadow` under a real Option-1 cap.

Tests: test_weg2_xchg_leg_slot_bytes_1385.py, 15 cases (hermetic,
CUDA_VISIBLE_DEVICES=""). RED-FIRST FIXTURE using the measured production
numbers verbatim (widest_layer=756,323,776 B, oncard slot=134,217,728 B,
max_tag_bytes=2907 MiB, the measured 18,151,770,624 B, the priced
3,221,225,472 B): pins the bug's own arithmetic as a permanent regression
anchor (`widest_layer_bytes * lane_slots == 18,151,770,624`, independent of
whether the fix is present), then proves the fix reproduces neither that
number nor a third one. Danger-direction mutant guard (price smaller than
allocation, the exact xsn31/4 state) plus structural wiring checks
(`_option1_leg` computed exactly once and reused at all three sites: slot
size, Amendment-2 skip, slot count) plus the small-scale real execution
smoke through the product's own `_weg2_xchg_bounce_leg` call site.
MANUALLY VERIFIED: reverting `leg_slot_bytes` to always return
`leg_geometry(terms)[0]` fails 7 tests immediately, including the core
guard, and reproduces 18,151,770,624 exactly; restored after (diff empty).

240/241 green across the full bounce/lane/ledger/chain neighbourhood plus
the two new sgl-project#1385 files (test_weg2_xchg_bounce_1332/perlane/depth-flag/
-formkey_1358, widest_layer_census_1332b, store_priced_x_1317,
xchg_bounce_execution_smoke_1273, xchg_bounce_phases_1330,
lane_coverage_1348, xchg_diagonal_lane_1334, lane_lockstep_1374,
xchg_lanes_concurrent_1385, xchg_leg_slot_bytes_1385,
xchg_chain_smoke_1342); the one red
(test_the_chain_runs_once_and_produces_the_graded_artifacts) reproduces
identically on unmodified HEAD (verified by temporarily reverting only
weight_exchange_bounce.py to HEAD's copy and rerunning) -- pre-existing,
unrelated to this diff. ruff clean.

STILL BOOT-UNPROVEN, AND HONESTLY SO. The fix makes the ALLOCATOR match the
PRICE for the first time (desk-proven: pure arithmetic on the exact
measured fixture, plus a real small-scale execution test moving real
bytes). What it cannot answer from the desk is whether the resulting REAL
reduction (concurrent=2: 33.81 GiB -> 6.75 GiB; concurrent=1: 16.905 GiB ->
3.75 GiB) clears the cushion floor on THIS box's current host budget:
xsn31/5's own measurement shows the relationship is NOT linear here (a
16.9 GiB real reduction in bounce size moved cushion only 0.19 -> wait,
0.19->0.85, +0.66 GiB -- roughly 3.9% pass-through, not 100%), because
other host terms (host-ring ~43-46 GiB per the coordinator's own
accounting) already consume most of the budget. Applying that OBSERVED
(single-sample, not a law) 3.9% rate to this fix's own reductions projects
cushion landing just under the 1.50 GiB floor at BOTH concurrent=1
(~1.36 GiB) and concurrent=2 (~1.25 GiB) -- while a naive 1:1 model
predicts tens of GiB of margin. The two models disagree by more than an
order of magnitude, so a boot with this fix applied is the only honest way
to learn which one describes the real box; the coordinator's own named
fallback if it does not clear the floor is the host-ring lever (sgl-project#1369,
30.42 GiB).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…dger priced

WAND, TRACED AND CLOSED: xsn31/4 (--xchg-lanes-concurrent 2) measured the
lane-concurrency cap working PERFECTLY (2 files, never 5 or more -- two
independent instruments, a 0.2s filesystem poller and the lane's own
WEG2-XCHG-HOST-SLOT lines, deckungsgleich) while each file was 18,151,770,624
B (16.905 GiB) against a priced 3,221,225,472 B (3.00 GiB) -- 5.6x over.
Cushion latched (0.19 GiB < 1.50 GiB floor) 4 seconds after flip start.

ROOT CAUSE, TRACED TO THE BYTE. `weight_exchange_bounce.run_bounce_leg` read
`leg_geometry(terms)` for the per-band SIZE unconditionally -- the PRE-sgl-project#1374
"Amendment 2" pair, where one band equals one WHOLE LAYER
(widest_layer_bytes=756,323,776 B on this checkpoint) -- while separately
reading `terms.lane_slots` (Option 1's band COUNT, 24, sized by
`xchg_bounce.tag_slots` under the assumption that a band is
`terms.slot_bytes` wide, 128 MiB) for the band count. Multiplying a count
sized for 128-MiB bands by the widest-LAYER size:
756,323,776 x 24 = 18,151,770,624 -- EXACT, to the byte, against both
measurements. Two mechanisms from the SAME sgl-project#1374 "Option 1" day, never
reconciled: the slot COUNT changed when Option 1 landed, the slot SIZE it
multiplies did not.

DIRECTION, VERIFIED TWICE ON FRESH METAL (xsn31/4 with concurrent=2,
xsn31/5 with concurrent=1): "Allokator folgt der Preisformel". Re-pricing
the ledger on the real, uneven-PP-stage tag size (the other option) was
never live -- P's `--pp-stage-ratio 39,13,12` makes some tags carry many
multiples of one layer, so an honest price would make the ARM number true
and the boot impossible. xsn31/5 independently confirmed the cap itself is
flawless (never more than one file, all boot) while the per-file size
stayed at the bug's 16.905 GiB, because that boot ran the allocator this
commit fixes, not the fix.

NOT FACHLICH NOETIG, VERIFIED RATHER THAN ASSUMED: "whole tag in one
buffer" (Option 1's own promise: a deposit completes without its collector)
is a claim about the BUFFER'S TOTAL CAPACITY (`lane_slots` bands must cover
the whole tag so nothing wraps mid-tag), never about writing it as one
contiguous blob. `weight_exchange_transport.batch_descs` already slices any
unit across as many slot-sized bands as it takes -- this is what already
lets `lm_head` (4x a layer) band across the pre-sgl-project#1374 slot size without
complaint. The small-scale execution test below moves real bytes through
512-byte bands (not through anything layer-sized) and gets every
destination row exactly right, `bands > 1`, `verdict=MATCH`: the layered
form loses nothing.

THE FIX: `weight_exchange_bounce.leg_slot_bytes(terms)` -- the ONE producer
`run_bounce_leg` now reads for the per-band size. Option 1 active
(`terms.max_tag_bytes > 0`): returns `terms.slot_bytes` (the SAME 128 MiB
oncard unit `BounceTerms.lane_buffer_bytes` already multiplies by
`terms.lane_slots` to get the priced total), so
`leg_slot_bytes(terms) * terms.lane_slots == terms.lane_buffer_bytes` BY
CONSTRUCTION -- never a third number. Option 1 absent: `leg_geometry`'s
pre-sgl-project#1374 pair, byte-identical (that function and its own pinned tests,
test_the_leg_geometry_comes_from_the_arm_term_not_from_this_module and the
whole non-Option-1 execution-smoke suite, are untouched).

A second, NECESSARY change: `refuse_if_plan_exceeds_slot`'s AMENDMENT-2
check ("a layer must be assembled complete in ONE slot") is now SKIPPED
under Option 1 -- not removed, SKIPPED, because its premise (slot_bytes ==
widest_layer_bytes, so a layer always fit trivially) is false the moment
`slot_bytes` becomes the 128 MiB oncard unit, and calling it unchanged
would refuse every Option-1 boot on its first layer. The equivalent
protection under Option 1 already existed and is unchanged: the in-loop
`bands >= slots` refusal (W68 Weg2XchgPlanDisagree), graded against the
SAME `slots` the buffer is actually built with.

NAMED, NOT FIXED (out of scope for this commit): `_compare_band`'s shadow
slot address (`bounce.slot_address(int(depth))`) is correct only in the
pre-Option-1 geometry (`slots = depth + 1`, so index `depth` is the one
extra slot); under Option 1 (`slots = lane_slots = 24`) the reserved shadow
slot is actually at index `lane_slots - 1`, not `depth`. This is a
pre-existing, LATENT defect -- unaffected by this commit either way, and
not yet exercised on any boot (xsn31/4's own INJECT lines all read
`verdict=NO-COMPARE pieces=0`: the flip died before a single comparison
ran). Commented in place; a future seat must reconcile it before trusting
`mode=shadow` under a real Option-1 cap.

Tests: test_weg2_xchg_leg_slot_bytes_1385.py, 15 cases (hermetic,
CUDA_VISIBLE_DEVICES=""). RED-FIRST FIXTURE using the measured production
numbers verbatim (widest_layer=756,323,776 B, oncard slot=134,217,728 B,
max_tag_bytes=2907 MiB, the measured 18,151,770,624 B, the priced
3,221,225,472 B): pins the bug's own arithmetic as a permanent regression
anchor (`widest_layer_bytes * lane_slots == 18,151,770,624`, independent of
whether the fix is present), then proves the fix reproduces neither that
number nor a third one. Danger-direction mutant guard (price smaller than
allocation, the exact xsn31/4 state) plus structural wiring checks
(`_option1_leg` computed exactly once and reused at all three sites: slot
size, Amendment-2 skip, slot count) plus the small-scale real execution
smoke through the product's own `_weg2_xchg_bounce_leg` call site.
MANUALLY VERIFIED: reverting `leg_slot_bytes` to always return
`leg_geometry(terms)[0]` fails 7 tests immediately, including the core
guard, and reproduces 18,151,770,624 exactly; restored after (diff empty).

240/241 green across the full bounce/lane/ledger/chain neighbourhood plus
the two new sgl-project#1385 files (test_weg2_xchg_bounce_1332/perlane/depth-flag/
-formkey_1358, widest_layer_census_1332b, store_priced_x_1317,
xchg_bounce_execution_smoke_1273, xchg_bounce_phases_1330,
lane_coverage_1348, xchg_diagonal_lane_1334, lane_lockstep_1374,
xchg_lanes_concurrent_1385, xchg_leg_slot_bytes_1385,
xchg_chain_smoke_1342); the one red
(test_the_chain_runs_once_and_produces_the_graded_artifacts) reproduces
identically on unmodified HEAD (verified by temporarily reverting only
weight_exchange_bounce.py to HEAD's copy and rerunning) -- pre-existing,
unrelated to this diff. ruff clean.

STILL BOOT-UNPROVEN, AND HONESTLY SO. The fix makes the ALLOCATOR match the
PRICE for the first time (desk-proven: pure arithmetic on the exact
measured fixture, plus a real small-scale execution test moving real
bytes). What it cannot answer from the desk is whether the resulting REAL
reduction (concurrent=2: 33.81 GiB -> 6.75 GiB; concurrent=1: 16.905 GiB ->
3.75 GiB) clears the cushion floor on THIS box's current host budget:
xsn31/5's own measurement shows the relationship is NOT linear here (a
16.9 GiB real reduction in bounce size moved cushion only 0.19 -> wait,
0.19->0.85, +0.66 GiB -- roughly 3.9% pass-through, not 100%), because
other host terms (host-ring ~43-46 GiB per the coordinator's own
accounting) already consume most of the budget. Applying that OBSERVED
(single-sample, not a law) 3.9% rate to this fix's own reductions projects
cushion landing just under the 1.50 GiB floor at BOTH concurrent=1
(~1.36 GiB) and concurrent=2 (~1.25 GiB) -- while a naive 1:1 model
predicts tens of GiB of margin. The two models disagree by more than an
order of magnitude, so a boot with this fix applied is the only honest way
to learn which one describes the real box; the coordinator's own named
fallback if it does not clear the floor is the host-ring lever (sgl-project#1369,
30.42 GiB).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…, not only its permit

BOOT-PROVED, HALF OF IT GOOD NEWS: xsn31/6 measured step 1's size fix
holding exactly -- bytes=3,221,225,472 (3.00 GiB, 128 MiB x 24) on every
observed leg, filesystem poller and WEG2-XCHG-HOST-SLOT lines deckungsgleich.
The 16.9 GiB bug is gone.

THE OTHER HALF: with --xchg-lanes-concurrent 1, up to FOUR lane files
(c0+p1+p2+p4, 12.00 GiB) coexisted on tmpfs at once against a promised
3.00 GiB -- the third instance of "a number is priced, a different one is
really held" on this one flag (sgl-project#1358's per-lane undercount, step 1's
slot-size/slot-count mismatch, now this).

TRACED, NOT ASSUMED. The coordinator's own hypothesis -- "the semaphore
caps within one group, not across P and D" -- does not survive source
inspection: `create_lane_permit_semaphore` is called exactly once in
`launcher.main`, keyed on `str(ring_plan.epoch)`, and `prepare_xchg_env`'s
returned `xchg_env` (built from that SAME boot_nonce) is merged into BOTH
groups' environment through the SAME `build_env(..., xchg_env=xchg_env)`
call (three call sites, `group="P"` and `group="D"`, all passing the
identical dict) -- so `_weg2_xchg_deposit_before_sleep` (D, hook=source)
and `_weg2_xchg_inject_from_peer` (P, hook=authoritative) read the
identical `SGLANG_WEG2_XCHG_BOOT` value and open the identical semaphore
name. The permit genuinely is boot-wide, and this branch's own
`test_at_most_N_permits_are_ever_held_at_once` already proves the
PRIMITIVE enforces a real cross-process bound -- POSIX named semaphores do
not know or care which process opens them.

THE REAL GAP: `LayerBounce.close()` deliberately never unlinks (its own
docstring: cross-process store-and-forward needs the file to outlive
either side's own close, since the depositor may exit long before the
collector even opens its mmap). Step 2 released the PERMIT once
`run_bounce_leg` returned, correctly letting the next lane start PINNING --
but the PREVIOUS lane's FILE stayed on tmpfs, uncounted by the semaphore
and unremoved until full boot teardown
(`weight_exchange_region.teardown_region`). A cap on how many buffers may
be PINNED at any instant is not the same claim as a cap on how many
ACCUMULATE unfreed over one flip; by the time a flip has touched every
lane once, the two converge to the SAME uncapped total regardless of the
cap -- consistent with "up to four files, growing as more lanes were
touched" and requiring no cross-group semaphore failure to explain.

THE FIX: `weight_exchange_bounce.unlink_lane_buffer(boot_nonce, shm_root,
lane)`, called from `weight_updater.py`'s lane loop at the ONE place that
already knows this tag's buffer is done with: right after
`CrossSlotRendezvous.post_drained(tag)`, on the COLLECT side only -- the
same signal that already tells the depositor it may reuse the buffer for
the next tag. Safe there because BOTH sides' own file descriptors are
already closed by that point (each inside its own, earlier,
`run_bounce_leg` call's `finally`), so the kernel frees the tmpfs pages the
instant the last directory entry is removed, and unlinking any earlier
would risk destroying bytes a real cross-process collector has not read
yet. Gated on the SAME `_lane_permit_active` boolean the permit itself
uses -- never a second, independent condition -- so the unset/default arm,
whose own `BounceTerms.total_bytes` formula already prices for every lane
accumulating (that is what `n_lanes` in the uncapped charge already means),
is completely untouched.

Tests, appended to test_weg2_xchg_lanes_concurrent_1385.py (42 total now):
  TheCollectorFreesTheFileNotOnlyThePermit -- REAL execution, not a mock:
    3 lanes (one diagonal, two cross, matching _all_descs' own N_DST=3)
    deposited then collected through TWO separate calls to the product's
    own `_weg2_xchg_bounce_leg` (matching D's and P's separate processes).
    With cap=1: every file exists after deposit, NONE survive the
    collector. Without a cap: files persist exactly as before (the
    byte-identical-default proof). Both check `_mismatched_rows == []` --
    the fix must not cost correctness, and it does not.
  TheUnlinkIsWiredAtExactlyTheRightPoint -- source-order proof: the unlink
    sits immediately after `post_drained`, gated by the identical
    `_lane_permit_active` boolean the permit uses, reached only on the
    collect side.
  MANUALLY VERIFIED: disabling the unlink call (`if False:` in place of the
    gate) fails the execution test immediately (a lane file survives its
    own collector) and the source-order test; restored after (diff empty).

244/244 green across the full bounce/lane/ledger/chain neighbourhood plus
both sgl-project#1385 files. ruff clean. No /dev/shm residue left by the test run
(unique per-test boot nonces via `_fresh_boot()`, unlinked in `finally`);
residue from earlier interactive desk exploration (three `s4bNNNNNNx0`
nonces, 60 semaphores + a 6480 B bounce-slot record each, 0 live holders
verified individually with `fuser` before removal) cleaned up separately,
not part of this commit's own test output.

STILL BOOT-UNPROVEN AT THIS STEP: this is DESK-proven (real deposit, real
collect, real bytes, real file removal, through the product's own call
site) but not yet confirmed on the metal that a full xsn31 flip with this
fix applied actually keeps tmpfs at <= lanes_priced files throughout. The
coordinator's own warning stands and is not re-litigated here: cushion is
NOT monotone in bounce size on this box (16.9 GiB bounce measured cushion
0.85 on xsn31/5, 12.0 GiB measured cushion 0.20 on xsn31/6 -- less bounce,
less cushion), because other host terms dominate the budget and shmem
moves in step-function jumps tied to allocation events, not to a smooth
function of bytes. This commit answers only what it was asked to answer:
what changes at the SIMULTANEOUS-occupancy layer (which is now genuinely
bounded by `lanes_priced`, proven at the desk) -- the cushion question is
the boot's to answer, not arithmetic's.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…, not only its permit

BOOT-PROVED, HALF OF IT GOOD NEWS: xsn31/6 measured step 1's size fix
holding exactly -- bytes=3,221,225,472 (3.00 GiB, 128 MiB x 24) on every
observed leg, filesystem poller and WEG2-XCHG-HOST-SLOT lines deckungsgleich.
The 16.9 GiB bug is gone.

THE OTHER HALF: with --xchg-lanes-concurrent 1, up to FOUR lane files
(c0+p1+p2+p4, 12.00 GiB) coexisted on tmpfs at once against a promised
3.00 GiB -- the third instance of "a number is priced, a different one is
really held" on this one flag (sgl-project#1358's per-lane undercount, step 1's
slot-size/slot-count mismatch, now this).

TRACED, NOT ASSUMED. The coordinator's own hypothesis -- "the semaphore
caps within one group, not across P and D" -- does not survive source
inspection: `create_lane_permit_semaphore` is called exactly once in
`launcher.main`, keyed on `str(ring_plan.epoch)`, and `prepare_xchg_env`'s
returned `xchg_env` (built from that SAME boot_nonce) is merged into BOTH
groups' environment through the SAME `build_env(..., xchg_env=xchg_env)`
call (three call sites, `group="P"` and `group="D"`, all passing the
identical dict) -- so `_weg2_xchg_deposit_before_sleep` (D, hook=source)
and `_weg2_xchg_inject_from_peer` (P, hook=authoritative) read the
identical `SGLANG_WEG2_XCHG_BOOT` value and open the identical semaphore
name. The permit genuinely is boot-wide, and this branch's own
`test_at_most_N_permits_are_ever_held_at_once` already proves the
PRIMITIVE enforces a real cross-process bound -- POSIX named semaphores do
not know or care which process opens them.

THE REAL GAP: `LayerBounce.close()` deliberately never unlinks (its own
docstring: cross-process store-and-forward needs the file to outlive
either side's own close, since the depositor may exit long before the
collector even opens its mmap). Step 2 released the PERMIT once
`run_bounce_leg` returned, correctly letting the next lane start PINNING --
but the PREVIOUS lane's FILE stayed on tmpfs, uncounted by the semaphore
and unremoved until full boot teardown
(`weight_exchange_region.teardown_region`). A cap on how many buffers may
be PINNED at any instant is not the same claim as a cap on how many
ACCUMULATE unfreed over one flip; by the time a flip has touched every
lane once, the two converge to the SAME uncapped total regardless of the
cap -- consistent with "up to four files, growing as more lanes were
touched" and requiring no cross-group semaphore failure to explain.

THE FIX: `weight_exchange_bounce.unlink_lane_buffer(boot_nonce, shm_root,
lane)`, called from `weight_updater.py`'s lane loop at the ONE place that
already knows this tag's buffer is done with: right after
`CrossSlotRendezvous.post_drained(tag)`, on the COLLECT side only -- the
same signal that already tells the depositor it may reuse the buffer for
the next tag. Safe there because BOTH sides' own file descriptors are
already closed by that point (each inside its own, earlier,
`run_bounce_leg` call's `finally`), so the kernel frees the tmpfs pages the
instant the last directory entry is removed, and unlinking any earlier
would risk destroying bytes a real cross-process collector has not read
yet. Gated on the SAME `_lane_permit_active` boolean the permit itself
uses -- never a second, independent condition -- so the unset/default arm,
whose own `BounceTerms.total_bytes` formula already prices for every lane
accumulating (that is what `n_lanes` in the uncapped charge already means),
is completely untouched.

Tests, appended to test_weg2_xchg_lanes_concurrent_1385.py (42 total now):
  TheCollectorFreesTheFileNotOnlyThePermit -- REAL execution, not a mock:
    3 lanes (one diagonal, two cross, matching _all_descs' own N_DST=3)
    deposited then collected through TWO separate calls to the product's
    own `_weg2_xchg_bounce_leg` (matching D's and P's separate processes).
    With cap=1: every file exists after deposit, NONE survive the
    collector. Without a cap: files persist exactly as before (the
    byte-identical-default proof). Both check `_mismatched_rows == []` --
    the fix must not cost correctness, and it does not.
  TheUnlinkIsWiredAtExactlyTheRightPoint -- source-order proof: the unlink
    sits immediately after `post_drained`, gated by the identical
    `_lane_permit_active` boolean the permit uses, reached only on the
    collect side.
  MANUALLY VERIFIED: disabling the unlink call (`if False:` in place of the
    gate) fails the execution test immediately (a lane file survives its
    own collector) and the source-order test; restored after (diff empty).

244/244 green across the full bounce/lane/ledger/chain neighbourhood plus
both sgl-project#1385 files. ruff clean. No /dev/shm residue left by the test run
(unique per-test boot nonces via `_fresh_boot()`, unlinked in `finally`);
residue from earlier interactive desk exploration (three `s4bNNNNNNx0`
nonces, 60 semaphores + a 6480 B bounce-slot record each, 0 live holders
verified individually with `fuser` before removal) cleaned up separately,
not part of this commit's own test output.

STILL BOOT-UNPROVEN AT THIS STEP: this is DESK-proven (real deposit, real
collect, real bytes, real file removal, through the product's own call
site) but not yet confirmed on the metal that a full xsn31 flip with this
fix applied actually keeps tmpfs at <= lanes_priced files throughout. The
coordinator's own warning stands and is not re-litigated here: cushion is
NOT monotone in bounce size on this box (16.9 GiB bounce measured cushion
0.85 on xsn31/5, 12.0 GiB measured cushion 0.20 on xsn31/6 -- less bounce,
less cushion), because other host terms dominate the budget and shmem
moves in step-function jumps tied to allocation events, not to a smooth
function of bytes. This commit answers only what it was asked to answer:
what changes at the SIMULTANEOUS-occupancy layer (which is now genuinely
bounded by `lanes_priced`, proven at the desk) -- the cushion question is
the boot's to answer, not arithmetic's.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…easurement, not rebuild

READ-ONLY on host_ledger.py/launcher.py (they belong to the ledger seat's
HiCache switch + flag-group work right now); this file is the deliverable
itself -- a replay harness plus the verdict table the coordinator asked
for, over the whole xsn31 lineage instead of just the two calibration
boots.

CALIBRATION ANCHORS, reused verbatim from test_weg2_cushion_gate_1377.py,
not re-derived: xsn31/2 alone reads GREEN (cushion_headroom_gib(6.99, 7.79,
7.79) == 6.99), the xsn31/2->3 transition reads RED (cushion_headroom_gib
(6.99, 15.75, 7.79) == -0.97). TheCalibrationAnchorsHold pins both, plus an
explicit "these are not the same reading" guard, before the chain extends
past them -- a replay that read both green would be measuring nothing.

EXTENDED OVER THE FULL CHAIN (xsn31/2 -> /3 -> /4 -> /5 -> /6 ->
/7-projected), invariant 1 (predicted_run_peak + FLOOR <= hard_bound)
passes for EVERY record, including the four that actually latched W98 on
the metal -- confirmed as "a floor, not the gate" across the whole chain,
not just the original pair. Invariant 2 (cushion_headroom_gib) is the one
that actually discriminates, replayed on PRICED bounce (what the ARM
believed at boot time) where that is all the record has (xsn31/3, which
predates the filesystem poller instrument), and on REAL measured bounce
where the poller or HOST-SLOT lines exist (xsn31/4 onward).

TWO FINDINGS, named with file:line for the ledger seat to route rather than
fixed here (file boundary):

1. WIRING GAP. `cushion_headroom_gib` (host_ledger.py:4589-4608) -- the
   ONLY function in the tree that correctly separates xsn31/2 from
   xsn31/3 -- has ZERO production call sites. `choose()` never reads it;
   neither does any other ARM-time or dry-run decision path. Its only
   callers anywhere are its own unit tests and this file
   (test_no_call_site_in_host_ledger_outside_its_own_definition_and_tests,
   test_choose_never_reads_cushion_headroom -- both executable, not prose).
   Practical consequence, visible in this same replay: xsn31/3, /4, /5 and
   /6 all passed their pre-flight dry run FUNDABLE and only discovered the
   cushion breach LIVE (W98, after VRAM had already been mutated) --
   exactly the class of defect this whole campaign otherwise refuses
   before the first byte moves.

2. MODEL BLIND SPOT, not an arithmetic bug. `cushion_headroom_gib`'s body
   is a single subtraction over ONE term (the bounce delta) and holds
   every other shmem-consuming quantity constant between the two records
   BY CONSTRUCTION. Replayed on REAL measured bounce, xsn31/5->/6 is the
   coordinator-named non-monotonic case: real bounce FELL (16.905 ->
   12.00 GiB) yet measured cushion ALSO fell (0.85 -> 0.20), the opposite
   of what the one-term model predicts. Not a defect in the subtraction
   itself (xsn31/2->/3 calibrates exactly) -- a documented blind spot: the
   model has no term for whatever else varied between two boots on the
   same box, matching that boot record's own conclusion ("der naechste
   Hebel ist der Host-Ring/die Baseline-Terme, NICHT der Lane-Knopf").
   xsn31/3->/4 (priced basis, the only basis available for xsn31/3) shows
   the THIRD instance of the same shape for a different reason: the price
   itself was wrong at the time (the sgl-project#1385/xsn31-4 slot-size bug, already
   found and fixed this session, commit 461fdeb) -- named explicitly
   as NOT a defect in this function, so a future reader does not conflate
   an already-fixed input error with a new arithmetic one.

xsn31/7 PROJECTION (the coordinator's actual question): xsn31/7 crashed at
model load (an unrelated --speculative-draft-kv-only / --hicache-
canonical-kv-page incompatibility, server_args.py:8420-8432, named in
BOOT_weg2xsn31_0913_4.md's own VERSUCH 7 section) before any bounce
allocation, so there is no measured cushion for it. Held bounce identical
to xsn31/6 (HiCache does not touch lane pricing or the still-open cross-
group concurrency gap) and fed cushion_headroom_gib only BOOT7's own
measured HiCache saving (-8.17 GiB predicted_run_peak, cross-checked
against ANALYSE_57GIB_SHMEM_0913.md's independent -8.14 GiB estimate, the
two agreeing within 0.03 GiB): the arithmetic reads GREEN at +8.37 GiB
margin. Prognosis stays prognosis, stated in the test's own docstring and
repeated in the closing message: the model's own blind spot (finding 2,
above) means this number describes the ARITHMETIC, not a verdict on the
boot.

11/11 green, ruff clean. test_weg2_cushion_gate_1377.py's own sampler test
(TheCushionMinimumComesFromTheSamplersOwnColumn, reading a LIVE, rig-wide,
continuously-appended CSV explicitly marked "rig-only evidence") is
independently flaky against today's accumulated sampler data -- confirmed
unrelated to this commit (no file this commit touches is anywhere near
that code path) and out of this task's file boundary either way.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…easurement, not rebuild

READ-ONLY on host_ledger.py/launcher.py (they belong to the ledger seat's
HiCache switch + flag-group work right now); this file is the deliverable
itself -- a replay harness plus the verdict table the coordinator asked
for, over the whole xsn31 lineage instead of just the two calibration
boots.

CALIBRATION ANCHORS, reused verbatim from test_weg2_cushion_gate_1377.py,
not re-derived: xsn31/2 alone reads GREEN (cushion_headroom_gib(6.99, 7.79,
7.79) == 6.99), the xsn31/2->3 transition reads RED (cushion_headroom_gib
(6.99, 15.75, 7.79) == -0.97). TheCalibrationAnchorsHold pins both, plus an
explicit "these are not the same reading" guard, before the chain extends
past them -- a replay that read both green would be measuring nothing.

EXTENDED OVER THE FULL CHAIN (xsn31/2 -> /3 -> /4 -> /5 -> /6 ->
/7-projected), invariant 1 (predicted_run_peak + FLOOR <= hard_bound)
passes for EVERY record, including the four that actually latched W98 on
the metal -- confirmed as "a floor, not the gate" across the whole chain,
not just the original pair. Invariant 2 (cushion_headroom_gib) is the one
that actually discriminates, replayed on PRICED bounce (what the ARM
believed at boot time) where that is all the record has (xsn31/3, which
predates the filesystem poller instrument), and on REAL measured bounce
where the poller or HOST-SLOT lines exist (xsn31/4 onward).

TWO FINDINGS, named with file:line for the ledger seat to route rather than
fixed here (file boundary):

1. WIRING GAP. `cushion_headroom_gib` (host_ledger.py:4589-4608) -- the
   ONLY function in the tree that correctly separates xsn31/2 from
   xsn31/3 -- has ZERO production call sites. `choose()` never reads it;
   neither does any other ARM-time or dry-run decision path. Its only
   callers anywhere are its own unit tests and this file
   (test_no_call_site_in_host_ledger_outside_its_own_definition_and_tests,
   test_choose_never_reads_cushion_headroom -- both executable, not prose).
   Practical consequence, visible in this same replay: xsn31/3, /4, /5 and
   /6 all passed their pre-flight dry run FUNDABLE and only discovered the
   cushion breach LIVE (W98, after VRAM had already been mutated) --
   exactly the class of defect this whole campaign otherwise refuses
   before the first byte moves.

2. MODEL BLIND SPOT, not an arithmetic bug. `cushion_headroom_gib`'s body
   is a single subtraction over ONE term (the bounce delta) and holds
   every other shmem-consuming quantity constant between the two records
   BY CONSTRUCTION. Replayed on REAL measured bounce, xsn31/5->/6 is the
   coordinator-named non-monotonic case: real bounce FELL (16.905 ->
   12.00 GiB) yet measured cushion ALSO fell (0.85 -> 0.20), the opposite
   of what the one-term model predicts. Not a defect in the subtraction
   itself (xsn31/2->/3 calibrates exactly) -- a documented blind spot: the
   model has no term for whatever else varied between two boots on the
   same box, matching that boot record's own conclusion ("der naechste
   Hebel ist der Host-Ring/die Baseline-Terme, NICHT der Lane-Knopf").
   xsn31/3->/4 (priced basis, the only basis available for xsn31/3) shows
   the THIRD instance of the same shape for a different reason: the price
   itself was wrong at the time (the sgl-project#1385/xsn31-4 slot-size bug, already
   found and fixed this session, commit 461fdeb) -- named explicitly
   as NOT a defect in this function, so a future reader does not conflate
   an already-fixed input error with a new arithmetic one.

xsn31/7 PROJECTION (the coordinator's actual question): xsn31/7 crashed at
model load (an unrelated --speculative-draft-kv-only / --hicache-
canonical-kv-page incompatibility, server_args.py:8420-8432, named in
BOOT_weg2xsn31_0913_4.md's own VERSUCH 7 section) before any bounce
allocation, so there is no measured cushion for it. Held bounce identical
to xsn31/6 (HiCache does not touch lane pricing or the still-open cross-
group concurrency gap) and fed cushion_headroom_gib only BOOT7's own
measured HiCache saving (-8.17 GiB predicted_run_peak, cross-checked
against ANALYSE_57GIB_SHMEM_0913.md's independent -8.14 GiB estimate, the
two agreeing within 0.03 GiB): the arithmetic reads GREEN at +8.37 GiB
margin. Prognosis stays prognosis, stated in the test's own docstring and
repeated in the closing message: the model's own blind spot (finding 2,
above) means this number describes the ARITHMETIC, not a verdict on the
boot.

11/11 green, ruff clean. test_weg2_cushion_gate_1377.py's own sampler test
(TheCushionMinimumComesFromTheSamplersOwnColumn, reading a LIVE, rig-wide,
continuously-appended CSV explicitly marked "rig-only evidence") is
independently flaky against today's accumulated sampler data -- confirmed
unrelated to this commit (no file this commit touches is anywhere near
that code path) and out of this task's file boundary either way.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1385 interaction

Coordinator order (Paket D): investigate --xchg-lanes-concurrent (sgl-project#1385)
x band_credit (sgl-project#1397) combined, unbuilt/untested before this commit.

Read weight_updater.py's lane loop (DESK9/sgl-project#1385, not my file, read-only):
it passes `terms` straight through to run_bounce_leg and never
independently re-derives a slot size, so the "ledger prices both knobs,
lane loop honours neither" mutant the coordinator asked about has no
second producer to go wrong in this codebase today. What COULD go wrong
is a caller over-stating n_cross_lanes, or stating band_credit without
its Option 1 precondition (max_tag_bytes > 0) -- the latter would price
the small oncard cross geometry while run_bounce_leg's _band_credit_leg
(which requires _option1_leg) falls back to the pre-Option-1,
widest-layer-sized floor: the identical slot-size/slot-count mismatch
sgl-project#1385 round 3 measured at 5.6x on boot weg2xsn31/4, with band_credit as
the new second reader. bounce_terms() now refuses that combination by
name instead of letting it coincide.

n_cross_lanes_priced/n_diag_lanes_priced were already derived from
lanes_priced (the sgl-project#1385 cap-aware property), not raw n_lanes, so a
lanes_concurrent cap already narrows the cross share correctly by
construction -- confirmed with a new pricing test rather than assumed.

unlink_lane_buffer (sgl-project#1385 round 4) sits at rv.post_drained(tag=...), the
per-tag drain row (sgl-project#1374, row 0 of `empty`) -- untouched by band_credit's
own row (row 1 of `full`). Proven end to end: a real multi-wrap
band-credit tag runs to completion, then the exact weight_updater.py
sequence (post_drained -> unlink_lane_buffer) is exercised and the file
is present before, gone after, bytes correct throughout.

Also read fix/1391-card0-collector round 4 (5d69392, DESK10, not
merged into train-0911, not my file) on the coordinator's explicit
question of whether it changes the diagonal-lane safety argument.
Verdict, not a decision: no. Round 4 fixes an inter-tag bug (shadow
mode's diagnostic collect ran once for the whole wake instead of per
tag); weight_updater.py:4671's _weg2_await_vram_credit still precedes
:4675's resume(tag) unconditionally, and every collect call (exchange or
now shadow) still runs only after that credit -- the per-tag,
whole-deposit-before-pause-before-credit sequence on the source side is
untouched. The diagonal fence this ticket's design doc describes stands.

23/23 tests green (17 pre-existing + 6 new), verified red-first for the
new refusal via git checkout + patch reapply. Design doc addendum:
/spinning/gpu-arb/weg2/DESIGN_option3_band_credit_0914.md section 8.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1385 interaction

Coordinator order (Paket D): investigate --xchg-lanes-concurrent (sgl-project#1385)
x band_credit (sgl-project#1397) combined, unbuilt/untested before this commit.

Read weight_updater.py's lane loop (DESK9/sgl-project#1385, not my file, read-only):
it passes `terms` straight through to run_bounce_leg and never
independently re-derives a slot size, so the "ledger prices both knobs,
lane loop honours neither" mutant the coordinator asked about has no
second producer to go wrong in this codebase today. What COULD go wrong
is a caller over-stating n_cross_lanes, or stating band_credit without
its Option 1 precondition (max_tag_bytes > 0) -- the latter would price
the small oncard cross geometry while run_bounce_leg's _band_credit_leg
(which requires _option1_leg) falls back to the pre-Option-1,
widest-layer-sized floor: the identical slot-size/slot-count mismatch
sgl-project#1385 round 3 measured at 5.6x on boot weg2xsn31/4, with band_credit as
the new second reader. bounce_terms() now refuses that combination by
name instead of letting it coincide.

n_cross_lanes_priced/n_diag_lanes_priced were already derived from
lanes_priced (the sgl-project#1385 cap-aware property), not raw n_lanes, so a
lanes_concurrent cap already narrows the cross share correctly by
construction -- confirmed with a new pricing test rather than assumed.

unlink_lane_buffer (sgl-project#1385 round 4) sits at rv.post_drained(tag=...), the
per-tag drain row (sgl-project#1374, row 0 of `empty`) -- untouched by band_credit's
own row (row 1 of `full`). Proven end to end: a real multi-wrap
band-credit tag runs to completion, then the exact weight_updater.py
sequence (post_drained -> unlink_lane_buffer) is exercised and the file
is present before, gone after, bytes correct throughout.

Also read fix/1391-card0-collector round 4 (5d69392, DESK10, not
merged into train-0911, not my file) on the coordinator's explicit
question of whether it changes the diagonal-lane safety argument.
Verdict, not a decision: no. Round 4 fixes an inter-tag bug (shadow
mode's diagnostic collect ran once for the whole wake instead of per
tag); weight_updater.py:4671's _weg2_await_vram_credit still precedes
:4675's resume(tag) unconditionally, and every collect call (exchange or
now shadow) still runs only after that credit -- the per-tag,
whole-deposit-before-pause-before-credit sequence on the source side is
untouched. The diagonal fence this ticket's design doc describes stands.

23/23 tests green (17 pre-existing + 6 new), verified red-first for the
new refusal via git checkout + patch reapply. Design doc addendum:
/spinning/gpu-arb/weg2/DESIGN_option3_band_credit_0914.md section 8.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…r schon erreichbar

Nutzer-Order 2026-09-14, relayed, auf DESK11s eigenen Befund "der
Mechanismus ist gebaut, getestet, aber UNGEWIRT -- weight_updater.py ruft
run_bounce_leg nie mit band_credit=True": "ja dann - bauen!".

Direkt mit DESK11 abgestimmt (cross-session), bevor die Aufrufstelle
festgenagelt wurde: weight_updater.py hat GENAU zwei BounceTerms-
Konstruktionsstellen, beide xb.read_published_terms() (:1069, :1204) --
keine lokale bounce_terms(...)-Rekonstruktion, die band_credit/
n_cross_lanes verwerfen koennte. _TERM_FIELDS traegt beide Felder bereits
durch publish_terms/read_published_terms. Der phasierte Cross-Pfad
(_weg2_xchg_bounce_leg) baut fuer einen echten Cross-Descriptor bereits
CrossSlotRendezvous(sems, slots, pair=pair) -- exakt _band_credit_legs
zweite Vorbedingung.

Ergebnis, unabhaengig verifiziert per Ausfuehrung (nicht nur per Lesen):
KEINE Codeluecke in der Durchreichung selbst. Sobald ein Launcher
band_credit=1 + konsistentes n_cross_lanes/max_tag_bytes>0 published,
reicht der bestehende Code es transparent bis run_bounce_leg durch. Die
tatsaechliche Luecke war zweigeteilt und liegt beide Male ausserhalb
dieser Datei: der Launcher published es nie (DESK9, sgl-project#1395), und nichts
bewies, dass die Durchreichung durch weight_updater.py's EIGENEN
Aufrufpfad wirklich funktioniert -- DESK11s eigene Suite treibt
ausschliesslich weight_exchange_bounce.run_bounce_leg direkt.

test_weg2_1397_band_credit_wiring.py (5 Tests, neu):

1. Positiver Execution-Smoke (sgl-project#1391-Form: zwei echte Threads auf der
   echten _weg2_xchg_bounce_leg, echtes FakeDeviceOps, echte POSIX-
   Semaphore, 5 Baender durch einen Cross-Puffer mit cross_lane_slots=1,
   erzwingt einen echten Wrap): Bytes landen korrekt UND die allozierte
   Datei ist messbar kleiner als der tag-grosse Lauf derselben
   Deskriptoren mit band_credit=False, mit den exakten Zahlen ueber die
   Produkt-eigenen leg_slot_bytes/lane_slots-Funktionen.
2. sgl-project#1397-Refusal-Erreichbarkeit vom echten Wake-Callsite
   (_weg2_xchg_inject_weights -> read_published_terms -> bounce_terms ->
   ValueError, ungefangen).
3. Gefahrrichtungs-Mutant (Koordinator-Order): die sgl-project#1397-Refusal
   wegmutiert -- Ledger preist klein (kein max_tag_bytes-Vorbehalt in
   diesem Zweig), realer Allokator faellt auf den grossen Widest-Layer-
   Boden zurueck (_option1_leg fehlt) -- die sgl-project#1385-Runde-3-Fehlerklasse,
   OOM-Richtung, durch den echten Callsite gezeigt.

Rot-vor-gruen selbst verifiziert ohne Produktionscode zu aendern (kein
Fix moeglich, wo kein Defekt ist): probeweise die Rendezvous-Konstruktion
auf card= statt pair= fuer eine Cross-Gruppe umgestellt (Pair-Identitaet
verloren) -- der Groessen-Vergleichstest geht dann rot (24576==24576,
kein Unterschied mehr), waehrend der schwaechere Bytes-Test allein gruen
geblieben waere. Zurueckgesetzt, Datei identisch zum Ausgangsstand.

Erwogen und verworfen (Design-Dokument, Abschnitt 9.3): eine dritte
Guard-Ebene, die terms.n_cross_lanes gegen die eigene Pair-Zaehlung
spiegelt, analog sgl-project#1358. Verworfen mit Begruendung: _band_credit_leg
entscheidet pro Lane ausschliesslich ueber rendezvous.pair is not None
(strukturell, aus src_rank/dst_rank), nie ueber n_cross_lanes' Zahlenwert
-- ein falscher n_cross_lanes ist ein Ledger-Preisungsfehler
(host_ledger.py, DESK9), kein Laufzeit-Korrektheitsfehler dieser Datei.

Volle Regression: 119/119 (diese Suite + DESK11s eigene sgl-project#1397-Suite +
Gate-Achse sgl-project#1273 + sgl-project#1391 + sgl-project#1369/sgl-project#1394 Paket B + Inject-Wiring sgl-project#1342 +
Wcode-Zensus sgl-project#1263).

Design-Dokument (/spinning/gpu-arb/weg2/DESIGN_option3_band_credit_0914.md,
Abschnitt 9) mit vollem Befund, Beleg-Stufen und dem UNPROVEN-Rest
(echter Boot mit band_credit=1 haengt an sgl-project#1395) ergaenzt.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…int_census.py

DESK11's own gap (design doc section 9.1, verified by reading rather than
trusted): checkpoint_census.widest_layer_terms took pairs/depth/slot_bytes/
n_lanes/max_tag_bytes/lanes_concurrent but never band_credit/n_cross_lanes
-- the ONE call site between the launcher and xchg_bounce.bounce_terms for
every OTHER field. DESK10's own commit (26bd280) independently confirmed
weight_updater.py's own two BounceTerms readers (xb.read_published_terms(),
never a local reconstruction) already carry both fields through
_TERM_FIELDS untouched.

ONE SOURCE, the --xchg-bounce-depth (48adc00) / --xchg-lanes-concurrent
(45477c1) shape reused, both precedents in this same file:
--xchg-band-credit (plain store_true, default off, byte-identical) ->
main() resolves it exactly once (_band_credit) -> both the ranks'
publication call (checkpoint_census.widest_layer_terms ->
xchg_bounce.bounce_terms -> _TERM_FIELDS -> publish_terms) and
choose_host_ledger's own pricing call read the identical resolved bool.
n_cross_lanes is deliberately NOT exposed as a second CLI flag anywhere in
this file -- design doc section 9.2's own finding: arming reduces to the
single boolean, xchg_bounce.resolve_cross_lanes derives a safe, structural
lower bound from n_lanes (measured, sgl-project#1358) and
weight_exchange_region.N_CARDS (a pigeonhole argument), so there is nothing
else to coordinate.

ORDER ITEM 1 -- reader enumeration BEFORE changing the producer, verified
by file:line reading (not assumed from DESK10's commit message):
weight_updater.py has EXACTLY two lane-buffer-size readers, :1078 and
:1213, both `xb.read_published_terms()`. No third reader, no local
BounceTerms reconstruction that could silently drop the two new fields.
Pinned as a regression tripwire
(TheReadersAreEnumeratedAndStayThatWay::test_weight_updater_has_exactly_
two_read_published_terms_call_sites).

ORDER ITEM 2 -- the sgl-project#1385 unlink interaction, checked: band_credit does
NOT touch the unlink side and needs none of its own.
weight_exchange_bounce.unlink_lane_buffer removes a file by PATH (the
lane's own name), independent of what size was ever written there --
band_credit only changes the byte count a cross lane's file holds, never
its path, existence, or when it is freed. The call site
(weight_updater.py:4170) gates on `_lane_permit_active`
(--xchg-lanes-concurrent), an axis independent of band_credit: with no
cap, sgl-project#1385's own pricing already charges for every lane accumulating "by
design", and band_credit's smaller per-lane cross price is still the
correct charge for that assumption. Pinned
(TheUnlinkSideIsUntouchedByBandCredit, 2 cases).

THE "WRONG REGION" DANGER DIRECTION (coordinator-named: "ein Band-Credit,
der die Baender der falschen Region liest, schreibt fremde Bytes = still
falsch, teurer als jede Refusal") is a runtime correctness question about
CrossSlotRendezvous/_band_credit_leg -- weight_exchange_bounce.py and
weight_updater.py, DESK11's and DESK10's own file boundaries, never
reachable from launcher.py/checkpoint_census.py (this file's boundary is
pricing and publication: no descriptors, no ranks, no pairs at this
layer). DESK10's own commit (26bd280) already ran exactly this mutant
by hand against the real execution path (rendezvous construction switched
to a card-only identity for a cross group, pair identity lost -- the
size-comparison test went red). Not duplicated here; cited instead.

DESIGN DOC MATH, VERIFIED THROUGH THE REAL xb.bounce_terms CALL rather
than adopted: slot=128 MiB matches exactly (15.75 -> 10.5 GiB, 5.25 GiB
saved); slot=64 MiB diverges slightly from the design doc's own
"gerechnet, nicht gemessen" 9.75 GiB estimate -- the real function returns
9.562 GiB (savings 5.5 GiB), which this commit treats as authoritative
per the order's own instruction ("nimm nicht meine Zahl").

Tests (test_weg2_1397_launcher_census_wiring.py, 17 cases): byte-identical
default (CLI flag off, no second n_cross_lanes flag anywhere), one-source
(all three layers accept band_credit, none exposes n_cross_lanes, main()
resolves exactly once, both call sites forward the same local), the
ledger sees the smaller charge (host_ledger.charge_terms), the design-doc
math verified at both slot sizes, the reader/unlink findings pinned as
tripwires, and the danger-direction mutant for THIS layer (a caller that
resolves band_credit but drops it from one of the two functions prices/
allocates the bigger, safe-direction total).

MUTANT APPLIED LIVE TO launcher.py AND REVERTED (diff empty after):
choose_host_ledger's own call to xchg_bounce_terms_for_arm with the
band_credit argument removed -- TheDangerDirectionMutantAppliedLiveAndReverted's
source pin went red immediately. Restored, diff empty, 17/17 green again.

Regression: this file (17), test_weg2_1397_band_credit_wiring.py (DESK10,
5), test_weg2_band_credit_1397.py (DESK11, 27), test_weg2_xchg_lanes_
concurrent_1385.py (23), test_weg2_widest_layer_census_1332b.py,
test_weg2_weights_cpu_backup_1369.py -- 129 total, all green.

pyright (desk-venv): launcher.py+checkpoint_census.py 120 errors after vs
156 before -- fewer, not more (this branch is based on an EARLIER train
commit than the pristine comparison point picked up additional unrelated
pyright debt meanwhile; no new errors attributable to this change, cross-
checked by symbol).

File boundary: launcher.py + checkpoint_census.py + own test file, as
ordered. xchg_bounce.py/weight_exchange_bounce.py (DESK11) and
weight_updater.py/weg2_memory_saver.py (DESK10) read but not modified.
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.

[Feature] Follow up on non power of 2 triton kernel

3 participants