{"id":26821,"library":"causal-conv1d","title":"causal-conv1d","description":"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.","status":"active","version":"1.6.1","language":"python","source_language":"en","source_url":"https://github.com/Dao-AILab/causal-conv1d","tags":["conv1d","causal","cuda","pytorch","state-space-models","mamba"],"install":[{"cmd":"pip install causal-conv1d","lang":"bash","label":"PyPI installation (CUDA required at runtime)"}],"dependencies":[{"reason":"Core dependency; provides tensor types and CUDA support","package":"torch","optional":false}],"imports":[{"note":"Not a submodule; direct import from package top-level.","wrong":"from causal_conv1d.causal_conv1d import causal_conv1d_fn","symbol":"causal_conv1d_fn","correct":"from causal_conv1d import causal_conv1d_fn"},{"note":"CausalConv1d class never existed; use CausalConv1dFn.","wrong":"from causal_conv1d import CausalConv1d","symbol":"CausalConv1dFn","correct":"from causal_conv1d import CausalConv1dFn"}],"quickstart":{"code":"import torch\nfrom causal_conv1d import causal_conv1d_fn\n\nx = torch.randn(2, 64, 128, device='cuda')\nweight = torch.randn(64, 3, device='cuda')  # depthwise, kernel_size=3\nbias = torch.randn(64, device='cuda')\nout = causal_conv1d_fn(x, weight, bias, activation='silu')\nprint(out.shape)  # torch.Size([2, 64, 128])","lang":"python","description":"Basic usage: apply causal depthwise conv1d on CUDA tensor."},"warnings":[{"fix":"Update calls: use activation='silu' (or None) and remove dims from kwargs.","message":"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.","severity":"breaking","affected_versions":">=1.4.0"},{"fix":"Move tensors to CUDA: x = x.cuda() before calling causal_conv1d_fn.","message":"The kernel only supports CUDA. Passing CPU tensors will raise a RuntimeError. Always ensure inputs are on CUDA device.","severity":"gotcha","affected_versions":"all"},{"fix":"Verify weight shape: weight.shape should be (C, K) where C is channels and K is kernel size (odd).","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"Change import to: from causal_conv1d import causal_conv1d_fn","message":"The old import path causal_conv1d.causal_conv1d_interface is deprecated since v1.2.0. Use causal_conv1d directly.","severity":"deprecated","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure weight is 2D: weight = weight.view(C, K) or torch.randn(C, K, device='cuda').","cause":"Weight tensor is not 2D (e.g., shape (C,) or (1,C,K)).","error":"AssertionError: Number of dimensions of weight tensor must be 2."},{"fix":"Cast bias to same dtype as input: bias = bias.to(x.dtype).","cause":"Input tensor is float32 but bias is float64 or vice versa.","error":"RuntimeError: Input type (float) and bias type (double) should be the same."},{"fix":"Run torch.cuda.is_available() to verify CUDA. If insufficient memory, reduce batch size or sequence length.","cause":"CUDA device not initialized or out of memory. Can also happen if PyTorch was compiled without CUDA.","error":"RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED"},{"fix":"Upgrade: pip install --upgrade causal-conv1d. Ensure CUDA toolkit is available at install time.","cause":"Installed version is too old (<1.0.0) or wrong package (e.g., installed from source without compiling CUDA).","error":"ImportError: cannot import name 'causal_conv1d_fn' from 'causal_conv1d'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}