Files
Strata/tests/prefill/fewrows_rule_test.cpp
T
Niko1221 af5803e4be [Engine] Prompt FP16 path: few-row experts on the quantized grouped kernels (research switch, off)
On the FP16 prompt path every routed expert is dequantized to FP16 before its
two GEMMs, at about 104 us an expert on a Tesla P100 whatever its row count; a
short piece routes only a few rows to most experts and pays it for nothing.
With STRATA_PF_FEWROWS set (research switch, off unless set, "0" off) an
expert with 1..12 rows of a native pack (no APR) runs on
native_expert_grouped, the quantized kernels the verify window uses, on its GGUF
blob with q8_1 activations and no dequantize. A one-block kernel writes the
expert's plan record on the device. The rule and the switch are in
include/strata/prefill/fewrows.hpp (fewrows_rule_test); the streamed and staged
walk takes it, the layer-major walk is unchanged.

With the switch unset nothing changes except one added kernel
(fewrows_record_kernel) that nothing launches. No default and no user-visible
text; settings register entry STRATA_PF_FEWROWS, status research.

Tesla P100 (sm_60), IQ3_XXS, STRATA_PREFILL_MMQ=0 with the switch on, from the
screen build (3 rotated rounds; prompt tok/s, ratio to MMQ):
  prompt  MMQ    FP16 path  few-rows  ratio few-rows / MMQ   plain FP16 / MMQ
  300     171.3  144.9      162.8     0.954                  0.846
  1,000   248.4  215.6      226.6     0.911                  0.868
  2K      291.1  264.5      270.7     0.931                  0.909
  4K      304.5  290.5      303.5     0.997                  0.954
  8K      343.6  352.1      358.3     1.044                  1.025
  20K     332.7  335.8      344.4     1.035                  1.009
First-token KL 2K / 8K (mean): few-rows vs plain FP16 0.0168 / 0.0048, vs MMQ
0.0065 / 0.0085 (plain FP16 vs MMQ 0.0155 / 0.0078, MMQ again 0.0012 / 0.0006).
Gate on the committed tree follows (lane P4-FALLBACK, phaseA-tests/par).
2026-11-12 08:56:51 +01:00

51 lines
2.4 KiB
C++

// Few-row experts on the FP16 prompt path (fewrows.hpp): the research switch STRATA_PF_FEWROWS and the rule that picks the
// experts. Header-only, no GPU.
#include <cstdio>
#include "strata/prefill/fewrows.hpp"
using strata::prefill::fewrows_switch;
using strata::prefill::fewrows_takes;
using strata::prefill::kFewRows;
using strata::prefill::kFewRowsRecBytes;
static int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
int main() {
// the switch: unset or empty = the default the caller passes; "0" off; anything else on
CHECK(!fewrows_switch(nullptr, false));
CHECK(fewrows_switch(nullptr, true));
CHECK(!fewrows_switch("", false));
CHECK(fewrows_switch("", true));
CHECK(!fewrows_switch("0", true));
CHECK(!fewrows_switch("0", false));
CHECK(fewrows_switch("1", false));
CHECK(fewrows_switch("12", false)); // a number is not a row count any more: any non-zero value is "on"
CHECK(fewrows_switch("on", false));
// the constant and the plan record: 12 rows, 24 bytes of header + one int32 destination per row
CHECK(kFewRows == 12);
CHECK(kFewRowsRecBytes == 24 + 4 * 12);
CHECK(kFewRowsRecBytes % 8 == 0); // the u64 blob pointer at the start of the next record stays aligned
// the rule: switch on, FP16 path, native pack, no APR, 1..kFewRows rows
CHECK(fewrows_takes(true, true, true, false, 1));
CHECK(fewrows_takes(true, true, true, false, kFewRows));
CHECK(!fewrows_takes(true, true, true, false, 0)); // an expert with no rows is skipped elsewhere
CHECK(!fewrows_takes(true, true, true, false, kFewRows + 1)); // 13 rows and up: dequantize + GEMMs
CHECK(!fewrows_takes(true, true, true, false, 600));
CHECK(!fewrows_takes(false, true, true, false, 6)); // switch off
CHECK(!fewrows_takes(true, false, true, false, 6)); // MMQ or the fused kernels take the layer
CHECK(!fewrows_takes(true, true, false, false, 6)); // a Strata pack's blob
CHECK(!fewrows_takes(true, true, true, true, 6)); // APR: the FP16 path rotates itself
CHECK(!fewrows_takes(true, true, true, false, -1));
if (failed) {
std::fprintf(stderr, "fewrows_rule_test: %d failed\n", failed);
return 1;
}
std::printf("fewrows_rule_test: ok\n");
return 0;
}