Transformers
GGUF
sparse-attention
approximate-nearest-neighbors
faiss
qwen3
long-context
conversational
Instructions to use datasysdev/ann-sparseattention with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use datasysdev/ann-sparseattention with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("datasysdev/ann-sparseattention", dtype="auto") - llama-cpp-python
How to use datasysdev/ann-sparseattention with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="datasysdev/ann-sparseattention", filename="gguf/Qwen3-4B-Instruct-2507-F16-ann-6layer-k128-v2.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use datasysdev/ann-sparseattention with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf datasysdev/ann-sparseattention:F16 # Run inference directly in the terminal: llama cli -hf datasysdev/ann-sparseattention:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf datasysdev/ann-sparseattention:F16 # Run inference directly in the terminal: llama cli -hf datasysdev/ann-sparseattention:F16
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf datasysdev/ann-sparseattention:F16 # Run inference directly in the terminal: ./llama-cli -hf datasysdev/ann-sparseattention:F16
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf datasysdev/ann-sparseattention:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf datasysdev/ann-sparseattention:F16
Use Docker
docker model run hf.co/datasysdev/ann-sparseattention:F16
- LM Studio
- Jan
- Ollama
How to use datasysdev/ann-sparseattention with Ollama:
ollama run hf.co/datasysdev/ann-sparseattention:F16
- Unsloth Studio
How to use datasysdev/ann-sparseattention with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for datasysdev/ann-sparseattention to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for datasysdev/ann-sparseattention to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for datasysdev/ann-sparseattention to start chatting
- Pi
How to use datasysdev/ann-sparseattention with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf datasysdev/ann-sparseattention:F16
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "datasysdev/ann-sparseattention:F16" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use datasysdev/ann-sparseattention with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf datasysdev/ann-sparseattention:F16
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default datasysdev/ann-sparseattention:F16
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use datasysdev/ann-sparseattention with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf datasysdev/ann-sparseattention:F16
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "datasysdev/ann-sparseattention:F16" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use datasysdev/ann-sparseattention with Docker Model Runner:
docker model run hf.co/datasysdev/ann-sparseattention:F16
- Lemonade
How to use datasysdev/ann-sparseattention with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull datasysdev/ann-sparseattention:F16
Run and chat with the model
lemonade run user.ann-sparseattention-F16
List all available models
lemonade list
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
base_model: Qwen/Qwen3-4B-Instruct-2507
|
| 6 |
+
tags:
|
| 7 |
+
- sparse-attention
|
| 8 |
+
- ann-attention
|
| 9 |
+
- distillation
|
| 10 |
+
- search-projection
|
| 11 |
+
- inference-optimization
|
| 12 |
+
library_name: pytorch
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# ann-sparseattention
|
| 16 |
+
|
| 17 |
+
Search projections for ANN-substituted attention on
|
| 18 |
+
[`Qwen/Qwen3-4B-Instruct-2507`](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507).
|
| 19 |
+
|
| 20 |
+
Code: [github.com/unixsysdev/ann-sparseattention](https://github.com/unixsysdev/ann-sparseattention)
|
| 21 |
+
|
| 22 |
+
## What's in this repo
|
| 23 |
+
|
| 24 |
+
Per-layer linear search projections `(W_Qs, W_Ks)` of shape `[2560, 64]`,
|
| 25 |
+
trained against the frozen base model's attention via contrastive +
|
| 26 |
+
distillation losses. At inference these produce 64-d "search vectors" that
|
| 27 |
+
let an off-the-shelf FAISS HNSW index pick the top-K keys to attend to,
|
| 28 |
+
replacing dense `O(L²)` attention with `O(L·K)` ANN-substituted attention.
|
| 29 |
+
|
| 30 |
+
Layers covered (pilot): `[4, 8, 12, 16, 20, 24]` — 6 of 36 layers, ~2M trainable params.
|
| 31 |
+
|
| 32 |
+
## Pilot results (intermediate, step 1000 / 2000)
|
| 33 |
+
|
| 34 |
+
| Step | Recall@K=128 | PPL gap (full vs ANN) |
|
| 35 |
+
|---|---|---|
|
| 36 |
+
| 500 | 47.4% | 1.21% |
|
| 37 |
+
| 1000 | 50.7% | 0.68% |
|
| 38 |
+
|
| 39 |
+
PPL gap is the primary signal — at <1% relative gap, the model's output
|
| 40 |
+
quality is preserved under ANN substitution. Final-checkpoint numbers and
|
| 41 |
+
the full recall@K curve over `K ∈ {64, 128, 256, 512}` will be added when
|
| 42 |
+
the 2K-step pilot completes.
|
| 43 |
+
|
| 44 |
+
## Files
|
| 45 |
+
|
| 46 |
+
| File | What |
|
| 47 |
+
|---|---|
|
| 48 |
+
| `search_step_1000.pt` | Search-projection state-dict + optimizer + scheduler at step 1000 (`~11 MB`) |
|
| 49 |
+
| `config.json` | Pilot hyperparams used for this checkpoint |
|
| 50 |
+
|
| 51 |
+
## Loading
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import torch
|
| 55 |
+
from transformers import AutoModelForCausalLM
|
| 56 |
+
from search_module import SearchProjectionModule # from the GitHub repo
|
| 57 |
+
|
| 58 |
+
base = AutoModelForCausalLM.from_pretrained(
|
| 59 |
+
"Qwen/Qwen3-4B-Instruct-2507",
|
| 60 |
+
dtype=torch.bfloat16,
|
| 61 |
+
device_map="auto",
|
| 62 |
+
attn_implementation="sdpa",
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
search = SearchProjectionModule(
|
| 66 |
+
d_model=2560, d_search=64,
|
| 67 |
+
layer_indices=[4, 8, 12, 16, 20, 24],
|
| 68 |
+
use_mlp=False,
|
| 69 |
+
).to(base.device).to(torch.bfloat16)
|
| 70 |
+
|
| 71 |
+
ckpt = torch.load("search_step_1000.pt", map_location="cpu")
|
| 72 |
+
search.load_state_dict(ckpt["search_module"])
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Use `inference.install_ann_attention(...)` (in the GitHub repo) to monkey-patch
|
| 76 |
+
the trained layers and run with FAISS HNSW retrieval at inference time.
|
| 77 |
+
|
| 78 |
+
## Training recipe
|
| 79 |
+
|
| 80 |
+
- Frozen base: Qwen3-4B-Instruct-2507 (36 layers, hidden 2560, GQA 32:8).
|
| 81 |
+
- Data: WikiText-103 raw, packed to 4K-token sequences.
|
| 82 |
+
- 2000 steps, batch 8, lr 1e-4 (cosine, 100-step warmup), AdamW.
|
| 83 |
+
- `α=β=1` (contrastive + KL distillation, both layers averaged).
|
| 84 |
+
- bf16 weights, fp32 loss math.
|
| 85 |
+
- SDPA attention (B200, no flash-attn package needed).
|
| 86 |
+
- Liger fused RMSNorm/SwiGLU/RoPE on the frozen base.
|
| 87 |
+
|
| 88 |
+
## License
|
| 89 |
+
|
| 90 |
+
The search projections are released under Apache-2.0 (matching the base model).
|