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

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.post20251110
File Actions
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp313-cp313-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp313-cp313-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp312-cp312-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp312-cp312-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp311-cp311-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp311-cp311-manylinux_2_28_aarch64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp310-cp310-manylinux_2_28_x86_64.whl
tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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.post20251110-cp310-cp310-manylinux_2_28_aarch64.whl

Total release size: 153.0 MB

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
7d0dca4a4f75cb32f16008a22aedc711dab70704dc2c7a7a283b513b1e7da902
BLAKE2b-256 checksum
How to use checksums
5f023d51933aab2b930dc3f224f077cd80d52500abc09f3b537770a356e12ee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
587489e1c48fb8af78f6a2ebcd4410b4f7c5b3e50c89ce099d571c5bf4986a64
BLAKE2b-256 checksum
How to use checksums
7309d3c5af15abbcd00314f67cc3d22ef3dc48856e06ee6b9f6513798885a97e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
1273bf9873a7784b6f4023375ebc62679b5e6fed373128d2e81c0e66c1431c8d
BLAKE2b-256 checksum
How to use checksums
2107853b6333f5d71041fe8820abd61ecfd23cd865d360367fd25b2d1972cab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
afa476318573b4f20f3e61888654993eda425e67b404cd5a20c230a403cf20a6
BLAKE2b-256 checksum
How to use checksums
03ecab311a489416ecb298decf7d479318bc8318eeae3792030a583d6bfa2f51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
f778caa85800d3df6ad833ac126d4006b416bcfaacfe23960aefbc0962627d72
BLAKE2b-256 checksum
How to use checksums
a4415957b2e8826cdc728aae41fc280b9c409cc2f4ba7eb656108d6b3416aee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
c34fd7fe8a2a56e2067c886006de632b3e1f0d2e619ba4c7f401adc804d34fab
BLAKE2b-256 checksum
How to use checksums
e01bac94aa97ed941b8f1617bb13775c0a5f7ab8706155095e370825f1ea54b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
838cb544d814287df126864c612686d61359d4f964e3cdea8bd54beb3045dbb3
BLAKE2b-256 checksum
How to use checksums
36722bbe836a191faf9986c84d2a99f786ec46ce563b353df081f089d05c63f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

Download URL tokenspeed_fast_hadamard_transform-1.1.0.post20251110-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
7411f20c53d551855755f3b18e734981865e047d65e3216f07da66ef0546636a
BLAKE2b-256 checksum
How to use checksums
6d18def90731236d467be34edd13374fab047fa143306133c3f4b9e9918aef34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 29, 2026.

Transparency log

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

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.post20251110-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 Mar 29, 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