149: io prefetch scheduling, RAM_ADAPT2, cold-read overlap and zero-copy GGUF experts (all opt-in)

- STRATA_IO_PF_SCHED=1 (with STRATA_IO_PREFETCH=1): confidence-scored read-ahead from the router
  lookahead, per-window speculative byte budget, deadlines (late jobs dropped), useful-share feedback;
  new per-request counters (read ahead MB, used before demand, late, not admitted).
- STRATA_RAM_ADAPT2=1 (with STRATA_RAM_ADAPT=n): RAM-tier promotions ranked by expected stall saved per
  byte (drive vs page cache), read on the source's I/O thread, installed at window boundaries; the
  prompt's routing seeds it with a limited weight (Prefill::on_routes).
- STRATA_COLD_OVERLAP: 1 reads a layer's staged blobs in the background while the pool computes the
  ready experts, each landed group computed as it lands; 2 measures R / C_r / C_c per layer; 3 adds
  zero-copy and 4 is zero-copy alone: an expert the page cache holds whole (GGUF in place, Linux mincore)
  is computed from the mapping through a per-job NativeFmt (ExpertJobMulti::fmt) instead of being
  assembled into a stage buffer. Same bytes, same rows, same bits.

Default (all unset) is the old code path: identity gates vs b829a3189 IDENTICAL (Q2_0 and IQ3_S,
fixed flags, 10/10 + exact_pp 4K/20K); mode 3 with --mmap-experts also 10/10 + 4K/20K IDENTICAL.
This commit is contained in:
Niko1221 committed 2026-10-18 05:06:29 +02:00
1 parent b829a3189d
commit c85cc6dd19
7 files changed
+831 -37

No files matched your search

+9 -8
View File
@@ -714,32 +714,33 @@ void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) {
const int e = (int) (r / per), r0 = (int) (r % per);
const int r1 = (int) std::min<int64_t>(per, r0 + (g1 - r));
SplitBufMulti& sb = split_multi_[(size_t) e];
if (mode_ == 5 && q2_native_kernels(nfmt_->gu_type)) {
const NativeFmt* const nfmt = mjobs_[e].fmt != nullptr ? mjobs_[e].fmt : nfmt_; // 149-cold: same types and rows
if (mode_ == 5 && q2_native_kernels(nfmt->gu_type)) {
// a native Q2_0 pack: gate and up rows on the Q2_0 kernels, then SwiGLU
thread_local float gbuf[MAXT][FF], ubuf[MAXT][FF];
float* gp[MAXT];
float* up[MAXT];
for (int t = 0; t < mjobs_[e].nt; ++t) { gp[t] = gbuf[t]; up[t] = ubuf[t]; }
const int nbk = (int) (nfmt_->n_embd / 64);
q2_rows_any(mjobs_[e].blob, nfmt_->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, gp, r0, r1);
q2_rows_any(mjobs_[e].blob + nfmt_->up_off, nfmt_->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, up, r0, r1);
const int nbk = (int) (nfmt->n_embd / 64);
q2_rows_any(mjobs_[e].blob, nfmt->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, gp, r0, r1);
q2_rows_any(mjobs_[e].blob + nfmt->up_off, nfmt->gu_row, nbk, mjobs_[e].act, mjobs_[e].nt, up, r0, r1);
for (int t = 0; t < mjobs_[e].nt; ++t)
for (int r = r0; r < r1; ++r)
sb.ff[t][r] = (gbuf[t][r] / (1.f + std::exp(-gbuf[t][r]))) * ubuf[t][r];
} else if (mode_ == 5) {
float* ff[MAXT];
for (int t = 0; t < mjobs_[e].nt; ++t) ff[t] = sb.ff[t];
native_gu_rows(*nfmt_, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1);
} else if (q2_native_kernels(nfmt_->d_type)) {
native_gu_rows(*nfmt, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1);
} else if (q2_native_kernels(nfmt->d_type)) {
// Q2_0 down (most IQ layers): the AVX-512 kernel, ggml-cpu has only a scalar one on x86
const ActQ* a2[MAXT];
for (int t = 0; t < mjobs_[e].nt; ++t) a2[t] = &sb.a2[t];
q2_rows_any(mjobs_[e].blob + nfmt_->down_off, nfmt_->d_row, (int) (nfmt_->n_ff / 64), a2,
q2_rows_any(mjobs_[e].blob + nfmt->down_off, nfmt->d_row, (int) (nfmt->n_ff / 64), a2,
mjobs_[e].nt, mjobs_[e].out, r0, r1);
} else {
const void* hq[MAXT];
for (int t = 0; t < mjobs_[e].nt; ++t) hq[t] = sb.hq[t];
native_down_rows(*nfmt_, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1);
native_down_rows(*nfmt, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1);
}
r += r1 - r0;
}