pool: the native-pack rows at the layer's widths, not the canonical FF / H; the served model's name from its file

Every verify window with an expert miss computed on the CPU decoded to
token 0 ("!!!!") on both Qwen3.6 files: the first serve of the Q4_K_XL
pack at 262,144 context (9,980 of 10,240 experts resident) and IQ3_XXS
under any --vram-cap.  Found by elimination on the 4090: all-resident runs
were correct at every context and KV format, --pcie-frac 1.0 (misses by
DMA, computed on the GPU) was correct, --pcie-frac 0 (misses on the CPU)
was wrong with ggml's plain dot products, with one pool worker and on the
IQ3 file alike.

ExpertPool::run_split_multi_native split its gate/up and down phases over
FF (640) and H (2560) rows per expert, the canonical Q2_0 pack's widths
compiled into expert.hpp, while a native layer's NativeFmt carries its own
n_ff / n_embd (512 / 2048 here): the down phase wrote 512 rows past every
output row into the next token's, the gate/up phase read 128 rows past
each expert's block.  The phases now take the layer's widths; native_fmt
refuses a layer wider than the pool's SplitBufMulti buffers (H x FF).

tests/core/pool_native_widths_test: three Q8_0 experts at 2048 x 512, four
tokens, the pool's rows against the kernels called directly, bitwise
equal, and a guard after every output row.  It fails on the old row
counts (the guard) and passes now.  After the fix on VM 221: Q4 at 8K with
forced CPU misses 328 tok/s correct, Q4 at 262,144 by default 322 tok/s
correct, IQ3 at 262,144 under --vram-cap 11264 (5,762 slots, 56%) correct
at 169 tok/s; the Qwen3.6 and native-expert ctest subset 32 of 32.

The front end reported every model as "qwen3.8-flash-next-iq3_xxs"; the
id is now the GGUF's base name without a shard suffix.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tPVMg2wGSNR1KANEiUtwr
This commit is contained in:
Robert KarlandClaude Fable 5.1 committed 2026-10-12 19:42:41 -07:00
1 parent 3a806b5af2
commit 22d72e69e7
5 files changed
+158 -9

No files matched your search

