From dd32704d4d7652ab4816362b6d3ebb2b594ccc7a Mon Sep 17 00:00:00 2001 From: Laurent Zuijdwijk Date: Mon, 5 Oct 2026 12:42:06 +0100 Subject: [PATCH] prefill: look up the APR sign vectors at the layout's widths, not 640 / N run_impl asked hadamard_device_signs for the down projection's signs at a literal 640 (and gate/up's at N), while carve and the peer path resolve them at lay.fmt[l].n_ff / n_embd. The widths are part of the device copy's key, so the two only shared an entry because the widths happen to match. All lookups now use the layout's widths. The other 640s next to the rotations are the row width of the prompt path's expert buffers and products (swiglu, quantize, GEMM), fixed for this model like N; Prefill::init now refuses a native layout whose experts are not N x 640 instead of assuming it. No other sign or rotation width in the tree is hardcoded (verify, peer and remote experts use the geometry). Ported from agentionai/Strata rc2 ff463c8 (rc2 = 9ff02c9), author Laurent Zuijdwijk. --- src/prefill/prefill.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 881d1c88..ddd7288a 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -1232,6 +1232,16 @@ bool Prefill::init(const core::WeightTable& wt, const core::ModelGeometry& g, co if (g.n_embd != N || g.hc != HC || g.hc_lr != LR || g.n_expert < 1 || ss.k != K) { err = "prefill: geometry differs from the artifact's"; return false; } + { // a native pack's experts: this path's expert buffers and products (and so their Hadamard rotations) are + // N wide in and 640 wide in the middle; the sign vectors are looked up at the layout's own widths + const strata::kernels::cpu::ExpertLayout& lay = strata::kernels::cpu::expert_layout(); + for (size_t l = 0; lay.native && l < lay.fmt.size(); ++l) + if (lay.fmt[l].n_embd != N || lay.fmt[l].n_ff != 640) { + err = "prefill: layer " + std::to_string(l) + "'s experts are " + std::to_string(lay.fmt[l].n_embd) + + " x " + std::to_string(lay.fmt[l].n_ff) + ", not the artifact's 2560 x 640"; + return false; + } + } cudaGetDevice(&m.device); if (stage_le_ < 0) stage_le_ = g.n_layers; if (stage_lb_ < 0 || stage_lb_ >= stage_le_ || stage_le_ > g.n_layers || (stage_le_ < g.n_layers) != (next_ != nullptr)) { @@ -3240,8 +3250,8 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri const bool had_d = lay.native && lay.fmt[(size_t) l].had_d; const bool use_mmq = mmq_plan().any && mmq_plan().layer[(size_t) l]; const int had_block = lay.native ? lay.fmt[(size_t) l].had_block : 0; - const float* had_sx = had_gu ? strata::kernels::hadamard_device_signs(lay.fmt[(size_t) l].gu_signs, N) : nullptr; - const float* had_sh = had_d ? strata::kernels::hadamard_device_signs(lay.fmt[(size_t) l].d_signs, 640) : nullptr; + const float* had_sx = had_gu ? strata::kernels::hadamard_device_signs(lay.fmt[(size_t) l].gu_signs, (int) lay.fmt[(size_t) l].n_embd) : nullptr; + const float* had_sh = had_d ? strata::kernels::hadamard_device_signs(lay.fmt[(size_t) l].d_signs, (int) lay.fmt[(size_t) l].n_ff) : nullptr; const int mmq_gt = lay.native ? lay.fmt[(size_t) l].gu_type : 42; const int mmq_dt = lay.native ? lay.fmt[(size_t) l].d_type : 42; // --peer-device: MMQ only, whether or not the peer took the prompt path (set_peer can decline), as