Skip to content

Remove synchronization in cuda graph replay - #1394

Closed
hnyls2002 wants to merge 1 commit into
mainfrom
optimize-cudagraph
Closed

hnyls2002 wants to merge 1 commit into
mainfrom
optimize-cudagraph

Conversation

@hnyls2002

Copy link
Copy Markdown
Collaborator

Motivation

Modifications

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.

@hnyls2002 hnyls2002 closed this Sep 11, 2024
@merrymercy
merrymercy deleted the optimize-cudagraph branch September 15, 2024 14:28
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…nd weights_draft's own wake

source

User order 2026-09-14, verbatim: the checkpoint on disk is the fallback net;
a correctly implemented exchange never needs another one. The host ring
(46.40 GiB) is redundancy to a net that is already there. That reframes
sgl-project#1394: the discarded option was "a small ring kept just for weights_draft"
-- disk is the smaller, more honest net for a tag the exchange structurally
never covers anyway.

sgl-project#1394 DECISION (b), not (a): weights_draft reloads straight from the
checkpoint on disk at wake, through the draft worker's OWN
update_weights_from_disk call (already exists, weight_updater.py:478-491,
used independently of the main shard's own update there) -- not a rework of
_weg2_shadow_plan's single-runner region resolution, which would touch the
join/plan machinery outside this desk's files and needs its own mutant-
tested pass. Verified at the source (sgl-project#1391 round 2, executed): both call
sites of _weg2_shadow_plan read self.tp_worker.model_runner alone, on every
call, regardless of tag -- weights_draft's descriptors are structurally
unreachable through the exchange, not merely untested. Full reasoning,
prior-art check and the rejected alternative in
/spinning/gpu-arb/weg2/DESIGN_1394_draftweights_quelle_0914.md.

New _weg2_xchg_draft_reload_from_disk: a no-op (returns False) whenever
there is no draft shard in this process or the ring still covers this tag
(weights_cpu_backup_armed() True) -- zero cost on every other tag and every
pre-sgl-project#1369 boot. Wired into resume_memory_occupation's per-tag loop, before
the CARRIER_EXCHANGE branch (which would collect nothing for this tag
anyway).

sgl-project#1369 THE COMPLETENESS REFUSAL, Weg2XchgWakeSourceGapRefused (W106 --
freed by manual grep against this branch's base and the fresh train tip,
since the wcode census tool's own regex caps at 2 digits and cannot see any
3-digit code at all, W100-W105/W107 included; a sixth instance of the sgl-project#1263
blind-spot class, worth fixing but out of this ticket's file boundary).
Checked at the sleep leg, before the pause that would make a gap real, in
two independent cases, either enough to refuse: (1) the tag's ring backup
is off but the exchange is not AUTHORITATIVE -- shadow mode only compares,
it never writes (sgl-project#1391's own lesson, generalised), so this fires regardless
of how complete the plan is; (2) the exchange is authoritative but this
rank's own plan carries zero descriptors for the tag -- weights_draft is
exempted from this one case only, covered instead by its own disk-reload
path.

This branch is based on the real, DESK9-corrected train tip (eeac3f5,
"auto must match ring_absent_by_design, not bare exchange_armed()") --
no local correction to weight_exchange.py needed or made; an earlier round
of this same work had to patch that formula locally against a stale tip and
flag it to the coordinator as a cross-package blocker, since resolved on
train itself.

Tests (test_weg2_1394_1369_wake_source_gap.py, 15 cases): the pure decision
function, both cases and the weights_draft exemption; the REAL production
callsite (_weg2_xchg_deposit_before_sleep) red-first (collection error
without the fix) then green; the draft reload's own no-op/call/failure
paths; and the danger-direction mutant the operator ordered (patch the gap
check to always answer "no gap" and show the deposit leg then reaches the
pre-sgl-project#1369 silent no-op instead of refusing -- exactly the still-wrong-
weights shape this refusal exists to prevent). 15/15 pass. Regression:
wcode census, inject-wiring, sgl-project#1391's own suite, and the gate-axis tests all
stay green (88/88 across the group).

No change to weg2_memory_saver.pause()'s own semantics -- only the existing
weights_region() context manager, used exactly as
_weg2_wake_reload_weights already does; nothing for the lane/buffer seat to
build against.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
… not the raw flag

DESK12's find, relayed by the coordinator after the blocker report: rebased
onto the real train tip (eeac3f5, which now carries DESK9's own
corrected auto formula, so the previous commit's temporary local patch to
weight_exchange.py was dropped -- the file is untouched here, back to the
train's own version).

_weg2_wake_weight_carrier's main_carried (weight_updater.py:912) read
server_args.enable_weights_cpu_backup -- the raw launcher bit, set
UNCONDITIONALLY (launcher.py:2702), never weights_cpu_backup_armed(). This
is an INDEPENDENT defect from W106, not a second instance of it: W106
refuses at the sleep leg, and only for a tag whose exchange is armed at
all -- _weg2_xchg_deposit_before_sleep returns immediately when the
exchange is not armed, so plain `ring` mode was never W106's half to guard.
`--weg2-weights-cpu-backup off` under `ring` (no exchange at all) reaches
W106's check never, and that is exactly where the raw-flag read was
dangerous: main_carried=True (raw) would pick CARRIER_TMS_BACKUP for a tag
nothing physically backed up once Paket C binds enable_cpu_backup to the
predicate -- the TMS branch does nothing, the remapped pages stay on
undefined content, no exception, no symptom besides wrong text later.

Fixed with a different MECHANISM than W106, not a shared guard: main_carried
now reads weights_cpu_backup_armed() (falling back to the raw flag only if
the predicate itself is unreadable -- the conservative, already-proven
direction). This is a ROUTING fix, not a refusal: under ring+off it now
honestly falls through to CARRIER_DISK, the checkpoint on disk -- the
user's own "das ist das Netz" (2026-09-14) -- instead of a TMS restore that
never happened. No new W-code needed (W108 stays unused): there is nothing
left to refuse once the routing itself is honest, since CARRIER_DISK is a
real, always-available, always-correct source. draft_carried is unaffected
in a way that could regress: the launcher never sets
--enable-draft-weights-cpu-backup (0 hits, server_args.py default False),
so draft_carried == main_carried by construction in every case, and the
disagreement refusal at line 916 cannot newly fire from this change.

On THIS train tip model_runner.py:2440-2441 still reads the raw flag
unconditionally (Paket C has not landed) -- so today this is a forward
correction: harmless where CARRIER_EXCHANGE wins first (exchange+
authoritative), a one-time extra disk reload instead of the still-real TMS
restore everywhere else until Paket C lands, never a correctness regression.

Tests added to test_weg2_1394_1369_wake_source_gap.py (3, all red-first):
the predicate-vs-raw-flag divergence (ring+explicit-off), a sanity
companion proving the ordinary ring-armed answer is unchanged, and the
danger-direction mutant the coordinator ordered (mute the predicate call to
raise, confirm the code's own conservative fallback reproduces DESK12's
exact misroute). Full suite re-verified green after the rebase: 91/91
across the W106/sgl-project#1394 tests, the gate-axis tests, sgl-project#1391's own suite, the
inject-wiring tests and the wcode census.

DESIGN_1394_draftweights_quelle_0914.md (/spinning/gpu-arb/weg2/) updated
with the full reasoning for why this is independent of W106, why no new
W-code is needed, and the explicit UNPROVEN note that only Paket C landing
and a real boot can show CARRIER_DISK is actually chosen and loads
correctly once enable_cpu_backup is truly gated.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…nd weights_draft's own wake

source

User order 2026-09-14, verbatim: the checkpoint on disk is the fallback net;
a correctly implemented exchange never needs another one. The host ring
(46.40 GiB) is redundancy to a net that is already there. That reframes
sgl-project#1394: the discarded option was "a small ring kept just for weights_draft"
-- disk is the smaller, more honest net for a tag the exchange structurally
never covers anyway.

sgl-project#1394 DECISION (b), not (a): weights_draft reloads straight from the
checkpoint on disk at wake, through the draft worker's OWN
update_weights_from_disk call (already exists, weight_updater.py:478-491,
used independently of the main shard's own update there) -- not a rework of
_weg2_shadow_plan's single-runner region resolution, which would touch the
join/plan machinery outside this desk's files and needs its own mutant-
tested pass. Verified at the source (sgl-project#1391 round 2, executed): both call
sites of _weg2_shadow_plan read self.tp_worker.model_runner alone, on every
call, regardless of tag -- weights_draft's descriptors are structurally
unreachable through the exchange, not merely untested. Full reasoning,
prior-art check and the rejected alternative in
/spinning/gpu-arb/weg2/DESIGN_1394_draftweights_quelle_0914.md.

New _weg2_xchg_draft_reload_from_disk: a no-op (returns False) whenever
there is no draft shard in this process or the ring still covers this tag
(weights_cpu_backup_armed() True) -- zero cost on every other tag and every
pre-sgl-project#1369 boot. Wired into resume_memory_occupation's per-tag loop, before
the CARRIER_EXCHANGE branch (which would collect nothing for this tag
anyway).

sgl-project#1369 THE COMPLETENESS REFUSAL, Weg2XchgWakeSourceGapRefused (W106 --
freed by manual grep against this branch's base and the fresh train tip,
since the wcode census tool's own regex caps at 2 digits and cannot see any
3-digit code at all, W100-W105/W107 included; a sixth instance of the sgl-project#1263
blind-spot class, worth fixing but out of this ticket's file boundary).
Checked at the sleep leg, before the pause that would make a gap real, in
two independent cases, either enough to refuse: (1) the tag's ring backup
is off but the exchange is not AUTHORITATIVE -- shadow mode only compares,
it never writes (sgl-project#1391's own lesson, generalised), so this fires regardless
of how complete the plan is; (2) the exchange is authoritative but this
rank's own plan carries zero descriptors for the tag -- weights_draft is
exempted from this one case only, covered instead by its own disk-reload
path.

This branch is based on the real, DESK9-corrected train tip (eeac3f5,
"auto must match ring_absent_by_design, not bare exchange_armed()") --
no local correction to weight_exchange.py needed or made; an earlier round
of this same work had to patch that formula locally against a stale tip and
flag it to the coordinator as a cross-package blocker, since resolved on
train itself.

Tests (test_weg2_1394_1369_wake_source_gap.py, 15 cases): the pure decision
function, both cases and the weights_draft exemption; the REAL production
callsite (_weg2_xchg_deposit_before_sleep) red-first (collection error
without the fix) then green; the draft reload's own no-op/call/failure
paths; and the danger-direction mutant the operator ordered (patch the gap
check to always answer "no gap" and show the deposit leg then reaches the
pre-sgl-project#1369 silent no-op instead of refusing -- exactly the still-wrong-
weights shape this refusal exists to prevent). 15/15 pass. Regression:
wcode census, inject-wiring, sgl-project#1391's own suite, and the gate-axis tests all
stay green (88/88 across the group).

No change to weg2_memory_saver.pause()'s own semantics -- only the existing
weights_region() context manager, used exactly as
_weg2_wake_reload_weights already does; nothing for the lane/buffer seat to
build against.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
… not the raw flag

DESK12's find, relayed by the coordinator after the blocker report: rebased
onto the real train tip (eeac3f5, which now carries DESK9's own
corrected auto formula, so the previous commit's temporary local patch to
weight_exchange.py was dropped -- the file is untouched here, back to the
train's own version).

_weg2_wake_weight_carrier's main_carried (weight_updater.py:912) read
server_args.enable_weights_cpu_backup -- the raw launcher bit, set
UNCONDITIONALLY (launcher.py:2702), never weights_cpu_backup_armed(). This
is an INDEPENDENT defect from W106, not a second instance of it: W106
refuses at the sleep leg, and only for a tag whose exchange is armed at
all -- _weg2_xchg_deposit_before_sleep returns immediately when the
exchange is not armed, so plain `ring` mode was never W106's half to guard.
`--weg2-weights-cpu-backup off` under `ring` (no exchange at all) reaches
W106's check never, and that is exactly where the raw-flag read was
dangerous: main_carried=True (raw) would pick CARRIER_TMS_BACKUP for a tag
nothing physically backed up once Paket C binds enable_cpu_backup to the
predicate -- the TMS branch does nothing, the remapped pages stay on
undefined content, no exception, no symptom besides wrong text later.

Fixed with a different MECHANISM than W106, not a shared guard: main_carried
now reads weights_cpu_backup_armed() (falling back to the raw flag only if
the predicate itself is unreadable -- the conservative, already-proven
direction). This is a ROUTING fix, not a refusal: under ring+off it now
honestly falls through to CARRIER_DISK, the checkpoint on disk -- the
user's own "das ist das Netz" (2026-09-14) -- instead of a TMS restore that
never happened. No new W-code needed (W108 stays unused): there is nothing
left to refuse once the routing itself is honest, since CARRIER_DISK is a
real, always-available, always-correct source. draft_carried is unaffected
in a way that could regress: the launcher never sets
--enable-draft-weights-cpu-backup (0 hits, server_args.py default False),
so draft_carried == main_carried by construction in every case, and the
disagreement refusal at line 916 cannot newly fire from this change.

On THIS train tip model_runner.py:2440-2441 still reads the raw flag
unconditionally (Paket C has not landed) -- so today this is a forward
correction: harmless where CARRIER_EXCHANGE wins first (exchange+
authoritative), a one-time extra disk reload instead of the still-real TMS
restore everywhere else until Paket C lands, never a correctness regression.

Tests added to test_weg2_1394_1369_wake_source_gap.py (3, all red-first):
the predicate-vs-raw-flag divergence (ring+explicit-off), a sanity
companion proving the ordinary ring-armed answer is unchanged, and the
danger-direction mutant the coordinator ordered (mute the predicate call to
raise, confirm the code's own conservative fallback reproduces DESK12's
exact misroute). Full suite re-verified green after the rebase: 91/91
across the W106/sgl-project#1394 tests, the gate-axis tests, sgl-project#1391's own suite, the
inject-wiring tests and the wcode census.

DESIGN_1394_draftweights_quelle_0914.md (/spinning/gpu-arb/weg2/) updated
with the full reasoning for why this is independent of W106, why no new
W-code is needed, and the explicit UNPROVEN note that only Paket C landing
and a real boot can show CARRIER_DISK is actually chosen and loads
correctly once enable_cpu_backup is truly gated.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1391)

TRAIN2's census against the MERGED tree (independently confirmed here by
manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts
on train tip bb70894): W100 was double-assigned. host_ledger.py's
Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first;
Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py,
picked tonight for sgl-project#1391) is the later arrival and moves, per the
"census keys on the exception name, never the digit" rule. W106
(this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected --
it was free against the merged tree from the start. W108 verified free by
the same manual grep, both against the merged tree and this branch.

Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for,
weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message
f-strings only -- no behavioural change, this is a label fix. The one
consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py
(two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused`
by name instead, which is the actual fix against the next collision
(sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name
pin survives a future renumber, a digit pin does not. Narrative
W100-mentions elsewhere in that file's own docstring and in
test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the
renumber rather than silently going stale.

Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS
Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py,
outside this desk's file boundary and not part of this collision) and
test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code
citation for the same unchanged host_ledger.py class).

Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the
gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode
census, and both the sleep-leg-gate and lanes-concurrent tests that cite
the OTHER W100 (confirming they are genuinely unaffected).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…gl-project#1391)

TRAIN2's census against the MERGED tree (independently confirmed here by
manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts
on train tip bb70894): W100 was double-assigned. host_ledger.py's
Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first;
Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py,
picked tonight for sgl-project#1391) is the later arrival and moves, per the
"census keys on the exception name, never the digit" rule. W106
(this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected --
it was free against the merged tree from the start. W108 verified free by
the same manual grep, both against the merged tree and this branch.

Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for,
weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message
f-strings only -- no behavioural change, this is a label fix. The one
consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py
(two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused`
by name instead, which is the actual fix against the next collision
(sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name
pin survives a future renumber, a digit pin does not. Narrative
W100-mentions elsewhere in that file's own docstring and in
test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the
renumber rather than silently going stale.

Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS
Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py,
outside this desk's file boundary and not part of this collision) and
test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code
citation for the same unchanged host_ledger.py class).

Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the
gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode
census, and both the sleep-leg-gate and lanes-concurrent tests that cite
the OTHER W100 (confirming they are genuinely unaffected).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…ontract untouched

TRAIN2 merge note (2026-09-14): cherry-pick onto train-0911-work hit a real
structural conflict in weight_updater.py at the if/elif chain this commit
extends -- Paket B (sgl-project#1394, DESK9/DESK10, already on this train as c103a5d)
independently inserted a draft-tag `if ... pass` / `elif carrier==
CARRIER_EXCHANGE` guard at the exact same line, on a base this round-4 commit
never saw. Resolved with the coordinator's confirmed walrus form so BOTH
properties hold in the SAME elif chain: Paket B's exclusivity (draft tags
never reach the carrier check) AND this round's lazy carrier capture for the
shadow-elif immediately below it --

    elif (_weg2_carrier_this_tag := self._weg2_wake_weight_carrier()) == self.CARRIER_EXCHANGE:

Nothing else in this commit's own diff was touched. Original message follows.

---

sgl-project#1391 round 4: per-tag shadow collect -- the actual fix, contract untouched

Coordinator's hypothesis, verified at the source before building anything:
under CARRIER_EXCHANGE, resume_memory_occupation's per-tag loop already
calls _weg2_xchg_inject_weights(tag=tag) per tag (weight_updater.py:4641-
4643, unchanged) -- so the per-tag post_drained gate already fires there.
The deadlock is specific to --weg2-xchg-inject shadow, where the only
collect was _weg2_xchg_shadow_compare, called once after family_complete
with tag=None. The instrument built to prove the lane assembles the right
bytes was what kept it from ever finishing.

The fix does not touch the drain-count contract: it changes WHEN the shadow
compare runs, not HOW post_drained is counted.

- resume_memory_occupation's per-tag loop now also runs a per-tag shadow
  collect (_weg2_xchg_inject_weights(tag=tag, mode=INJECT_SHADOW)) whenever
  _weg2_xchg_shadow_armed_for(carrier) is true (armed, shadow inject mode,
  carrier != stock) -- mirroring the CARRIER_EXCHANGE branch beside it
  exactly, including a declared (not lazily-assigned) stand-down flag
  (_weg2_xchg_shadow_compared_per_tag) that stops _weg2_xchg_shadow_compare
  from grading the whole plan a second time after the loop -- same pattern
  _weg2_wake_reload_weights already uses for _weg2_xchg_collected_per_tag.
- New shared predicate _weg2_xchg_shadow_armed_for(carrier), read from both
  the per-tag loop and the once-per-wake stand-down check, so the two
  cannot disagree about whether this is a shadow wake.

Tests (test_weg2_undrained_lane_refusal_1391.py, now 17 cases):
- test_M2_old_style_whole_plan_collect_deadlocks_RED_on_the_wall: hermetic
  reproduction of boot weg2xsn31's own wedge through the REAL
  _weg2_xchg_bounce_leg method (two threads, real SemSet/BounceSlots,
  FakeDeviceOps, a 2s-budget CrossSlotRendezvous) -- source deposits
  weights_0/weights_1 per tag (D's real shape, always per-tag regardless of
  carrier), dest collects ONCE with tag=None after both (shadow mode's
  shape before this round). Source raises the exact W68 "waited for the
  collector to drain the previous tag and it did not" boot weg2xsn31 hit.
- test_the_fix_per_tag_collect_drains_the_same_lane: the SAME lane, dest
  now collecting per tag -- both threads complete.
- test_M3_mismatched_tag_between_grade_and_drain_must_not_be_reachable: the
  danger-direction mutant the operator ordered (a per-tag grade that posts
  drained for a different tag than it compared would report MATCH on
  unchecked bytes -- worse than the deadlock). Verified live: mutating the
  drain-side tag argument in weight_updater.py made this test fail
  immediately, then reverted.

17/17 pass. Full weg2 suite: 3416 passed, 26 failed -- the exact same 26 as
the very first (pre-sgl-project#1391) baseline measured tonight, zero new failures;
the extra failures seen in rounds 2/3 (BOOT7's own concurrent instrument
boot on this shared box) are gone now that boot has moved on.
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
…region per

runner), disk-reload becomes the fallback not the default

User order 2026-09-14, relayed and reprioritised: "draft ist auch nur ein
layer, genau wie die anderen? keinerlei (ABSOLUT KEIN!) unterschied. warum
muss er ueber den ring gehen?" -- correct, and the code agrees once the
STALE premise underneath the earlier sgl-project#1394 decision (this branch's own
prior commit, "the exchange structurally never covers weights_draft") is
checked against the current tree rather than assumed.

THE STALE HALF, FOUND AND CORRECTED (weight_exchange.py
weights_region_tag_for): its own docstring claimed
is_weights_family_tag never matches weights_draft, "so they are never in a
leg, never in a census and never in a wave" -- untrue since AMENDMENT 6
(user ruling 2026-09-11) added weg2_memory_saver.draft_tag_in_family(),
which already returns exchange_armed(). The draft tag has been a family
member (paused, censused, waved) all along; the two texts were never
reconciled.

THE REAL, NARROWER GAP: weight_updater._weg2_shadow_plan resolved every
leg's region from self.tp_worker.model_runner alone (the MAIN runner), so
family membership bought weights_draft a pause with no mover behind it
(verified by execution, sgl-project#1391 round 2). Fixed here: _weg2_shadow_plan now
additionally asks the new _weg2_xchg_draft_plan_or_none for the draft
runner's OWN region, through the SAME xchg_manifest.leg_plan_from_join
every other tag already uses, and unions the descriptors into the
returned plan. The existing per-tag filter both production callers already
apply downstream needs no change: it scopes to weights_draft correctly
the moment real descriptors exist for it.

launcher.py's DRAFT_KV_ON_P_DEFAULT = "on" (read only, DESK9's file):
group P's shipped default DOES carry the four speculative flags
(P_DRAFT_KV_FLAGS), so the older "Group P carries no --speculative-* in
this form" premise is stale on the default serving form -- P's own
draft/producer runner is a real candidate SOURCE, not a structural
impossibility.

THE (a)/(b) POPULATION FINDING, verified rather than assumed away
(coordinator's own explicit invitation: report a finding with file:line
instead of inventing a clean split where none exists). Group D's
weights_draft tag measures 1382/1311/1311 MiB, of which the checkpoint's
mtp.* term is only 0.396 GiB -- the rest is embed/head shards the draft
runner re-materialises. xchg_manifest.join_manifests (DESK9's file, read
not edited) is ALL-OR-NOTHING per region: any one-sided name refuses the
WHOLE region's join (:930-934), discarding matches that would have joined
along with the ones that would not -- confirmed against DESK9's own
pre-existing test (test_the_join_still_works_when_every_rank_has_two_
runner_files, test_weg2_xchg_manifest_join_1330.py), which already proves
the positive case end to end. There is therefore no clean way to move
ONLY the mtp.* layer through the exchange while leaving the re-materialised
shards to disk within one region/tag -- so this fix does not attempt one.
It tries the real join for the WHOLE tag; if group P's producer holds a
matching counterpart for every one of group D's draft-region tensors, the
whole tag moves through the real exchange (byte-identical population (a)
bytes included, which is correct, not merely harmless, since both sides
already compute them identically from the same checkpoint). If even one
name is genuinely one-sided, the whole region's join refuses and the
method reports that reason upward WITHOUT sinking the unrelated main
region's leg -- the caller then keeps the disk-reload fallback (sgl-project#1394,
_weg2_xchg_draft_reload_from_disk), never the ring, never a mini-ring.

THE WAKE SIDE'S OWN PRIORITY IS REVERSED to match: resume_memory_
occupation's per-tag loop used to try the disk-reload FIRST for
weights_draft, before even asking the carrier -- correct only while the
exchange structurally never covered the tag at all. That would now
silently prevent the real exchange from ever being tried. The exchange is
asked first, exactly like any other tag; disk is the fallback, taken only
when this leg's own collect found zero descriptors for the tag
(_weg2_xchg_inject_weights/_weg2_xchg_inject_from_peer now return whether
real descriptors were found, computed once at the frame that already holds
the filtered set, not re-derived).

Tests (test_weg2_1394_draft_in_exchange.py, 9 cases, hermetic, CUDA_
VISIBLE_DEVICES=""):
- Execution smoke on the REAL production callsite (_weg2_shadow_plan
  itself, not the new helper in isolation), driven through written
  manifest files and DESK9's own real join/manifest functions: the merge
  succeeds when a matching producer exists (RED-FIRST verified: reverting
  the merge call reproduces exactly "the draft region's descriptor never
  joined the plan", restored after), and fails soft (main plan unaffected)
  when it does not.
- Danger-direction mutant (coordinator order): the wrong region_tag
  resolves a name both runners share to the WRONG (main) runner's real
  address -- proven via the actual address-book function, not asserted --
  exactly "a draft leg that reads the main region's bands writes foreign
  bytes into the draft head, silently". The real code never does this
  because it always resolves the draft region from the draft runner's own
  shape, never a caller-supplied tag.
- Regression guard (mutant 2's own scenario): roll_forward_weights_tag
  still refuses the combined disk reload under an armed exchange with a
  draft shard, unaffected by this change -- that refusal is a different,
  older wake path and stays exactly as strict.
- Wake-dispatch-order tests: exchange tried before disk, disk only as the
  fallback when the exchange collects nothing.

Regression: 168/168 across this new suite, W106/sgl-project#1394's own prior suite,
the gate-axis tests, sgl-project#1391's suite, inject-wiring, the wcode census, the
sgl-project#1397 band-credit wiring suite, and DESK9's own manifest-join suite
(sgl-project#1330) -- all unaffected. A separate full test/registered/unit/weg2/ run
was started for a final broad sweep; 11 pre-existing failures (confirmed
identical on the clean train tip, unrelated to this commit: stale
main_carried-era tests in test_weg2_xchg_seam_wiring_1273.py, a launcher.py
argv_p signature drift in test_weg2_scheduling_slice_a_0907.py, flip-order
retry flakiness, and one xchg_chain_smoke_1342 failure) are noted but out
of this ticket's scope.

NOT RESOLVED, NAMED RATHER THAN CLAIMED: no available boot log (weg2ring1,
weg2xsn31, weg2xsn17) shows a single GENUINE occurrence of "WEG2-XCHG
DEPOSIT" -- the emitter inside the function this whole fix's callsite
lives in -- checked via logindex's trap-safe grep, bare=0/genuine=0 on
every one tried. BOOT7 (xsn32) has not produced a readable log yet. This
is exactly the class the coordinator's own 14.09. 03:4xZ finding named
(W100 tied to a function with zero real-metal occurrences): the hermetic
proof above is DESK-BEWIESEN; that this exact callsite fires on real
metal remains UNPROVEN pending BOOT7's own log.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
… agrees with weights_cpu_backup_armed(), pin it, build nothing

Coordinator follow-up after the ring-off-allocation closeout (697c604323 /
e201d19): "argued (not boot-proven) safe" was not good enough --
resolve it, don't leave it standing. Traced the actual wiring instead of
trusting the inject_mode()/weight_source() pattern-match:

1. main() resolves weights_cpu_backup_armed ONCE (launcher.py:10434-10439):
   auto = not ring_absent_by_design(ns.weg2_weight_source,
   ns.weg2_xchg_inject); on/off short-circuit inside
   weight_exchange.weights_cpu_backup_armed(explicit=...).
2. That ONE local feeds common_flags's conditional
   (--enable-weights-cpu-backup, launcher.py:2712) at all 4 real argv-build
   call sites (form_argv_p, shipped argv_p, both argv_d) -- grepped, none
   re-derive it. This is what server_args.enable_weights_cpu_backup IS on
   every rank.
3. The SAME ns fields feed prepare_xchg_env's WEIGHT_SOURCE_ENV/INJECT_ENV
   publication (launcher.py:11117-11131), and WEIGHTS_CPU_BACKUP_ENV is
   published unconditionally outside that function's own {} early-return
   (launcher.py:11145-11147) specifically so on/off reaches every rank even
   under ring.
4. WEIGHT_SOURCE_ENV also reaches every rank redundantly via
   os.environ[...] set on the launcher's OWN process (launcher.py:10488)
   BEFORE the first build_env() call, whose baseline is dict(os.environ)
   (launcher.py:4553) -- covers the ring arm, where prepare_xchg_env
   returns {} and never sets it itself.
5. A stray, shell-inherited INJECT_ENV under `ring` cannot matter:
   exchange_armed() is False there and Python's `and` never reaches
   inject_authoritative() in weights_cpu_backup_armed()'s auto branch.

CONCLUSION: no divergence path exists between what argv gives
server_args.enable_weights_cpu_backup and what
weight_exchange.weights_cpu_backup_armed() would independently compute
from a rank's own published env, across all three arms -- verified by
executing both formulas against each other for 6 (weight_source,
inject_mode) pairs, not merely asserted from pattern similarity. Per the
coordinator's own instruction: divergence provably impossible -> PIN it,
report file:line, build nothing. scheduler.py/model_runner.py/core.cpp
are UNCHANGED by this commit; launcher.py/host_ledger.py (DESK9's files)
are read-only in the new test, never edited.

New file: test_weg2_1369_scheduler_flag_consistency.py (9 tests):
- the core behavioural identity across 6 arm/inject pairs (mutated by
  hand -- weights_cpu_backup_armed's auto formula reduced to bare
  exchange_armed(), the exchange+authoritative pair immediately
  disagreed; reverted, git diff on weight_exchange.py empty, 9/9 green
  again)
- the ring-arm short-circuit proof (no INJECT_ENV published, answer still
  correct)
- on/off short-circuit regardless of the axis
- 5 structural pins on the wiring the behavioural proof assumes (the 4
  call sites, prepare_xchg_env's ns fields, WEIGHTS_CPU_BACKUP_ENV's
  unconditional placement, WEIGHT_SOURCE_ENV's self-publication ordering,
  build_env's os.environ baseline)
- one pin on scheduler.py itself (the method is
  init_watch_dog_memory_saver_input_blocker, not __init__ as a naive
  guess would have it -- located by grep, not assumed) so a future edit
  that turned this into a second predicate call would be a visible,
  deliberate choice rather than a silent drift this proof stops covering

Rebased onto origin/weg2/train-0911 (18bb175, DESK10's sgl-project#1394 draft-
weights-in-exchange piece landed concurrently in weight_updater.py /
weight_exchange.py -- no overlap with this commit's files).

Full trace and file:line list: /spinning/gpu-arb/weg2/INVENTAR_ringleser_0914.md.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…ght axis --

bounce_lane_armed(), not shadow_armed() -- fixed two stale comments,
execution-smoke pins the arm matrix

Coordinator relay, register hypothesis (/spinning/gpu-arb/weg2/
PLAN_ZIEL_0914.md's A1 failure-mode table, a watchlist entry for
"pieces=0", not a confirmed defect): "ZWEI Produktions-Gates lesen
shadow_armed(), waehrend die Order exchange armt." Checked as instructed
("pruefe das, statt es zu uebernehmen") rather than adopted, since BOOT7's
A1 runs --weg2-weight-source exchange right now and a wrong-axis gate
there would mean pieces=0 by construction.

VERIFIED, NOT ADOPTED: every gate in weight_updater.py / weg2_memory_saver.py
(this desk's file boundary) that decides whether ANY bounce-lane machinery
runs already reads the correct axis, and neither calls
weight_exchange.shadow_armed() literally:

- _weg2_shadow_hook (called from _weg2_shadow_source_leg /
  _weg2_shadow_destination_leg) gates on
  weight_exchange_shadow.bounce_lane_armed() -- weight_source() != "ring",
  True under BOTH exchange and shadow. Its own docstring already documents
  the sgl-project#1273 B4q fix this hypothesis describes ("It read shadow_armed()
  until sgl-project#1273 B4q ... the hook was dead on the exchange arm by
  construction -- boot weg2xsn16"). Already fixed, not a live defect.
- _weg2_xchg_deposit_before_sleep / _weg2_xchg_inject_weights /
  _weg2_xchg_bounce_leg (the authoritative movers BOOT7's A1 actually
  needs for pieces>0) gate on exchange_armed(), independent of
  shadow_armed() entirely -- already execution-proven under this EXACT
  arm by test_weg2_1394_draft_in_exchange.py and
  test_weg2_1397_band_credit_wiring.py (same desk, same day), both
  driving real cross-pair legs through _weg2_xchg_bounce_leg under
  WEIGHT_SOURCE_EXCHANGE + INJECT_AUTHORITATIVE.
- _weg2_xchg_shadow_armed_for (this desk's own sgl-project#1391 round 4 predicate)
  checks inject_mode() == INJECT_SHADOW deliberately -- a DIFFERENT
  question ("is the shadow-grading branch due") than "does the lane run
  at all", and gating it on bounce_lane_armed() instead would be wrong:
  it would run the shadow comparison under authoritative too.

CONCLUSION per task step 1's own instruction ("wenn beide Gates RICHTIG
liegen, sag das mit file:line und baue nichts"): no shared-predicate
refactor is built. There is nothing to unify -- the three questions
(does the lane run / whose bytes are they / is injection the authority)
already have three separate, correctly-scoped predicates, which is
sgl-project#1273 B4q's own stated design intent, not an accident to fix.

TWO STALE COMMENTS FOUND AND FIXED (documentation drift, not a functional
gate defect -- the instrument-text-luegt class): both described the
ALREADY-CORRECT bounce_lane_armed()-gated behaviour as if only
--weg2-weight-source shadow armed it, unreconciled since sgl-project#1273 B4q widened
the actual gate:
- _weg2_shadow_source_leg's call-site comment ("on every arm but
  --weg2-weight-source shadow it returns having touched nothing").
- _weg2_shadow_destination_leg's docstring and call-site comment ("the
  ring's bytes are final here" / "ground truth" framed as ring-only,
  stale under CARRIER_EXCHANGE where the peer group's live VRAM is the
  ground truth instead).

EXECUTION SMOKE (task step 4, "nicht per Unit-Double"):
test_weg2_1334_bounce_lane_axis.py, 9 cases, on the REAL
_weg2_shadow_hook through its own two production callers:
- The three-arm matrix (ring/exchange/shadow) proven by execution, not
  read: bounce_lane_armed() itself is asserted per arm AND the hook's own
  reachability past its gate is spied and checked to match, for both the
  source and destination legs.
- Danger-direction mutant (order's own): bounce_lane_armed monkeypatched
  to shadow_armed reproduces boot weg2xsn16's exact shape (the lane never
  arms under exchange) -- proving the real code is what stands between
  this and BOOT7's A1 measuring pieces=0 for this exact reason.

Regression: 125/125 (this suite + the sgl-project#1329 shadow execution smoke +
sgl-project#1394 draft-in-exchange + sgl-project#1394/sgl-project#1369 wake-source-gap + gate-axis sgl-project#1273 +
sgl-project#1391's own suite + inject-wiring sgl-project#1342 + wcode census sgl-project#1263 + sgl-project#1397
band-credit wiring).

No new W-code (none needed -- no refusal added, only a verification and
two comment fixes).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…c-smoke, fix the caller

Third sighting. Traced to source, not pattern-matched (shm-residue-nur-
per-halter): section [4] patches only weight_exchange_bounce.
run_bounce_leg to a stub -- the REAL, borrowed method it drives,
SchedulerWeightUpdaterManager._weg2_xchg_bounce_leg (weight_updater.py:
3718), unconditionally constructs a real bx.BounceSlots(boot_nonce,
shm_root=root, create=True, ...) with root = xr.SHM_ROOT (the script never
passes shm_root=) and boot_nonce="smoke" (a bare literal). weight_
exchange_region.teardown_region would not have fixed this even if called:
it only unlinks the region file and bounce.bin.* entries INSIDE
region_dir(boot_nonce) -- BounceSlots' own file lives directly under
shm_root (weight_exchange_bounce.bounce_slots_path), a different path.

Fix: PID-scope the nonce (SMOKE_NONCE = f"smoke{os.getpid()}", the same
sgl-project#1344 rule the phase tests' own shm sweep already states -- "the NAME is
the proof of ownership"), threaded through build()'s manifest boot_token
too (it has to match what the join reads via ENV_REGION_BOOT). Clean up
in the existing finally block with BounceSlots(SMOKE_NONCE, shm_root=xr.
SHM_ROOT, create=False).unlink() -- the class's own existing method,
holder-scoped by construction (this PID's own nonce, never a glob), no
new mechanism.

Verified at the metal, not assumed: two consecutive real runs (no GPU
needed, CUDA_VISIBLE_DEVICES=""), 19/19 PASS both times, /dev/shm checked
before and after -- no weg2-xchg-bnc-smoke* file created by either run,
pre-existing foreign artifacts from other sessions (weg2-xchg-bnc-1391boot,
weg2-xchg-bnc-desk10-1391-r4-*) left untouched as the holder-scoping rule
requires.

Separate finding, NOT fixed here (out of this ticket's scope and file
boundary): on the current train tip section [1] now fails with
"'_Stub' object has no attribute '_weg2_xchg_draft_plan_or_none'" --
weight_updater.py:2905, introduced by sgl-project#1394 (draft weights join the real
exchange), unrelated to this fix. Confirmed present identically with and
without this commit's changes. My own fix's correctness was verified
independently on an earlier train-tip commit (18bb175, before sgl-project#1394
landed) where section [1]/[4] still run for real; the cleanup code's own
FileNotFoundError guard is exactly what makes it inert and safe on the
current tip too, where the loop body that would create the file never
runs at all.

File boundary: scripts/weg2/xchg_provider_smoke.py only -- no change to
weight_exchange_bounce.py/xchg_bounce.py (this ticket needed none) or to
any DESK9/DESK10-owned file.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…s undefined on a

quantized checkpoint too -- refuse by name (W4/W106 reused), never attempt
it

Coordinator relay of a real boot death: A2 (Ring AUS, authoritative) died
at scheduler init with W4 Weg2WakeRefused (weg2_memory_saver.py:368,
"--enable-memory-saver without --enable-weights-cpu-backup on a
'compressed-tensors' checkpoint"). Verification requested in three steps,
answered here with file:line, per the coordinator's own explicit
"pruefe das, statt es zu uebernehmen" doctrine (third time today):

(1) Does the guard, or either of its two callers, read any exchange axis?
NO. assert_backup_off_wake_refill_is_defined (weg2_memory_saver.py:328-382)
reads only `quantization`; its predicate contains no exchange_armed() /
weight_source() / CARRIER_EXCHANGE check anywhere. Of its two callers:
scheduler.py:2310-2316 (the ACTUAL death site, launch-time, before any
weight load or plan exists) reads only the raw `server_args.
enable_weights_cpu_backup` flag -- no exchange axis, unconditional refusal
whenever that flag is off and the checkpoint is quantized. weight_updater.
py:1753 (this file, the wake-time call) is reached ONLY when
_weg2_wake_weight_carrier() already resolved to CARRIER_DISK -- it never
runs under CARRIER_EXCHANGE, so it is already correctly gated by the
carrier routing above it, just not by a literal axis read inside the
guard call itself. CONFIRMS the coordinator's reading for the death site:
scheduler.py's launch-time check predates the exchange entirely and does
not know a third lane exists -- OUT OF THIS FILE'S BOUNDARY, reported
rather than edited.

(2) Does the exchange carry post-transform bytes on the wake side? YES,
confirmed against today's own execution smokes (test_weg2_1394_draft_
in_exchange.py, test_weg2_1397_band_credit_wiring.py, both driving real
cross-pair legs under WEIGHT_SOURCE_EXCHANGE + INJECT_AUTHORITATIVE).
_weg2_join_dst_addr resolves the DESTINATION's own EXISTING, already-
loaded parameter's data_ptr() (weight_updater.py, via
_weg2_rank_param_table); run_bounce_leg / _weg2_xchg_bounce_leg write raw
bytes into that address via device-to-device-through-host copy. Neither
touches load_weights, process_weights_after_loading, or constructs a new
Parameter at any point -- the bytes it moves are the peer's own live,
already-transformed VRAM tensor. Matches the guard's own "defined" lane
("the TMS restore carries the post-transform bytes and no reload runs").

(3) Completeness -- THIS DESK'S OWN PART, fixed here: a tag without an
exchange source falls to the sgl-project#1394 disk-reload path today, and that path
is the SAME undefined operation the W4 guard names, reached through a
caller (_weg2_xchg_draft_reload_from_disk) the guard did not know about
either. The exemption in _weg2_xchg_wake_source_gap that unconditionally
answered "covered by disk" for weights_draft assumed the fallback was
always safe -- it is not, on a quantized checkpoint, and this morning's
own sgl-project#1394 doctrine ("der Checkpoint ist das Netz") never actually checked
that against the process's real checkpoint.

FIX, reusing W4 and W106 -- no new W-code:

- _weg2_xchg_wake_source_gap: the weights_draft exemption now checks
  _weg2_draft_checkpoint_quantization() (new helper, mirrors
  checkpoint_quantization's own two-holder order for the draft runner)
  before granting it. Quantized + no descriptors -> a real gap, refused by
  name (W106) at the sleep leg, before the pause, with the tag's own
  reasoning cited alongside assert_backup_off_wake_refill_is_defined's.
  Unquantized: unchanged, still exempt.
- _weg2_xchg_draft_reload_from_disk: calls
  assert_backup_off_wake_refill_is_defined itself, BEFORE anything is
  locked or entered, with the draft checkpoint's own quantization --
  defense in depth for the boot-time INITIAL sleep, which
  _weg2_xchg_deposit_before_sleep skips by construction (flip_index < 0),
  so the sleep-leg's own gap-check never ran for it. No guard weakened:
  this calls the SAME guard the launch arm and the main wake already call,
  one caller wider, exactly the "one definition, shared" doctrine already
  established for the other two call sites.

Tests (test_weg2_1394_1369_wake_source_gap.py, 4 new cases, RED-FIRST
verified by reverting the production change and observing both new tests
fail with exactly the expected shapes, restored after):
- the quantized-checkpoint gap, its text checked against the REAL W4 text
  (driven through assert_backup_off_wake_refill_is_defined itself, never
  hand-typed -- the fixture the order asked for) for shared reasoning, not
  a duplicated string;
- the unquantized regression guard (unchanged behaviour);
- the draft-reload guard firing before the fake draft worker's
  update_weights_from_disk is ever called;
- the danger-direction mutant (coordinator order): the OLD, unconditional
  exemption restored inline, shown to answer "no gap" on exactly the case
  that must refuse (zero descriptors, quantized checkpoint) -- passes only
  because it demonstrates the danger the real code prevents.

Regression: 122/122 (this suite + sgl-project#1394 draft-in-exchange + sgl-project#1397 band-
credit wiring + sgl-project#1334 bounce-lane axis + gate-axis sgl-project#1273 + sgl-project#1391's own
suite + inject-wiring sgl-project#1342 + wcode census sgl-project#1263).

NOT FIXED, OUTSIDE THIS FILE'S BOUNDARY, REPORTED PER "SAGEN, NICHT TUN":
this commit does not unblock A2's own observed death. scheduler.py:2310-
2316's launch-time check is a blanket, argv-only refusal that fires
before any weight load, any manifest, or any plan exists -- it structurally
cannot verify per-tag exchange completeness at that point, which is
exactly the tension between "recognise a third lane" and "vollstaendigkeit
als Bedingung, nicht als Annahme" the coordinator's own order names. This
desk's fix makes the WAKE-TIME logic (weight_updater.py /
weg2_memory_saver.py) correctly safe once that gate is ever relaxed; it
does not relax it, and does not decide who should.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…ole class

Coordinator finding: `_weg2_xchg_draft_plan_or_none` = 0 hits in the
script, 4 in weight_updater.py -- sgl-project#1394 added a new call from
`_weg2_shadow_plan` that `_Stub` never borrowed, so section [1] of
xchg_provider_smoke.py has been silently degraded (a real AttributeError
caught by _weg2_shadow_plan's own `except BaseException` and returned as
an ordinary "derivation failed" string) since sgl-project#1394 landed, with nobody
noticing except by reading the output. This is the sgl-project#624/sgl-project#978 stub-drift
class.

(1) THE FIX: borrowed the real `_weg2_xchg_draft_plan_or_none` onto
`_Stub`, the same doctrine as the four names already there -- not a
hand-written neutral stub. Justified in code: the real method's own body
already answers "no draft worker in this process" gracefully
(`getattr(self, "draft_worker", None)`, returns `(None, "")`, never
raises) -- exactly the state a `_Stub` instance is in, since it never
sets `draft_worker`. A fabricated neutral stub would be a second,
hand-maintained copy of a judgement call the real method already makes
for itself, and would violate this file's own stated rule ("what runs
here is byte-for-byte the code the flip leg runs").

(2) THE RATCHET: `test_weg2_1363_smoke_stub_drift.py` +
`weg2_smoke_stub_support.py`. Read the sgl-project#624 precedent first
(27c1791, barlink_stub_support.py) and adapted its shape rather than
reinventing it -- but the mechanism differs on purpose: sgl-project#624 audits
`__init__`-ASSIGNED ATTRIBUTES via one non-transitive AST walk; this
audits `self.<name>` READS via a walk that is TRANSITIVE (a production
entry point calls other production methods on the same class, and those
may call further ones -- `self_reads_reachable` follows any discovered
name that is itself a method defined on the real class). A
`getattr(self, "name", default)`-style read is deliberately invisible to
this audit: it passes the name as a string argument, never as `self.name`
AST syntax, and the real code already tolerates its absence by
construction.

Prerequisite refactor (behaviour-preserving): `_LegStub`, `_Sems`,
`_Region` were local classes inside `main()`, so the ratchet test could
not import and introspect them. Hoisted to module level; `_Region` picked
up an explicit `boot_nonce` constructor argument instead of closing over
`main()`'s local `SMOKE_NONCE`. `_Stub` was already module-level.

Computed the real, transitive requirement empirically rather than
guessing: `_Stub`/`_weg2_shadow_plan` needs exactly 5 names (4 already
borrowed/set, the one gap this commit closes) -- exclusion table starts
EMPTY, as ordered. `_LegStub`/`_weg2_xchg_bounce_leg` needs 2 names
(`_weg2_xchg_tag_seen`, `_weg2_xchg_undrained_lanes`) that this smoke's
own call never reaches (guarded by `tag is not None` /
`rank is not None`, and this script passes neither) -- both excluded
with a reason naming the guard, per weg2_smoke_stub_support.py.

(3) RED-FIRST, against today's tip: with the `_weg2_xchg_draft_plan_or_
none` borrow line removed by hand,
test_stub_covers_or_excludes_every_reachable_name failed naming exactly
that one attribute -- the calibration proof, verified by temporarily
reverting the fix and reapplying it (git diff / git apply), not merely
asserted. Mutant test_M_removing_a_borrowed_method_the_stub_needs_goes_
red drives a deliberately incomplete double (`_weg2_join_src_addr`
removed) through the identical audit logic and asserts it is caught.

Metal proof, same form as round 1: two consecutive real runs on this
exact base (train tip includes sgl-project#1334's unrelated doc corrections, no
functional change to the audited methods), 19/19 PASS both times,
/dev/shm checked before and after both runs -- no weg2-xchg-bnc-smoke*
residue.

Structural verdict on the coordinator's fallback question (is this
script's stub approach ratchet-capable at all?): yes -- `_Stub`/
`_LegStub` are ordinary classes with a finite, fixed set of borrowed
methods and constructor-set attributes, never `__new__`-built with
hand-set fields the way sgl-project#624's BAR1 transport is, and (after the hoist)
both are module-level and import cleanly. Pinned as its own test
(TheScriptItselfIsRatchetable) so this finding does not have to be
re-derived from the ratchet's mere existence.

File boundary: scripts/weg2/xchg_provider_smoke.py (now mine, since
sgl-project#1363 round 1) plus two new test-directory files. No change to any
DESK9/DESK10-owned file; weight_updater.py was read only, to compute the
real transitive requirement and to confirm the unrelated sgl-project#1334 diff
between my two verification points touches no audited method body.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…s undefined on a

quantized checkpoint too -- refuse by name (W4/W106 reused), never attempt
it

Coordinator relay of a real boot death: A2 (Ring AUS, authoritative) died
at scheduler init with W4 Weg2WakeRefused (weg2_memory_saver.py:368,
"--enable-memory-saver without --enable-weights-cpu-backup on a
'compressed-tensors' checkpoint"). Verification requested in three steps,
answered here with file:line, per the coordinator's own explicit
"pruefe das, statt es zu uebernehmen" doctrine (third time today):

(1) Does the guard, or either of its two callers, read any exchange axis?
NO. assert_backup_off_wake_refill_is_defined (weg2_memory_saver.py:328-382)
reads only `quantization`; its predicate contains no exchange_armed() /
weight_source() / CARRIER_EXCHANGE check anywhere. Of its two callers:
scheduler.py:2310-2316 (the ACTUAL death site, launch-time, before any
weight load or plan exists) reads only the raw `server_args.
enable_weights_cpu_backup` flag -- no exchange axis, unconditional refusal
whenever that flag is off and the checkpoint is quantized. weight_updater.
py:1753 (this file, the wake-time call) is reached ONLY when
_weg2_wake_weight_carrier() already resolved to CARRIER_DISK -- it never
runs under CARRIER_EXCHANGE, so it is already correctly gated by the
carrier routing above it, just not by a literal axis read inside the
guard call itself. CONFIRMS the coordinator's reading for the death site:
scheduler.py's launch-time check predates the exchange entirely and does
not know a third lane exists -- OUT OF THIS FILE'S BOUNDARY, reported
rather than edited.

(2) Does the exchange carry post-transform bytes on the wake side? YES,
confirmed against today's own execution smokes (test_weg2_1394_draft_
in_exchange.py, test_weg2_1397_band_credit_wiring.py, both driving real
cross-pair legs under WEIGHT_SOURCE_EXCHANGE + INJECT_AUTHORITATIVE).
_weg2_join_dst_addr resolves the DESTINATION's own EXISTING, already-
loaded parameter's data_ptr() (weight_updater.py, via
_weg2_rank_param_table); run_bounce_leg / _weg2_xchg_bounce_leg write raw
bytes into that address via device-to-device-through-host copy. Neither
touches load_weights, process_weights_after_loading, or constructs a new
Parameter at any point -- the bytes it moves are the peer's own live,
already-transformed VRAM tensor. Matches the guard's own "defined" lane
("the TMS restore carries the post-transform bytes and no reload runs").

(3) Completeness -- THIS DESK'S OWN PART, fixed here: a tag without an
exchange source falls to the sgl-project#1394 disk-reload path today, and that path
is the SAME undefined operation the W4 guard names, reached through a
caller (_weg2_xchg_draft_reload_from_disk) the guard did not know about
either. The exemption in _weg2_xchg_wake_source_gap that unconditionally
answered "covered by disk" for weights_draft assumed the fallback was
always safe -- it is not, on a quantized checkpoint, and this morning's
own sgl-project#1394 doctrine ("der Checkpoint ist das Netz") never actually checked
that against the process's real checkpoint.

FIX, reusing W4 and W106 -- no new W-code:

- _weg2_xchg_wake_source_gap: the weights_draft exemption now checks
  _weg2_draft_checkpoint_quantization() (new helper, mirrors
  checkpoint_quantization's own two-holder order for the draft runner)
  before granting it. Quantized + no descriptors -> a real gap, refused by
  name (W106) at the sleep leg, before the pause, with the tag's own
  reasoning cited alongside assert_backup_off_wake_refill_is_defined's.
  Unquantized: unchanged, still exempt.
- _weg2_xchg_draft_reload_from_disk: calls
  assert_backup_off_wake_refill_is_defined itself, BEFORE anything is
  locked or entered, with the draft checkpoint's own quantization --
  defense in depth for the boot-time INITIAL sleep, which
  _weg2_xchg_deposit_before_sleep skips by construction (flip_index < 0),
  so the sleep-leg's own gap-check never ran for it. No guard weakened:
  this calls the SAME guard the launch arm and the main wake already call,
  one caller wider, exactly the "one definition, shared" doctrine already
  established for the other two call sites.

Tests (test_weg2_1394_1369_wake_source_gap.py, 4 new cases, RED-FIRST
verified by reverting the production change and observing both new tests
fail with exactly the expected shapes, restored after):
- the quantized-checkpoint gap, its text checked against the REAL W4 text
  (driven through assert_backup_off_wake_refill_is_defined itself, never
  hand-typed -- the fixture the order asked for) for shared reasoning, not
  a duplicated string;
- the unquantized regression guard (unchanged behaviour);
- the draft-reload guard firing before the fake draft worker's
  update_weights_from_disk is ever called;
- the danger-direction mutant (coordinator order): the OLD, unconditional
  exemption restored inline, shown to answer "no gap" on exactly the case
  that must refuse (zero descriptors, quantized checkpoint) -- passes only
  because it demonstrates the danger the real code prevents.

Regression: 122/122 (this suite + sgl-project#1394 draft-in-exchange + sgl-project#1397 band-
credit wiring + sgl-project#1334 bounce-lane axis + gate-axis sgl-project#1273 + sgl-project#1391's own
suite + inject-wiring sgl-project#1342 + wcode census sgl-project#1263).

NOT FIXED, OUTSIDE THIS FILE'S BOUNDARY, REPORTED PER "SAGEN, NICHT TUN":
this commit does not unblock A2's own observed death. scheduler.py:2310-
2316's launch-time check is a blanket, argv-only refusal that fires
before any weight load, any manifest, or any plan exists -- it structurally
cannot verify per-tag exchange completeness at that point, which is
exactly the tension between "recognise a third lane" and "vollstaendigkeit
als Bedingung, nicht als Annahme" the coordinator's own order names. This
desk's fix makes the WAKE-TIME logic (weight_updater.py /
weg2_memory_saver.py) correctly safe once that gate is ever relaxed; it
does not relax it, and does not decide who should.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 15, 2026
…guard orders

MEASURED on the weg2xsn53 boot (P log 001701): the wake was refused W4
Weg2WakeRefused with 'join-plan-tag-divergence: card 0: the two groups'
tag sets diverge for region weights: only_src=[weights_5, weights_6,
weights_7] only_dst=[]' -- the 52d96f3 guard refused because the
narrowing its own sentence orders was never written. The exchange scope
is now the per-card INTERSECTION of the two groups' tag sets, narrowed
BEFORE the join: dropped tags are named per group with their byte count
and pointed at the disk-reload fallback (sgl-project#1394), never silently. A tag
the exchange does not cover on a card comes back from the fallback.

The guard stays and is now load bearing: 3 new hermetic tests pin that a
divergent tag set still produces a plan, that the dropped tags are named,
and that removing the narrowing brings the measured refusal back
(dying mutant, verified red with the pass disabled).

Provider smoke 19/19, 300 tests over the touched files green,
leg replay self-test: the P ranks' draft-region legs still refuse in the
harness (non-narrowed descs) -- documented, not hidden.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 15, 2026
…must share names

MEASURED on the weg2xsn53 boot 014119 P log: the wake was refused
join-plan-name-divergence (first: lm_head.weight, layers.39.*) -- the
MIRROR of the sleep refusal. A subset check refuses in BOTH directions on
this topology: sleep source P = 6 tags / 893 names vs destination D 9/1249;
wake source D = 9/1249 vs destination P 6/893. The TP source legitimately
holds every layer; the PP destination only its stage's.

What the exchange moves is the NAME INTERSECTION (measured 893, P subset
D, only-P=0), and destination-only names are the disk-reload fallback's
business (sgl-project#1394). The one defect the guard can still catch is a card whose
two groups share NO name in the region -- a deposit and a collect that
never meet, the W68 shape. That is now the check, and it is the last one
that can hold in both directions.

DESK PROOF on the boot's real manifests: leg_plan_from_join returns 2679
descs (hook=source/group=P) and 1249 descs (hook=authoritative/group=D) --
BOTH directions plan. 231 tests over the touched files green.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 15, 2026
…d form (xsn53 join contract, sequential lanes)

Nutzer-Order 2026-09-15: the pre-existing red tests are part of the task.

- test_weg2_draft_lmhead_share_1378 (2): since xsn53 join_manifests names a
  destination-only tensor and covers the intersection (WEG2-XCHG-PLAN
  destination-only-names=, the sgl-project#1394 disk-reload fallback) instead of W74;
  measured every leg on weg2xsn87-89 (D's own lm_head) with MATCH x12 and
  GEN-SMOKE MATCH. The two tests now assert the exclusion is NAMED and the
  tensor never planned (the danger direction the mutant was written for).
- test_weg2_1397_band_credit_wiring (2) and
  test_weg2_undrained_lane_refusal_1391 (2): the sequential transport
  derives each lane's units from the manifests; these harnesses hand
  explicit descs to the leg, so _lane_descs_filter feeds them through
  _weg2_seq_lane_descs filtered by tag and lane. The band-credit size proof
  asserts the lane's own sum under either term (band_credit is a lever of
  the retired LayerBounce form); the M2 whole-plan deadlock mutant runs at
  buffer depth 1 (the law it models) and accepts either wedge side.

Tests: lmhead_share 3/3, band_credit_wiring 5/5, undrained_lane_refusal
45/45, sequential_transport 14/14, wake_source_gap 30/30, flip_order 23/23,
xchg_provider_smoke 19/19.
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