okami.mom/strata

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

Niko1221Merge f-q36-testpad 9f0056e41 into f-p4-intf2b41fd29

main
23.0 KiB403 linesraw
1// Standalone diagnostic harness for strata-prefill's optional MMQ path.
2// Keep this artifact outside the project source until it is reviewed and wired into a HIP test target.
3// It compares GGML's MMQ result (with its intended q8_1 activation rounding) to a CPU FP32 product using
4// GGML's own dequantizer for the exact same weight blocks. The tolerances screen layout/stride/bounds errors;
5// they do not assert bitwise or FP16 parity.
6#include "strata/prefill/mmq_ids_margin.hpp"
7#include "strata/prefill/moe_mmq.hpp"
8#include "ggml.h"
9#include <hip/hip_runtime.h>
10
11#include <algorithm>
12#include <cmath>
13#include <cstdint>
14#include <cstring>
15#include <cstdlib>
16#include <fstream>
17#include <iostream>
18#include <numeric>
19#include <sstream>
20#include <stdexcept>
21#include <string>
22#include <vector>
23
24namespace {
25using strata::prefill::mmq::Context;
26using strata::prefill::mmq::Product;
27using strata::prefill::mmq::matrix_bytes;
28using strata::prefill::mmq::q8_bytes;
29using strata::prefill::mmq::quantize;
30using strata::prefill::mmq::supported;
31
32void hip_check(hipError_t e, const char * what) {
33    if (e != hipSuccess) throw std::runtime_error(std::string(what) + ": " + hipGetErrorString(e));
34}
35
36struct DeviceBuffer {
37    void * p = nullptr;
38    explicit DeviceBuffer(size_t n) { hip_check(hipMalloc(&p, n), "hipMalloc"); }
39    ~DeviceBuffer() { if (p) hipFree(p); }
40    DeviceBuffer(const DeviceBuffer &) = delete;
41    DeviceBuffer & operator=(const DeviceBuffer &) = delete;
42    template<class T> T * as() const { return static_cast<T *>(p); }
43};
44
45size_t row_bytes(ggml_type type, int64_t cols) {
46    return ggml_row_size(type, cols);
47}
48
49std::vector<float> decode_matrix(ggml_type type, const std::vector<uint8_t> & q, int64_t rows, int64_t cols) {
50    const auto * tr = ggml_get_type_traits(type);
51    if (!tr || !tr->to_float) throw std::runtime_error("GGML type has no host dequantizer");
52    const size_t rb = row_bytes(type, cols);
53    if (q.size() != (size_t) rows * rb) throw std::runtime_error("matrix byte count mismatch");
54    std::vector<float> out((size_t) rows * (size_t) cols);
55    for (int64_t r = 0; r < rows; ++r) {
56        tr->to_float(q.data() + (size_t) r * rb, out.data() + (size_t) r * (size_t) cols, cols);
57    }
58    return out;
59}
60
61std::vector<uint8_t> make_q2_matrix(int64_t rows, int64_t cols, int expert, int trial,
62                                    ggml_type type = GGML_TYPE_Q2_0) {
63    const auto * tr = ggml_get_type_traits(type);
64    if (!tr || !tr->from_float_ref) throw std::runtime_error("host quantizer unavailable");
65    const size_t rb = row_bytes(type, cols);
66    std::vector<uint8_t> out((size_t) rows * rb);
67    std::vector<float> row((size_t) cols);
68    for (int64_t r = 0; r < rows; ++r) {
69        for (int64_t k = 0; k < cols; ++k) {
70            const int code = (int) ((k * 37 + r * 19 + expert * 23 + trial * 11) % 101) - 50;
71            row[(size_t) k] = 0.025f * std::sin(0.013f * (float) (k + 1) + 0.17f * (float) r + 0.31f * (float) expert) +
72                              0.0015f * (float) code;
73        }
74        tr->from_float_ref(row.data(), out.data() + (size_t) r * rb, cols);
75    }
76    return out;
77}
78
79std::vector<float> make_activations(int rows, int64_t cols, int trial) {
80    std::vector<float> x((size_t) rows * (size_t) cols);
81    for (int r = 0; r < rows; ++r) {
82        for (int64_t k = 0; k < cols; ++k) {
83            x[(size_t) r * (size_t) cols + (size_t) k] =
84                0.45f * std::sin(0.009f * (float) (k + 1) + 0.23f * (float) r + 0.07f * (float) trial) +
85                0.17f * std::cos(0.021f * (float) (k + 3) - 0.19f * (float) r) +
86                0.002f * (float) (((k * 7 + r * 13 + trial * 5) % 19) - 9);
87        }
88    }
89    // Exercise a complete all-zero row; its expected output is exactly zero even though Q8_1 rounding is enabled.
90    std::fill(x.end() - cols, x.end(), 0.0f);
91    return x;
92}
93
94std::vector<int32_t> permutation(int rows, int shift, bool reverse) {
95    std::vector<int32_t> p((size_t) rows);
96    for (int i = 0; i < rows; ++i) {
97        p[(size_t) i] = reverse ? (int32_t) ((rows - 1 - i + shift) % rows)
98                                : (int32_t) ((i + shift) % rows);
99    }
100    return p;
101}
102
103std::vector<int32_t> make_bounds(const std::vector<int> & counts) {
104    std::vector<int32_t> b(counts.size() + 1, 0);
105    for (size_t i = 0; i < counts.size(); ++i) b[i + 1] = b[i] + counts[i];
106    return b;
107}
108
109struct Metrics { double rel_l2 = 0, max_over_rms = 0, zero_row_max = 0, ref_rms = 0; };
110
111Metrics run_product(Context & ctx, hipStream_t stream, const std::string & name, ggml_type type,
112                    int64_t out_rows, int64_t cols, const std::vector<std::vector<uint8_t>> & expert_weights,
113                    const std::vector<int> & counts, const std::vector<float> & x,
114                    const std::vector<int32_t> & src_ids, const std::vector<int32_t> & dst_ids) {
115    const int rows = (int) src_ids.size();
116    const int experts = (int) expert_weights.size();
117    const std::vector<int32_t> bounds = make_bounds(counts);
118    if (!supported((int) type) || experts <= 0 || counts.size() != expert_weights.size() ||
119        bounds.back() != rows || dst_ids.size() != (size_t) rows || x.size() != (size_t) rows * (size_t) cols) {
120        throw std::runtime_error(name + ": invalid test geometry");
121    }
122    const size_t expert_bytes = matrix_bytes((int) type, out_rows, cols);
123    const size_t tail = 4096; // match the production group's zero guard after its last expert
124    std::vector<uint8_t> w((size_t) experts * expert_bytes + tail, 0);
125    for (int e = 0; e < experts; ++e) {
126        if (expert_weights[(size_t) e].size() != expert_bytes) throw std::runtime_error(name + ": expert size mismatch");
127        std::copy(expert_weights[(size_t) e].begin(), expert_weights[(size_t) e].end(),
128                  w.begin() + (size_t) e * expert_bytes);
129    }
130
131    DeviceBuffer dx(x.size() * sizeof(float));
132    DeviceBuffer dsrc(src_ids.size() * sizeof(int32_t));
133    // llama.cpp's mul_mat_q and its stream-k fixup read the row-id table up to a J-column tile (J <= 128) past the last row, up to roundup(max_rows, J) from an
134    // expert's first row (mmq_ids_margin.hpp): the table has the margin, its extra entries hold row index 0 (valid; they are read, never used)
135    const size_t ids_rows = (size_t) strata::prefill::mmq::mmq_ids_table_rows((uint64_t) rows, (uint64_t) *std::max_element(counts.begin(), counts.end()));
136    std::vector<int32_t> dst_table(dst_ids);
137    dst_table.resize(ids_rows, 0);
138    DeviceBuffer ddst(dst_table.size() * sizeof(int32_t));
139    DeviceBuffer dbounds(bounds.size() * sizeof(int32_t));
140    DeviceBuffer dw(w.size());
141    DeviceBuffer dxq(q8_bytes(rows, cols));
142    DeviceBuffer dy((size_t) rows * (size_t) out_rows * sizeof(float));
143    hip_check(hipMemcpy(dx.p, x.data(), x.size() * sizeof(float), hipMemcpyHostToDevice), "copy x");
144    hip_check(hipMemcpy(dsrc.p, src_ids.data(), src_ids.size() * sizeof(int32_t), hipMemcpyHostToDevice), "copy src ids");
145    hip_check(hipMemcpy(ddst.p, dst_table.data(), dst_table.size() * sizeof(int32_t), hipMemcpyHostToDevice), "copy dst ids");
146    hip_check(hipMemcpy(dbounds.p, bounds.data(), bounds.size() * sizeof(int32_t), hipMemcpyHostToDevice), "copy bounds");
147    hip_check(hipMemcpy(dw.p, w.data(), w.size(), hipMemcpyHostToDevice), "copy weights and zero tail");
148    // On the product's stream: a plain hipMemset runs on the null stream, which a non-blocking stream does not wait
149    // for - on a Radeon 8060S (gfx1151, Windows) it landed after the MMQ kernel and left only the sentinel
150    hip_check(hipMemsetAsync(dy.p, 0xff, (size_t) rows * (size_t) out_rows * sizeof(float), stream),
151              "initialize output sentinel");
152
153    quantize(dx.as<float>(), dsrc.as<int32_t>(), dxq.p, (int) type, cols, cols, rows, (void *) stream);
154    const int max_rows = *std::max_element(counts.begin(), counts.end());
155    Product p;
156    p.w = dw.p; p.type = (int) type; p.w_rows = out_rows; p.w_cols = cols; p.expert_bytes = expert_bytes;
157    p.n = experts; p.xq = dxq.p; p.bounds = dbounds.as<int32_t>(); p.ids = ddst.as<int32_t>();
158    p.total_rows = rows; p.max_rows = max_rows; p.dst = dy.as<float>(); p.ld_dst = out_rows;
159    ctx.run(p, (void *) stream);
160    hip_check(hipGetLastError(), "MMQ launch");
161    hip_check(hipStreamSynchronize(stream), "MMQ synchronize");
162    std::vector<float> got((size_t) rows * (size_t) out_rows);
163    hip_check(hipMemcpy(got.data(), dy.p, got.size() * sizeof(float), hipMemcpyDeviceToHost), "copy output");
164
165    std::vector<float> ref(got.size(), 0.0f);
166    double err2 = 0, ref2 = 0;
167    float max_abs = 0, zero_max = 0;
168    for (int e = 0; e < experts; ++e) {
169        const std::vector<float> wd = decode_matrix(type, expert_weights[(size_t) e], out_rows, cols);
170        for (int r = bounds[(size_t) e]; r < bounds[(size_t) e + 1]; ++r) {
171            const int src = src_ids[(size_t) r];
172            const int dst = dst_ids[(size_t) r];
173            const float * xr = x.data() + (size_t) src * (size_t) cols;
174            for (int64_t o = 0; o < out_rows; ++o) {
175                double acc = 0;
176                const float * wr = wd.data() + (size_t) o * (size_t) cols;
177                for (int64_t k = 0; k < cols; ++k) acc += (double) wr[k] * xr[k];
178                ref[(size_t) dst * (size_t) out_rows + (size_t) o] = (float) acc;
179            }
180        }
181    }
182    {
183        size_t bad = 0, first = got.size();
184        uint32_t first_bits = 0;
185        for (size_t i = 0; i < got.size(); ++i)
186            if (!std::isfinite(got[i])) { if (!bad++) { first = i; std::memcpy(&first_bits, &got[i], 4); } }
187        if (bad)
188            throw std::runtime_error(name + ": " + std::to_string(bad) + " non-finite or unwritten MMQ outputs, first at row " +
189                                     std::to_string(first / (size_t) out_rows) + " col " + std::to_string(first % (size_t) out_rows) +
190                                     " bits " + std::to_string(first_bits));
191    }
192    for (size_t i = 0; i < got.size(); ++i) {
193        const double d = (double) got[i] - ref[i];
194        err2 += d * d; ref2 += (double) ref[i] * ref[i]; max_abs = std::max(max_abs, (float) std::fabs(d));
195    }
196    const double rms = std::sqrt(ref2 / (double) ref.size());
197    for (int r = 0; r < rows; ++r) {
198        if (std::all_of(x.begin() + (size_t) src_ids[(size_t) r] * (size_t) cols,
199                        x.begin() + ((size_t) src_ids[(size_t) r] + 1) * (size_t) cols,
200                        [](float v) { return v == 0.0f; })) {
201            for (int64_t o = 0; o < out_rows; ++o)
202                zero_max = std::max(zero_max, std::fabs(got[(size_t) dst_ids[(size_t) r] * (size_t) out_rows + (size_t) o]));
203        }
204    }
205    Metrics m;
206    m.rel_l2 = rms > 0 ? std::sqrt(err2 / (double) ref.size()) / rms : std::sqrt(err2);
207    m.max_over_rms = rms > 0 ? max_abs / rms : max_abs;
208    m.zero_row_max = zero_max; m.ref_rms = rms;
209    std::cout << name << ": type=" << (int) type << " rows=" << rows << " experts=" << experts
210              << " ref_rms=" << m.ref_rms << " rel_l2=" << m.rel_l2
211              << " max_abs/ref_rms=" << m.max_over_rms << " zero_row_max=" << m.zero_row_max << '\n';
212    // Q8_1 rounding is expected. These deliberately broad limits catch wrong block order, row strides, ids,
213    // expert bounds, or stale output while allowing ordinary activation-quantization error.
214    if (m.rel_l2 > 0.04 || m.max_over_rms > 0.35 || m.zero_row_max > std::max(1e-5, 1e-4 * rms))
215        throw std::runtime_error(name + ": parity screen failed");
216    return m;
217}
218
219std::vector<std::vector<uint8_t>> synthetic_q2(int experts, int64_t out_rows, int64_t cols, int trial,
220                                               ggml_type type = GGML_TYPE_Q2_0) {
221    std::vector<std::vector<uint8_t>> w;
222    for (int e = 0; e < experts; ++e) w.push_back(make_q2_matrix(out_rows, cols, e, trial, type));
223    return w;
224}
225
226// A synthetic matrix of any ggml type with a host quantizer (the K-quants: the dense GGUF tensors the
227// STRATA_DENSE_MMQ path multiplies on HIP).  K stays a 256-value multiple: the dense path only takes
228// such K, and a partial 256-value chunk would read past the synthetic tensor's end.
229std::vector<std::vector<uint8_t>> synthetic_of_type(ggml_type type, int experts, int64_t out_rows, int64_t cols,
230                                                     int trial) {
231    const auto * tr = ggml_get_type_traits(type);
232    if (!tr || !tr->from_float_ref) throw std::runtime_error("no host quantizer for the type");
233    std::vector<std::vector<uint8_t>> w;
234    for (int e = 0; e < experts; ++e) {
235        std::vector<uint8_t> blocks((size_t) out_rows * row_bytes(type, cols));
236        std::vector<float> row((size_t) cols);
237        for (int64_t r = 0; r < out_rows; ++r) {
238            for (int64_t k = 0; k < cols; ++k) {
239                const int code = (int) ((k * 29 + r * 17 + e * 31 + trial * 13) % 97) - 48;
240                row[(size_t) k] = 0.02f * std::sin(0.011f * (float) (k + 2) + 0.29f * (float) r + 0.37f * (float) e) +
241                                  0.0009f * (float) code;
242            }
243            tr->from_float_ref(row.data(), blocks.data() + (size_t) r * row_bytes(type, cols), cols);
244        }
245        w.push_back(std::move(blocks));
246    }
247    return w;
248}
249
250// A synthetic matrix of any ggml type through ggml_quantize_chunk (the i-quants need an importance matrix; ones here).
251std::vector<std::vector<uint8_t>> synthetic_chunk(ggml_type type, int experts, int64_t out_rows, int64_t cols, int trial) {
252    std::vector<std::vector<uint8_t>> w;
253    const std::vector<float> imatrix((size_t) cols, 1.0f);
254    for (int e = 0; e < experts; ++e) {
255        std::vector<float> f((size_t) out_rows * (size_t) cols);
256        for (int64_t r = 0; r < out_rows; ++r)
257            for (int64_t k = 0; k < cols; ++k) {
258                const int code = (int) ((k * 29 + r * 17 + e * 31 + trial * 13) % 97) - 48;
259                f[(size_t) (r * cols + k)] = 0.02f * std::sin(0.011f * (float) (k + 2) + 0.29f * (float) r + 0.37f * (float) e) +
260                                             0.0009f * (float) code;
261            }
262        std::vector<uint8_t> blocks((size_t) out_rows * row_bytes(type, cols));
263        ggml_quantize_chunk(type, f.data(), blocks.data(), 0, out_rows, cols,
264                            ggml_quantize_requires_imatrix(type) ? imatrix.data() : nullptr);
265        w.push_back(std::move(blocks));
266    }
267    return w;
268}
269
270bool run_real_iq3_first_expert(Context & ctx, hipStream_t stream, const std::string & pack) {
271    std::ifstream meta(pack + "/native_experts.txt");
272    if (!meta) throw std::runtime_error("cannot open native_experts.txt: " + pack);
273    int layer = -1, gt = -1, dt = -1;
274    uint64_t offset = 0, blob_bytes = 0;
275    std::string line;
276    bool found = false;
277    while (std::getline(meta, line)) {
278        if (line.empty() || line[0] == '#') continue;
279        std::istringstream ss(line);
280        if (ss >> layer >> gt >> dt >> offset >> blob_bytes && layer == 0) { found = true; break; }
281    }
282    if (!found) throw std::runtime_error("native metadata has no layer 0");
283    if (gt != GGML_TYPE_IQ3_XXS || !supported(gt) || !supported(dt)) {
284        std::cout << "real-IQ3 first expert skipped: layer 0 types are " << gt << "/" << dt << '\n';
285        return false;
286    }
287    std::ifstream file(pack + "/experts.bin", std::ios::binary);
288    if (!file) throw std::runtime_error("cannot open experts.bin: " + pack);
289    std::vector<uint8_t> blob((size_t) blob_bytes);
290    file.seekg((std::streamoff) offset);
291    file.read((char *) blob.data(), (std::streamsize) blob.size());
292    if (!file) throw std::runtime_error("short read of first native expert");
293
294    constexpr int64_t N = 2560, FF = 640;
295    const size_t gu_row = row_bytes((ggml_type) gt, N), d_row = row_bytes((ggml_type) dt, FF);
296    const size_t one_gu = (size_t) FF * gu_row, down_off = 2 * one_gu, one_down = (size_t) N * d_row;
297    if (down_off + one_down != blob.size()) throw std::runtime_error("native blob shape/offset mismatch");
298    std::vector<uint8_t> gu(blob.begin(), blob.begin() + (ptrdiff_t) down_off);
299    std::vector<uint8_t> down(blob.begin() + (ptrdiff_t) down_off, blob.end());
300    const int rows = 5;
301    const std::vector<int> counts{rows};
302    const auto src = permutation(rows, 2, false), dst = permutation(rows, 1, true);
303    run_product(ctx, stream, "real-first-IQ3_XXS-GU", (ggml_type) gt, 1280, N, {gu}, counts,
304                make_activations(rows, N, 71), src, dst);
305    run_product(ctx, stream, "real-first-down", (ggml_type) dt, N, FF, {down}, counts,
306                make_activations(rows, FF, 73), src, dst);
307    std::cout << "real first expert tested: layer=0 expert=0 blob_bytes=" << blob_bytes << '\n';
308    return true;
309}
310} // namespace
311
312int main(int argc, char ** argv) {
313    try {
314        if (argc > 2) throw std::runtime_error("usage: mmq-parity-test [optional-native-pack-dir]");
315        hip_check(hipSetDevice(0), "hipSetDevice");
316        hipStream_t stream = nullptr;
317        hip_check(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking), "create stream");
318        int failures = 0;
319        {
320            Context ctx; // reuse one MMQ context/pool across every pass below
321            const std::vector<std::vector<int>> batches{{1, 3, 3}, {4, 1, 2}, {2, 3}};
322            int trial = 0;
323            for (const auto & counts : batches) {
324                const int rows = std::accumulate(counts.begin(), counts.end(), 0);
325                const int n = (int) counts.size();
326                const auto src = permutation(rows, trial + 1, false);
327                const auto dst = permutation(rows, trial + 2, true);
328                run_product(ctx, stream, "synthetic-Q2_0-GU-pass" + std::to_string(trial), GGML_TYPE_Q2_0,
329                            1280, 2560, synthetic_q2(n, 1280, 2560, trial), counts,
330                            make_activations(rows, 2560, trial), src, dst);
331                run_product(ctx, stream, "synthetic-Q2_0-down-pass" + std::to_string(trial), GGML_TYPE_Q2_0,
332                            2560, 640, synthetic_q2(n, 2560, 640, trial + 9), counts,
333                            make_activations(rows, 640, trial + 3), src, dst);
334                ++trial;
335            }
336            // The K-quant instances a STRATA_MMQ_KQUANTS build adds (the dense GGUF projections of the
337            // mixed-quant packs through Gemm::native).  Skipped when the build does not have them.
338            for (const auto & [name, type] : std::initializer_list<std::pair<const char *, ggml_type>>{
339                     {"Q4_K", GGML_TYPE_Q4_K}, {"Q5_K", GGML_TYPE_Q5_K}, {"Q6_K", GGML_TYPE_Q6_K},
340                     {"Q5_1", GGML_TYPE_Q5_1}}) {
341                if (!supported((int) type)) {
342                    std::cout << "synthetic-" << name << " skipped: not built (STRATA_MMQ_KQUANTS off?)\n";
343                    continue;
344                }
345                const int rows = 5;
346                const std::vector<int> counts{rows};
347                const auto src = permutation(rows, 3, false), dst = permutation(rows, 2, true);
348                run_product(ctx, stream, std::string("synthetic-") + name, type,
349                            1280, 2560, synthetic_of_type(type, 1, 1280, 2560, 5), counts,
350                            make_activations(rows, 2560, 77), src, dst);
351            }
352            // Round 0214 (the new Unsloth Qwen3.8-Flash-Next quants): every gate/up type of the new sets at 1280 x 2560 and
353            // every down type at 2560 x 640 (FF 640 is not a multiple of 256: the 32-block types only).  Q5_0 is built
354            // only with STRATA_ORCA_Q4KS_MMQ (the opt-in); IQ1_M has no MMQ instance (its prompts take the gather route).
355            for (const auto & [name, type] : std::initializer_list<std::pair<const char *, ggml_type>>{
356                     {"IQ1_M", GGML_TYPE_IQ1_M}, {"IQ2_XXS", GGML_TYPE_IQ2_XXS}, {"IQ2_XS", GGML_TYPE_IQ2_XS},
357                     {"IQ2_S", GGML_TYPE_IQ2_S}, {"IQ3_XXS", GGML_TYPE_IQ3_XXS}, {"IQ4_XS", GGML_TYPE_IQ4_XS},
358                     {"Q2_0", GGML_TYPE_Q2_0}, {"Q5_0", GGML_TYPE_Q5_0}}) {
359                if (!supported((int) type)) { std::cout << "gate/up " << name << ": no MMQ instance in this build (skipped)\n"; continue; }
360                const std::vector<int> counts{2, 3};
361                const auto src = permutation(5, 1, false), dst = permutation(5, 2, true);
362                run_product(ctx, stream, std::string("new-set-GU-") + name, type, 1280, 2560, synthetic_chunk(type, 2, 1280, 2560, 7),
363                            counts, make_activations(5, 2560, 8), src, dst);
364            }
365            for (const auto & [name, type] : std::initializer_list<std::pair<const char *, ggml_type>>{
366                     {"Q2_0", GGML_TYPE_Q2_0}, {"IQ4_NL", GGML_TYPE_IQ4_NL}, {"Q5_0", GGML_TYPE_Q5_0}, {"Q8_0", GGML_TYPE_Q8_0}}) {
367                if (!supported((int) type)) { std::cout << "down " << name << ": no MMQ instance in this build (skipped)\n"; continue; }
368                const std::vector<int> counts{2, 3};
369                const auto src = permutation(5, 1, false), dst = permutation(5, 2, true);
370                run_product(ctx, stream, std::string("new-set-down-") + name, type, 2560, 640, synthetic_chunk(type, 2, 2560, 640, 9),
371                            counts, make_activations(5, 640, 10), src, dst);
372            }
373            // APR trellis experts (ggml types 144-146), when the build has their MMQ instances (agention fork): gate/up
374            // 1280 x 2560 and down 2560 x 640 (5 blocks per row: the last 256-slice reads past the row, against zero
375            // activations)
376            for (const ggml_type t : {(ggml_type) 145, (ggml_type) 146, (ggml_type) 144}) {
377                if (!supported((int) t)) { std::cout << "type " << (int) t << ": no MMQ instance in this build\n"; continue; }
378                if ((int) t >= (int) GGML_TYPE_COUNT) { std::cout << "type " << (int) t << ": this ggml has no host traits for the trellis types (skipped)\n"; continue; }
379                const std::vector<int> counts{2, 3};
380                const auto src = permutation(5, 1, false), dst = permutation(5, 2, true);
381                const char* known = ggml_type_name(t);   // null when this ggml has no name for the id (no trellis types in it): #3358
382                const std::string tn = known ? known : "type" + std::to_string((int) t);
383                const char* rep = std::getenv("MMQ_PARITY_REPEAT");   // repeat each product (flakiness screen)
384                const int reps = rep ? std::max(1, std::atoi(rep)) : 1;
385                const auto wgu = synthetic_q2(2, 1280, 2560, 5, t), wd = synthetic_q2(2, 2560, 640, 6, t);
386                for (int r = 0; r < reps; ++r) {
387                    run_product(ctx, stream, "synthetic-" + tn + "-GU", t, 1280, 2560, wgu, counts,
388                                make_activations(5, 2560, 5), src, dst);
389                    run_product(ctx, stream, "synthetic-" + tn + "-down", t, 2560, 640, wd, counts,
390                                make_activations(5, 640, 6), src, dst);
391                }
392            }
393            if (argc == 2) run_real_iq3_first_expert(ctx, stream, argv[1]);
394        }
395        hip_check(hipStreamSynchronize(stream), "final synchronize");
396        hip_check(hipStreamDestroy(stream), "destroy stream");
397        std::cout << "MMQ parity screen passed\n";
398        return failures ? 1 : 0;
399    } catch (const std::exception & e) {
400        std::cerr << "MMQ parity screen failed: " << e.what() << '\n';
401        return 1;
402    }
403}