Skip to main content

FP64-accurate matrix multiplication from BF16 hardware via Ozaki Extract in JAX

Project description

ozaki-jax

FP64-accurate matrix multiplication built from BF16 GEMMs using Ozaki Extract in JAX.

For square test matrices, the default implementation uses 36 BF16 GEMMs and reaches about 1e-16 relative error against FP64 reference results.

Usage

import numpy as np
from ozaki_jax import matmul

A = np.random.randn(256, 256)
B = np.random.randn(256, 256)
C = matmul(A, B)

Without JAX runtime dependency:

from ozaki_jax import matmul_numpy
C = matmul_numpy(A, B)

Method summary

Given C = A @ B:

  1. Split A and B into n_slices magnitude-controlled slices with Extract.
  2. Compute BF16-derived GEMM pairs where i + j <= n_slices - 1.
  3. Rescale and accumulate products in FP64.

With n_slices = 8, this keeps 8 * 9 / 2 = 36 slice-pair GEMMs.

Exactness condition

For BF16 slice values bounded by 2^p - 1, exact FP32 accumulation requires:

K * (2^p - 1)^2 < 2^24

In the default BF16 setting (p = 7), this gives K <= 1040.

Notes on rho for BF16

For FP64 source values (m1=53) and BF16 storage (m2=8), storage exactness requires:

rho >= m1 + 1 - m2 = 46

The accumulation constraint is also at least 46 for typical K values in this project, so the implementation uses rho=46 as the lower bound.

Limitations

  • K <= 1040 for the default unblocked exactness condition.
  • JAX on CPU does not represent TPU BF16 execution behavior.
  • Blocking for larger K is not implemented.

Benchmarks

python benchmarks/precision.py
python benchmarks/tpu_validate.py

References

  • Mukunoki, D., Ogita, T., & Imamura, T. (2020). "DGEMM using Tensor Cores, and Its Accurate and Reproducible Versions." ISC High Performance 2020.
  • Mukunoki, D. (2025). "Ozaki Scheme-Based Accurate Matrix Multiplication on FP8 Tensor Cores." arXiv:2508.00441
  • Ozaki, K., Ogita, T., Oishi, S., & Rump, S.M. (2012). "Error-Free Transformations of Matrix Multiplication by Using Fast Routines of Matrix Multiplication and Its Applications." Numerical Algorithms, 59(1).

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ozaki_jax-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ozaki_jax-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file ozaki_jax-0.1.0.tar.gz.

File metadata

  • Download URL: ozaki_jax-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ozaki_jax-0.1.0.tar.gz
Algorithm Hash digest
SHA256 472ad8519e2839ba33cbab2959b0824761db48e391dafbc9076f4b4fbb9d4b6c
MD5 21075213a006e33af3b4d6ac09b83824
BLAKE2b-256 7680f451838554b9aa08c618f045626177b929f043e62a76163784f1edec0d93

See more details on using hashes here.

File details

Details for the file ozaki_jax-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ozaki_jax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ozaki_jax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bafdd2acb6010a9f4a8d01baf61f595cae508c31b1c4f0dec2eda237a29fc31
MD5 a7b7dfd1824a7487816a748e96f0e2c7
BLAKE2b-256 94900e008d080f61d30be30e67801ad4bda271a7d0f14cc122572f9dcd7a7486

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page