Skip to content

Latest commit

 

History

History
131 lines (98 loc) · 6.98 KB

DEEPSEEK_L40S.md

File metadata and controls

131 lines (98 loc) · 6.98 KB

DeepSeek-V4.1 on 2x L40S + 1 TB RAM

Not yet measured on L40S. The settings follow from the code and from the synthetic 2-layer test (tests/deepseek_synthetic.rs, run on one RTX 3060 listed twice). Measure on the real host before you trust them, and add the numbers to BENCHMARKS.md with their conditions.

Recommended command

M=/models/DeepSeek-V4.1-Flash.gguf          # the first shard of a split GGUF also works
rustingstrata serve --model $M --gpu --device 0,1 --threads <physical cores> --addr 0.0.0.0:8080
# quick speed check with the per-token profile
STRATA_DS_PROF=1 rustingstrata bench --model $M --gpu --device 0,1 --pp 512,4096 --tg 128

What the model supports is in MODELS.md. All flags are in USAGE.md.

Settings

Plain weights are the non-expert weights. The weight budget is the plain weights plus the expert cache.

Flag or variable Default What it does
--gpu on DeepSeek uses the GPU with or without this flag.
STRATA_DS_GPU 1 0 runs everything on the CPU, which is slow.
--device 0,1 (STRATA_DS_DEVICES) every CUDA device The GPUs to use.
--threads N one per physical core CPU threads. The CPU computes the experts that miss VRAM.
--ctx N (STRATA_DS_CTX) the trained context Prompt plus reply limit in tokens.
STRATA_DS_GPU_FRACTION 0.95, or 0.8 on a card with less than 8 GB free Share of free VRAM for the weight budget.
STRATA_DS_GPU_EXPERTS unset The weight budget in GB, split between the GPUs in proportion to their free VRAM.
STRATA_DS_ROOM_GB free VRAM less the expert cache and 768 MB GB of plain weights a GPU takes before the layers move on to the next GPU.
STRATA_DS_CHUNK 512 Prefill tokens per chunk. Larger means fewer weight passes and more scratch memory.
STRATA_DS_CPU_SHARE adapts per layer Share of the VRAM misses that the CPU computes, 0 to 1. Set it only to test a fixed split.
  • To balance the two cards, set STRATA_DS_ROOM_GB to about half of the plain-weight total. A layer's plain weights and its attention stay on one GPU.
  • STRATA_DS_CHUNK: a larger chunk gives each routed expert more tokens per weight read. With 384 experts and 6 used, 512 gives each expert about 8 tokens. 2048 gives about 32, if the scratch memory fits.

Check after start

  • The log has a cuda device N: ... line for each GPU.
  • STRATA_DS_PROF=1 prints one line per forward pass: the time in experts and attn, gpu-round-trips, vram-expert-lookups hit and miss, and disk_read_MB.
  • With 1 TB of RAM the page cache holds the whole GGUF. Experts that miss VRAM are then read from RAM, not from disk.
  • gpu-round-trips counts the host-device synchronizations per token. Each one waits for the GPU, so fewer is better. The count grows with the layer count. The synthetic 2-layer model reports 11 per decoded token on one GPU and 14 with the layers split over two device entries.

CPU threads

The experts that miss VRAM run on the CPU. On this host the CPU sets much of the decode speed, and most of the prefill speed when the expert cache is small. Time the CPU expert kernels on the serving host:

cargo run --release --example ds_cpu_bench -- IQ2_XXS,Q4_K <threads> 8

It needs no model file and no GPU. It prints three numbers per quant type: the one-thread dot rate, the decode expert step and the prefill step. Run it with the physical cores of one socket, of both sockets, and with the logical count. Then try the same counts with rustingstrata bench ... --threads N and keep the fastest.

Measured on the development machine only (Ryzen 5 7600X, 6 cores and 12 threads):

  • The SMT threads made the CPU expert step 4% to 16% faster in decode and 9% to 21% faster in prefill. The full DeepSeek model with SMT threads is not measured.
  • IQ2_XXS is compute-bound on the CPU, so more cores help in a near-linear way. Q4_K stops at the memory bandwidth.

NUMA

Not measured on two nodes. numactl --interleave=all is the reliable way to spread the model's pages over both sockets. Try it against one socket alone:

numactl --interleave=all rustingstrata serve ...
numactl --cpunodebind=0 --membind=0 rustingstrata serve ... --threads <cores of node 0>
echo 3 > /proc/sys/vm/drop_caches     # between the two runs, so the second reads the file under its own policy

Choose the second only if the model fits in the RAM of one node.

Without numactl, RustingStrata reads the GGUF into the page cache at load with one reader thread per CPU. The pages should then spread over both sockets, but the scheduler decides where the reader threads run.

Build

The release binary is built for x86-64-v3 (AVX2). On a CPU with AVX-512VL and VNNI it picks a copy of the prefill kernels for those features at run time, with the same result bits. A local build uses -C target-cpu=native.

Prefill step of ds_cpu_bench on the development machine, 6 threads, 48 experts x 8 tokens. The columns are the release binary's AVX2 kernels alone, the release binary with the run-time copy, and a native build:

Quant x86-64-v3 kernels With the run-time AVX-512VL copy Native build
Q2_K 27.7-27.8 ms 21.6-22.1 ms 19.0-20.3 ms
IQ1_M 42.0-42.4 ms 36.0 ms 34.9-35.0 ms
IQ2_XXS 30.2-31.1 ms 29.1-29.5 ms 27.3-27.5 ms
Q4_K 32.9-34.6 ms 35.2-35.5 ms 28.5-29.2 ms

The build does not change decode: the memory bandwidth limits it.

Problems

What you see What to do
The KV rows or the prefill scratch run out of memory on a long context Lower STRATA_DS_GPU_FRACTION.
GPU N: ...; running without it in the log A GPU did not open, so the whole model runs on the CPU. Fix that GPU or leave it out of --device.
The GGUF has MXFP4 experts Not supported. Use an IQ2_XXS, Q2_K, Q4_K or other GGML k-quant or i-quant GGUF.
Decode is much slower than llama.cpp on the same host Collect the output below.
STRATA_DS_PROF=1 rustingstrata bench --model $M --gpu --device 0,1 --pp 512 --tg 64 --threads <N>
cargo run --release --example ds_cpu_bench -- IQ2_XXS,Q4_K <N> 8

Run both with N = the physical cores of one socket, of both sockets, and the logical count. Compare the decode GB/s of ds_cpu_bench with the bandwidth of one socket (from mlc or STREAM). Add the llama.cpp command line and its tokens per second, so both run the same quant and the same expert split.

Test and tuning switches

Name What it does
STRATA_DS_PROF=1 Prints per-token timings and gpu-round-trips.
STRATA_DS_CPU_ATTN=1 Attention on the CPU with f32 keys. For checking only.
STRATA_Q4K_X8=0 Turns off the 8-row prefill kernels.
STRATA_AVX512=1 Selects the 512-bit kernels of a binary built with -C target-feature=+avx512f,+avx512bw,.... Not faster on Zen 4, so do not build for them there. Not measured on Intel Xeon.
STRATA_BENCH_GAP_US=300 ds_cpu_bench only: idles 300 us before each timed run.