Manuscript Offprint

arXiv:2609.39816

Beyond Accuracy: Prefix-Invariant Realizations of Low-Precision Fast Matrix Multiplication

Shuxiao Xie, Shuyang Xie, Yuan Cao, Dezhi Ran, Wei Yang, Tao Xie

Abstract

Fast matrix multiplication saves multiplications through exact cancellation, but rounding sums that mix token rows can leave contributions from later tokens in earlier language model outputs. This threatens prefix invariance, which multiple-choice likelihood scoring relies on: a scored likelihood must depend only on its allowed prefix. On Qwen2.5-14B-Instruct, two fast FP8 realizations repaired to ordinary-looking accuracy still change the answers chosen by likelihood on 5.83% and 10.00% of 240 OpenBookQA items when only the text after the allowed prefix is replaced with the bf16 model's own greedy continuation. Both row-local controls, the bf16 model and a deployed FP8 matrix multiplication kernel, change none. Accuracy thus does not certify prefix invariance, and the stability criteria we analyze cannot tell realizations apart: across all 512 sign variants of two-level Strassen they stay constant while teacher-forced perplexities span a 772.4× range on the same model. We therefore construct certified realizations of two-level Strassen on bounded integer codes that quantize token rows independently, then mix and cancel exactly before rescaling, using 49 block multiplications instead of 64. Our certificate guarantees bitwise equality to a prescribed row-local classical int8 operator at the same quantization specification, so every certified realization inherits its prefix invariance. Certification thus turns realization choice into a pure cost decision: which certified realization runs can no longer change a single scored likelihood.

1 Introduction

Fast matrix multiplication saves multiplications: it multiplies sums of matrix blocks and lets the unwanted cross terms cancel exactly [30]. Low-precision kernels for large language model (LLM) inference now run such algorithms [15, 41], and in a linear layer the rows of the activation matrix are token positions, so these block sums add rows of different tokens. In exact arithmetic the cross terms cancel and each output row depends only on its own input row; after rounding they can fail to cancel [20], and a later token can then contribute to an earlier token's output. Such a contribution arises inside a linear layer, where the causal attention mask has no effect. It violates prefix invariance [17]: what a model computes at a position must depend only on its allowed prefix, the text of its own sequence up to that position. Likelihood-based evaluation relies on this property: it can

∗^{*}Equal contribution.

†^{\dagger}Corresponding authors: dezhiran@pku.edu.cn and taoxie@pku.edu.cn.

PREPRINT

A Accuracy repaired, invariance not OpenBookQA, 240 items

Figure

B 512 exact equivalents teacher-forced WikiText-2

Figure

C One certified operator

Figure

Figure 1: A Accuracy on the original input, and answers changed (95% intervals) when the text after the allowed prefix is replaced by the bf16 model's greedy continuation; #1, #2: two fast algorithms, each with both repairs. B Perplexity of the 512 sign variants of two-level Strassen under one FP8 schedule, sorted, and the criteria we analyze. C A certified realization and classical int8; strip: synthetic row pairs in which a later row changes an earlier output (FP8: our schedule, same coefficients). A, B: Qwen2.5-14B-Instruct.

score all tokens of a candidate answer in one forward pass, and the likelihood of each must depend only on the text before it.

The natural first check on a fast low-precision realization, an algorithm's coefficients together with how it is quantized and executed, is the model's accuracy. In 8-bit floating point (FP8), fast algorithms can lose much of that accuracy (Figure 1A), and two repairs adapted from prior work aim to restore it by changing how the algorithm is quantized [3, 9, 25]. With both repairs, FP8 realizations of two different fast algorithms bring Qwen2.5-14B-Instruct [36] to 35.42% and 32.92% accuracy on OpenBookQA [22], against 34.58% for the model in bfloat16 (bf16). Yet when only the text after the allowed prefix is replaced by the bf16 model's own greedy continuation of that prefix, with the original answer still the one scored, they change the answer chosen by likelihood on 5.83% and 10.00% of 240 items, respectively (Figure 1A). Two row-local controls, the bf16 model and a deployed FP8 matrix multiplication kernel, change none. The allowed prefix, input shapes and execution plan are unchanged, so the changed answers expose a dependence on text the answer must not see. The same kind of dependence crosses requests packed into one forward pass, so prefix invariance matters for LLM serving as well as for evaluation.

Since accuracy did not reveal these violations and rounding can produce them, the natural next check is the numerical analysis used to choose among fast algorithms. It compares them by stability criteria computed from their coefficients, such as the parameters of a bound on rounding error [3] or a measure of expected error [35]. The criteria we analyze read only coefficient magnitudes. Changing an algorithm's coefficient signs in ways that cancel out leaves the exact product unchanged [20]; two-level Strassen, Strassen's algorithm applied to its own blocks, has 512 such sign variants, and each criterion gives all of them one value [8, 20]. Under the same FP8 schedule with block scaling, however, their teacher-forced perplexity on the same model spans a 772.4× range (Figure 1B).

Accuracy did not flag the violations above, and the criteria we analyze did not even separate realizations whose quantized behavior differs widely. A test like ours can expose a violation but not prove its absence, so a guarantee that a realization keeps prefix invariance has to come from how it is built. The most direct construction forbids every intermediate product that feeds an output row from depending on a later row, but we prove that this forces the classical number of multiplications (Section 4.1), which gives up the saving. A realization that keeps the saving must therefore contain products that mix later rows into earlier ones, and prefix invariance can then hold only for its final output: the mixing must be undone exactly by the time that output is formed.

We therefore construct realizations of two-level Strassen that undo the mixing exactly, by carrying it out on bounded integer codes, whose sums do not round. Where EmuGEMM uses this exactness to save multiplications through cancellation without rounding error [19, 27], we use it to make a fast realization compute exactly what classical int8 matrix multiplication computes. Each token row is quantized to integer codes on its own, the algorithm mixes and cancels these codes, and the scales are applied only afterwards. Our certificate checks that

PREPRINT

the integer computation stays exact and that the scales can still be applied as in classical int8. Every realization that passes computes, bit for bit, the classical int8 operator with the same codes and scales, rescaled and accumulated in the same order (Figure 1C); since that operator is row-local, every certified realization inherits its prefix invariance. All 512 sign variants of two-level Strassen pass the certificate and compute the same output bits.

The certified realizations match classical int8 bit for bit while using 49 block multiplications instead of 64. Making them run faster than classical int8 is a separate task: Section 5 reports our first timings and leaves faster kernels to future work. Certification makes the choice between them a decision about cost alone: taking the saving no longer risks prefix invariance.

References (37)