CS-T speed: the file tier fetched in parallel, PCIe planning without file reads, a partial pin of the RAM tier, bit-exact AVX2 multi-token kernels for Q4_K / Q5_1 / Q8_0 experts, decode-only tier stats

Where the 288 ms/token at a 40 GiB budget went (UD-Q4_K_XL, --stats): of the 945 ms CPU pool call per verify
round (3.46 tokens), 871 ms were the dispatch thread assembling missed experts from the mapped GGUF one after
another (~391 blobs, 1.3 GB per round, ~1.5 GB/s: page faults from the SSD); the kernels were 42 ms gate/up and
30 ms down.  At 24 GiB, 771 ms/round more went into the PCIe planning, which asked blob() - a file read with the
GGUF in place - of every miss just to learn it was not pinned.

- ExpertSource::prefetch: the dispatch hands the source the layer's missed experts before its jobs loop;
  FileExpertSource with the GGUF in place assembles them on STRATA_FETCH_THREADS threads (default 8) so the
  SSD sees a queue instead of one fault at a time.  A no-op for every other source.  Staging buffers being
  filled are never reused, and a blob asked while its fill runs waits for it.
- The PCIe planning asks pinned() before blob(): the same decisions and bytes for every source.
- --resident-budget-gib: when the driver refuses to page-lock the whole budget, the locked arena's hottest
  prefix (profile order) is registered with cudaHostRegister, as much as it takes (from the whole down in 2 GiB
  steps), so the GPU can read those misses over PCIe and the prompt path can DMA them; pinned() answers for
  that prefix only.  STRATA_PARTIAL_PIN=0 is the A/B arm.
- src/kernels/cpu/kq_avx2.cpp: ggml-cpu's AVX2 vec_dot for Q4_K x Q8_K, Q5_1 x Q8_1 and Q8_0 x Q8_0 with the
  token loop inside the block loop - the weight side decoded once per verify window, each token's integer chain
  and float operations exactly ggml's, so the results are ggml's to the bit for any group size (no #152 rule).
  native_gu_rows / native_down_rows use them for those types (only UD-Q4_K_XL has them); STRATA_NO_KQ256 is the
  A/B arm.  native_expert_parity checks them bit for bit against vec_dot for 1..8 tokens and times 4 tokens.
- Stats: the decode's file tier alone (blobs, MB, MB/round, reading ms/round and GB/s per thread) and the
  prompt path's copies separately.
This commit is contained in:
Niko1221 committed 2026-10-01 00:51:30 +02:00
1 parent 1e663cc70e
commit 003ec62140
9 files changed
+522 -28

No files matched your search

+15 -6
View File
@@ -2320,6 +2320,8 @@ int main(int argc, char** argv) {
// CS-T: a native pack without experts.bin maps the model's GGUF shards instead (native_experts.txt's spans,
// checked against the files first) - no 30-77 GB copy of the experts on the disk
src.set_gguf(o.native_preset);
if (const char* v = std::getenv("STRATA_FETCH_THREADS"); v != nullptr && std::atoi(v) > 0)
src.set_fetch_threads(std::atoi(v));
if (!src.open(o.pack, g.n_layers, g.n_expert, err)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;
@@ -5477,6 +5479,10 @@ int main(int argc, char** argv) {
if (drive.d.pcie_num < 0) drive.d.pcie_num = 0;
if (drive.d.pcie_num > 256) drive.d.pcie_num = 256;
const int64_t pcie0 = drive.d.pcie_experts;
// CS-T: the file tier since the decode began (the prompt path's copies are before this)
const int64_t files0 = src.file_reads(), ram0 = src.ram_reads();
const uint64_t fbytes0 = src.file_blob_bytes(), fall0 = src.file_read_bytes();
const double fms0 = src.file_ms();
if (o.adapt_every > 0 && o.adapt_swaps > 0) drive.d.usage.assign((size_t) (g.n_layers * g.n_expert), 0.0f);
int64_t swaps_total = 0;
double ms_adapt = 0;
@@ -5716,12 +5722,15 @@ int main(int argc, char** argv) {
std::printf("%-24s %.2f GiB of experts in RAM, %lld exchanged with the VRAM tier, %lld blob reads from "
"the file\n", "resident RAM", (double) src.resident_bytes() / 1073741824.0,
(long long) src.exchanges(), (long long) src.file_reads());
if (srcp == &src) // CS-T: the RAM and file tiers (the GPU cache's share is the hit rate above)
std::printf("%-24s RAM %lld blobs, files %lld blobs, %.1f MB read from the files (%.2f MB/round)%s\n",
"expert tiers", (long long) src.ram_reads(), (long long) src.file_reads(),
(double) src.file_read_bytes() / 1e6,
rounds > 0 ? (double) src.file_read_bytes() / 1e6 / rounds : 0.0,
src.gguf_mode() ? " (the GGUF in place)" : "");
if (srcp == &src) { // CS-T: the RAM and file tiers (the GPU cache's share is the hit rate above)
const double fms = src.file_ms() - fms0, fmb = (double) (src.file_blob_bytes() - fbytes0) / 1e6;
std::printf("%-24s decode: RAM %lld blobs, files %lld blobs, %.1f MB read from the files (%.2f MB/round, "
"%.1f ms/round of reading, %.2f GB/s per reading thread)%s; prompt copies %.1f MB\n",
"expert tiers", (long long) (src.ram_reads() - ram0), (long long) (src.file_reads() - files0),
fmb, rounds > 0 ? fmb / rounds : 0.0, rounds > 0 ? fms / rounds : 0.0,
fms > 0 ? fmb / fms : 0.0, src.gguf_mode() ? " (the GGUF in place)" : "",
(double) (fall0 - fbytes0) / 1e6);
}
if (rounds > 0 && drive.d.pcie_num > 0)
std::printf("%-24s %.2f distinct experts per layer read over PCIe (share %d/256 of the misses)\n",
"pcie experts", (double) (drive.d.pcie_experts - pcie0) / (double) (rounds * g.n_layers),