Archived
minimaxh3 convert: restore the SwiGLU gate-half swap — cont.25's identity maps rendered tile-scrambled garbage
77ef8f0 flipped the three ff.net.0.proj map_rows sites (dit/refiner ffn_gate_up, vae ffn_up + bias) to identity because the container bytes were "gate-second" against a gate-first CPU reference. That reference was circular: it read CONTAINER rows through comfy's gate-first `_swiglu_eager`, so it agrees with whichever order the container carries. The checkpoint's own library settles it: ff.net.0.proj is diffusers' SwiGLU (diffusers/models/activations.py, `hidden, gate = proj(x).chunk(2,-1); hidden * silu(gate)`) — VALUE first, gate second — transformer AND VAE (autoencoder_kl_minimax_h3 builds its FFNs from the same FeedForward). `silu_mul`/`gated_quant_fp8` gate with the FIRST half, so the convert must swap. The swap was load-bearing. Device evidence (task #64): every render of the identity-map container (minimax-h3-dasiwa-w8a8-gatefix.rad) — including the pinned FL2VA frame-0 — was a full-frame grid of ~16px tile-scrambled colour squares, while the original swapped container on the SAME binary renders coherent video with both pins forced (cmp45/FINAL_t2va512.mp4, FINAL_fl2va512.mp4; frames read by eye). Aggregate metrics (luma 81, clipHi 0.1%) were perfectly normal on the scrambled output — only vision caught it, and the cont.25 "device-verified" claim was metrics-only. Reverted maps verified by byte round-trip: rad-convert with the restored recipe and --reuse minimax-h3-dasiwa-w8a8.rad writes 3273/3273 tensors byte-identical to it. Kept: the R4D_DIT_SEL-gated decoder shadows + driver readback, the trailing-optional operand arity fix (43a6768), and the ABI-24 table regen (3f0f4ef) — all still valid. minimax-h3-dasiwa-w8a8-gatefix.rad stays only as the documented bad artifact; the good container remains minimax-h3-dasiwa-w8a8.rad. The fried look itself stays OPEN: the restored renders are coherent but still over-bright vs the reference. Docs cont.26 supersedes cont.25. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
c2e4dea468
commit
f7cc1b3a3b
2 files changed
+71
-24
No files matched your search
@@ -929,11 +929,9 @@ static int declare_te(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
/* ================================================================== the token refiner */
|
||||
/* `context_embedder` (5120 -> 5376, bf16, replicated), two plain blocks with full attention over
|
||||
* the prompt and no rotary, and the final RMSNorm into the lane's prompt rows. The feed-forward is
|
||||
* SwiGLU over `ff.net.0.proj`, gated with the FIRST half -- comfy's `_swiglu_eager` (the reference
|
||||
* that produced the ground-truth clips) chunks gate-first, and `silu_mul` reads gate-first, so the
|
||||
* rows are stored in checkpoint order. (An earlier convert moved the gate half second-hand --
|
||||
* swapping the halves -- which made every block's FFN compute `silu(up) * gate`; see the
|
||||
* `ffn_gate_up` map_rows below and #63's container byte inspection.) */
|
||||
* diffusers' SwiGLU, `value * silu(gate)` with the value first in the checkpoint; the gate half is
|
||||
* moved first at convert, which is the order `silu_mul` reads (see the `ffn_gate_up` map_rows in
|
||||
* declare_dit -- the proof comment lives there). */
|
||||
static int declare_refiner(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
Geom& g = m.gr;
|
||||
Names& nm = m.nm;
|
||||
@@ -1012,11 +1010,8 @@ static int declare_refiner(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
RAD_ARCH_TRY(R.q_h2.declare(b, g, m.a_rh, D));
|
||||
const char* fw = nm.f("%s.ffn_gate_up.weight", dn);
|
||||
const char* fsrc = nm.ckpt("%s.ff.net.0.proj.weight", pre);
|
||||
/* Gate-first, matching the reference `swiglu` (gate = first half of ff.net.0.proj) and
|
||||
* `silu_mul`'s first-half gate. The checkpoint stores the gate half first -- the container
|
||||
* bytes for the old swapped map (row 0 == ckpt row n_ff, verified byte-identical after
|
||||
* dequantising the int8 codes) made every DiT FFN compute silu(up)*gate. */
|
||||
RAD_ARCH_TRY(map_rows(b, fw, { { fsrc, 0, ff_all }, { fsrc, (int)ff_all, ff_all } }));
|
||||
/* Gate-first: swap the halves, the checkpoint's are value-first (see declare_dit). */
|
||||
RAD_ARCH_TRY(map_rows(b, fw, { { fsrc, (int)ff_all, ff_all }, { fsrc, 0, ff_all } }));
|
||||
R.gate_up.mapped = true;
|
||||
R.gate_up.access = acc;
|
||||
RAD_ARCH_TRY(R.gate_up.declare(b, nm, g, nm.f("%s.ffn_gate_up", dn), 2 * g.n_ff, D,
|
||||
@@ -1501,10 +1496,23 @@ static int declare_dit(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
B.op_mq2 = mod_q(B.w_n2, true);
|
||||
const char* fw = nm.f("%s.ffn_gate_up.weight", dn);
|
||||
const char* fsrc = nm.ckpt("%s.ff.net.0.proj.weight", pre);
|
||||
/* Same gate-first identity as the fp8 builder above -- the two sites must agree or the
|
||||
* int8 and bf16 paths disagree (the likelier culprit for the old "swap removal -> noise"
|
||||
* experiment). Row group=128 scales are quantised from the mapped rows, so they follow. */
|
||||
RAD_ARCH_TRY(map_rows(b, fw, { { fsrc, 0, ff_all }, { fsrc, (int)ff_all, ff_all } }));
|
||||
/* Gate-first: swap the halves, exactly as the fp8 builder above -- the two sites must
|
||||
* agree or the int8 and bf16 paths disagree. THIS SWAP IS LOAD-BEARING; it has now been
|
||||
* "fixed" (removed) twice and reverted twice, so settle it here with the proof:
|
||||
* `ff.net.0.proj` is diffusers' SwiGLU (diffusers/models/activations.py):
|
||||
* `value, gate = chunk(2); value * silu(gate)` -- the checkpoint stores the gate HALF
|
||||
* SECOND. `silu_mul` / `gated_quant_fp8` gate with the FIRST half, so the halves must be
|
||||
* swapped at convert for the device to compute the reference's silu(gate)*value. The
|
||||
* decisive experiment (task #64, 2026-10-22): the identity map -- "gate already first,
|
||||
* keep checkpoint order" -- was converted to minimax-h3-dasiwa-w8a8-gatefix.rad and
|
||||
* served on this same binary: EVERY render, including the pinned FL2VA frame-0, came out
|
||||
* as a grid of tile-scrambled colour squares, while the swapped (original) container on
|
||||
* the same binary renders coherent video. A harness agreement between the device and a
|
||||
* CPU reference that reads CONTAINER rows through comfy's gate-first `_swiglu_eager` is
|
||||
* circular and cannot adjudicate the half order -- only the ckpt convention can, and it
|
||||
* says value-first. Row group=128 scales are quantised from the mapped rows, so they
|
||||
* follow. */
|
||||
RAD_ARCH_TRY(map_rows(b, fw, { { fsrc, (int)ff_all, ff_all }, { fsrc, 0, ff_all } }));
|
||||
B.gate_up.mapped = true;
|
||||
RAD_ARCH_TRY(B.gate_up.declare(b, nm, g, nm.f("%s.ffn_gate_up", dn), 2 * g.n_ff, D,
|
||||
RAD_SHARD_ROW, grp_layer(grp), { fsrc }, m.a_hm, m.b_gu, 0,
|
||||
@@ -1894,15 +1902,13 @@ static int declare_video(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
const char* ub = nm.f("%s.ffn_up.bias", dn);
|
||||
const char* usrc = nm.ckpt("%s.ff.net.0.proj.weight", pre);
|
||||
const char* ubsrc = nm.ckpt("%s.ff.net.0.proj.bias", pre);
|
||||
/* #63 value-parity: the VAE's FeedForward is `linear(w2, swiglu(linear(w1, x)))` and
|
||||
* comfy's `_swiglu_eager` gates with the FIRST half of `ff.net.0.proj` -- so the rows must
|
||||
* stay in checkpoint order for `silu_mul` (which also gates with its first half) to
|
||||
* reproduce the reference. The block-0 internals dump (dn window) measured the swapped map
|
||||
* below computing silu(up_half)*gate_half -- cos 0.49 against the reference -- while attn
|
||||
* and to_out matched at the bf16 floor. Identity rows fix the FFN exactly (`ff.net.2`'s
|
||||
* columns stay aligned because the act columns inherit the checkpoint's row order). */
|
||||
RAD_ARCH_TRY(map_rows(b, un, { { usrc, 0, ff }, { usrc, (int)ff, ff } }));
|
||||
RAD_ARCH_TRY(map_rows(b, ub, { { ubsrc, 0, ff }, { ubsrc, (int)ff, ff } }));
|
||||
/* Gate-first: swap the halves. The VAE is diffusers' AutoencoderKLMiniMaxH3, whose
|
||||
* `ff.net.0.proj` is the same value-first SwiGLU as the transformer's -- see the proof
|
||||
* comment at the `ffn_gate_up` map_rows in declare_dit. The act columns inherit the
|
||||
* swapped row order and `ff.net.2`'s columns follow it, so the swap is self-consistent
|
||||
* end to end (and the swapped container is the one that decodes coherently). */
|
||||
RAD_ARCH_TRY(map_rows(b, un, { { usrc, (int)ff, ff }, { usrc, 0, ff } }));
|
||||
RAD_ARCH_TRY(map_rows(b, ub, { { ubsrc, (int)ff, ff }, { ubsrc, 0, ff } }));
|
||||
V.w_up = decl_w(b, un, RAD_BF16, { 2 * ff, dim }, acc, RAD_SHARD_NONE, grp_layer(gv));
|
||||
V.b_up = decl_w(b, ub, RAD_F32, { 2 * ff }, acc, RAD_SHARD_NONE, grp_layer(gv));
|
||||
V.w_down = wcopy(b, nm.f("%s.ffn_down.weight", dn), nm.ckpt("%s.ff.net.2.weight", pre),
|
||||
|
||||
+42
-1
@@ -1280,7 +1280,7 @@ video ENCODER itself hid two real bugs: the norm1/norm3 swap and the shortcut-af
|
||||
Next: **video VAE decoder value parity** (new build: R4D_DEC_SEL shadows + AST-extracted comfy decoder
|
||||
forward, mirroring `tests/data/ref2va/ref_venc_parity.py`).
|
||||
|
||||
### cont.25 (2026-10-22) — #63 CLOSED, the fried look ROOT-CAUSED AND FIXED: the container stored every SwiGLU FFN gate-second
|
||||
### cont.25 (2026-10-22) — [SUPERSEDED by cont.26: the "fixed" verdict below is WRONG — the gatefix container renders tile-scrambled garbage; keep reading] — #63 CLOSED, the fried look ROOT-CAUSED AND FIXED: the container stored every SwiGLU FFN gate-second
|
||||
The decoder-parity build (R4D_DIT_SEL-gated shadows `dbg_vd_lat/x0/blk/n/pix` in
|
||||
RadVideoGenDecl + driver readback to R4D_ENC_DUMPDIR, kept) measured block 0 of the video VAE
|
||||
decoder straight off the device: **attn cos 0.999990 and to_out cos 0.999994 (bf16 floor) but the
|
||||
@@ -1330,3 +1330,44 @@ Two host tests were red on the way and are green now:
|
||||
`tests/abi_layout_table.h`; `abi_layout_rows.h` also never listed Batch.sampler or any trailing
|
||||
dbg_* field (dbg_ve_*, dbg_dit_*, dbg_vd_* — 61 rows). Regenerated from the printout, verified
|
||||
purely additive (no listed field moved), kTableAbi 24.
|
||||
|
||||
### cont.26 (2026-10-22) — cont.25 REVERSED: the gatefix container is TILE-SCRAMBLED GARBAGE; the original row-swap was load-bearing after all; the fried look is still OPEN
|
||||
The user opened the cmp45 mp4s in VLC: both gatefix renders — INCLUDING the pinned FL2VA
|
||||
frame-0 — are a full-frame grid of ~16px colour tiles, whole video. Aggregate metrics (luma
|
||||
81, clipHi 0.1%, sat) were perfectly normal on scrambled pixels: the exact failure mode
|
||||
memory warned about ("judge on actual frames, not luma/clip numbers"). cont.25's "device-
|
||||
verified, fried look gone" was never looked at by eye — RETRACTED.
|
||||
|
||||
**Decisive control (task #64).** Old container `minimax-h3-dasiwa-w8a8.rad` served on the
|
||||
CURRENT binary (`serve_old.sh`, port 8135): T2VA and FL2VA both render COHERENT video
|
||||
(`cmp45/OLD_t2va512.mp4`, `OLD_fl2va512.mp4`; frames read: f0 standing pose, mid, f157 =
|
||||
exact fire-breath endpoint — pins force, spatial structure intact, fried/bright look
|
||||
present). The binary since `e28cf86` is exonerated for the scramble; the gatefix CONTAINER
|
||||
is the cause.
|
||||
|
||||
**The half order, settled from the ckpt's own library — cont.25's error.** The source
|
||||
tensor is `ff.net.0.proj` = diffusers' `SwiGLU` (`diffusers/models/activations.py`, verified
|
||||
in the installed 0.36 tree; `transformer_minimax_h3.py` and `autoencoder_kl_minimax_h3.py`
|
||||
both build FFNs from `..attention.FeedForward` with this activation):
|
||||
`hidden, gate = proj(x).chunk(2, -1); return hidden * silu(gate)` — **value FIRST, gate
|
||||
SECOND**, transformer AND VAE. `silu_mul`/`gated_quant_fp8` gate with the FIRST half ⇒ the
|
||||
convert MUST swap. The original three `map_rows` sites did exactly that; `77ef8f0`'s
|
||||
identity maps made every DiT/refiner/VAE FFN compute `silu(value)*gate` ⇒ global FFN
|
||||
garbage ⇒ tile-scrambled latents (and they explain the pinned frame-0: the scramble comes
|
||||
from the DiT's velocity stream and the decoder FFNs both being mis-paired). comfy's
|
||||
`_swiglu_eager` (gate-first) is NOT an anchor — how comfy's loader maps `ff.net.0.proj`
|
||||
into its `mlp.fc1` was never located (no remap found in comfy's tree), and every harness
|
||||
number quoted in cont.25 — the "cos 0.49 vs 0.999989" dn windows, the velocity cos 0.9886 /
|
||||
ratio 1.071 — came from a CPU reference that reads CONTAINER rows through gate-first
|
||||
chunking: self-consistent with whichever container was served, circular, unable to
|
||||
adjudicate. Only the ckpt convention + real pixels can. (cont.25's "the checkpoint stores
|
||||
the gate half first" was an assertion, not a measurement; `verify_gatefix_bytes.py`'s
|
||||
"identity relFro 1.7e-3" only proves the new rows EQUAL the ckpt rows — which is exactly
|
||||
the wrong thing to prove for a value-first tensor.)
|
||||
|
||||
**Revert.** The three map_rows sites are back to the swap (`{fsrc, ff, ff}, {fsrc, 0, ff}`
|
||||
× weight/bias), with a proof comment at the DiT site; the cont.25 shadows/driver readback,
|
||||
the arity fix and the ABI table stay. The GOOD container remains
|
||||
`minimax-h3-dasiwa-w8a8.rad`; `minimax-h3-dasiwa-w8a8-gatefix.rad` is kept only as the
|
||||
documented bad artifact. The fried look is NOT an FFN half-order issue and stays OPEN
|
||||
(#54/#45): the coherent-but-bright OLD_* renders are the standing artifact to explain.
|
||||
Reference in new issue
Block a user