causal-conv1d
raw JSON → 1.6.1 verified Mon Apr 27 auth: no python
Causal depthwise 1D convolution CUDA kernel with PyTorch interface, commonly used as a building block for state-space models like Mamba. Current version: 1.6.1. Active development; breaking API changes between v1.x versions.
pip install causal-conv1d Common errors
error AssertionError: Number of dimensions of weight tensor must be 2. ↓
cause Weight tensor is not 2D (e.g., shape (C,) or (1,C,K)).
fix
Ensure weight is 2D: weight = weight.view(C, K) or torch.randn(C, K, device='cuda').
error RuntimeError: Input type (float) and bias type (double) should be the same. ↓
cause Input tensor is float32 but bias is float64 or vice versa.
fix
Cast bias to same dtype as input: bias = bias.to(x.dtype).
error RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED ↓
cause CUDA device not initialized or out of memory. Can also happen if PyTorch was compiled without CUDA.
fix
Run torch.cuda.is_available() to verify CUDA. If insufficient memory, reduce batch size or sequence length.
error ImportError: cannot import name 'causal_conv1d_fn' from 'causal_conv1d' ↓
cause Installed version is too old (<1.0.0) or wrong package (e.g., installed from source without compiling CUDA).
fix
Upgrade: pip install --upgrade causal-conv1d. Ensure CUDA toolkit is available at install time.
Warnings
breaking In v1.4.0, the function signature changed: activation parameter must be passed as a string (e.g., 'silu') instead of None or torch.nn.SiLU. Also dims argument was removed. ↓
fix Update calls: use activation='silu' (or None) and remove dims from kwargs.
gotcha The kernel only supports CUDA. Passing CPU tensors will raise a RuntimeError. Always ensure inputs are on CUDA device. ↓
fix Move tensors to CUDA: x = x.cuda() before calling causal_conv1d_fn.
gotcha Weight tensor must be 2D (out_channels, kernel_size) for depthwise convolution. Using 1D or transposed dimensions causes silent shape errors or kernel launch failures. ↓
fix Verify weight shape: weight.shape should be (C, K) where C is channels and K is kernel size (odd).
deprecated The old import path causal_conv1d.causal_conv1d_interface is deprecated since v1.2.0. Use causal_conv1d directly. ↓
fix Change import to: from causal_conv1d import causal_conv1d_fn
Imports
- causal_conv1d_fn wrong
from causal_conv1d.causal_conv1d import causal_conv1d_fncorrectfrom causal_conv1d import causal_conv1d_fn - CausalConv1dFn wrong
from causal_conv1d import CausalConv1dcorrectfrom causal_conv1d import CausalConv1dFn
Quickstart
import torch
from causal_conv1d import causal_conv1d_fn
x = torch.randn(2, 64, 128, device='cuda')
weight = torch.randn(64, 3, device='cuda') # depthwise, kernel_size=3
bias = torch.randn(64, device='cuda')
out = causal_conv1d_fn(x, weight, bias, activation='silu')
print(out.shape) # torch.Size([2, 64, 128])