Skip to main content

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.post20260810

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for tokenspeed-fast-hadamard-transform 1.1.0.post20260810
File Actions
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ ARM64 Details for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_aarch64.whl

Total release size: 154.2 MB

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_x86_64.whl
Size 19.3 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3d3668018f6fbf4053dae4c02856bf20eb43ccfd371cb1c27be1dd1182a2e21e
BLAKE2b-256 checksum
How to use checksums
4f4e69af1931aac46e8fa46a745b101d14c8fb0de7d6da505f216a2880e68cc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_aarch64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp313-cp313-manylinux_2_28_aarch64.whl
Size 19.3 MB
Tags CPython 3.13 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
9943220b401077c186acfee75119092e7a16a95670f5f710b4b8f99af13cbcca
BLAKE2b-256 checksum
How to use checksums
e66b58ada2080fcbc42195c37eb17b8ec8720d301c005c4d97ed5388aaa35ebc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_x86_64.whl
Size 19.3 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0f5b1fd0461058fa466ebdfea1eb99aeb7c6e981fe992c66485b1ea331a71995
BLAKE2b-256 checksum
How to use checksums
9693ad7b61f437277f1bc0eb4902fa77fc3cb8af1e1fcd0e02b71ebeed4eb6f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_aarch64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp312-cp312-manylinux_2_28_aarch64.whl
Size 19.3 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
22d49783ce9316e25aa415ad71df4f3aa962b636e1e9a45b8a46746e57cb3073
BLAKE2b-256 checksum
How to use checksums
750306a9374ae220cbae34939f3e78ef31bd9c3064ae14f85e8ee08ab28a19b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_x86_64.whl
Size 19.3 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b7034c074778d7dd1e2af5a0b5c4039144b5c1565433befdcf308e25ca595aef
BLAKE2b-256 checksum
How to use checksums
ac87967a65091c63eab5e1c06e717680d42d3feca7041d85a44e91a3fc1f0187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_aarch64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp311-cp311-manylinux_2_28_aarch64.whl
Size 19.3 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
ea28f5724e62094f1a3592064447113c7ddb01b9832fcc75af7de10852c3af2e
BLAKE2b-256 checksum
How to use checksums
0ccb1ea4e963ea17b2f42bfc9d40fa44ab489b64d8d70cb7a9508e3c5c4846ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_x86_64.whl
Size 19.3 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
35c0c7c55f13d70272bf5fa22b2be741bfe6fca40742218e1f4009acd9199f8b
BLAKE2b-256 checksum
How to use checksums
69e218baa829133fd621db7f05f37bb1bacc66161ab28ae0a6989813e20c55a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Release files / tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_aarch64.whl

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20260810-cp310-cp310-manylinux_2_28_aarch64.whl
Size 19.3 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
a55b51a174408b57ab6535f52140348ee76f1c624e2b9ce191070b057b39d2f1
BLAKE2b-256 checksum
How to use checksums
41f45503e67f78024b5c70d039d48d0260d533fd71654312317c46d54891bcd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 11, 2026.

Transparency log

Security for tokenspeed-fast-hadamard-transform 1.1.0.post20260810

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.

Select from 8 files

Attestation for tokenspeed_fast_hadamard_transform-1.1.0.post20260810-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 Aug 11, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page