Skip to content

AI Infrastructure

A Valid Matrix Product Can Score the Wrong Query–Vector Pairs

Compatible matrix dimensions establish a valid product, but the operand ranks determine which query–candidate pairs it scores. In PAIR-39, PyTorch 2.14's matmul rule reuses a two-row query matrix across two candidate batches, producing four scores: 2, 3, 5 and 7. The stipulated one-pair-per-batch request instead requires the identified pairs q0 with k0 and q1 with k1, whose scores are 2 and 7. A mean over all four describes a different population from the requested paired mean.

Technical contentPublished Updated

01

Read the matrix axes before assigning batch meaning

A dot product combines corresponding vector components into one score. A matrix product can form many such scores at once. Which vectors meet depends on the axes presented to the operation, rather than the names a supplier gives the input files.

PyTorch 2.14 documents matmul as using the final two dimensions for matrix multiplication in the matrix-batch case. Earlier dimensions are batch dimensions and are broadcast. A 2D operand contributes one matrix with no leading batch axis.

For Q shaped (n, d) and K shaped (b, d, 1), Q's n query rows are therefore reused for each of K's b batches. The result has shape (b, n, 1): each candidate batch receives a score from every query row. The d components are multiplied and summed within each score.

Here, n counts query rows and b counts candidate batches. Setting both lengths to 2 does not make them the same axis or establish a record-by-record pairing. Axis role follows the operand's rank and the operation's rules.

References: [M1]

02

PAIR-39 requests two identified pairs

Fictional PAIR-39 supplies queries q0 = (1, 0) and q1 = (0, 1), with candidates k0 = (2, 3) and k1 = (5, 7). The requested deliverable contains exactly two dot products: q0 with k0, and q1 with k1. The identities and that correspondence are explicit premises.

All components are dimensionless finite integers. The calculations below use exact arithmetic to explain pair membership; they are not observed framework outputs or a model evaluation.

In the broadcast comparison, Q is a 2D matrix with shape (2, 2). Its first row is q0 and its second row is q1. K is 3D with shape (2, 2, 1): batch 0 contains k0 as a two-entry column, and batch 1 contains k1 as a two-entry column. The first dimension of Q counts rows. The first dimension of K counts matrices.

03

The broadcast representation forms all four combinations

At candidate batch 0, the complete Q matrix multiplies the column k0. Its first row gives q0·k0 = 1×2 + 0×3 = 2. Its second row gives q1·k0 = 0×2 + 1×3 = 3. That batch contains both query rows, with scores 2 and 3.

At candidate batch 1, the same Q matrix multiplies k1. The two rows give q0·k1 = 1×5 + 0×7 = 5 and q1·k1 = 0×5 + 1×7 = 7. That batch contains scores 5 and 7.

The product's shape is (2, 2, 1). Reading by candidate batch, then query row, the four contributing pairs are (q0, k0), (q1, k0), (q0, k1) and (q1, k1). Only the first and last belong to the stipulated paired request.

All four scores are correct dot products. The discrepancy is the set of contributors: reusing both query rows in every candidate batch adds two combinations the paired request did not ask to summarize.

References: [M1]

PAIR-39: every score in the broadcast product
Candidate batchQuery rowContributing pairScoreIn the stipulated paired request?Source
00q0 with k02YesPlanning analysis
01q1 with k03NoPlanning analysis
10q0 with k15NoPlanning analysis
11q1 with k17YesPlanning analysis

Original fictional inputs and exact arithmetic. The table identifies output membership, not measured execution or application quality.

04

An explicit paired batch supports scores 2 and 7

Now consider a separately supplied representation of the same query values: Qpair has shape (2, 1, 2). Batch 0 contains the single row q0; batch 1 contains the single row q1. K remains shaped (2, 2, 1), with k0 in batch 0 and k1 in batch 1. The stipulated batch identities agree on both sides.

Each batch now multiplies a 1×2 query matrix by its corresponding 2×1 candidate matrix. Under matmul's documented batch rule, the result has shape (2, 1, 1). Batch 0 contains q0·k0 = 2, and batch 1 contains q1·k1 = 7.

These representations give the same query values different axis roles. In Q, they were rows of one matrix reused across candidates. In Qpair, they are separate batches, each containing one query row. For the declared request and explicit identity mapping, this second representation accounts for both required pairs.

References: [M1]

05

A no-broadcast contract still needs the right record order

