virajdeshwal commited on
Commit
f52bbda
Β·
1 Parent(s): 1c51ca5

release: Qwen3.6-35B-A3B Spiral 3-bit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.gguf filter=lfs diff=lfs merge=lfs -text
37
+ *.spiralcb filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen3.6-35B-A3B
4
+ base_model_relation: quantized
5
+ language:
6
+ - en
7
+ pipeline_tag: text-generation
8
+ library_name: spiral
9
+ tags:
10
+ - spiral
11
+ - quantization
12
+ - int3
13
+ - kv-cache-compression
14
+ - apple-silicon
15
+ - metal
16
+ - gguf
17
+ - llama-cpp
18
+ - qwen
19
+ - qwen3.6
20
+ - moe
21
+ - deltanet
22
+ ---
23
+
24
+ # Qwen3.6-35B-A3B Spiral
25
+
26
+ **Geometric compression of Qwen3.6-35B-A3B.** 3.5 bits per weight. 7.1Γ— K-cache compression. +0.113 nats vs bf16 on wikitext-2. Runs at 23–24 tok/s on Apple M2 Max.
27
+
28
+ This is a Spiral-compressed version of [Qwen/Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B) β€” the hybrid MoE + DeltaNet architecture from Qwen, compressed via Walsh-Hadamard rotation and Lloyd-Max INT3 weights with product-quantized K cache.
29
+
30
+ ![Qwen3.6-35B-A3B Spiral release results](spiral_release_slide.svg)
31
+
32
+ ## Quality
33
+
34
+ Cross-method perplexity comparison on H100, identical methodology (HF AutoTokenizer, 131,008 wikitext-2 tokens, same NLL formula across all methods):
35
+
36
+ | Method | Bits/weight | Disk size | NLL (nats/token) | Gap vs bf16 |
37
+ |---|---|---|---|---|
38
+ | bf16 (reference) | 16.0 | 67.0 GB | 1.8968 | β€” |
39
+ | unsloth Q8_0 | 8.5 | 34.4 GB | 1.8962 | βˆ’0.0006 |
40
+ | unsloth Q4_K_XL | 5.2 | 20.8 GB | 1.8976 | +0.0008 |
41
+ | **Spiral 3-bit (this model)** | **3.5** | **14.2 GB** | **2.0101** | **+0.1133** |
42
+
43
+ Spiral is **1.46Γ— smaller than Q4_K_XL** for +0.11 nats of additional perplexity β€” practically invisible in generation.
44
+
45
+ ## KV cache compression
46
+
47
+ Spiral additionally compresses the K cache via product quantization (256 codewords Γ— 4-dim subspaces). Unlike weight quantization, KV compression is online β€” every token at inference time encodes through PQ on write and decodes on read.
48
+
49
+ | Method | bytes / token | K compression | Combined K+V |
50
+ |---|---|---|---|
51
+ | f16 (default for Q8_0, Q4_K_XL, bf16) | 20,480 | 1Γ— | 1Γ— |
52
+ | **Spiral PQ K + f16 V** | **11,680** | **7.1Γ—** | **1.75Γ—** |
53
+
54
+ At 1M context, this saves 8.6 GiB β€” the difference between fitting on a 64 GB Mac or not.
55
+
56
+ ## Total memory at 1M context
57
+
58
+ Weights + KV cache for Qwen3.6-35B-A3B:
59
+
60
+ | Method | Total at 1M | Fits 96 GB Mac? | Fits 64 GB Mac? |
61
+ |---|---|---|---|
62
+ | **Spiral 3-bit** | **25.6 GiB** | βœ“ comfortable | βœ“ comfortable |
63
+ | Q4_K_XL | 40.8 GiB | βœ“ | tight |
64
+ | Q8_0 | 54.4 GiB | tight | βœ— |
65
+ | bf16 | 87.0 GiB | βœ— | βœ— |
66
+
67
+ Add ~1 GiB compute scratch for realistic peak.
68
+
69
+ ## Files in this repo
70
+
71
+ | File | Size | Purpose |
72
+ |---|---|---|
73
+ | `qwen36-35b-a3b.gguf` | 14.0 GB | Quantized weights (INT3 + rotation) |
74
+ | `qwen36-35b-a3b-codebooks.spiralcb` | 11 MB | PQ codebooks + rotation seeds |
75
+ | `README.md` | β€” | This model card |
76
+ | `spiral_release_slide.svg` | 14 KB | Results visualization |
77
+
78
+ **Both the GGUF and the `.spiralcb` file are required.** The codebooks contain the Walsh-Hadamard rotation parameters and PQ codebook centroids β€” they are loaded at inference time alongside the weights.
79
+
80
+ ## Quick start (Apple Silicon)
81
+
82
+ Spiral runs via a custom build of `llama.cpp` with Metal kernels for fused PQ flash attention.
83
+
84
+ ### Install
85
+
86
+ ```bash
87
+ brew install reinforceai/spiral/spiral
88
+ ```
89
+
90
+ ### Run
91
+
92
+ ```bash
93
+ spiral-chat --model qwen-36-35b-spiral
94
+ ```
95
+
96
+ The first run downloads this repo's files. Subsequent runs use the local cache.
97
+
98
+ ### Manual download
99
+
100
+ ```bash
101
+ hf download Reinforce-ai/Qwen3.6-35B-A3B-Spiral \
102
+ qwen36-35b-a3b.gguf qwen36-35b-a3b-codebooks.spiralcb \
103
+ --local-dir ./models/spiral-35b/
104
+ ```
105
+
106
+ Then point `spiral-chat` at the local directory.
107
+
108
+ ## Performance (Apple M2 Max)
109
+
110
+ | Configuration | Decode | Prefill |
111
+ |---|---|---|
112
+ | PQ KV + flash attention | 23–24 tok/s | 80 tok/s |
113
+ | f16 KV | 36 tok/s | β€” |
114
+
115
+ PQ KV trades ~30% decode speed for 7.1Γ— K compression. For long-horizon agent tasks where context capacity is the binding constraint, the trade is favorable. Switch with `-ctk f16` at the CLI.
116
+
117
+ ## How it works
118
+
119
+ Spiral applies multi-pass block Walsh-Hadamard rotation to weights before INT3 quantization. The rotation makes weight distributions near-Gaussian with equalized variance across all dimensions β€” outlier channels (the primary source of quantization error) vanish under rotation. Lloyd-Max scalar quantization in the rotated space is then optimal.
120
+
121
+ For the K cache, product quantization with learned codebooks compresses each 4-dim subspace independently into 8-bit codes. A fused Metal kernel decodes PQ codes, applies RoPE, and computes attention in a single pass β€” no intermediate decompressed tensor is materialized.
122
+
123
+ For the hybrid Qwen3.6-35B-A3B architecture (10 full attention layers + 30 DeltaNet linear attention layers, 256 MoE experts with 8 active per token), Spiral applies weight compression uniformly across all layer types, with KV compression specific to the 10 attention layers (DeltaNet has no KV cache).
124
+
125
+ Full method documentation, source, and reproduction scripts: https://github.com/ReinforceAI/spiral
126
+
127
+ ## Methodology
128
+
129
+ The +0.1133 nats gap is measured with rigorous cross-method protocol on H100:
130
+
131
+ - HuggingFace AutoTokenizer applied to wikitext-2-raw-v1 validation, **single tokenizer source of truth** for all four methods
132
+ - 64 sequences Γ— 2048 tokens = 131,008 tokens
133
+ - bf16 and Spiral evaluated via PyTorch `F.cross_entropy`
134
+ - Q8_0 and Q4_K_XL evaluated via `llama-cpp-python` with **pre-tokenized inputs** (logits_all=True) β€” the GGUF tokenizer is never invoked, eliminating tokenizer mismatch as a confound
135
+ - All numbers from the same H100 pod, same eval session
136
+
137
+ The eval script `eval_cross_method.py` is included in the [GitHub repo](https://github.com/ReinforceAI/spiral) for independent reproduction.
138
+
139
+ ## Limitations
140
+
141
+ - Apple Silicon focus. CUDA kernels not yet shipped β€” Spiral models on Linux/CUDA require fp16 fallback for inference. Mac is the production target.
142
+ - PQ KV cache is currently K-only (V stays at fp16). Full K+V PQ is in development; would extend the 1.75Γ— combined compression toward 7.1Γ—.
143
+ - Brew formula installs a custom `llama.cpp` build with Spiral kernels. Standard llama.cpp builds will not load the SPIRAL_3BIT or SPIRAL_PQ2 GGUF types.
144
+ - This is a research preview. APIs may change before 1.0.
145
+
146
+ ## Citation
147
+
148
+ ```bibtex
149
+ @misc{spiral2026,
150
+ title={Spiral: Geometric Compression of Rotated Transformers},
151
+ author={Deshwal, Viraj},
152
+ year={2026},
153
+ publisher={ReinforceAI},
154
+ url={https://github.com/ReinforceAI/spiral}
155
+ }
156
+ ```
157
+
158
+ ## License
159
+
160
+ Inference engine: Based on llama.cpp (MIT)
161
+ Spiral compression framework: ReinforceAI
162
+ Model weights: Apache 2.0 (inherited from Qwen3.6-35B-A3B)
qwen36-35b-a3b-codebooks.spiralcb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b90f087b69b73905798ae0ee0ad55e474d6bab6c69da5908b96b383e1c123bb
3
+ size 11190440
qwen36-35b-a3b.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a56745857654215b8bbc30afd64d7fde6d28727932d8c1f9159b9ca5a978b6b
3
+ size 15281584160
spiral_release_slide.svg ADDED