Skip to main content

Fast Hadamard Transform in CUDA, with a PyTorch interface

Project description

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

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_aarch64.whl (19.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_aarch64.whl (19.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_aarch64.whl (19.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_aarch64.whl (19.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7d0dca4a4f75cb32f16008a22aedc711dab70704dc2c7a7a283b513b1e7da902
MD5 64fc6e65bf5b1db493d4e45db1881e2a
BLAKE2b-256 5f023d51933aab2b930dc3f224f077cd80d52500abc09f3b537770a356e12ee5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 587489e1c48fb8af78f6a2ebcd4410b4f7c5b3e50c89ce099d571c5bf4986a64
MD5 26c072c87d250281cbfb121998eccc5e
BLAKE2b-256 7309d3c5af15abbcd00314f67cc3d22ef3dc48856e06ee6b9f6513798885a97e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1273bf9873a7784b6f4023375ebc62679b5e6fed373128d2e81c0e66c1431c8d
MD5 feee5bc11f179b5d46d2704b61dbd6d3
BLAKE2b-256 2107853b6333f5d71041fe8820abd61ecfd23cd865d360367fd25b2d1972cab9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 afa476318573b4f20f3e61888654993eda425e67b404cd5a20c230a403cf20a6
MD5 cd0e1fb7ad1a254c6e5b6954230ac0e3
BLAKE2b-256 03ecab311a489416ecb298decf7d479318bc8318eeae3792030a583d6bfa2f51

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f778caa85800d3df6ad833ac126d4006b416bcfaacfe23960aefbc0962627d72
MD5 37687488607cae00582e58033460622c
BLAKE2b-256 a4415957b2e8826cdc728aae41fc280b9c409cc2f4ba7eb656108d6b3416aee9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c34fd7fe8a2a56e2067c886006de632b3e1f0d2e619ba4c7f401adc804d34fab
MD5 8fa1751421121d571dc94f32944cc6f3
BLAKE2b-256 e01bac94aa97ed941b8f1617bb13775c0a5f7ab8706155095e370825f1ea54b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 838cb544d814287df126864c612686d61359d4f964e3cdea8bd54beb3045dbb3
MD5 a2893296a603c46dad71041c90eec76e
BLAKE2b-256 36722bbe836a191faf9986c84d2a99f786ec46ce563b353df081f089d05c63f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7411f20c53d551855755f3b18e734981865e047d65e3216f07da66ef0546636a
MD5 59532c2cce0197da5f85aad7c2b4916c
BLAKE2b-256 6d18def90731236d467be34edd13374fab047fa143306133c3f4b9e9918aef34

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenspeed_fast_hadamard_transform-1.1.0.post20251110-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: tokenspeed-fast-hadamard-transform.yml on lightseekorg/tokenspeed-third-party

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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