Skip to content

mono(v41, gfx950): follow in-place weight updates on the layer-kernel and hi decode paths - #3950

Draft
yifehuan wants to merge 1 commit into
mainfrom
yifehuan/mono-v41-weight-update
Draft

yifehuan wants to merge 1 commit into
mainfrom
yifehuan/mono-v41-weight-update

Conversation

@yifehuan

Copy link
Copy Markdown
Contributor

Why

An in-place weight update (the rollout sync update_weights*, later a weight-cache daemon's load) rewrites the
model's parameters at their own addresses, so captured graphs stay valid. DeepSeek-V4.1's mono decode read copies made
at bind time that nothing refreshed: after an update it would keep serving the old weights, and no shape or dtype check
could notice. That is why atom/mono/runtime/deployment.py refuses every runner that takes updates.

This PR makes every weight pointer a V4.1 gfx950 mono launch reads either in place (inside a parameter's storage)
or a registered derived buffer that is rebuilt in place after an update. A bind-time audit refuses anything
else. The refusal is lifted for V4.1 gfx950 only.

Scope: DeepSeek-V4.1, gfx950, mono only: the layer-kernel (LK) path and the hi monokernel path. Everything V4.1-specific
lives in atom/models/deepseek_v41/mono/. The only shared change is a small model hook in the rollout updater.

What changed

Copies removed; the kernel reads the parameter in place, with unchanged arithmetic:

Path Before After
LK compressor f32 copies of compressor.norm / indexer.k_norm bf16 read in place (bf16 -> f32 is exact)
LK draft context write DSpark's fused _context_kv_fused each stage's own wkv rows of wqkv_a (3 pointers; the 16x16 preshuffle permutes within 16-row groups, so the rows are one contiguous run)
LK Engram gate EngramOp.gate_weight (derived at load) q_weight * k_weight multiplied in the kernel (exact in f32)
hi compressor comp.aux = cat(norm, pack_wk(wk), k_norm) comp.norm / comp.knorm read in place; comp.aux keeps only the re-laid-out wk
hi draft context 3 duplicated wkv packs the draft stages' own wkv packs
hi block draft DSpark's cached _noise_row the noise token's row read from its owner rank's vocab shard (PeerEmbedding)
hi eng.gw aliased EngramOp.gate_weight its own q * k product (registered, rebuilt)

Derived weights: atom/models/deepseek_v41/mono/weight_refresh.py

  • DerivedWeights.register(name, sources, dests, rebuild): rebuild() re-derives dests from sources into the same
    storage. A rebuild that moves an address raises. Only entries whose sources were rewritten are rebuilt.
  • hi registers every buffer it packs, and its rebuild is the install's own packing re-run and copied into the bound
    tensors. That covers the layers' MXFP8 linears, the shared expert, indexer wq_b, comp.aux, eng.gw, the Engram
    wkv column shards, the head, the draft stages and the draft context's main_proj. LK registers nothing: it reads
    every weight in place.
  • audit: every weight pointer must lie in a parameter's storage or a registered destination, and every entry's sources
    in a parameter's storage. This covers each LK runner's launches (layers, compressor, LM head, Engram, draft context,
    draft head) and every hi pointer-table weight set. Under a runner that takes weight updates the audit is strict: a
    failing path is refused at bind, agreed over the TP group.
  • rebuild_after_weight_update(model, changed) / weight_update_refusal(model) are the entry points for a
    weight-cache daemon's load later.

Wiring

  • config.config_refusal drops the shared "rollout weight updates" refusal, which V4.1 now answers at bind. gfx1250 and
    every other model keep it. V4.1 still refuses a weight-updating runner unless Config.sleep_keeps_memory_resident is
    set, because a sleep would move the weights and the KV pool that mono binds.
  • MonoDecodeModel answers the update path's model hooks: weight_sync_target (the parameters keep the model's own
    names), weight_update_refusal() and after_weight_update(changed).
  • atom/rollout/weight_updater.py calls those hooks, if a model defines them: the refusal before a sync's first write,
    and after_weight_update at the sync's last bucket (after the expert relayout, behind the readers' fence). This runs
    on every path: direct, SHM, IPC and RDMA. weight_sync_record.py gains touched().

Verification (MI355X, TP8)

