[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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017tPVMg2wGSNR1KANEiUtwr
This commit is contained in:
1 parent
5c6eb91ca8
commit
ac14bacddf
3 files changed
+20
-13
No files matched your search
@@ -16,6 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "strata/core/weights.hpp"
|
||||
#include "strata/kernels/gdn.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -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
|
||||
|
||||
+5
-5
@@ -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
|
||||
|
||||
+8
-8
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user