From ac14bacddf40c71fbc0ee89f116cef6615a9982e Mon Sep 17 00:00:00 2001 From: Robert Karl Date: Sun, 11 Oct 2026 11:24:01 -0700 Subject: [PATCH] [shared] ModelGeometry::gdn_gate() and the seven GDN output call sites pass it `ModelGeometry::gdn_gate()` is SiLU for qwen35moe and sigmoid for qwen4exp, decided by the architecture like `hc` and the indexer. layer.cpp's three output-norm calls and verify.cpp's four `gdn_step_norm_multi` calls pass it; nothing else in either file changes. The parameter is required (no default) so a call site the block agent rewrites cannot silently keep sigmoid for Qwen3.6. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_017tPVMg2wGSNR1KANEiUtwr --- include/strata/core/layout.hpp | 7 +++++++ src/core/layer.cpp | 10 +++++----- src/core/verify.cpp | 16 ++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/strata/core/layout.hpp b/include/strata/core/layout.hpp index 7030dd4..0273178 100644 --- a/include/strata/core/layout.hpp +++ b/include/strata/core/layout.hpp @@ -16,6 +16,7 @@ #pragma once #include "strata/core/weights.hpp" +#include "strata/kernels/gdn.hpp" #include #include @@ -83,6 +84,12 @@ struct ModelGeometry { int64_t n_gdn_layers() const { return n_layers - n_qsa_layers(); } /// Whether the full-attention layers carry the sparse indexer (QSA). Qwen3.6's attention is dense. bool has_indexer() const { return arch == ModelArch::Qwen4Exp; } + /// The GDN output gate: `rms_norm(o) * ssm_norm * act(z)` with act = sigmoid for Flash-Next and SiLU for Qwen3.6 + /// (geometry-inventory.md row 39; `kernels::GdnGate`). From the architecture, like `hc` and the indexer: no key + /// says it. Every GDN output kernel takes this value from the layer; none reads a global. + kernels::GdnGate gdn_gate() const { + return arch == ModelArch::Qwen35Moe ? kernels::GdnGate::Silu : kernels::GdnGate::Sigmoid; + } /// The members that follow from others: conv channels `2*S*k_heads + S*v_heads` and the value dim /// `S*v_heads`. They are stored (the kernels read them as plain members) and derived here, so a file that diff --git a/src/core/layer.cpp b/src/core/layer.cpp index 4853a9f..f438c61 100644 --- a/src/core/layer.cpp +++ b/src/core/layer.cpp @@ -314,15 +314,15 @@ st_begin(layer, 12, stream); st_end(layer, 13, stream); st_begin(layer, 14, stream); // ---- 6. the recurrence. q and k are the (16, 128) views; v is the (48, 128) view. The stage marks for // it live at the end of the alpha/beta/gate line above, because the gate and the step are one sequence. -// ---- 7. z, then y = rms_norm(o) * ssm_norm * sigmoid(z). SIGMOID, not SiLU. +// ---- 7. z, then y = rms_norm(o) * ssm_norm * act(z). SIGMOID for Flash-Next, SiLU for Qwen3.6: `g.gdn_gate()`. // qkv's native quantize of `mixed` is still in the shared q8_1 scratch: nothing native ran in between. if (!gemv_quantized(*w_gate, p_gate, f_gate, b.x_q8_0, b.x_q8k, b.z, g.n_embd, g.ssm_value_dim, v.name("attn_gate.weight"), stream, err, mixed, w_qkv->native_data != nullptr && w_gate->native_data != nullptr)) return false; try { - if (fused_gdn) fused_gdn_step_norm(b.state, b.h, b.h + qk, b.h + 2 * qk, b.gate, b.beta, b.z, ssm_norm, RMS_EPS, b.y, - (int) g.ssm_k_heads, (int) g.ssm_v_heads, stream); - else if (native_gdn_enabled()) native_gdn_out_norm(b.o, b.z, ssm_norm, b.y, g.ssm_v_heads, g.ssm_state_size, RMS_EPS, stream); - else gdn_out_norm(b.o, b.z, ssm_norm, b.y, g.ssm_v_heads, g.ssm_state_size, RMS_EPS, stream); + if (fused_gdn) fused_gdn_step_norm(b.state, b.h, b.h + qk, b.h + 2 * qk, b.gate, b.beta, b.z, ssm_norm, RMS_EPS, + g.gdn_gate(), b.y, (int) g.ssm_k_heads, (int) g.ssm_v_heads, stream); + else if (native_gdn_enabled()) native_gdn_out_norm(b.o, b.z, ssm_norm, b.y, g.ssm_v_heads, g.ssm_state_size, RMS_EPS, g.gdn_gate(), stream); + else gdn_out_norm(b.o, b.z, ssm_norm, b.y, g.ssm_v_heads, g.ssm_state_size, RMS_EPS, g.gdn_gate(), stream); } catch (const std::exception& error) { err = v.name("gdn_out_norm") + ": " + error.what(); return false; } st_end(layer, 14, stream); // ---- 8. out = ssm_out @ y, whose activation is whatever THIS layer's `ssm_out` asks for diff --git a/src/core/verify.cpp b/src/core/verify.cpp index 857ba97..6fac954 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -794,12 +794,12 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { SessionState& sx = slot_ss(t); float* stx = sx.gdn_state + (size_t) (gi - sx.gdn_ord0) * gdn_floats; gdn_step_norm_multi(stx, hb + (size_t) t * C, (int) C, gate + (size_t) t * HV, beta + (size_t) t * HV, - z_ + (size_t) t * ZV, (const float*) wnm->data, EPS, y_ + (size_t) t * ZV, - (int) HK, (int) HV, 1, nullptr, cs, 0); + z_ + (size_t) t * ZV, (const float*) wnm->data, EPS, g.gdn_gate(), + y_ + (size_t) t * ZV, (int) HK, (int) HV, 1, nullptr, cs, 0); } } else - gdn_step_norm_multi(state, hb, (int) C, gate, beta, z_, (const float*) wnm->data, EPS, y_, (int) HK, - (int) HV, te, nullptr, cs, tb); + gdn_step_norm_multi(state, hb, (int) C, gate, beta, z_, (const float*) wnm->data, EPS, g.gdn_gate(), y_, + (int) HK, (int) HV, te, nullptr, cs, tb); stamp(l, 6, grp); native_quantize_q8_1(y_ + (size_t) tb * ZV, xq_, (int) ZV, n, cs); native_mmvq(wout->native_type, wout->native_data, xq_, bo_ + tb * N, (int) ZV, (int) N, n, cs); @@ -1375,8 +1375,8 @@ bool Verifier::capture_commit(std::string& err) { const float* qkv = qkv_L_ + (size_t) gdn_index * MT * C; gdn_conv_commit(conv, qkv, (int) C, commit_, cs_); gdn_step_norm_multi(state, h_L_ + (size_t) gdn_index * MT * C, (int) C, gate_L_ + (size_t) gdn_index * MT * HV, - beta_L_ + (size_t) gdn_index * MT * HV, z_, (const float*) wnm->data, EPS, y_dummy_, - (int) g.ssm_k_heads, (int) HV, (int) MT, commit_, cs_, (int) MT); + beta_L_ + (size_t) gdn_index * MT * HV, z_, (const float*) wnm->data, EPS, g.gdn_gate(), + y_dummy_, (int) g.ssm_k_heads, (int) HV, (int) MT, commit_, cs_, (int) MT); ++gdn_index; } else { const QsaState& st = ss.qsa_states[qsa_index]; @@ -1928,8 +1928,8 @@ bool Verifier::capture_commit_batch(const int* rows, int S, int hbase, std::stri gdn_step_norm_multi(state, h_L_ + (size_t) gdn_index * MT * C + (size_t) t * C, (int) C, gate_L_ + (size_t) gdn_index * MT * HV + (size_t) t * HV, beta_L_ + (size_t) gdn_index * MT * HV + (size_t) t * HV, z_ + (size_t) t * ZV, - (const float*) wnm->data, EPS, y_dummy_ + (size_t) t * ZV, (int) g.ssm_k_heads, - (int) HV, 1, keep, cs_); + (const float*) wnm->data, EPS, g.gdn_gate(), y_dummy_ + (size_t) t * ZV, + (int) g.ssm_k_heads, (int) HV, 1, keep, cs_); } ++gdn_index; } else {