The GPU runs below used this change on origin/main 215b924. Since then I moved the registry into the V4.1 package and
replaced the rollout integration with the model hooks; that changes no kernel, packing or rebuild code. The branch is
rebased on current main.

Checkpoint B is checkpoint A (DeepSeek-V4.1-Flash) with a deterministic perturbation of layer 2 and the LM head:

  • sign flips on some rows of wq_a, wkv, indexer wq_b and wo_b;
  • scaled compressor.norm, k_norm and attn_norm;
  • negated rows of indexer wk, and scaled rows of head.

Updates go A -> B -> A on a live engine (RLHF runner, CUDA graphs captured). Seven tensors go through update_weights
over SHM. The TP-sharded FP8 wo_b is written in place followed by rebuild_after_weight_update, as a daemon load
would do it. Configs: hi (bf16 KV, fp4 index, DSpark 5 drafts) and LK (fp8 KV).

  • Bit-exact rebuild. I compared sha256 digests of every derived buffer and of every perturbed parameter on all 8
    ranks:

    • hi, hot A->B vs a fresh engine started on B: 5064/5064 buffers and 64/64 parameters byte-equal;
    • hi, B->A vs A before the updates: 5064/5064 and 64/64 byte-equal;
    • LK has no derived buffers; its parameters are byte-equal in both comparisons.

    Greedy outputs cannot serve as this check: the engine is not run-to-run deterministic at this configuration (two
    identical runs on origin/main already differ in a few tokens), so the comparison is made on the bytes the kernels read.

  • Negative control. The same A->B update with the rebuild skipped leaves 48 buffer digests (6 a rank) unequal to
    fresh B, all of them in exactly the touched entries (hi head, hi layer 2).

  • Class A, value identity on the live model (all ranks):

    • Engram: q*k == gate_weight;
    • hi: eng.gw == gate_weight; [comp.norm, comp.aux, comp.knorm] equals the old aux, and the norms are the
      parameters;
    • hi context wkv is the stage packs and equals a fresh context pack;
    • hi noise row read from the owner shard equals _noise_row;
    • LK draft context stage rows and scales equal DSpark's fused copy;
    • LK compressor norms are the bf16 parameters.
  • Addresses and graphs are stable across A->B, B->A and the skipped A->B: unchanged are every derived-buffer
    pointer (633 a rank), every parameter pointer (1517), all 336 hi pointer tables (address and contents) and the
    captured decode and draft graph objects. Nothing was recaptured.

  • Audit: hi passes strict on every rank: 1402 weight pointers, 762 in place and 640 in 47 derived entries. LK passes
    for both the target and draft runners.

  • Rebuild time per update (per rank, min-max): hi rollout 15-18 ms (A->B) and 38-43 ms (B->A), hi daemon path
    13-14 ms; LK 1-3 ms (nothing to rebuild).

  • No TPOT change (forced acceptance).

  • CPU tests:

    • tests/test_deepseek_v41_mono_weight_refresh.py: the registry, the audit (a positive case and an
      unregistered-pointer case), the refusals, and the rollout hooks;
    • tests/test_deepseek_v41_mono_weight_update.py: LK/hi binding on stand-ins; its layer-kernel cases need the GPU
      stack.

    The mono, V4.1 and rollout suites fail the same tests as origin/main does.

Out of scope / notes

  • gfx1250 (mono/gfx1250/) keeps the refusal.
  • ATOM's own non-mono derived caches are untouched: _context_kv_fused, _draft_kv_tail, _noise_row,
    hc_*_fn_packed and EngramOp.gate_weight. Mono no longer reads any of them.
  • The weight-cache daemon's load is not part of this PR. It would call weight_update_refusal before writing and
    after_weight_update (or rebuild_after_weight_update) after.
  • Seen while testing, independent of mono, and left as they are:
    • reload_policy._unreloadable_params refuses V4.1-Flash's MXFP4 experts and per_1x32 FP8 for full-precision
      writes. The test runner overrode only that check and sent tensors in their native dtype.
    • MemoryManagerMixin.clear_kv_cache assumes a runner-level kv_cache pool, which a V4.1 runner does not have.

