Unified Attention: single projection replacing Q/K/V with 67% fewer parameters
Project description
Unified Attention
One projection replaces Q, K, V. 67% fewer attention parameters.
Standard self-attention uses three separate weight matrices (W_Q, W_K, W_V) to project the same input. Unified Attention uses one. The output splits into three functional bands that serve as query, key, and value. The bands form naturally during training through amplitude and phase differentiation in the weight matrix.
from uattn import UnifiedAttention
attn = UnifiedAttention(dim=528, num_heads=4)
y = attn(x) # [batch, seq, 528] -> [batch, seq, 528]
Install
pip install uattn
From source:
pip install git+https://github.com/ReinforceAI/unified-attention.git
For FA3 (Hopper, 1.57x faster):
pip install uattn[fa3]
Why
Attention routes tokens to each other. The MLP transforms them. In parameter-constrained models, every byte spent on routing is a byte not spent on computation. Unified Attention cuts the routing budget:
| Standard Q/K/V | Unified | |
|---|---|---|
| Attention projection params | 3d² | d² |
| Share of layer params | ~33% | ~18% |
| Compressed attention bytes (16MB model) | 5.10 MB | 2.82 MB |
| Compressed MLP bytes (16MB model) | 10.21 MB | 12.70 MB |
Results
Validated on OpenAI Parameter Golf (16MB artifact, FineWeb):
| Setting | BPB | vs Standard SOTA |
|---|---|---|
| 10-min record (8xH100) | 1.1412 | Rank 7, only novel architecture in top 10 |
| 1-hr unlimited (8xH100) | 1.1088 | Beats all submissions on both leaderboards |
Also tested at small scale (484K params, TinyStories): 9.58 perplexity, matching models 2-4x larger.
Usage
Standalone (owns its own weights)
from uattn import UnifiedAttention
attn = UnifiedAttention(
dim=528, # must be divisible by 3
num_heads=4, # heads for multi-head attention
rope_base=10000.0, # RoPE base frequency
seeking_gain_init=0.5,# per-head query scaling
rope_fraction=1.0, # fraction of head_dim for RoPE
)
x = torch.randn(batch, seq_len, 528)
y = attn(x) # uses internal W_unified and W_out
With external weight banks (for Muon optimizer)
# Weights stored in contiguous 3D banks for batched optimization
unified_bank = nn.Parameter(torch.randn(K, d, d))
output_bank = nn.Parameter(torch.randn(K, d, d//3))
attn = UnifiedAttention(dim=d, num_heads=4, output_proj=False)
y = attn(x, unified_w=unified_bank[k], output_w=output_bank[k])
Check backend
from uattn import backend
print(backend()) # 'fa3', 'fa2', or 'sdpa'
How It Works
# Standard: 3 separate projections
q = W_q @ x; k = W_k @ x; v = W_v @ x
# Unified: 1 projection, 3 bands
unified = W_unified @ x
seeking, offering, content = unified.split(d//3, dim=-1)
RoPE is applied to seeking and offering bands only. Position affects routing, not content.
For FA3 (Hopper): head_dim is zero-padded to the nearest multiple of 8 before the kernel call and sliced back after. Padded zeros contribute nothing to dot products. Mathematically lossless.
Citation
@misc{deshwal2026yocto,
title={Attention Fields: Unified Projections for Efficient Language Models},
author={Deshwal, Viraj},
year={2026},
url={https://github.com/ReinforceAI/yocto},
howpublished={\url{https://github.com/ReinforceAI/unified-attention}}
}
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uattn-0.1.0.tar.gz.
File metadata
- Download URL: uattn-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5a4324d5661d339cd549b37f17cc2f7efe32cf67ca2f30674e161c7fb85bbbd
|
|
| MD5 |
ce378caec50304a7fdab83933c8dc946
|
|
| BLAKE2b-256 |
b1cadaaa69dea94741f0cea0d03f7499a062e0e081ed28f616ca1df995ba663d
|
File details
Details for the file uattn-0.1.0-py3-none-any.whl.
File metadata
- Download URL: uattn-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5417f9b6b057f5a183d01f1f8762b189b7baba00793983bdc7922bbe276c9e69
|
|
| MD5 |
8e40cecd7c178f276db85c525e78a01c
|
|
| BLAKE2b-256 |
16eddc2e345cce2b59072e0028f1aa7c6bec7e3769c1700a7b6d4db053643a49
|