| 1350 | } |
| 1351 | |
| 1352 | void ExpertPool::native_rows(int e, int r0, int r1) { |
| 1353 | // the native row phases' work for expert `e` of the batch, rows [r0, r1) of its gate/up (mode 5) or down (mode 6) |
| 1354 | SplitBufMulti& sb = split_multi_[(size_t) e]; |
| 1355 | const NativeFmt* const nfmt = mjobs_[e].fmt != nullptr ? mjobs_[e].fmt : nfmt_; // 149-cold: same types and rows |
| 1356 | if (mode_ == 5 && q2_native_kernels(nfmt->gu_type)) { |
| 1357 | // a native Q2_0 pack: gate and up rows on the Q2_0 kernels, then SwiGLU |
| 1358 | thread_local float gbuf[MAXT][FF], ubuf[MAXT][FF]; |
| 1359 | float* gp[MAXT]; |
| 1360 | float* up[MAXT]; |
| 1361 | for (int t = 0; t < mjobs_[e].nt; ++t) { gp[t] = gbuf[t]; up[t] = ubuf[t]; } |
| 1362 | const int nbk = (int) (nfmt->n_embd / 64); |
| 1363 | q2_rows_any(mjobs_[e].blob, nfmt->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, gp, r0, r1); |
| 1364 | q2_rows_any(mjobs_[e].blob + nfmt->up_off, nfmt->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, up, r0, r1); |
| 1365 | for (int t = 0; t < mjobs_[e].nt; ++t) |
| 1366 | for (int r = r0; r < r1; ++r) |
| 1367 | sb.ff[t][r] = (gbuf[t][r] / (1.f + std::exp(-gbuf[t][r]))) * ubuf[t][r]; |
| 1368 | } else if (mode_ == 5) { |
| 1369 | float* ff[MAXT]; |
| 1370 | for (int t = 0; t < mjobs_[e].nt; ++t) ff[t] = sb.ff[t]; |
| 1371 | if (narithmetic_ == NativeArithmetic::WindowInvariant) |
| 1372 | native_gu_rows_invariant(*nfmt, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1); |
| 1373 | else |
| 1374 | native_gu_rows(*nfmt, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1); |
| 1375 | } else if (q2_native_kernels(nfmt->d_type)) { |
| 1376 | // Q2_0 down (most IQ layers): the AVX-512 kernel, ggml-cpu has only a scalar one on x86 |
| 1377 | const ActQ* a2[MAXT]; |
| 1378 | for (int t = 0; t < mjobs_[e].nt; ++t) a2[t] = &sb.a2[t]; |
| 1379 | q2_rows_any(mjobs_[e].blob + nfmt->down_off, nfmt->d_row, (int) (nfmt->n_ff / 64), a2, |
| 1380 | mjobs_[e].nt, mjobs_[e].out, r0, r1); |
| 1381 | } else { |
| 1382 | const void* hq[MAXT]; |
| 1383 | for (int t = 0; t < mjobs_[e].nt; ++t) hq[t] = sb.hq[t]; |
| 1384 | if (narithmetic_ == NativeArithmetic::WindowInvariant) |
| 1385 | native_down_rows_invariant(*nfmt, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1); |
| 1386 | else |
| 1387 | native_down_rows(*nfmt, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) { |
| 1392 | if (per_worker_) { // task j on worker j, once per batch; the host has none (it never calls this for such a batch) |
nothing calls this directly
no test coverage detected