# Run DeepSeek v4.1 1017 Flash(2-bit) on a single 80GB VRAM GPU at 100 tok/s

> Source: <https://github.com/Tensward/tensward/tree/main/examples/deepseek-v4.1-flash-h100>
> Published: 2026-11-29 22:18:10+00:00

**Recommendation:** Pin MoE experts in host RAM and cache the hottest in free GPU VRAM, but set decode threads to physical cores only; on this box -t 26 fell below 3 tok/s while -t 13 held 114.5 tok/s.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

A recipe for running [DeepSeek-V4.1-Flash-1017](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017) (748B parameters) as a local coding-agent model on **one H100 80 GB with about 230 GB of host RAM**, using a 2-bit GGUF and two small llama.cpp patches.

- Model file: [Tensward/DeepSeek-V4.1-Flash-1017-Coding-2bit-GGUF](https://huggingface.co/Tensward/DeepSeek-V4.1-Flash-1017-Coding-2bit-GGUF) (392.9 GB, routed experts in Q2_K)
- Draft model: `dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf` from[Unsloth's repository](https://huggingface.co/unsloth/DeepSeek-V4.1-Flash-1017-GGUF)
- Engine: Unsloth's llama.cpp fork, release `b12823-mix-034de92` (it adds the MXFP8 type the model's n-gram table uses)

```
bash scripts/build_llama_h100.sh ./llama_build_h100          # downloads the fork's source (sha256-checked), applies both patches, builds for sm_90

MODEL_PATH=/models/DeepSeek-V4.1-Flash-1017-Tensward-Coding-2bit-00001-of-00009.gguf \
DSPARK_PATH=/models/dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf \
bash scripts/serve_coding_64k.sh                             # Recipe 1: one user, 64k context, OpenAI-compatible API on 127.0.0.1:8080
```

Before the first start, once as root: `echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag`. Put the model on local NVMe if you have it. `configs/opencode.json` points OpenCode at the server. For non-thinking replies, send `"chat_template_kwargs": {"enable_thinking": false}`.

All routed experts stay in host RAM (`-ot ...ffn_.*_exps=CPU`, `-lm none` so they are pinned rather than memory-mapped), and the free GPU memory becomes a cache of the most-used experts (`--moe-cache-mib 55000`). Experts that miss the cache run on the CPU 80% of the time (`--moe-cache-cpu-share 0.80`) instead of being copied over PCIe. The 202.8 GB n-gram table stays on disk and is read lazily. Decode threads are the physical cores (`-t 13`); prefill uses more (`-tb 24`). Do not set `-t` to all vCPUs: on our box `-t 26` (all 26 vCPUs) made decode collapse to under 3 tok/s.

Both are off unless their environment variable is set; the serve scripts set them.

- **`01_decode_fast.patch` (`LLAMA_DECODE_FAST=1`).** Less CPU work per token in the expert cache's CPU path: rows the GPU cache already served are skipped instead of quantised and zero-filled on one thread, the expert ids are read back through pinned memory, and one scheduler wait is skipped when the cache's own copy step has already synchronised.
- **`02_spec_max_concurrency.patch` (`LLAMA_SPEC_MAX_CONCURRENCY=2`).** Switches the draft model off while more than N requests are generating and back on when the load drops. With several users, drafting multiplies the batch size and pushes the expert cache out of its fast path.

Hardware: GCP `a3-highgpu-1g`, H100 80 GB (host link PCIe Gen4 x16), Xeon Platinum 8481C (13 cores, 26 vCPUs), 230 GiB RAM, 2 x 375 GB local NVMe.

**Answers.** We ran this recipe, built with the scripts in this folder, on 110 tasks we wrote for the test (none from public benchmarks: coding with hidden tests, multi-turn agent repairs with real tool execution, 30k-54k-token long context, tool calls), against the same model on two FP8 API providers. No quality loss was readable at this size (details and limits on the [model card](https://huggingface.co/Tensward/DeepSeek-V4.1-Flash-1017-Coding-2bit-GGUF)). The patched build's 997 responses were byte-identical to the unpatched build's.

**Single user (Recipe 1).** "Patches off" is the patched binary with `LLAMA_DECODE_FAST=0` on the gate and 7.2k rows, and an unpatched build in our 110-task run; the 7.2k row is three restarts per arm, the others one run each:

|  | Patches off | Patches on | 
|---|---|---|
| 60-task coding gate at 64k context, pooled decode | 107.0 tok/s | 114.5 tok/s (+7.0%; 59 of 60 tasks faster, all 60 outputs identical) | 
| Our 110-task run, median decode: coding / agent turns | 98.7 / 90.0 tok/s | 102.9 / 90.3 tok/s | 
| Prefill, 53k-token prompts (our run) | about 680 tok/s | about 650 tok/s | 
| Prefill, 7.2k-token prompt ( `-ub 4096` ) | 662-691 tok/s | 662-691 tok/s (1.3% lower on average) | 

Draft acceptance on the gate: 91.4%; expert cache hit rate: 86.8%; GPU memory at the end of the run: 77.2 GiB.

**Prompt cache.** With `--cache-ram 8192`, a follow-up turn after another request had evicted the slot started in 0.30 s instead of 13.4 s at 8k tokens, and 0.39 s instead of 44.0 s at 32k (one trial each, on an earlier experimental build that also carried other patches).

**Several users.** Auto-flip against always-on drafting, same binary and box, one session each, `-np 8 -c 16384 -kvu`, 56,000 MiB expert cache, `--cache-ram 0`:

| Concurrent requests | Always-on drafting | Auto-flip | 
|---|---|---|
| 4 | 73.7 tok/s | 119.2 tok/s | 
| 8 | 42.4 tok/s | 146.5 tok/s | 

No draft tokens were wasted during bursts, and single-request speed after a burst stayed within the burst-to-burst spread (81.0 vs 86.1 tok/s).

**Recipe 2** (`scripts/serve_team_multistream.sh`: no draft, 63 GiB cache, `-np 8`) reached 165.3 tok/s decode at 8 concurrent requests and 61.3 at 1 (one session). At 4 concurrent requests 2 of 3 bursts collapsed to about 54 tok/s, because idle and busy slots interleave and the server stops reusing its decode graph; `CACHE_RAM_MIB=0` should avoid it at the cost of the RAM prompt cache (not tested on this recipe). We are working on a fix.

**Without the recipe.** The default memory-mapped load with `-ub 512` prefilled a 7.2k-token prompt at 64.3 tok/s; `-lm none` alone made that 170.4 tok/s, and the full recipe reaches 662-691.

- **Model:** DeepSeek,[DeepSeek-V4.1-Flash-1017](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017) , MIT License.
- **Source GGUF, draft model and the llama.cpp fork with the expert cache:**[Unsloth](https://huggingface.co/unsloth/DeepSeek-V4.1-Flash-1017-GGUF) , MIT License.
- **llama.cpp:** the[ggml / llama.cpp authors](https://github.com/ggml-org/llama.cpp) , MIT License.
