Skip to content

Panama FP32 matmul: first call in a JVM differs by an ULP from later calls (JIT-dependent reduceLanes order) #1261

Description

@michalharakal

Summary

On a fresh DirectCpuExecutionContext() the first dense FP32 matmul in a JVM process produces results that differ by 1 ULP (in ~37k of 153k elements for m=300, k=64, n=512) from every later call on the same context with the same inputs. After that first call the results are stable and independent of threading or schedule.

Observed while writing SKEEP-005 parity tests (DirectCpuExecutionContextScheduleTest): probe output

same-ctx twice diff=37355   (first call vs second call)
seq twice diff=0
par-vs-seq diff=0

Likely cause

PanamaVectorMatmulKernel reduces with FloatVector.reduceLanes(ADD), whose lane-reduction order is unspecified and differs between the interpreter/C1 fallback and the C2 intrinsic. The first call runs before the intrinsic is compiled.

Why it matters

  • Golden-token parity gates (*GoldenTokenParityTest in SKaiNET-transformers) assert exact llama.cpp text equality; a warm-up-dependent ULP can flip a greedy argmax.
  • Any test comparing two contexts must warm up first (the SKEEP-005 tests now do).

Options

  • Replace reduceLanes with an explicit fixed-order tree reduction (reduceLanesToLong-style) or accumulate into a vector and reduce with a deterministic scalar loop.
  • Document the property and add a warm-up helper for parity tests.

Not fixed in feature/skeep-005-schedules; the schedule tests warm up before comparing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompute-backendCompute backends and graphsskill:numericsPyTorch/NumPy/math background, no Kotlin required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions