Add pipeline tag, GitHub link and improve model card

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +30 -43
README.md CHANGED
@@ -1,6 +1,12 @@
1
  ---
 
 
 
 
 
2
  language: en
3
  license: mit
 
4
  tags:
5
  - deepseek-v4
6
  - retrieval
@@ -8,27 +14,24 @@ tags:
8
  - sparse-attention
9
  - long-context
10
  - flashmemory
11
- datasets:
12
- - ruler
13
- - longmemeval
14
- - longbench-v2
15
- - mrcr
16
- paper: https://huggingface.co/papers/2606.09079
17
  ---
18
 
19
  # FlashMemory DS-V4 Retriever
20
 
21
- A lightweight retriever that sparsifies **DeepSeek-V4 CSA KV-cache**. Given a
22
- decode-token hidden state, it predicts which compressed-K chunks the next
23
- ~64 tokens will attend to β€” keeping only those on GPU, offloading the rest.
 
 
24
 
25
- In downstream evaluation it matches or beats full-attention baseline on
26
- reasoning-heavy long-context tasks (**RULER, LongMemEval, LongBench V2**)
27
- while reducing KV-cache usage by **~85–90%**. Precise needle-retrieval tasks
28
- require an additional threshold-fallback mechanism (not in this release).
29
 
30
  ## Quick start
31
 
 
 
32
  ```bash
33
  pip install torch safetensors
34
  python demo.py --ckpt weights/flashmemory_ds_v4.safetensors
@@ -43,20 +46,26 @@ model = FlashMemoryRetriever.from_checkpoint(
43
  "weights/flashmemory_ds_v4.safetensors", device="cuda"
44
  )
45
 
46
- # hidden: [B, 4096] decode hidden state
47
- # compressed_k: [B, N, 132] uint8 CSA keys
48
- # positions: [B] int64 token positions
 
 
 
49
 
50
- scores = model.ensemble(hidden, compressed_k, positions, mode="max") # [B, N]
51
- keep = model.select_topk(hidden, compressed_k, positions, top_k=512) # boolean mask
 
 
 
 
52
  ```
53
 
54
  **`compressed_k` format:** each chunk = 128 bytes `float8_e4m3` values + 4 bytes `float32` scale. See `make_mock_compressed_k()` in `demo.py`.
55
 
56
  ## Architecture
57
 
58
- 3-layer joint model (`l10`, `l12`, `l20`), 128 heads, 2048 LoRA rank. Per-layer
59
- sigmoid scores are ensembled (`max` or `mean`) per chunk.
60
 
61
  ```
62
  hidden [B,4096] β†’ q-proj β†’ RoPE(YaRN) β†’ Hadamard β†’ q [B,128,128]
@@ -66,28 +75,6 @@ compressed_k β†’ FP8 dequant β†’ k [B,N,128]
66
  score = sigmoid( Ξ£( relu(k @ qα΅€) Β· fused_w ) ) ∈ [0,1]
67
  ```
68
 
69
- ## Toy inference reference
70
-
71
- `toy_flashmemory_inference.py` illustrates how the retriever drives memory
72
- recall during decode: every 64 steps it re-scores all chunks, and unselected
73
- ones are masked from attention (equivalent to "not recalled to GPU").
74
-
75
- ```bash
76
- python toy_flashmemory_inference.py --ckpt weights/flashmemory_ds_v4.safetensors
77
- ```
78
-
79
- > The decoder is a few toy layers with random weights β€” it is **not** a real
80
- > DeepSeek-V4. The retriever, scoring math, and decode-time control flow are real.
81
-
82
- ## Files
83
-
84
- | File | Purpose |
85
- |------|---------|
86
- | `retriever.py` | `FlashMemoryRetriever` model (torch-only, self-contained) |
87
- | `demo.py` | minimal demo with mock inputs |
88
- | `toy_flashmemory_inference.py` | toy sparse-decode loop |
89
- | `weights/flashmemory_ds_v4.safetensors` | trained weights (~510 MB) |
90
-
91
  ## Citation
