A q8_1 block stores d = amax / 127 and the sum of its 32 activations as fp16: one massive activation (amax > 8.3 M, or a sum past 65504) rounded to inf and the dot products then read inf * 0 = NaN (NonFiniteMmqOutput here, "!!!!" upstream). The quantizers now clamp both to the largest finite half and keep the codes inside int8 (strata/kernels/q8_1_finite.hpp); a NaN input still gives a NaN sum. Finite blocks are stored bit for bit as before. Sites: head_quant (mtp_original_full_head_native, native_head_native), mtp_original_quantize (mtp_original_tail, mtp_original_full_checks), quantize_q8_1_kernel (mtp_original_full_head_iq, native_head_iq: the routed experts' input and SwiGLU output) and the opt-in chain swiglu+quantize (chain_window). Not taken: the MMQ prompt quantizers (ggml quantize_mmq_q8_1, mtp_prefill_q8), which upstream did not clamp. The sealed PTX are patched entry by entry (scripts/q8): three were built with CUDA 13.0.88, which is not installed, and a recompile renames the hashed anonymous-namespace entries; only the quantizer entries change, every other byte is the sealed one. Pins, the seal plan digests and the sm_86 companions (sm86_assets.py build) follow. tools/q8-probe compares old and new PTX on the GPU. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
77 lines
3.3 KiB
Python
77 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Row-by-row comparison of two port smoke logs of the SAME teacher-forced corpus (docs/quality-gate.md, scripts/quality/q-common.sh port_run).
|
|
|
|
The question it answers is the one of a change that must not alter normal output (docs/upstream-port-plan.md row 1.1): are the top-16
|
|
log-probability rows of build B equal to those of build A, bit for bit? A row is keyed by (position, the window's inputs up to the row),
|
|
so two runs that cut their windows differently still meet on the rows whose context is the same. For rows that are not identical it
|
|
prints the deviation of the reference's top-1 (d_top1), the argmax flips and the largest differences, so the same log pair can also be
|
|
read with the yardsticks of q_tail_gate.py (p99 / max / flip rate against the run-to-run control of two runs of build A).
|
|
|
|
usage: q_pair.py LOG_A LOG_B [--pass N] [--control LOG_A2] exit 0 if every common forced row is identical
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import q_lib
|
|
|
|
|
|
def rows_of(log, wanted_pass):
|
|
out = {}
|
|
for run in q_lib.parse_port_log(log):
|
|
if not run["forced"] or run["pass"] != wanted_pass:
|
|
continue
|
|
for position, inputs, rows in run["windows"]:
|
|
for r, row in enumerate(rows):
|
|
out.setdefault((run["index"], position + r, tuple(inputs[: r + 1])), row)
|
|
return out
|
|
|
|
|
|
def render(row):
|
|
return ' '.join(f'{t}:{lp!r}' for t, lp in row.topk)
|
|
|
|
|
|
def compare(a, b, label):
|
|
common = sorted(set(a) & set(b))
|
|
same = [k for k in common if render(a[k]) == render(b[k])]
|
|
diff = [k for k in common if k not in set(same)]
|
|
flips = [k for k in diff if a[k].top1 != b[k].top1]
|
|
d1 = sorted((abs(a[k].topk[0][1] - (b[k].lp(a[k].top1) if b[k].lp(a[k].top1) is not None else float('nan'))) for k in diff), reverse=True)
|
|
d1 = [x for x in d1 if x == x]
|
|
print(f'{label}: rows A {len(a)}, rows B {len(b)}, common {len(common)}: identical {len(same)}, different {len(diff)}, argmax flips {len(flips)}')
|
|
if diff:
|
|
print(f' d_top1 of the different rows: max {d1[0] if d1 else float("nan"):.4f}, p99 {q_lib.quantile(d1, .99):.4f}, median {q_lib.quantile(d1, .5):.4f}')
|
|
for k in diff[:5]:
|
|
print(f' differs: request {k[0]} position {k[1]}: A {render(a[k])[:90]} | B {render(b[k])[:90]}')
|
|
return len(common), len(diff), len(flips), d1
|
|
|
|
|
|
def main():
|
|
args = sys.argv[1:]
|
|
wanted, control = 0, None
|
|
if '--pass' in args:
|
|
i = args.index('--pass')
|
|
wanted = int(args[i + 1])
|
|
del args[i:i + 2]
|
|
if '--control' in args:
|
|
i = args.index('--control')
|
|
control = args[i + 1]
|
|
del args[i:i + 2]
|
|
if len(args) != 2:
|
|
print(__doc__)
|
|
sys.exit(2)
|
|
a, b = rows_of(args[0], wanted), rows_of(args[1], wanted)
|
|
if not a or not b:
|
|
print('no forced rows in a log (was the run teacher-forced? LELEKA_SMOKE_FORCE_DIR, LELEKA_TRACE_LOGPROBS=16)')
|
|
sys.exit(2)
|
|
n, bad, flips, _ = compare(a, b, 'B against A')
|
|
if control:
|
|
compare(a, rows_of(control, wanted), 'run-to-run control (A2 against A)')
|
|
ok = n > 0 and bad == 0
|
|
print('VERDICT:', 'IDENTICAL' if ok else 'DIFFERENT (read it against the control)')
|
|
sys.exit(0 if ok else 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|