PyTorch 2.14's bmm reference provides a useful comparison. It requires two 3D operands containing the same number of matrices, multiplies corresponding batch matrices and does not broadcast. Its documented shape relation is (b, n, m) with (b, m, p), returning (b, n, p).

Qpair and K fit that contract with two batches, one query row per batch and one candidate column per batch. Their corresponding matrix products are the same two mathematical scores derived above. The original 2D Q does not satisfy bmm's two-3D-input requirement.

That narrower shape contract cannot establish semantic correspondence. A hypothetical supplied query batch that places q1 first and q0 second still has shape (2, 1, 2). Against the unchanged K, it pairs q1 with k0, giving 3, and q0 with k1, giving 5. There are two scores and equal batch counts, yet neither pair matches the request.

Nor does the word bmm alone establish one scalar per batch: the matrix row and column counts also determine each batch's output. For PAIR-39, one row and one column supply that scalar shape. Correct shapes, documented operation behavior and the intended identities must agree.

References: [M2]

06

The mean belongs to the pairs actually included

The mean across all four broadcast scores is (2 + 3 + 5 + 7) / 4 = 17/4 = 4.25. Its population contains every query–candidate combination in PAIR-39. The requested paired mean is (2 + 7) / 2 = 9/2 = 4.5.

Both calculations are correct. Their numerators and denominators describe different score populations. No vector component or dot-product formula changed. The four-score return includes the two requested scores, but averaging the whole return does not preserve their two-score summary.

A supplier reporting a mean of 4.25 for this broadcast return has explained an all-combinations statistic. That number cannot answer a request for the mean of the two stipulated pairs. A report that gives only a scalar mean, without the included contributor pairs, leaves the population unresolved.

A separate buyer request for every query against every candidate could legitimately require all four scores and their mean. Broadcasting serves that requirement in this construction. The reader's decision depends on the requested pair set, rather than a general preference for fewer output values.

07

Accept the contributor mapping that answers the request

For PAIR-39's paired requirement, the supplied Qpair and K representation supports scores 2 and 7 because it identifies the intended query and candidate in each corresponding batch. The original Q and K representation supports four combinations. A valid product and equal first-axis lengths do not establish that it delivered one stipulated pair per record.

Ask the appointed software or data provider to connect the actual operand versions and operation to each axis's role, the identities at each batch or row position, and the contributors to the delivered scores. Then connect the reported statistic to the exact output entries it includes. A source-file identity list leaves a gap if the consumer receives a different ordering or rank.

This evidence lets the buyer distinguish three returns: every query against every candidate; the two requested corresponding pairs; or two scores whose batch identities remain unproven. Output counts help describe those returns, while the contributor mapping resolves which one answers the request.

The related Xarray guide explains label-based arithmetic pairing. The tensor-views guide explains how shape and storage sharing can differ. Those questions are useful at their respective handoffs; neither establishes the matrix product's query–candidate membership. This comparison holds the dot-product definition fixed and evaluates the delivered pairs.

08

Discuss physical installation when the equipment needs it

If the wider AI project also needs selected servers, storage or switches installed, Leviathan's related Rack-and-Stack & Colocation Installation service provides a route to discuss agreed mounting, physical IT cabling, labels and installation records. Use the project inquiry with a nonconfidential equipment list, rack layout, site requirements and connection outline to discuss scope and availability.

That inquiry concerns the physical installation. Tensor preparation, software implementation and acceptance of the score population remain with the appointed data and software owners.

References: [L1]

09Sources

Primary sources

  1. [M1]
    PyTorch 2.14: torch.matmulChecked 2026-10-21. The matrix-batch dimensionality rule distinguishes final matrix axes from leading broadcast batch axes. Applicable here to a 2D query matrix with a 3D candidate operand and to the separate two-3D-operand comparison.
  2. [M2]
    PyTorch 2.14: torch.bmmChecked 2026-10-21. Requires two 3D inputs with equal matrix-batch counts and defines corresponding batch products without broadcasting. This shape contract does not establish the identities or ordering of the supplied records.
  3. [L1]
    Leviathan Systems: Rack-and-Stack & Colocation InstallationChecked 2026-10-21. Defines physical equipment mounting, agreed IT cabling, labels and installation records. Supports the equipment-installation inquiry.

Contact

Does the selected equipment need physical installation?

Share a nonconfidential equipment, rack, site and IT connection outline to discuss installation scope, handoff records and availability.