LLM API Guide

ds4: required metadata key is missing: deepseek4.block_count

If ds4 exits with "required metadata key is missing: deepseek4.block_count", learn why the GGUF header fails and how to fix this model loading error.

Editorial illustration: ds4: required metadata key is missing: deepseek4.block_count
Photo-style image, AI-generated

Summary

  1. The error means the GGUF header does not match what the ds4 C loader expects, not that your 100GB+ download is corrupted.
  2. Community DeepSeek V4 GGUFs (Unsloth, bullerwins) use the llama.cpp dialect and will fail in ds4.
  3. If you see this error while loading a Qwen model (qwen4-exp vs qwen4exp).
  4. Patching deepseek4.block_count into a community GGUF by hand does not work—the loader will immediately fail on 9 other custom keys and ~20 tensor name.

When ./ds4 or ./ds4-server exits immediately with ds4: required metadata key is missing: deepseek4.block_count (or a sibling error complaining about deepseek4.vocab_size or deepseek4.attention.output_lora_rank), your GGUF file is not corrupted. You do not need to re-hash or delete a 150 GB download.

What actually happened is a header mismatch before the weights even touched Metal or CUDA. DwarfStar (antirez/ds4) is not a general-purpose GGUF runner. Its C loader (ds4.c) runs strict required_u32() checks against a custom set of metadata keys that only exist in GGUF files produced by the ds4 quantizer itself.

Depending on which model file you just passed to -m, you are hitting one of two completely different bugs.

On this page

Case 1: You are loading a DeepSeek V4 or V4.1 Flash GGUF from Hugging Face

If you downloaded a standard community quantization of DeepSeek V4 Flash (or DeepSeek V4.1 Flash)—such as an Unsloth build (UD-IQ3_XXS, Q4_K_M) or a bullerwins MXFP4 export—that file was quantized using standard llama.cpp conversion scripts.

Both llama.cpp and ds4 use the .gguf container format, and both set general.architecture for the model, which makes them look interchangeable. Underneath, they use incompatible metadata dialects. Standard llama.cpp GGUFs omit deepseek4.vocab_size, deepseek4.block_count (which is 43 on Flash and 61 on Pro), and eight custom deepseek4.* keys covering hyper-connections (hc), LoRA ranks (deepseek4.attention.output_lora_rank), and hash layers. When ds4 opens the file, it walks its required key list in order and aborts on the very first key it cannot find.

You have two ways out, depending on whether you care more about saving bandwidth or using ds4's specific hardware paths (like Apple Silicon Metal unified memory tuning or --ssd-streaming):

Option A: Keep your current GGUF and run it in llama.cpp

If you already spent hours pulling an 80 GB to 165 GB community GGUF, do not re-download it. Mainline llama.cpp natively supports the DeepSeek V4 hybrid attention architecture (CSA and HCA). Point llama-server or llama-cli at the exact same file you already have on disk:

bash
llama-server \
  -m /path/to/DeepSeek-V4-Flash-Q4_K_M.gguf \
  --n-gpu-layers 99 \
  --ctx-size 65536 \
  --port 8080

Watch out for multi-engine wrappers: If you didn't invoke ds4 directly and instead got this error through a local launcher (like older builds of mlx-serve), the router misidentified the file and handed your llama.cpp GGUF to the ds4 backend. The reverse happens too—passing a native ds4 GGUF into llama.cpp fails with llama_model_load: error loading model: unknown model architecture: 'deepseek4'. Update the launcher or invoke llama-server directly.

Option B: Keep ds4 and pull the ds4-dialect GGUF

If you specifically need ds4—for example, you are running on a 128 GB or 256 GB Mac Studio, a Strix Halo ROCm box, or relying on --ssd-streaming to swap routed experts off NVMe—you have to use the weights published for antirez/deepseek-v4-gguf.

Use the download script shipped inside the ds4 repository so the metadata and mixed-precision expert layouts match what ds4.c expects:

