Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -2,134 +2,85 @@
|
|
| 2 |
license: mit
|
| 3 |
tags:
|
| 4 |
- attention
|
|
|
|
| 5 |
- efficient-attention
|
| 6 |
- number-theory
|
| 7 |
- calabi-yau
|
| 8 |
-
-
|
| 9 |
-
|
| 10 |
-
- benchmark
|
| 11 |
-
datasets: []
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
A
|
| 17 |
|
| 18 |
$$S_{20}(n) = \sum_{k=0}^{n} \binom{n}{k}^4 \binom{n+k}{k}$$
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
| 38 |
-
|---
|
| 39 |
-
|
|
| 40 |
-
|
|
| 41 |
-
|
|
| 42 |
-
|
|
| 43 |
-
|
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
---
|
| 71 |
-
|
| 72 |
-
## Method: Global SDPA Patching (Forward Hook Option A)
|
| 73 |
-
|
| 74 |
-
```python
|
| 75 |
-
import torch
|
| 76 |
-
import torch.nn.functional as F
|
| 77 |
-
from math import comb
|
| 78 |
-
|
| 79 |
-
# 1. Build S20 decay sequence
|
| 80 |
-
def s20(n): return sum(comb(n, k)**4 * comb(n+k, k) for k in range(n+1))
|
| 81 |
-
_S20 = [s20(d) for d in range(18)]
|
| 82 |
-
|
| 83 |
-
# 2. Vectorized log-bias matrix
|
| 84 |
-
def build_s20_log_bias(seq_len, device="cuda", dtype=torch.float16):
|
| 85 |
-
base = float(_S20[0])
|
| 86 |
-
weights = [base/float(x) if x > 0 else 0.0 for x in _S20] + [0.0]
|
| 87 |
-
dv = torch.tensor(weights, dtype=torch.float32, device=device)
|
| 88 |
-
idx = torch.arange(seq_len, device=device)
|
| 89 |
-
dist = (idx.unsqueeze(0) - idx.unsqueeze(1)).abs().clamp(max=len(_S20))
|
| 90 |
-
decay = dv[dist]
|
| 91 |
-
log_bias = torch.log(decay.clamp(min=1e-30))
|
| 92 |
-
causal = torch.tril(torch.ones(seq_len, seq_len, device=device))
|
| 93 |
-
log_bias = log_bias * causal + (1 - causal) * (-1e9)
|
| 94 |
-
return log_bias.unsqueeze(0).unsqueeze(0).to(dtype)
|
| 95 |
-
|
| 96 |
-
# 3. Monkey-patch F.scaled_dot_product_attention
|
| 97 |
-
_original_sdpa = F.scaled_dot_product_attention
|
| 98 |
-
_bias_cache = {}
|
| 99 |
-
|
| 100 |
-
def patched_sdpa(q, k, v, attn_mask=None, dropout_p=0.0, is_causal=False, **kw):
|
| 101 |
-
L = q.shape[-2]
|
| 102 |
-
if L not in _bias_cache:
|
| 103 |
-
_bias_cache[L] = build_s20_log_bias(L, q.device, q.dtype)
|
| 104 |
-
bias = _bias_cache[L][:, :, :L, :k.shape[-2]]
|
| 105 |
-
if attn_mask is not None:
|
| 106 |
-
attn_mask = attn_mask + bias
|
| 107 |
-
else:
|
| 108 |
-
attn_mask = bias
|
| 109 |
-
return _original_sdpa(q, k, v, attn_mask=attn_mask, dropout_p=dropout_p, **kw)
|
| 110 |
-
|
| 111 |
-
F.scaled_dot_product_attention = patched_sdpa
|
| 112 |
-
# Now ANY model using SDPA will have S20 decay injected automatically
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
---
|
| 116 |
-
|
| 117 |
-
## Reproducibility
|
| 118 |
|
| 119 |
```bash
|
| 120 |
-
# Clone and run on any CUDA GPU
|
| 121 |
git clone https://github.com/xaviercallens/Mirror-Map-Sieve.git
|
| 122 |
-
cd Mirror-Map-Sieve
|
| 123 |
-
pip install
|
| 124 |
-
python
|
| 125 |
```
|
| 126 |
|
| 127 |
## Citation
|
| 128 |
|
| 129 |
```bibtex
|
| 130 |
-
@
|
| 131 |
author = {Callens, Xavier},
|
| 132 |
-
title = {
|
| 133 |
year = {2026},
|
| 134 |
url = {https://huggingface.co/callensxavier/s20-attention-kernel},
|
| 135 |
doi = {10.5281/zenodo.20747943}
|
|
|
|
| 2 |
license: mit
|
| 3 |
tags:
|
| 4 |
- attention
|
| 5 |
+
- positional-encoding
|
| 6 |
- efficient-attention
|
| 7 |
- number-theory
|
| 8 |
- calabi-yau
|
| 9 |
+
- negative-result
|
| 10 |
+
datasets:
|
| 11 |
+
- callensxavier/cy-sieve-attention-benchmark
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# CY-Sieve Attention Kernel — a falsifiable experiment (NEGATIVE result)
|
| 15 |
|
| 16 |
+
A positional-attention bias derived from the weight-5 Apéry-like binomial sum
|
| 17 |
|
| 18 |
$$S_{20}(n) = \sum_{k=0}^{n} \binom{n}{k}^4 \binom{n+k}{k}$$
|
| 19 |
|
| 20 |
+
whose holonomic structure is a Calabi–Yau **3-fold** period (an order-4 MUM block;
|
| 21 |
+
the geometry fixes the long-range decay slope $\log\lambda = 3.762$ and curvature
|
| 22 |
+
$\beta = 2$). The engineering bet: generate the positional bias *on the fly* from
|
| 23 |
+
the order-4 recurrence, costing **O(L)** HBM instead of an **O(L²)** table.
|
| 24 |
+
|
| 25 |
+
> **Code:** [GitHub — Mirror-Map-Sieve](https://github.com/xaviercallens/Mirror-Map-Sieve)
|
| 26 |
+
> · **Math paper:** [Zenodo 10.5281/zenodo.20747943](https://doi.org/10.5281/zenodo.20747943)
|
| 27 |
+
> · **Benchmark data:** [callensxavier/cy-sieve-attention-benchmark](https://huggingface.co/datasets/callensxavier/cy-sieve-attention-benchmark)
|
| 28 |
+
|
| 29 |
+
## ⚠️ Honest result (2026-06-22, NVIDIA L4): the quality gate KILLED it
|
| 30 |
+
|
| 31 |
+
This card **corrects** an earlier version that claimed "zero overhead" and implied
|
| 32 |
+
a win. Those numbers came from an invalid method (monkey-patching the bias into a
|
| 33 |
+
*frozen* pretrained model, which collapses every alternative scheme equally). The
|
| 34 |
+
correct test — **training small GPTs from scratch**, one per positional scheme, on
|
| 35 |
+
real WikiText-2 — gives:
|
| 36 |
+
|
| 37 |
+
| scheme | ppl @512 (train) | @1024 (2×) | @2048 (4×) |
|
| 38 |
+
|---|---|---|---|
|
| 39 |
+
| **learned-absolute** | **4.22** | 12.10 | 20.82 |
|
| 40 |
+
| ALiBi | 10.74 | 11.73 | 11.35 |
|
| 41 |
+
| **sliding-window** | **4.99** | **5.07** | **5.03** |
|
| 42 |
+
| CY-Sieve τ-ladder | 11.33 | 12.31 | 12.05 |
|
| 43 |
+
| CY-Sieve τ=128 | 6.80 | 7.12 | 7.00 |
|
| 44 |
+
| CY-Sieve τ=512 | 4.65 | 6.08 | 10.62 |
|
| 45 |
+
|
| 46 |
+
**Verdict: KILL (+10.15%).** Best CY-Sieve (4.65) vs best baseline (4.22) exceeds
|
| 47 |
+
the pre-committed >5% kill threshold; a plain **sliding window won outright**. The
|
| 48 |
+
geometry-fixed slope is too steep for a drop-in positional scheme.
|
| 49 |
+
|
| 50 |
+
## What *did* hold up
|
| 51 |
+
|
| 52 |
+
- **§4 kernel correctness — PASS.** The Triton kernel matches the NumPy reference
|
| 53 |
+
within FP16 tolerance (4/4 tests).
|
| 54 |
+
- **§6 memory claim — confirmed.** The on-the-fly bias reads **O(L)** bytes of HBM
|
| 55 |
+
vs **O(L²)** for a materialized table (**8192× less at L=16384**). *But* the
|
| 56 |
+
current unfused kernel is **~4–6× slower** than fused dense SDPA — a
|
| 57 |
+
memory-traffic win, **not** a latency win. Per the project's reporting rule,
|
| 58 |
+
with the quality gate failing, these numbers are **not** a contribution.
|
| 59 |
+
|
| 60 |
+
## Why publish a negative result?
|
| 61 |
+
|
| 62 |
+
Because a fast, correct kernel that degrades model quality is a *failed* kernel,
|
| 63 |
+
and saying so is the point. The Calabi–Yau geometry is a sound **prior** for the
|
| 64 |
+
bias shape, not the right **value** — pinning the attention slope to the
|
| 65 |
+
sequence's growth rate was the mistake. Redesign directions (learnable
|
| 66 |
+
geometry-initialized slope; exact-local-window + gentle-tail hybrid; β=2 ablation)
|
| 67 |
+
are in the [findings writeup](https://github.com/xaviercallens/Mirror-Map-Sieve/blob/main/docs/PHASE3_CYSIEVE_GPU_FINDINGS.md).
|
| 68 |
+
|
| 69 |
+
## Reproduce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
```bash
|
|
|
|
| 72 |
git clone https://github.com/xaviercallens/Mirror-Map-Sieve.git
|
| 73 |
+
cd Mirror-Map-Sieve
|
| 74 |
+
pip install -r 4_ai_hardware_attention/requirements-gpu.txt
|
| 75 |
+
python 4_ai_hardware_attention/run_gpu_phase.py # §4 parity + §5 quality + §6 perf
|
| 76 |
```
|
| 77 |
|
| 78 |
## Citation
|
| 79 |
|
| 80 |
```bibtex
|
| 81 |
+
@misc{callens2026cysieve,
|
| 82 |
author = {Callens, Xavier},
|
| 83 |
+
title = {CY-Sieve Attention: a Calabi--Yau positional bias and its negative quality result},
|
| 84 |
year = {2026},
|
| 85 |
url = {https://huggingface.co/callensxavier/s20-attention-kernel},
|
| 86 |
doi = {10.5281/zenodo.20747943}
|