SMA-Attention
Symmetric Mamba Attention — a dual-path attention module for multi-scale feature fusion.
Unlike standard attention where query and key come from the same source, SMA takes two distinct inputs (e.g., different temporal scales, modalities, or branches) and produces a single fused output. Both Q and K are generated through a shared Mamba state-space model — the symmetric design ensures neither input path is privileged.
Key Features
- Symmetric Q/K via Mamba: A single shared Mamba layer processes both inputs. The selective state-space mechanism captures long-range dependencies that standard projections miss.
- Fused Value Projection: V1 and V2 are merged via
concat(V1+V2, V1*V2)— capturing both additive and multiplicative cross-path interactions. - Sigma-Modulated Attention: Element-wise gating
sigma(Q) * sigma(K)^Tmodulates attention logits, enabling dimension-aware soft-thresholding. - Multiple Residual Paths: Residual connections at Q/K, V fusion, and final output ensure stable gradient flow.
Installation
pip install sma-attention
Note: This package depends on
mamba-ssm, which requires a CUDA-compatible GPU and CUDA toolkit. See mamba-ssm installation guide for details.
Quick Start
import torch
from sma_attention import SymmetricMambaAttention
# B=batch, D=feature_dim, N=sequence_length
x1 = torch.randn(2, 128, 60) # e.g., high-frequency component
x2 = torch.randn(2, 128, 60) # e.g., low-frequency component
sma = SymmetricMambaAttention(d_model=128, n_heads=4)
output = sma(x1, x2) # shape: (2, 128, 60)
API Reference
SymmetricMambaAttention
SymmetricMambaAttention(
d_model: int, # feature dimension
n_heads: int, # number of attention heads
d_state: int = 16, # Mamba state dimension
d_conv: int = 4, # Mamba conv kernel size
expand: int = 2, # Mamba inner expansion factor
)
| Parameter | Description |
|---|---|
d_model |
Feature dimension (must be divisible by n_heads) |
n_heads |
Number of attention heads |
d_state |
Mamba SSM state expansion factor |
d_conv |
Mamba 1D convolution kernel width |
expand |
Inner dimension multiplier for Mamba blocks |
forward(x1, x2)
| Argument | Shape | Description |
|---|---|---|
x1 |
(B, D, N) |
First input (e.g., one temporal scale) |
x2 |
(B, D, N) |
Second input (e.g., another temporal scale) |
| Returns | (B, D, N) |
Fused output |
Architecture
The figure above illustrates the processing flow:
- Inputs: Two paths
x₁andx₂(e.g., adjacent scales in a circular topology), both shape(B, D, N) - Symmetric Q/K: Shared Mamba SSM with residual connections generates query from
x₁and key fromx₂ - Dual-Path Value: Independent linear projections → fusion via
concat(sum, product)→ linear projection - Multi-Head Reshape: Standard head splitting for attention computation
- Sigma Modulation:
σ(Q)·σ(K)ᵀelement-wise gating modulates attention logits before softmax - Output: Weighted V aggregation + average residual from both inputs
Requirements
- Python >= 3.10
- PyTorch >= 2.0
- einops >= 0.6
- mamba-ssm >= 2.0 (CUDA required)
License
MIT
Metadata
Release files for sma-attention 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sma_attention-0.1.1.tar.gz | 7.2 kB | Without provenance | Details for sma_attention-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sma_attention-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for sma_attention-0.1.1-py3-none-any.whl |
Total release size: 13.4 kB
Release files / sma_attention-0.1.1.tar.gz
| Download URL | sma_attention-0.1.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5adce217b34a4d13f59d1dc39d54d6b123f50e0505ed9102dd9fd336394ecfa9
|
|
BLAKE2b-256 checksum How to use checksums |
82fbb522dfab551b640644324fc3ba6ca91baad81a9e235df75c38f61d619ba9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / sma_attention-0.1.1-py3-none-any.whl
| Download URL | sma_attention-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e98246a69c4385d5fc2497cd58b7d493be306548ffe88ce12260480bbe6f25d
|
|
BLAKE2b-256 checksum How to use checksums |
21c43dc0b470bb2e9fce99985d6b2b73ace8f79ab99a4b76da4a42a37b137ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for sma-attention 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.