bash
# Inside your cloned antirez/ds4 directory:
./download_model.sh q2   # ~86.7 GB, fits 128 GB unified memory Macs
./download_model.sh q4   # ~165 GB, targets 256 GB+ unified memory Macs
./download_model.sh mtp  # ~3.81 GB, optional speculative decoding weights

Case 2: You are loading a Qwen model (or another non-DeepSeek GGUF)

This is the confusing one: you pass a 75 GB Qwen file (like Qwen3.8-Flash-Next) to ds4-server, and it immediately exits with rc=1 complaining about deepseek4.block_count.

The error names deepseek4 because DeepSeek V4 is the fallback validation path in ds4, not because your file is a DeepSeek model.

When ds4 opens a GGUF, it reads general.architecture first to decide which loader branch to run. In forks and newer builds of ds4 that support multiple architectures, the dispatcher checks for an exact string match:

What the GGUF header has What the ds4 binary checks for What happens on mismatch
general.architecture = qwen4-exp (with a hyphen) qwen4exp (no hyphen) Dispatcher misses, falls through to the default deepseek4 loader, and dies asking for deepseek4.block_count.
general.architecture = qwen4exp (no hyphen) qwen4-exp (older ds4-metal builds) Same fallback, same deepseek4.block_count error.
Empty or tensorless GGUF test fixture Any valid ds4 architecture Falls through to the default loader and exits 1 on deepseek4.block_count.

One hyphen between qwen4-exp and qwen4exp is enough to trigger it.

Do not try to fix this by editing general.architecture in place to remove the hyphen. All the layer metadata keys inside the file share that prefix (qwen4-exp.block_count, etc.), so changing the architecture string alone just makes the loader crash one millisecond later on missing: qwen4exp.block_count.

To fix a qwen4-exp / qwen4exp mismatch:

  1. Pull the matching upstream build first. Update ds4 to current main and check that your GGUF package comes from the matching release train (qwen4exp imatrix packs on current ds4-server).
  2. If you are converting an older -q4 (qwen4-exp) package using qwen4_pack_to_qwen4exp.py, pass --ple-external. Running the conversion script with default inline PLE writes a massive per_layer_token_embd.weight tensor (~95.37 GiB) into a 177 GB file, which Apple Silicon Metal will reject on a 128 GB Mac because it exceeds the single-buffer allocation cap (max buffer 80.64 GiB). Passing --ple-external keeps the file around 74.6 GB alongside the external PLE sidecar and loads cleanly.

Why patching deepseek4.block_count into the GGUF header doesn't work

When people first hit this on a 156 GB file, the obvious temptation is to write a quick Python script using gguf-py to inject deepseek4.block_count = 43 into the file header.

Save yourself the disk I/O—rewriting a 150 GB GGUF takes minutes and will still fail to boot:

  • 9 more missing keys follow immediately: As soon as you satisfy deepseek4.block_count, ds4.c checks deepseek4.vocab_size and the eight custom hc, lora, and hash-layer keys.
  • ~20 tensor names do not match: Even if you derive and inject every missing metadata key from the existing tokenizer.ggml.tokens and architecture fields, the llama.cpp GGUF dialect uses different prefix and suffix naming conventions for attention and routed expert tensors. As soon as metadata parsing succeeds, the tensor loader fails to bind the weights.

Unless you are maintaining a custom ds4 C fork with a full metadata derivation and tensor-alias translation layer, match the file to the runtime: run llama.cpp-dialect files in llama.cpp, and use ./download_model.sh when you want to run ds4.

If you would rather skip shuffling 160 GB GGUF files and debugging local C loaders altogether, you can also call DeepSeek V4 Flash and other frontier models directly through an OpenAI- or Anthropic-compatible endpoint—or route across upstream providers with automatic failover using SeedRouter. For troubleshooting hosted endpoints instead of local weights, see our guides on fixing Claude Code API 400 errors and Gemini 3 Flash API errors.

Sources and checks

  1. antirez/ds4
  2. DeepSeek V4 Flash
  3. llama.cpp