mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
tests: prefill_fused_iq_test no longer fails a layer on the worst row of fused against MMQ; pair statistics are printed instead
The timing part of prefill_fused_iq_test compared the fused path with MMQ over every row and failed the layer when the worst row differed by more than 2e-2 of the row's largest value. That bound is the wrong yardstick. It compares two paths that both carry int8 activation rounding with each other, and the largest of a tail of per-row differences grows with the number of rows: for Q2_0 / Q2_0 (STRATA_PF_FUSED_Q2N=1) on an RTX A4000 the worst row was 1.0e-2 at 8,192 tokens and 2.6e-2 at 20,000 and 32,768, with a relative RMS of 2e-5 throughout. Measured against the FP32 reference on 3,000 sampled pairs at 8,192 / 16,384 / 20,000 tokens, MMQ, the int8 kernel and the fused kernel have the same relative RMS and the same worst row to three digits, and fused and int8 differ from MMQ on the same 0.4 to 0.8 % of the pairs (15 to 23 pairs above 1e-5, largest 3.8e-3 to 5.8e-3, median 2.2e-7). The check that a fused path is not further from the truth than MMQ is the one the test already has against the FP32 reference (fused against MMQ's own error: at most 1.5x the RMS and 2x the worst row, or the K-quant and own-model rules), and it does not grow with the row count. The fused-against-MMQ comparison keeps its relative RMS bound and gets a worst-row backstop of 1e-1, which still catches a wrong row, and the test now prints, per layer, how many pairs differ from MMQ by more than 1e-5 and the largest two and the median.
This commit is contained in:
1 parent
289dd66fc2
commit
3204685e4c
1 file changed
+27
-1
@@ -733,6 +733,28 @@ void timing_part(const Pair& p, int T, cudaStream_t s) {
|
||||
std::printf("%s - timing part: %d tokens x top %d over %d experts, one layer: MMQ path %.3f ms, fused %.3f ms "
|
||||
"(%.2fx); fused vs MMQ rel RMS %.3e worst row %.3e\n",
|
||||
p.name, T, K, E, t_mmq, t_f, t_mmq / t_f, efm.rms, efm.worst);
|
||||
// fused against MMQ pair by pair (information): the share of pairs that differ by more than 1e-5 of the pair's largest MMQ value, and the largest two. Two int8 paths that round the
|
||||
// activations differently disagree on a few pairs by up to a few 1e-3, and the largest of those over all pairs grows with their number (Q2_0 / Q2_0 on an RTX A4000, measured 11-13,
|
||||
// 3,000 sampled pairs at 8,192 / 16,384 / 20,000 tokens: 15 .. 23 pairs above 1e-5, largest 4.5e-3 .. 5.8e-3, median 2.2e-7; the same two kernels sit at the same distance from FP32 as MMQ)
|
||||
if (mq && !no_mmq) {
|
||||
std::vector<double> rel((size_t) rows);
|
||||
for (size_t i = 0; i < (size_t) rows; ++i) {
|
||||
const float* a = y_f.data() + (size_t) slot[i] * N;
|
||||
const float* m = y_mmq.data() + (size_t) r.row_of[i] * N;
|
||||
double me = 0, mr = 0;
|
||||
for (int o = 0; o < N; ++o) { me = std::max(me, (double) std::fabs(a[o] - m[o])); mr = std::max(mr, (double) std::fabs(m[o])); }
|
||||
rel[i] = mr > 0 ? me / mr : (me > 0 ? 1e30 : 0.0);
|
||||
}
|
||||
size_t above = 0;
|
||||
for (double v : rel) above += v > 1e-5;
|
||||
std::vector<double> top(rel);
|
||||
std::nth_element(top.begin(), top.begin() + (ptrdiff_t) (top.size() / 2), top.end());
|
||||
const double med = top[top.size() / 2];
|
||||
std::sort(rel.rbegin(), rel.rend());
|
||||
std::printf("%s - fused vs MMQ per pair (information): %zu of %lld pairs above 1e-5, largest %.3e, second %.3e, median %.3e
|
||||
", p.name, above, (long long) rows,
|
||||
rel.size() > 0 ? rel[0] : 0.0, rel.size() > 1 ? rel[1] : 0.0, med);
|
||||
}
|
||||
{ // the grouping: every pair in its expert's rows (the near-identical blobs here would hide a wrong expert)
|
||||
const std::vector<int32_t> fsrc = download_i(fb.src, (size_t) rows);
|
||||
int64_t bad = 0, bad_src = 0;
|
||||
@@ -875,7 +897,11 @@ void timing_part(const Pair& p, int T, cudaStream_t s) {
|
||||
// the two int8 paths at the real shape, every tile of the layer: R9700 rel RMS 1.3-1.9e-4, worst row 2.9e-3-8.3e-3
|
||||
// (STRATA_PF_F16=1: F16 products against MMQ's int8, gfx1151 rel RMS 2.5-2.7e-3, worst row 6.4e-3-8.8e-3)
|
||||
// (K-quant gate/up pairs: fused against MMQ is information only, see kq_gu)
|
||||
if (mq && !no_mmq && !kq_gu(p) && (efm.rms > (f16_on() ? 5e-3 : 1e-3) || efm.worst > 2e-2))
|
||||
// Fused against MMQ is a comparison of two noisy paths with each other, not against the truth: its worst row is the largest of many tail values and grows with the row count (Q2_0 / Q2_0,
|
||||
// RTX A4000: 1.0e-2 at 8,192 tokens, 2.6e-2 at 20,000 and 32,768 with rel RMS 2e-5, while both paths stand at the same distance from the FP32 reference). So the worst row here is only a
|
||||
// backstop against a wrong row (a few 1e-1 and up), and the pair statistics above are information; the check that a fused path is not further from FP32 than MMQ is the sample's
|
||||
// (ef against em, 1.5x RMS and 2x worst row, or the K-quant and own-model rules), which does not grow with the row count.
|
||||
if (mq && !no_mmq && !kq_gu(p) && (efm.rms > (f16_on() ? 5e-3 : 1e-3) || efm.worst > 1e-1))
|
||||
throw std::runtime_error(std::string(p.name) + ": the paths disagree at the real shape");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in new issue
Block a user