okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-p4-fb-gate 0d6308de6 into f-p4-int (Tesla P100: the FP16 prompt path with few-row experts is the default instead of MMQ)d59dc3e6f

main
2.4 KiB50 linesraw
1// Few-row experts on the FP16 prompt path (fewrows.hpp): the research switch STRATA_PF_FEWROWS and the rule that picks the
2// experts.  Header-only, no GPU.
3#include <cstdio>
4
5#include "strata/prefill/fewrows.hpp"
6
7using strata::prefill::fewrows_switch;
8using strata::prefill::fewrows_takes;
9using strata::prefill::kFewRows;
10using strata::prefill::kFewRowsRecBytes;
11
12static int failed = 0;
13#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
14
15int main() {
16    // the switch: unset or empty = the default the caller passes; "0" off; anything else on
17    CHECK(!fewrows_switch(nullptr, false));
18    CHECK(fewrows_switch(nullptr, true));
19    CHECK(!fewrows_switch("", false));
20    CHECK(fewrows_switch("", true));
21    CHECK(!fewrows_switch("0", true));
22    CHECK(!fewrows_switch("0", false));
23    CHECK(fewrows_switch("1", false));
24    CHECK(fewrows_switch("12", false));    // a number is not a row count any more: any non-zero value is "on"
25    CHECK(fewrows_switch("on", false));
26
27    // the constant and the plan record: 12 rows, 24 bytes of header + one int32 destination per row
28    CHECK(kFewRows == 12);
29    CHECK(kFewRowsRecBytes == 24 + 4 * 12);
30    CHECK(kFewRowsRecBytes % 8 == 0);       // the u64 blob pointer at the start of the next record stays aligned
31
32    // the rule: switch on, FP16 path, native pack, no APR, 1..kFewRows rows
33    CHECK(fewrows_takes(true, true, true, false, 1));
34    CHECK(fewrows_takes(true, true, true, false, kFewRows));
35    CHECK(!fewrows_takes(true, true, true, false, 0));              // an expert with no rows is skipped elsewhere
36    CHECK(!fewrows_takes(true, true, true, false, kFewRows + 1));   // 13 rows and up: dequantize + GEMMs
37    CHECK(!fewrows_takes(true, true, true, false, 600));
38    CHECK(!fewrows_takes(false, true, true, false, 6));             // switch off
39    CHECK(!fewrows_takes(true, false, true, false, 6));             // MMQ or the fused kernels take the layer
40    CHECK(!fewrows_takes(true, true, false, false, 6));             // a Strata pack's blob
41    CHECK(!fewrows_takes(true, true, true, true, 6));               // APR: the FP16 path rotates itself
42    CHECK(!fewrows_takes(true, true, true, false, -1));
43
44    if (failed) {
45        std::fprintf(stderr, "fewrows_rule_test: %d failed\n", failed);
46        return 1;
47    }
48    std::printf("fewrows_rule_test: ok\n");
49    return 0;
50}