RaffaelloMolinari commited on
Commit
fdef2d8
·
verified ·
1 Parent(s): e8b5a40

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +322 -0
README.md ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: deepseek
4
+ license_link: https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-DSpark/blob/main/LICENSE
5
+ base_model: deepseek-ai/DeepSeek-V4-Flash-DSpark
6
+ language:
7
+ - en
8
+ - zh
9
+ tags:
10
+ - deepseek
11
+ - deepseek-v4
12
+ - moe
13
+ - mxfp4
14
+ - mla
15
+ - speculative-decoding
16
+ - dspark
17
+ - amd-npu
18
+ - xdna2
19
+ - ryzen-ai
20
+ - fst
21
+ pipeline_tag: text-generation
22
+ library_name: fst
23
+ ---
24
+
25
+ # Model Card for DeepSeek-V4-Flash-DSpark-FST
26
+
27
+ This is the **FaStar `.fst` container** of DeepSeek V4 Flash (DSpark), a 284-billion-parameter
28
+ Mixture-of-Experts model. It is a **format/quantization conversion** of
29
+ [`deepseek-ai/DeepSeek-V4-Flash-DSpark`](https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-DSpark),
30
+ not a retrained or fine-tuned model. The `.fst` format packs the model for execution on the
31
+ **AMD Ryzen AI 9 365 XDNA2 NPU** via the [FaStar](https://github.com/RaffaelloMolinari/FaStar)
32
+ inference engine, which spills the ~150 GB of expert weights across **SSD → RAM → NPU scratch
33
+ buffers** using *expert virtual memory*.
34
+
35
+ ## Model Details
36
+
37
+ ### Model Description
38
+
39
+ - **Developed by:** Original model by [DeepSeek-AI](https://github.com/deepseek-ai); `.fst`
40
+ conversion and FaStar inference engine by Raffaello Molinari.
41
+ - **Funded by [optional]:** Independent research/engineering project.
42
+ - **Shared by [optional]:** Raffaello Molinari.
43
+ - **Model type:** Decoder-only Transformer with Mixture-of-Experts (MoE) and Multi-head Latent
44
+ Attention (MLA), MXFP4-quantized, with a DSpark draft model for speculative decoding.
45
+ - **Language(s) (NLP):** English, Chinese (DeepSeek V4 is multilingual; primarily en/zh).
46
+ - **License:** DeepSeek Model License (inherited from the upstream checkpoint — see `license_link`).
47
+ - **Finetuned from model [optional]:** Not fine-tuned. Converted (quantized + repackaged) from
48
+ `deepseek-ai/DeepSeek-V4-Flash-DSpark`.
49
+
50
+ ### Model Sources [optional]
51
+
52
+ - **Repository:** https://github.com/RaffaelloMolinari/FaStar
53
+ - **Paper [optional]:** N/A (engineering showcase; see the upstream DeepSeek V4 / DSpark
54
+ materials).
55
+ - **Demo [optional]:** FaStar ships a built-in HTTP chat UI (`ds4_npu_engine --serve`); see the
56
+ repository README.
57
+
58
+ ## Uses
59
+
60
+ ### Direct Use
61
+
62
+ On-device research inference of DeepSeek V4 Flash on an AMD Ryzen AI 9 365 laptop NPU, using the
63
+ FaStar engine. Suitable for studying expert virtual memory, on-NPU MLA/FFN via IRON-generated
64
+ MLIR-AIE kernels, and consumer-NPU execution of a 284B model. Generation modes: one-shot,
65
+ interactive multi-turn, and a streaming web chat UI.
66
+
67
+ ### Downstream Use [optional]
68
+
69
+ As a reference format/checkpoint for porting other DeepSeek MoE models to the `.fst` container
70
+ and XDNA2 target, or as a substrate for experimenting with NPU kernel fusion, expert prefetch
71
+ strategies, and speculative-decoding acceptance tuning.
72
+
73
+ ### Out-of-Scope Use
74
+
75
+ - **Not a production serving system.** Decode throughput is ~0.05 tokens/sec (see
76
+ [Bias, Risks, and Limitations]); do not use for latency-sensitive or multi-user serving.
77
+ - **Not fine-tuned for any downstream task** and not safety-aligned — outputs are raw
78
+ completions from the converted base model.
79
+ - **Not for deployment on non-XDNA2 hardware.** The `.fst` container, sidecars, and bundled
80
+ `.xclbin` kernels target the AMD Ryzen AI NPU; they are not a drop-in replacement for the
81
+ upstream HuggingFace checkpoint on CPU/GPU.
82
+ - Do not use to generate misleading, harmful, or disallowed content; the upstream DeepSeek
83
+ acceptable-use terms apply.
84
+
85
+ ## Bias, Risks, and Limitations
86
+
87
+ - **Throughput: ~0.05 tokens/sec.** Decode is NPU-compute-bound per dispatch. Dispatch-count
88
+ reduction (op-replication packing) was proven correct on silicon but does not move tok/s; a
89
+ packed N-copy blob does N× the NPU compute. Reaching >1 tok/s requires IRON-level kernel
90
+ fusion (future work).
91
+ - **First-token latency.** The first token of a turn takes ~2 minutes (prefill of a 43-layer,
92
+ 284B model on this NPU); subsequent tokens stream at ~0.05 tok/s.
93
+ - **Numerical residual.** A recurrent hidden-state drift (~±40 RMS at deep layers) is intrinsic
94
+ to the MXFP4 / MLA numerics of this checkpoint — it is reproduced in a pure-PyTorch HF
95
+ ground-truth reference and is not a FaStar bug. Output remains coherent English with greedy
96
+ prefill argmax matching the HF ground truth.
97
+ - **Memory footprint.** ~150 GB of expert weights; requires 64 GB RAM and ~200 GB NVMe SSD via
98
+ expert paging. Expert cache thrash drops throughput if the working set exceeds RAM.
99
+ - **Inherited biases.** All biases, risks, and limitations of the upstream DeepSeek V4 Flash
100
+ base model carry over unchanged — this is a lossy-format conversion, not an alignment
101
+ intervention.
102
+
103
+ ### Recommendations
104
+
105
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations
106
+ inherited from the upstream DeepSeek model, the very low decode throughput, and the on-device
107
+ NPU-only target. Verify the DeepSeek license terms before redistribution or commercial use.
108
+
109
+ ## How to Get Started with the Model
110
+
111
+ Requirements: AMD Ryzen AI 9 365 (XDNA2 NPU), 64 GB RAM, ~200 GB NVMe SSD, Ubuntu 24.04 with
112
+ XRT, AIEBU, and the AMDXDNA driver.
113
+
114
+ ```bash
115
+ # Build the FaStar engine (CMake fetches header-only deps on first configure)
116
+ git clone https://github.com/RaffaelloMolinari/FaStar.git
117
+ cd FaStar
118
+ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
119
+ cmake --build build -j$(nproc)
120
+
121
+ # XRT lives in /usr on Ubuntu, not /opt/xilinx
122
+ export XILINX_XRT=/usr
123
+
124
+ # One-shot generation (greedy, deterministic):
125
+ ./build/ds4_npu_engine --model deepseek_v4_dspark.fst \
126
+ --prompt "Explain quantum computing" --tokens 128 --temp 0.0
127
+
128
+ # Speculative decoding with the DSpark draft model:
129
+ ./build/ds4_npu_engine --model deepseek_v4_dspark.fst --draft_model dspark_draft.fst \
130
+ --prompt "Hello world" --tokens 256
131
+
132
+ # Web UI / chat server:
133
+ ./build/ds4_npu_engine --model deepseek_v4_dspark.fst --serve --port 8080
134
+ ```
135
+
136
+ This HuggingFace repo must contain: the `.fst` file, its `.fst.hc` / `.fst.norm` /
137
+ `.fst.tid2eid` sidecars, `tokenizer.json`, and (for speculative decoding) `dspark_draft.fst`.
138
+ The `.fst.norm` and `.fst.hc` sidecars are required for coherent output.
139
+
140
+ ## Training Details
141
+
142
+ This model was **not trained** — it is a conversion of an existing checkpoint. Training details
143
+ below describe the *source* model and the conversion procedure.
144
+
145
+ ### Training Data
146
+
147
+ Inherited from the upstream `deepseek-ai/DeepSeek-V4-Flash-DSpark` checkpoint. See that model
148
+ card for the original training data.
149
+
150
+ ### Training Procedure
151
+
152
+ #### Preprocessing [optional]
153
+
154
+ Conversion to the `.fst` container (no weight fine-tuning):
155
+
156
+ ```bash
157
+ python3 scripts/fst_converter.py --model deepseek-ai/DeepSeek-V4-Flash-DSpark \
158
+ --output deepseek_v4_dspark.fst
159
+ ```
160
+
161
+ The `.fst` format stores a page-aligned config header, shared tensors (attention, router, norms)
162
+ in Q8_0 / BF16, and expert blocks as dense DS4 MXFP4 (17-byte blocks: 1 e8m0 scale + 16 FP4
163
+ nibbles). Verify integrity with `scripts/verify_fst.py` and `scripts/check_fst.py`.
164
+
165
+ #### Training Hyperparameters
166
+
167
+ - **Training regime:** N/A — not trained. Inference weights are MXFP4 (experts) + Q8_0/BF16
168
+ (shared tensors), dequantized to BF16 on-NPU for compute.
169
+
170
+ #### Speeds, Sizes, Times [optional]
171
+
172
+ - **Parameters:** ~284B (MoE).
173
+ - **Layers:** 43.
174
+ - **Experts:** 1376 total (~32 per layer) + 1 shared expert per layer, routed with top-k = 6
175
+ and hash routing over the first 3 layers (route_scale = 1.5).
176
+ - **Hidden size:** 4096; expert intermediate: 2048; vocabulary: 129,280.
177
+ - **Attention:** MLA — Q latent 1024, KV latent 512.
178
+ - **Decode throughput:** ~0.05 tokens/sec on Ryzen AI 9 365 NPU.
179
+ - **Prefill latency:** ~2 minutes for the first token of a turn.
180
+ - **Container size:** ~150 GB on disk (paged across SSD/RAM/NPU).
181
+
182
+ ## Evaluation
183
+
184
+ ### Testing Data, Factors & Metrics
185
+
186
+ #### Testing Data
187
+
188
+ Numerical correctness was verified against a pure-PyTorch HuggingFace ground-truth reference
189
+ (`hf_bos_ref.py`, `hf_gen_ref.py`) using the real DeepSeek weights, and qualitative coherence
190
+ was checked with free-form prompts (e.g. *"The importance of NPU…"*).
191
+
192
+ #### Factors
193
+
194
+ Per-layer cosine similarity vs. the HF reference (MLA projections, FFN GEMM, dequantization);
195
+ greedy prefill argmax token match; multi-token speculative-decoding acceptance rate; output
196
+ coherence over a 43-layer prefill.
197
+
198
+ #### Metrics
199
+
200
+ - GEMM / dequant cosine similarity vs. reference: ~0.998 (MLA), ~0.998 (FFN),
201
+ ~0.999998 (fused FFN gate, deterministic).
202
+ - Greedy prefill argmax: matches HF ground truth (e.g. argmax 671 = "The").
203
+ - Speculative-decoding acceptance: ~0.5–0.67 depending on configuration.
204
+
205
+ ### Results
206
+
207
+ The engine produces coherent English, and greedy prefill argmax matches the HF ground truth.
208
+ A deep-layer hidden-state residual (~±40 RMS at layer 42) is reproduced identically in the
209
+ pure-PyTorch HF reference and is intrinsic to this checkpoint's MXFP4/MLA numerics, not a
210
+ FaStar defect.
211
+
212
+ #### Summary
213
+
214
+ FaStar is mathematically faithful to the HuggingFace reference for this checkpoint, at the cost
215
+ of very low on-NPU throughput (~0.05 tok/s). Correctness holds; throughput is the open problem.
216
+
217
+ ## Model Examination [optional]
218
+
219
+ Per-layer cosine audits of MLA (`wq_a`, `wkv_a`, `wo_a`, output projection), FFN
220
+ (gate/up/down GEMM), and MXFP4 dequantization are built into the repository
221
+ (`scripts/fst_layer_benchmark.py`, `scripts/verify_fst_weights.py`,
222
+ `scripts/verify_fused_ffn.py`, plus `tools/` probes). These localize divergence to the
223
+ intrinsic deep-layer residual noted above.
224
+
225
+ ## Environmental Impact
226
+
227
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute)
228
+ presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). This is an
229
+ **inference-only** artifact; the dominant carbon cost was paid upstream during DeepSeek's
230
+ original training and is not attributable to this conversion.
231
+
232
+ - **Hardware Type:** AMD Ryzen AI 9 365 laptop (XDNA2 NPU), 64 GB RAM, NVMe SSD.
233
+ - **Hours used:** Conversion + on-device verification only (single laptop, no cluster training).
234
+ - **Cloud Provider:** None — entirely on-device.
235
+ - **Compute Region:** Local consumer hardware.
236
+ - **Carbon Emitted:** Negligible for this artifact (inference/conversion on one laptop);
237
+ upstream training emissions belong to DeepSeek-AI.
238
+
239
+ ## Technical Specifications [optional]
240
+
241
+ ### Model Architecture and Objective
242
+
243
+ Decoder-only MoE Transformer with Multi-head Latent Attention (Q latent 1024, KV latent 512),
244
+ per-layer shared + routed experts (top-k = 6, hash-routed over the first 3 layers with
245
+ route_scale = 1.5, swiglu_limit = 10), MXFP4 expert weights with e8m0 scales, Q8_0/BF16 shared
246
+ tensors, and a V4 KV-compressor that streams 512-dim compressed KV rows. A small DSpark draft
247
+ model enables speculative decoding. Objective: next-token text generation.
248
+
249
+ ### Compute Infrastructure
250
+
251
+ #### Hardware
252
+
253
+ - APU: AMD Ryzen AI 9 365 (XDNA2 NPU is the compute target; iGPU unused).
254
+ - RAM: 64 GB minimum (~54 GB peak RSS observed).
255
+ - Storage: NVMe SSD, ~200 GB free (experts live on SSD; read latency dominates miss cost).
256
+ - GPU: not required.
257
+
258
+ #### Software
259
+
260
+ - Ubuntu 24.04; XRT (Xilinx Runtime) at `/usr`; AIEBU assembler; AMDXDNA kernel driver.
261
+ - FaStar engine (`ds4_npu_engine`, C++17, CMake build).
262
+ - NPU kernels generated with AMD IRON / MLIR-AIE; prebuilt `.xclbin` + `_insts.bin` ship in the
263
+ repo `kernels/` directory.
264
+ - Python 3 + `tokenizers` for the HF BPE tokenizer bridge.
265
+
266
+ ## Citation [optional]
267
+
268
+ If you use this work, please cite the upstream DeepSeek model and the FaStar engine.
269
+
270
+ **BibTeX:**
271
+
272
+ ```bibtex
273
+ @misc{deepseek-v4-flash-dspark,
274
+ author = {{DeepSeek-AI}},
275
+ title = {DeepSeek V4 Flash (DSpark)},
276
+ howpublished = {\url{https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-DSpark}}
277
+ }
278
+
279
+ @misc{fastar,
280
+ author = {Raffaello Molinari},
281
+ title = {FaStar: Expert Virtual Memory Inference Engine for DeepSeek V4 Flash on AMD Ryzen AI NPU},
282
+ howpublished = {\url{https://github.com/RaffaelloMolinari/FaStar}}
283
+ }
284
+ ```
285
+
286
+ **APA:**
287
+
288
+ DeepSeek-AI. (n.d.). *DeepSeek V4 Flash (DSpark)*. HuggingFace. https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-DSpark
289
+
290
+ Molinari, R. (n.d.). *FaStar: Expert virtual memory inference engine for DeepSeek V4 Flash on AMD Ryzen AI NPU*. GitHub. https://github.com/RaffaelloMolinari/FaStar
291
+
292
+ ## Glossary [optional]
293
+
294
+ - **`.fst`:** FaStar's page-aligned model container (config header + shared tensors in
295
+ Q8_0/BF16 + dense DS4 MXFP4 expert blocks).
296
+ - **Expert virtual memory:** MoE experts treated as virtual-memory pages — stored on SSD,
297
+ cached in RAM (`ExpertPager` LRU), uploaded to NPU scratch on demand.
298
+ - **MXFP4:** Microscaling FP4 — 16 FP4 nibbles per block plus one shared e8m0 scale (17 bytes
299
+ per expert block).
300
+ - **MLA:** Multi-head Latent Attention — compresses Q (1024-d) and KV (512-d) into latent
301
+ projections; the KV cache stores compressed latents + positional embeddings.
302
+ - **DSpark:** Draft-model speculative decoding — a small model proposes tokens that the main
303
+ model verifies in a block.
304
+ - **IRON / MLIR-AIE:** AMD's compiler toolchain that generates the NPU kernels (`.xclbin`).
305
+ - **hw_context:** An AMDXDNA device context bound to an xclbin; the driver caps simultaneous
306
+ contexts at 9 (managed by `AiebuKernelCache`).
307
+
308
+ ## More Information [optional]
309
+
310
+ See the [FaStar repository README](https://github.com/RaffaelloMolinari/FaStar) for the full
311
+ architecture overview, CLI flags, web-UI API, kernel rebuild instructions, and known
312
+ limitations.
313
+
314
+ ## Model Card Authors [optional]
315
+
316
+ Raffaello Molinari (`.fst` conversion + model card). Model weights and architecture by
317
+ DeepSeek-AI.
318
+
319
+ ## Model Card Contact
320
+
321
+ Open an issue on the [FaStar GitHub repository](https://github.com/RaffaelloMolinari/FaStar).
322
+ ````