okami.mom/strata

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

Niko1221Merge f-own-4x c915680bd into f-own-int (round 15: opt-in Q8_0-down, Q8_0 gate/up and Q6_K fused prompt kernels, the leaner Q6_K loads, the split engine's golden dot test; not the trellis side branch)41a63c550

main
3.4 KiB69 linesraw
1// split_qdot_golden: the split engine's decode dots (src/qdot.cuh) against the stored digests of src/split/tools/qdot_golden.txt, without ggml (see
2// qdot_golden.cuh for the file and the inputs).  Prints one line per format and every group that differs (format, group, its dots), exits 1 on any
3// difference, 77 without a GPU.
4//   split_qdot_golden <qdot_golden.txt> [--family cuda|hip]      (default family: hip in a HIP build, else cuda)
5#include "qdot_golden.cuh"
6
7#include <cstdlib>
8
9namespace {
10
11using namespace fnx_golden;
12
13struct Check {
14    const std::map<std::string, Line>* ref;   // "format group" -> the line in force for this family
15    int bad_groups = 0, groups = 0;
16    template <GgmlType T> bool operator()(const Format& f, const Inputs& in) {
17        const std::vector<float> dots = run_ours<T>(in, f.nblocks);
18        if (dots.empty()) { std::printf("%-8s cuda error\n", f.name); ++bad_groups; return false; }
19        int bad = 0, missing = 0, n = 0;
20        for (const Line& l : group_lines("x", f.name, in, dots)) {
21            ++n;
22            const auto it = ref->find(std::string(f.name) + " " + std::to_string(l.group));
23            if (it == ref->end()) { ++missing; continue; }
24            const Line& r = it->second;
25            const bool in_ok = r.in_digest == l.in_digest, out_ok = r.out_digest == l.out_digest && r.dots == l.dots;
26            if (!in_ok || !out_ok) {
27                ++bad;
28                std::printf("  DIFFER %s group %d (dots %d-%d): %s%s\n", f.name, l.group, l.group * kGroupDots, l.group * kGroupDots + l.dots - 1,
29                            in_ok ? "" : "inputs differ (the generator, not the dots) ", out_ok ? "" : "output digest differs");
30            }
31        }
32        groups += n;
33        bad_groups += bad + missing;
34        std::printf("%-8s %7zu dots, %3d groups, %d differ%s\n", f.name, dots.size(), n, bad, missing ? ", some groups missing in the file" : "");
35        return bad == 0 && missing == 0;
36    }
37};
38
39}  // namespace
40
41int main(int argc, char** argv) {
42    if (argc < 2) { std::fprintf(stderr, "usage: split_qdot_golden <qdot_golden.txt> [--family cuda|hip]\n"); return 2; }
43#if FNX_HIP
44    std::string family = "hip";
45#else
46    std::string family = "cuda";
47#endif
48    for (int i = 2; i + 1 < argc; ++i)
49        if (std::strcmp(argv[i], "--family") == 0) family = argv[i + 1];
50    int ndev = 0;
51    if (cudaGetDeviceCount(&ndev) != cudaSuccess || ndev == 0) { std::printf("no GPU: skipped\n"); return 77; }
52    std::vector<Line> lines;
53    if (!read_lines(argv[1], lines) || lines.empty()) { std::fprintf(stderr, "cannot read %s\n", argv[1]); return 2; }
54    // the cuda line of every group, replaced by this family's own line where it has one
55    std::map<std::string, Line> ref;
56    int own = 0;
57    for (const Line& l : lines)
58        if (l.family == "cuda") ref.emplace(l.format + " " + std::to_string(l.group), l);
59    for (const Line& l : lines)
60        if (l.family == family && family != "cuda") { ref[l.format + " " + std::to_string(l.group)] = l; ++own; }
61    cudaDeviceProp p{};
62    cudaGetDeviceProperties(&p, 0);
63    std::printf("split_qdot_golden: %s, family %s (%d own lines), %zu lines in the file\n", p.name, family.c_str(), own, lines.size());
64    Check c;
65    c.ref = &ref;
66    const bool ok = for_each_format(c);
67    std::printf("%s: %d groups, %d differ\n", ok ? "qdot_golden: PASS" : "qdot_golden: FAIL", c.groups, c.bad_groups);
68    return ok ? 0 : 1;
69}