An in-place weight update (the rollout sync, a weight-cache daemon's load)
rewrites the parameters at their addresses. V4.1 mono read copies made at
bind time that nothing refreshed, so every runner that takes updates was
refused. Now every weight pointer a V4.1 gfx950 mono launch reads is either
in place or a registered derived buffer rebuilt in place after an update; a
bind-time audit refuses anything else.

Copies removed (the kernel reads the parameter in place, same arithmetic):
- LK compressor: compressor.norm / indexer.k_norm as bf16 (bf16 -> f32 exact).
- LK draft context: each stage's own wkv rows of wqkv_a (3 pointers; the
  preshuffle permutes within 16-row groups) instead of _context_kv_fused.
- LK Engram gate: q_weight * k_weight in the kernel (exact in f32) instead of
  EngramOp.gate_weight.
- hi compressor: norm / k_norm in place; comp.aux keeps only pack_wk(wk).
- hi draft context: the draft stages' own wkv packs, not 3 duplicates.
- hi block draft: the noise row from its owner rank's vocab shard
  (PeerEmbedding), not DSpark's cached _noise_row.
- hi eng.gw: its own q*k product (registered) instead of aliasing gate_weight.

Derived weights (atom/models/deepseek_v41/mono/weight_refresh.py): hi
registers every buffer it packs and rebuilds it by re-running the install's
packing into the bound tensors; only entries whose sources changed rebuild,
and a rebuild that moves an address raises. The audit covers every LK
launch's weights and every hi pointer-table weight set; strict (refusing at
bind, agreed over TP) under a runner that takes updates.

Wiring: V4.1's config_refusal drops the shared rollout refusal (gfx1250 and
other models keep it) and still refuses a weight-updating runner without
sleep_keeps_memory_resident. MonoDecodeModel answers the update path's model
hooks (weight_sync_target, weight_update_refusal, after_weight_update), which
weight_updater calls before a sync's first write and at its last bucket (all
paths), behind the readers' fence.

Verified on MI355X TP8 (hi: bf16 KV + DSpark; LK: fp8 KV), A -> B -> A on a
live engine (update_weights over SHM + an in-place wo_b write with
rebuild_after_weight_update), B = A with layer 2 / head perturbed:
- sha256 of every derived buffer and perturbed parameter, all ranks: hot
  A->B == fresh B on 5064/5064 buffers and 64/64 params; B->A == A0 likewise;
  LK has no derived buffers, params equal.
- negative control (rebuild skipped): 48 buffer digests differ, exactly the
  touched entries (hi head, hi layer 2).
- class-A value identity on the live model: all checks true on all ranks.
- addresses and graphs unchanged: 633 derived pointers, 1517 parameter
  pointers, 336 hi pointer tables, decode/draft graph objects.
- rebuild per update: hi 15-43 ms (rollout), 13-14 ms (daemon path); LK 1-3 ms.
- no TPOT change (forced acceptance).
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Gate checks are published on every PR so required checks do not stay missing
  • ✅ Expensive jobs run only after the PR is approved, or when a matching ci:* label is present
  • ✅ Pre Checkin must pass before approved heavy jobs continue
  • ✅ Without a matching label, expensive jobs also require a relevant path
  • ✅ A matching ci:* label is an explicit request and can open the gate even when paths would otherwise skip it

Path scope:

  • Native ATOM uses an ignore list: docs/markdown and plugin or Mesh paths are skipped
  • vLLM and SGLang use include lists: their own plugin code under atom/plugin/, plugin CI scripts, model list and release images. A core-only change does not run them; add ci:vllm / ci:sglang to ask for them
  • ATOMesh uses an include list: Mesh code, the ATOMesh accuracy workflow and its 1P1D launcher, plus the shared models_accuracy.json and accuracy_to_dashboard.py. ATOMesh benchmarks run after merge or on dispatch, not on PRs
  • Relevant path alone does not start expensive jobs; approval still opens the automatic path-scoped gate
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, SGLang, and ATOMesh
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests
ci:mesh Run the ATOMesh accuracy tests, standalone and 1P1D, for Mesh-related changes

Without a matching ci:* label, heavy jobs are skipped when the path is not relevant or the PR is not approved.
Add labels via the sidebar or gh pr edit 3950 --add-label <label>

This branch has not been deployed

No deployments
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