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_cu12-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl (402.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu12-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (419.4 MB view details)

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

subquadratic_ops_torch_cu12-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl (402.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu12-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (419.3 MB view details)

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

subquadratic_ops_torch_cu12-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl (402.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu12-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (419.3 MB view details)

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

subquadratic_ops_torch_cu12-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl (402.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

subquadratic_ops_torch_cu12-0.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (419.3 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_cu12-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu12-0.2.1-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 fd00c987026c832be084c62a1ffd11be89c8750abc8c2007b5be847b485b1a94
MD5 4cb86e3a48dada7c8049f3181ef9c733
BLAKE2b-256 2b042400141169f249b1b5ab151790b3c93bf6e621048cf54c63cd38618e4358

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu12-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_cu12-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 019ca9dcf935217c6f39814e68c5565f66a271c12789761687eee236f201bd9b
MD5 9ebd2ba0f02687b94c723aeece6c0f9e
BLAKE2b-256 01be7d671f11de953409371b2909ff4d56cee1690dba5d538a26d38c9eaa02f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu12-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 319b0fc410e3faa966d8ab05608aa4a9486fccda1d8ab4e83346421fa53e8bad
MD5 7aa65ea973f11fa1d0018c39f7e48e21
BLAKE2b-256 372089e9ef5b1e28904a864e17409e0f8df7fd28b73acae8a94b88e301f9c4a3

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu12-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_cu12-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee90a930835b2eee5403532731e54d63659579ca3b0bf09fbd47dc9a6ba76d2b
MD5 7eb15d4bc893a1a00b2d992342a817ca
BLAKE2b-256 293f5f2927773316c09d45d2771725b6414a5e0bdc24db902ad51b7c9a097dc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu12-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9d9f68cd797dd19221dd5bab081dc73b6b025d1827f3405d033841c5710ee6cd
MD5 29797bbf365e112d248bb336ed544c78
BLAKE2b-256 793bd4ae0b84b0ad6a59f413d4258344fc2319d6b4607b69a69a428888a258c4

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu12-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_cu12-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df475180c89b6706fefa65d60395daee7e9f09aa7115cb6e9e161908b39efedd
MD5 ada7ab33f7cc17e52be62615f46fe74f
BLAKE2b-256 7a13a36682b43c615981788aab27f8ec1a1f1c7fff9ab360cb521ec7bc65db01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subquadratic_ops_torch_cu12-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b0b1d2ee705e1aea5882f9474f3f4f74d72823f4190187b9c73cdca05eff330c
MD5 64e6ba888060f17524132f187ac60465
BLAKE2b-256 7ab4af801be2dbef9100bb895d08f5b6769c44e55c2027b010c04be7eaa3f162

See more details on using hashes here.

File details

Details for the file subquadratic_ops_torch_cu12-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_cu12-0.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2d0eed323d27879dda702159fd37a6ac42f2669e7c6caf5c11188072bf32ebc
MD5 5bca2887e76559776ae0eed1ad845f57
BLAKE2b-256 5c91d05287435d516f8235153a0131c1ee71a3bcd77c2ae514ca12e064559073

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