92
 
93
  If you use FlashMemory in your research, please cite:
@@ -106,4 +93,4 @@ If you use FlashMemory in your research, please cite:
106
 
107
  ## License
108
 
109
- MIT
 
1
  ---
2
+ datasets:
3
+ - ruler
4
+ - longmemeval
5
+ - longbench-v2
6
+ - mrcr
7
  language: en
8
  license: mit
9
+ pipeline_tag: feature-extraction
10
  tags:
11
  - deepseek-v4
12
  - retrieval
 
14
  - sparse-attention
15
  - long-context
16
  - flashmemory
 
 
 
 
 
 
17
  ---
18
 
19
  # FlashMemory DS-V4 Retriever
20
 
21
+ A lightweight retriever that sparsifies **DeepSeek-V4 Compressed-Sparse-Attention (CSA) KV-cache**. Given a decode-token hidden state, it predicts which compressed-K chunks the next ~64 tokens will attend to β€” keeping only those on GPU, offloading the rest.
22
+
23
+ This model is the Neural Memory Indexer presented in [FlashMemory-DeepSeek-V4: Lightning Index Ultra-Long Context via Lookahead Sparse Attention](https://huggingface.co/papers/2606.09079).
24
+
25
+ Detailed code and inference scripts can be found on GitHub: [libertywing/FlashMemory-Deepseek-V4](https://github.com/libertywing/FlashMemory-Deepseek-V4).
26
 
27
+ ## Performance
28
+
29
+ In downstream evaluation, it matches or beats the full-attention baseline on reasoning-heavy long-context tasks (**RULER, LongMemEval, LongBench V2**) while reducing KV-cache usage by **~85–90%**. Precise needle-retrieval tasks require an additional threshold-fallback mechanism (not in this release).
 
30
 
31
  ## Quick start
32
 
33
+ To use this model, you will need the `retriever.py` file from the [official repository](https://github.com/libertywing/FlashMemory-Deepseek-V4).
34
+
35
  ```bash
36
  pip install torch safetensors
37
  python demo.py --ckpt weights/flashmemory_ds_v4.safetensors
 
46
  "weights/flashmemory_ds_v4.safetensors", device="cuda"
47
  )
48
 
49
+ # hidden: [B, 4096] decode-token hidden state
50
+ # comp_k: [B, N, 132] uint8 compressed CSA keys
51
+ # positions: [B] int64 token positions
52
+
53
+ # Per-layer sigmoid scores: {"l10": [B,N], "l12": [B,N], "l20": [B,N]}
54
+ per_layer = model(hidden, comp_k, positions)
55
 
56
+ # Cross-layer ensemble (mode="max" or "mean")
57
+ scores = model.ensemble(hidden, comp_k, positions, mode="max") # [B, N]
58
+
59
+ # Boolean keep mask
60
+ keep = model.select_topk(hidden, comp_k, positions, top_k=512) # top-K
61
+ keep = model.select_topk(hidden, comp_k, positions, threshold=0.5) # threshold
62
  ```
63
 
64
  **`compressed_k` format:** each chunk = 128 bytes `float8_e4m3` values + 4 bytes `float32` scale. See `make_mock_compressed_k()` in `demo.py`.
65
 
66
  ## Architecture
67
 
68
+ 3-layer joint model (`l10`, `l12`, `l20`), 128 heads, 2048 LoRA rank. Per-layer sigmoid scores are ensembled (`max` or `mean`) per chunk.
 
69
 
70
  ```
71
  hidden [B,4096] β†’ q-proj β†’ RoPE(YaRN) β†’ Hadamard β†’ q [B,128,128]
 
75
  score = sigmoid( Ξ£( relu(k @ qα΅€) Β· fused_w ) ) ∈ [0,1]
76
  ```
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  ## Citation
79
 
80
  If you use FlashMemory in your research, please cite:
 
93
 
94
  ## License
95
 
96
+ MIT