+5
View File
@@ -475,6 +475,11 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
target_link_libraries(expert_layout_test PRIVATE strata_engine) target_link_libraries(expert_layout_test PRIVATE strata_engine)
add_test(NAME expert_layout_test COMMAND expert_layout_test ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/native_experts) add_test(NAME expert_layout_test COMMAND expert_layout_test ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/native_experts)
set_tests_properties(expert_layout_test PROPERTIES TIMEOUT 60) set_tests_properties(expert_layout_test PROPERTIES TIMEOUT 60)
# the pool's native-pack rows at the layer's widths (Qwen3.6's 2048 x 512), not the canonical FF / H
add_executable(pool_native_widths_test tests/core/pool_native_widths_test.cpp)
target_link_libraries(pool_native_widths_test PRIVATE strata_engine)
add_test(NAME pool_native_widths_test COMMAND pool_native_widths_test)
set_tests_properties(pool_native_widths_test PROPERTIES TIMEOUT 120)
# #326: a native pack's BF16 (--compat-bf16) PLE key stays in the arena; a quantized key row loads as before # #326: a native pack's BF16 (--compat-bf16) PLE key stays in the arena; a quantized key row loads as before
add_executable(native_dense_ple_key_test tests/core/native_dense_ple_key_test.cpp) add_executable(native_dense_ple_key_test tests/core/native_dense_ple_key_test.cpp)
target_link_libraries(native_dense_ple_key_test PRIVATE strata_engine) target_link_libraries(native_dense_ple_key_test PRIVATE strata_engine)
+14 -4
View File
@@ -39,7 +39,16 @@ int strata_engine_main(int argc, char** argv);
namespace { namespace {
const char* const kModelName = "qwen3.8-flash-next-iq3_xxs"; // the model id reported on /v1/models and in every completion: the GGUF's base name (`Qwen3.6-35B-A3B-UD-IQ3_XXS`,
// `Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS` for shard 1 without its `-00001-of-00002`), set once the options are parsed
std::string g_model_name = "unbiased-strata";
std::string model_name_of(const std::string& path) {
std::string b = path.substr(path.find_last_of('/') == std::string::npos ? 0 : path.find_last_of('/') + 1);
if (b.size() > 5 && b.compare(b.size() - 5, 5, ".gguf") == 0) b.resize(b.size() - 5);
const size_t at = b.rfind("-00001-of-");
if (at != std::string::npos) b.resize(at);
return b.empty() ? std::string("unbiased-strata") : b;
}
struct Options { struct Options {
std::string model; // shard 1 of the GGUF std::string model; // shard 1 of the GGUF
@@ -443,7 +452,7 @@ struct Server {
out["id"] = id; out["id"] = id;
out["object"] = "chat.completion"; out["object"] = "chat.completion";
out["created"] = created; out["created"] = created;
out["model"] = kModelName; out["model"] = g_model_name;
out["choices"] = common_json::array(); out["choices"] = common_json::array();
out["choices"].push_back(choice); out["choices"].push_back(choice);
out["usage"] = usage_json(r); out["usage"] = usage_json(r);
@@ -464,7 +473,7 @@ struct Server {
out["id"] = id; out["id"] = id;
out["object"] = "chat.completion.chunk"; out["object"] = "chat.completion.chunk";
out["created"] = created; out["created"] = created;
out["model"] = kModelName; out["model"] = g_model_name;
out["choices"] = common_json::array(); out["choices"] = common_json::array();
out["choices"].push_back(choice); out["choices"].push_back(choice);
if (done) { out["usage"] = usage_json(*done); out["timings"] = timings_json(*done); } if (done) { out["usage"] = usage_json(*done); out["timings"] = timings_json(*done); }
@@ -606,6 +615,7 @@ int main(int argc, char** argv) {
Server srv; Server srv;
Options& o = srv.opt; Options& o = srv.opt;
if (!parse_args(argc, argv, o)) { usage(); return 2; } if (!parse_args(argc, argv, o)) { usage(); return 2; }
g_model_name = model_name_of(o.model);
// every file the engine needs must already be here: nothing is fetched // every file the engine needs must already be here: nothing is fetched
// Flash-Next ships as two shards and the second holds the PLE table, so it is the engine's --ple-gguf; a one-file // Flash-Next ships as two shards and the second holds the PLE table, so it is the engine's --ple-gguf; a one-file
@@ -716,7 +726,7 @@ int main(int argc, char** argv) {
http.Get("/v1/models", [&](const httplib::Request&, httplib::Response& res) { http.Get("/v1/models", [&](const httplib::Request&, httplib::Response& res) {
if (!srv.engine.alive()) return json_error(res, 503, "the engine is not running", "server_error"); if (!srv.engine.alive()) return json_error(res, 503, "the engine is not running", "server_error");
common_json m = common_json::object(); common_json m = common_json::object();
m["id"] = kModelName; m["id"] = g_model_name;
m["object"] = "model"; m["object"] = "model";
m["owned_by"] = "local"; m["owned_by"] = "local";
m["context_length"] = srv.opt.ctx; m["context_length"] = srv.opt.ctx;
+5
View File
@@ -43,6 +43,11 @@ bool native_fmt(int gu_type, int d_type, int64_t n_embd, int64_t n_ff, NativeFmt
err = "native experts: ggml-cpu cannot quantize an activation for this layer"; err = "native experts: ggml-cpu cannot quantize an activation for this layer";
return false; return false;
} }
if (n_embd <= 0 || n_ff <= 0 || n_embd > H || n_ff > FF) { // the pool's SplitBufMulti rows are FF / H wide
err = "native experts: expert geometry " + std::to_string(n_embd) + " x " + std::to_string(n_ff) +
" exceeds the pool's buffers (" + std::to_string(H) + " x " + std::to_string(FF) + ")";
return false;
}
if (n_embd % ggml_blck_size((ggml_type) gu_type) || n_ff % ggml_blck_size((ggml_type) d_type) || if (n_embd % ggml_blck_size((ggml_type) gu_type) || n_ff % ggml_blck_size((ggml_type) d_type) ||
n_embd % ggml_blck_size(tg->vec_dot_type) || n_ff % ggml_blck_size(td->vec_dot_type)) { n_embd % ggml_blck_size(tg->vec_dot_type) || n_ff % ggml_blck_size(td->vec_dot_type)) {
err = "native experts: expert geometry is not whole blocks"; err = "native experts: expert geometry is not whole blocks";
+9 -5
View File
@@ -559,8 +559,12 @@ void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) {
const int r0 = H * part / parts_b_, r1 = H * (part + 1) / parts_b_; const int r0 = H * part / parts_b_, r1 = H * (part + 1) / parts_b_;
s2_expert_down_rows(jobs_[e].blob, split_[(size_t) e].a2, jobs_[e].out, r0, r1); s2_expert_down_rows(jobs_[e].blob, split_[(size_t) e].a2, jobs_[e].out, r0, r1);
} else if (mode_ >= 5) { } else if (mode_ >= 5) {
// plan v0.3 P6: native layers, 5 = gate/up rows, 6 = down rows // plan v0.3 P6: native layers, 5 = gate/up rows, 6 = down rows. The widths are the layer's own
const int per = mode_ == 5 ? FF : H; // (NativeFmt n_ff / n_embd: 512 / 2048 for Qwen3.6-35B-A3B), not the canonical pack's FF / H: with
// those, the down phase wrote H - n_embd rows past every output row and the gate/up phase read
// FF - n_ff rows past every expert's gate/up block, and every verify window with a CPU-computed
// expert miss decoded to token 0.
const int per = mode_ == 5 ? (int) nfmt_->n_ff : (int) nfmt_->n_embd;
const int64_t g0 = mrows_ * (int64_t) i / mtasks_, g1 = mrows_ * (int64_t) (i + 1) / mtasks_; const int64_t g0 = mrows_ * (int64_t) i / mtasks_, g1 = mrows_ * (int64_t) (i + 1) / mtasks_;
for (int64_t r = g0; r < g1;) { for (int64_t r = g0; r < g1;) {
const int e = (int) (r / per), r0 = (int) (r % per); const int e = (int) (r / per), r0 = (int) (r % per);
@@ -696,16 +700,16 @@ void ExpertPool::run_split_multi_native(const NativeFmt& f, ExpertJobMulti* jobs
nfmt_ = &f; nfmt_ = &f;
const int threads = n_ + (host_works_ ? 1 : 0); const int threads = n_ + (host_works_ ? 1 : 0);
mtasks_ = 3 * threads; mtasks_ = 3 * threads;
mrows_ = (int64_t) nb * FF; mrows_ = (int64_t) nb * f.n_ff; // the layer's widths (see run_phase mode 5 / 6), not FF / H
const auto a = std::chrono::steady_clock::now(); const auto a = std::chrono::steady_clock::now();
run_phase(5, mtasks_); run_phase(5, mtasks_);
const auto b = std::chrono::steady_clock::now(); const auto b = std::chrono::steady_clock::now();
for (int e = 0; e < nb; ++e) for (int e = 0; e < nb; ++e)
for (int t = 0; t < mjobs_[e].nt; ++t) for (int t = 0; t < mjobs_[e].nt; ++t)
if (q2_native_kernels(f.d_type)) act_quant_any(split_multi_[(size_t) e].ff[t], FF, split_multi_[(size_t) e].a2[t]); if (q2_native_kernels(f.d_type)) act_quant_any(split_multi_[(size_t) e].ff[t], (int) f.n_ff, split_multi_[(size_t) e].a2[t]);
else native_quant_h(f, split_multi_[(size_t) e].ff[t], split_multi_[(size_t) e].hq[t]); else native_quant_h(f, split_multi_[(size_t) e].ff[t], split_multi_[(size_t) e].hq[t]);
const auto c = std::chrono::steady_clock::now(); const auto c = std::chrono::steady_clock::now();
mrows_ = (int64_t) nb * H; mrows_ = (int64_t) nb * f.n_embd;
run_phase(6, mtasks_); run_phase(6, mtasks_);
const auto d = std::chrono::steady_clock::now(); const auto d = std::chrono::steady_clock::now();
ms_multi_gu += std::chrono::duration<double, std::milli>(b - a).count(); ms_multi_gu += std::chrono::duration<double, std::milli>(b - a).count();
+125
View File
@@ -0,0 +1,125 @@
// The expert pool's native-pack path (run_split_multi_native: gate/up rows, the intermediate's quantization, down
// rows, each split across the workers) must use the LAYER'S widths, NativeFmt::n_ff and n_embd, not the canonical
// Q2_0 pack's FF / H (640 / 2560). Qwen3.6-35B-A3B's experts are 2048 x 512: with FF / H the down phase wrote 512
// rows past every output row and the first verify window with a CPU-computed expert miss decoded to token 0.
//
// Three Q8_0 experts at 2048 x 512, four tokens; the pool's rows against the same kernels called directly, and a
// guard after every output row that must stay untouched.
#include "strata/kernels/cpu/native_expert.hpp"
#include "strata/kernels/cpu/pool.hpp"
#include "ggml.h"
#include <cmath>
#include <cstdio>
#include <cstring>
#include <random>
#include <string>
#include <vector>
using namespace strata::kernels::cpu;
namespace {
int g_fail = 0;
void check(bool ok, const std::string& what) {
std::printf(" %-90s %s\n", what.c_str(), ok ? "ok" : "FAIL");
if (!ok) ++g_fail;
}
} // namespace
int main() {
const int64_t n_embd = 2048, n_ff = 512; // Qwen3.6-35B-A3B's expert geometry
const int kType = (int) GGML_TYPE_Q8_0;
NativeFmt f;
std::string err;
if (!native_fmt(kType, kType, n_embd, n_ff, f, err)) { std::printf("native_fmt: %s\n", err.c_str()); return 1; }
check(f.n_embd == n_embd && f.n_ff == n_ff, "the format carries the layer's widths 2048 x 512");
check(n_embd < H && n_ff < FF, "the layer is narrower than the canonical FF / H, so the old row counts overran");
NativeFmt wide;
const bool wide_ok = native_fmt(kType, kType, H + 64, n_ff, wide, err);
check(!wide_ok, "a layer wider than the pool's buffers is refused: " + err);
const int E = 3, T = 4;
std::mt19937 rng(7);
std::normal_distribution<float> nd(0.f, 0.5f);
std::vector<std::vector<uint8_t>> blobs((size_t) E);
std::vector<float> row((size_t) std::max(n_embd, n_ff));
for (int e = 0; e < E; ++e) {
auto& b = blobs[(size_t) e];
b.assign(f.bytes, 0);
for (int part = 0; part < 3; ++part) { // gate, up: n_ff rows of n_embd; down: n_embd rows of n_ff
const int64_t rows = part < 2 ? n_ff : n_embd, cols = part < 2 ? n_embd : n_ff;
std::vector<float> m((size_t) (rows * cols));
for (float& v : m) v = nd(rng);
uint8_t* dst = b.data() + (part == 0 ? 0 : part == 1 ? f.up_off : f.down_off);
ggml_quantize_chunk((ggml_type) kType, m.data(), dst, 0, rows, cols, nullptr);
}
}
std::vector<std::vector<float>> x((size_t) T, std::vector<float>((size_t) n_embd));
std::vector<std::vector<uint8_t>> act((size_t) T, std::vector<uint8_t>(kNativeActBytes));
for (int t = 0; t < T; ++t) {
for (float& v : x[(size_t) t]) v = nd(rng);
native_quant_act(f, x[(size_t) t].data(), act[(size_t) t].data());
}
// token -> expert: tokens 0,1 on expert 0; token 2 on expert 1; token 3 on expert 2 (then 1 again: two experts)
const int routes[][2] = {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {3, 1}};
const int R = 5;
// the reference: the kernels directly, one expert at a time, over exactly the layer's rows
std::vector<std::vector<float>> ref((size_t) R, std::vector<float>((size_t) n_embd));
for (int e = 0; e < E; ++e) {
const void* nact[MAXT] = {};
float* ffp[MAXT] = {};
const void* hq[MAXT] = {};
float* out[MAXT] = {};
std::vector<std::vector<float>> ff;
std::vector<std::vector<uint8_t>> h;
int nt = 0;
for (int r = 0; r < R; ++r)
if (routes[r][1] == e) {
ff.emplace_back((size_t) n_ff);
h.emplace_back(kNativeHBytes);
++nt;
}
int i = 0;
for (int r = 0; r < R; ++r)
if (routes[r][1] == e) {
nact[i] = act[(size_t) routes[r][0]].data();
ffp[i] = ff[(size_t) i].data();
hq[i] = h[(size_t) i].data();
out[i] = ref[(size_t) r].data();
++i;
}
native_gu_rows(f, blobs[(size_t) e].data(), nact, nt, ffp, 0, (int) n_ff);
for (int k = 0; k < nt; ++k) native_quant_h(f, ffp[k], h[(size_t) k].data());
native_down_rows(f, blobs[(size_t) e].data(), hq, nt, out, 0, (int) n_embd);
}
// the pool: every output row followed by a guard of H floats (the old overrun was H - n_embd rows)
const int64_t guard = H, pitch = n_embd + guard;
const float sentinel = 1234.5f;
std::vector<float> outbuf((size_t) (R * pitch), sentinel);
ExpertJobMulti jobs[E];
for (int e = 0; e < E; ++e) jobs[e].blob = blobs[(size_t) e].data();
for (int r = 0; r < R; ++r) {
ExpertJobMulti& j = jobs[routes[r][1]];
j.nact[j.nt] = act[(size_t) routes[r][0]].data();
j.out[j.nt] = outbuf.data() + (size_t) r * pitch;
++j.nt;
}
ExpertPool pool(2, false, true);
pool.run_split_multi_native(f, jobs, E);
double worst = 0;
bool guards = true;
for (int r = 0; r < R; ++r) {
const float* got = outbuf.data() + (size_t) r * pitch;
for (int64_t i = 0; i < n_embd; ++i)
worst = std::max(worst, (double) std::fabs(got[i] - ref[(size_t) r][(size_t) i]));
for (int64_t i = n_embd; i < pitch; ++i)
if (got[i] != sentinel) { guards = false; break; }
}
check(guards, "no output row's guard was written (the down phase stopped at n_embd rows)");
check(worst <= 1e-5, "the pool's rows equal the kernels' direct rows (worst abs diff " + std::to_string(worst) + ")");
std::printf("%s: %d failure(s)\n", g_fail == 0 ? "PASS" : "FAIL", g_fail);
return g_fail == 0 ? 0 : 1;
}