Fast Hadamard Transform in CUDA, with a PyTorch interface
Features:
- Support fp32, fp16, bf16, for dimension up to 32768.
- Implicitly pad with zeros if dimension is not a power of 2.
Installation
git clone https://github.com/Dao-AILab/fast-hadamard-transform.git fast-hadamard-transform
cd fast-hadamard-transform
pip install -v .
How to use
from fast_hadamard_transform import hadamard_transform
def hadamard_transform(x, scale=1.0):
"""
Arguments:
x: (..., dim)
scale: float. Multiply the output by this number.
Returns:
out: (..., dim)
Multiply each row of x by the Hadamard transform matrix.
Equivalent to F.linear(x, torch.tensor(scipy.linalg.hadamard(dim))) * scale.
If dim is not a power of 2, we implicitly pad x with zero so that dim is the next power of 2.
"""
Speed
Benchmarked on A100, for not too small batch size, compared to memcpy (torch.clone), which is a lower bound for the time taken as we'd need to read inputs from GPU memory and write output to GPU memory anyway.
| Data type | Dimension | Time taken vs memcpy |
|---|---|---|
| fp16/bf16 | <= 512 | 1.0x |
| 512 - 8192 | <= 1.2x | |
| 16384 | 1.3x | |
| 32768 | 1.8x | |
| fp32 | <= 8192 | 1.0x |
| 16384 | 1.1x | |
| 32768 | 1.2x |
Metadata
Release files for tokenspeed-fast-hadamard-transform 1.1.0.post20260310
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 153.0 MB
Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
7ad767f97ab649ae108e0e5b22d9d428ea84f0a232efeb5cf1fbfdafa096e7d0
|
|
BLAKE2b-256 checksum How to use checksums |
391ed41d2af24a146d72f493cfe9688caaf523e6f60f1803f9c01b1cce6128fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp313-cp313-manylinux_2_28_aarch64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp313-cp313-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
e20daf925e179c8387639bc14e2ef509c6eda0d34073e545d814c3b650e35955
|
|
BLAKE2b-256 checksum How to use checksums |
0ee703f0ab2a4d7ba323de5f91fe7f4e6d0f25ad2fcaeae40f7ca3298c5f414b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
4ad277a0df2e3f67bd141f62de347b810852e5acb0dc35b5c21c9ccc119b3867
|
|
BLAKE2b-256 checksum How to use checksums |
b26be30345f7a9c7f16d644f78910dc217a76db06765de9618ecb372f53395ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp312-cp312-manylinux_2_28_aarch64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp312-cp312-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
75c2de7978f6ad2174ad7223300291fe5692f8c527a3f748f677cfca6b53d85a
|
|
BLAKE2b-256 checksum How to use checksums |
3ed9de7d14b97dd1ecf25ee494dd9a98c5ff48ee2d064eb83b0d6d152ffd3650
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
c32ed7ffd989fa57aebe1e701ea0b0fa35021cae57db139829c838ac16542fc8
|
|
BLAKE2b-256 checksum How to use checksums |
e464a4467d751968d5c1c0b7047ea5fe9b5fdc1c89b11bb0cf3e9cb37f7a3132
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp311-cp311-manylinux_2_28_aarch64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp311-cp311-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
28e525d819969a85f08f0d735945b4ae49e1c680a55fa3cf78dcac63b9247521
|
|
BLAKE2b-256 checksum How to use checksums |
9c36db80cb16b38cebec2ca9cb8b43038c3faf8f2783c15702e7e953ebe72182
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
5bab932d5c50f5a15ad899bd136a4b448beff3a3e3a2fb900f24682e45ce1529
|
|
BLAKE2b-256 checksum How to use checksums |
b0fca38ee858e3a0f9974ef5e175f5dea915d7a96e1f74489310ca24778aa22e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp310-cp310-manylinux_2_28_aarch64.whl
| Download URL | tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp310-cp310-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 19.1 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
d78f01263a64b9c06776cc485e9c38f5cec9abdb530a9dbb21fa05262a05cd38
|
|
BLAKE2b-256 checksum How to use checksums |
0c55cd154d02329b52add98eec0157b6d1b9b5724fea6adf1790c391feac4c87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logSecurity for tokenspeed-fast-hadamard-transform 1.1.0.post20260310
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 8 files in this release have been uploaded with provenance metadata.
Attestation for tokenspeed_fast_hadamard_transform-1.1.0.post20260310-cp313-cp313-manylinux_2_28_x86_64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.