| 5347 | } |
| 5348 | |
| 5349 | void expert_pool_dispatch(void* user, const float* x_f, const int32_t* ids, const float* weights, int64_t n_embd, |
| 5350 | int64_t k, float* out) { |
| 5351 | (void) weights; // clause 2: `moe_combine` applies it on the device. Not an oversight. |
| 5352 | ExpertDispatch& d = *(ExpertDispatch*) user; |
| 5353 | if (d.failed) return; // a previous layer already failed; do not make it worse |
| 5354 | |
| 5355 | using namespace strata::kernels::cpu; |
| 5356 | // Clause 3: the blob's internal offsets are compile-time constants, so a mismatched geometry does not |
| 5357 | // produce a wrong answer - it produces a walk off the end of the blob into the next expert's bytes, which |
| 5358 | // is finite and plausible. Refuse, name the number, and let the driver report it. |
| 5359 | if (n_embd != H) { |
| 5360 | d.failed = true; |
| 5361 | d.fail = "the expert kernel is compiled for a 2560-wide activation"; |
| 5362 | d.fail_layer = d.layers; |
| 5363 | return; |
| 5364 | } |
| 5365 | if (expert_layout().native) { |
| 5366 | // plan v0.3 P6: a native pack runs its experts in verify windows only (the driver guarantees it) |
| 5367 | d.failed = true; |
| 5368 | d.fail = "the single-token expert path does not take a native (IQ) pack"; |
| 5369 | d.fail_layer = d.layers; |
| 5370 | return; |
| 5371 | } |
| 5372 | if (k > (int64_t) d.jobs.size()) d.jobs.resize((size_t) k); |
| 5373 | |
| 5374 | d.src->begin_layer(d.layers, ids, k); |
| 5375 | |
| 5376 | // Clause 1: rebuilt from `x_f` on EVERY call. `x_f` is mapped pinned memory whose address never changes, |
| 5377 | // so anything cached against it would be layer 0's activation reused 48 times. |
| 5378 | act_quant_q8_1(x_f, H, d.act); |
| 5379 | |
| 5380 | // ---- R4.2c: THE POOL'S HALF OF THE SPLIT. **IT DOES NOT DECIDE ANYTHING - `Launch` ALREADY DID.** |
| 5381 | // |
| 5382 | // The decision has to be made on THIS layer's ids, and `Launch` is the only callback that runs before the |
| 5383 | // pool while the ids are known (the doorbell publishes them when the ring fires). So `expert_hit_run` |
| 5384 | // decides, and this consumes `d.is_hit`. The first version decided here instead, which meant `Launch` |
| 5385 | // computed the PREVIOUS layer's experts into this layer's rows: C1 went from mean KL 9.69e-02 to 1.03e+00. |
| 5386 | // |
| 5387 | // `njobs` indexes the JOB ARRAY and `i` indexes the OUTPUT - they are the same only when nothing is a hit. |
| 5388 | const bool graph_hits = d.host_res != nullptr; |
| 5389 | const bool use_hits = graph_hits || (d.hits_ready() && d.decided); |
| 5390 | int64_t njobs = 0; |
| 5391 | |
| 5392 | if (d.remote_count > 0) { |
| 5393 | int32_t kind[32]; |
| 5394 | if (k > 32) { |
| 5395 | d.failed = true; d.fail = "remote experts: routing width exceeds 32"; return; |
| 5396 | } |
| 5397 | for (int64_t i = 0; i < k; ++i) |
| 5398 | kind[i] = use_hits && ids[i] >= 0 && ids[i] < d.n_expert && (graph_hits |
| 5399 | ? d.host_res[(size_t) d.layers * (size_t) d.n_expert + (size_t) ids[i]] >= 0 |
| 5400 | : d.is_hit[(size_t) i] != 0) ? 0 : -1; |
| 5401 | static thread_local std::string remote_error; |
| 5402 | for (int r = 0; r < d.remote_count; ++r) |
| 5403 | if (!d.remote[r]->begin(d.layers, x_f, ids, 1, k, kind, d.host_res, remote_error)) { |
| 5404 | d.failed = true; d.fail = remote_error.c_str(); d.fail_layer = d.layers; return; |
| 5405 | } |
| 5406 | } |
nothing calls this directly
no test coverage detected