Skip to main content

subquadratic_ops_torch

Introduction

subquadratic_ops_torch provides CUDA kernels for subquadratic operations, e.g. long and short convolution. It contains PyTorch bindings to optimized kernels.

Installation

Please install using pip install subquadratic-ops-torch-cu[12,13]

Documentation

For detailed usage information of the kernels, please refer to the docstrings in their respective functions.

Usage

You can import the library from python:

import subquadratic_ops_torch as subq

Kernels are primarily exposed as function calls underlying torch.ops, which also provide a lower-level interface as torch.library operators. This allows you to export models using these operations via torch.export and run inference on them using TensorRT.

Support and Feedback

Please contact the developers for any issues you might encounter.

Requirements

  • CUDA-compatible NVIDIA GPU (Ampere+)
  • CUDA Toolkit 12.0 or higher
  • Python 3.11-3.13

Modules

B2B CausalConv1d

Operation

Back-to-back causal conv1d for the Striped Hyena 2 architecture used in the Evo2 model. The operation is performed in a causal manner, meaning each position only attends to previous positions in the sequence. In code terms,

in_dim = 8192

width_proj = 8
width_mixer = 128

dtype = torch.float32

class Conv1DModel(nn.Module):
    def __init__(self, in_dim, width, dtype, skip_bias=False):
        super(Conv1DModel, self).__init__()

        self.conv = nn.Conv1d(
            in_dim,
            in_dim,
            width,
            padding=width - 1,
            groups=in_dim,
            bias=False,
            dtype=dtype,
            device="cuda:0",
        )
        self.width = width
        self.weight = self.conv.weight.reshape(-1, width)
        if skip_bias:
            self.skip_bias = nn.Parameter(torch.zeros(in_dim, dtype=dtype, device="cuda:0").reshape(1, -1, 1))
        else:
            self.skip_bias = None

    def forward(self, x):
        seqlen = x.shape[-1]
        out = self.conv(x)
        return out[..., :seqlen]

def model(x, conv1d_proj, conv1d_mixer):
    xv = conv1d_proj(x)
    z = xv[:,1::3, :] * xv[:, 2::3, :]
    y = conv1d_mixer(z) + conv1d_mixer.skip_bias * z
    return y * xv[:, ::3, :]
x = torch.randn(batch_size, 3*in_dim, seq_dim)
conv1d_proj = Conv1DModel(3*in_dim, width_proj)
conv1d_mixer = Conv1DModel(in_dim, width_mixer, True)

y = model(x, conv1d_proj, conv1d_mixer)

is equivalent to,

weight_proj = torch.randn(3*in_dim, width_proj).to(dtype)
weight_mixer = torch.randn(in_dim, width_mixer).to(dtype)
skip_bias = torch.randn(in_dim).to(dtype)

b2b_causal_conv1d(x, weight_proj, weight_mixer, skip_bias)

Supported Kernel Sizes for B2B Causal Conv1d

Kernel Type Supported Sizes
Projection 2, 3, 4, 8, 16, 32
Mixer 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256

CausalConv1d

Causal conv1d: the convolution operation is performed in a causal manner, meaning each position only attends to previous positions in the sequence. In code terms,

in_dim = 8192
width = 8
dtype = torch.float32
model = nn.Conv1d(
            in_dim,
            in_dim,
            width,
            padding=width - 1,
            groups=in_dim,
            bias=False,
            dtype=dtype,
            device="cuda:0",
        )
y = model(x)

is equivalent to,

weight = torch.randn((in_dim, width))
causal_conv1d(x, weight)

Supported Kernel Sizes for Causal Conv1d

Kernel Type Supported Sizes Channel Last
CausalConv1d <= 256 False
CausalConv1d <= 128 (64 fp64) True

FFT Conv1d

Non-causal 1D convolution using real FFT. Supports sequences up to FFT size 8192.

from subquadratic_ops_torch.fft_conv1d import fft_conv1d

batch_size, dim, seq_len, filter_dim = 64, 128, 512, 1024
x = torch.randn(batch_size, dim, seq_len, device="cuda")
weight = torch.randn(dim, filter_dim, device="cuda")
y = fft_conv1d(x, weight)  # shape: (64, 128, 512)

FFT CausalConv1d

FFT Causal Conv1d: the convolution operation is performed in a causal manner, meaning each position only attends to previous positions in the sequence. It uses real FFT and IFFT instead of direct summation for convolution. In code terms,

in_dim = 8192
width = 1024
dtype = torch.float32
weight = torch.randn(1, in_dim, width)
def model(x, w):
    fft_size = x.shape[-1] * 2
    xf = torch.fft.rfft(x, n=fft_size, dim=-1)
    wf = torch.fft.rfft(w, n=fft_size, dim=-1)
    return torch.fft.irfft(xf*wf, n=fft_size, dim=-1)[..., :x.shape[-1]]

y = model(x, weight)

is equivalent to,

weight = torch.randn((in_dim, width))
y = fft_causal_conv1d(x, weight)

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.

subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl (207.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (224.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl (207.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (224.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl (207.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (224.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl (207.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (224.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 cd8d7622c0ff990ee48ef2647377f21c5cc6cdaad42e71df6b806fa142ac42bc
MD5 f6da23232c00538c66809c874af99fb2
BLAKE2b-256 b1626b07257a5e7adb6e17737c66ca167e1e31bc6f25f1012ace4353684b93e9

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 151ad1320c2de1173755bd72ccbff6f17fc10788dc153cfdcd5fcdc7f306b0f4
MD5 9e74ccc8d347b1998bd5ecb4a99c4292
BLAKE2b-256 e42cb1702a9b46a521a5aa4fd71c95c814e86a6f1a4efb07a8311694e815aa14

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 40afc7e26a56599775a7f4c90ad43d7999ad2de5369e214a4fa43daf410146a0
MD5 4ccadd3a253bcd66f648cf442c555a2e
BLAKE2b-256 6651b2dca62656d51fe5b8d27c4fe14b58ba7547c111afe5562aff52983f08ff

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f08aee03040b6bf528c5a1983ef6c560ad4b71622cf0a432c3ec490800bea3d
MD5 0ac9ad31c20c043d9cc8b143fca44db5
BLAKE2b-256 a70c62fcf3271a2f4502fca8f1ac4e02e356c72fd4e72d31ae500a72b6b3ccde

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 874c16433e2d85f9a5cf530eb2f2856da4dabdfa6b835b544be0eed70069dee3
MD5 f9afb1a94327211ed6a75dd619c14b68
BLAKE2b-256 57cd7f4ba2a90dbca1f1e4f9e2317e3ad07e6d5958b37042ddb31f4d8677d91f

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 042210db8b26a5d9703a311a9fd408fc701cdfc85aea4500295684a06672564b
MD5 2b577e322c291b536b291f438c7bf8a0
BLAKE2b-256 7dd138ba057713b61cda7a00dea5ee5e1b99b295ee8ed5b639a1656c05abe42d

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ad28a0168e55267a2c348a33723a4470c62f6597af409b4bb3b8544a6cce1ab0
MD5 13ccf624b68557096c9de8018a6fa210
BLAKE2b-256 7fb482b1af30d88c839c26631fea8453ea007d673aae876976e2a8f9c565a3ce

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu13-0.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b52168509a3e03bdf298bd377eec9077f888efe8e870ebb669e4820afab6539d
MD5 b390ddfb24b6bb479831f49410b2a5e3
BLAKE2b-256 fc8a29debacb6ed8b38dea2e4b20d3339e88748b59be4685a3509a6ec16b848e

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 Sentry Error logging StatusPage Status page