Skip to content

DeepSeek V4.1 Flash Module Inventory

Qubitium edited this page Nov 30, 2026 · 10 revisions

🔎 DeepSeek V4.1 Flash: checkpoint module inventory

🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help

On this page

GPT-QModel loads the published DeepSeek V4.1 Flash and Flash-1017 checkpoints. Use this page to choose a loading route, quantize selected projections, or audit which tensors belong to the checkpoint.

🧭 Read this as an integration audit

Reading depth Jump to What it establishes
Choose / understand Pinned evidence and whole checkpoint What was inspected and the scope of the inventory
Practical usage Load a checkpoint and quantize selected projections Placement, backend choices, and export
Theory / advanced Decoder layer, tags, scale ownership Source-to-runtime ownership

The registry maps deepseek_v41 to DeepSeekV41FlashQModel. Its LocalModelLoader selects the bundled Flash config and model from gptqmodel/models/ports/deepseek_v41_flash/ on the Transformers 5.23 ABI. Registry · Flash definition

The pinned inventory below describes the published Flash checkpoint.

Load a checkpoint

from gptqmodel import GPTQModel

model = GPTQModel.load(
    "deepseek-ai/DeepSeek-V4.1-Flash-1017",
    placement="accel:auto",
)

GPTQModel.load() uses the selected checkpoint's tokenizer by default. Pass a compatible tokenizer object with tokenizer=... to override it. The Flash loader uses the selected tokenizer to initialize Engram. Public dispatcher · Flash loader

Pass a Hub repository ID or a local indexed safetensors directory. revision selects a Hub revision and subfolder selects a nested checkpoint. The loader uses the same checkpoint selection for the index, config, weight shards, and default tokenizer. It accepts the published block-32 FP8/FP4 format and uses BF16 compute. Automatic placement keeps each decoder and draft layer on a single device; explicit module-path rules can pin those layers. Use Placement.budget(...) to set device byte limits. Disk placement, adapters, custom module trees, and projection fusion are not supported. Loader · Checkpoint resolution

backend Published packed projections
"auto" (default) Native Triton block-scaled MMA on NVIDIA compute capability 10.x, 11.x, or 12.x. On other NVIDIA CUDA devices at SM 8.0+, uses Marlin for tile-aligned projections. Otherwise uses the Torch reference path. An unavailable selected native runtime raises rather than silently switching.
"marlin" Requires NVIDIA CUDA SM 8.0+, an available Marlin runtime, and tile-aligned dimensions for every remaining packed projection. Repacking happens at load time.
"torch" Reference path; decodes a projection at a time.

The Engram embedding and scale tables are mapped from safetensors and only requested hashed rows are decoded. Text inputs must be unpadded. Image prefill uses input_ids with the checkpoint's image placeholders, flattened RGB patches in pixel_values, and one [1, patch_rows, patch_columns] row per image in image_grid_thw. Include an image start token, a newline after each placeholder row, and an image end token. With inputs_embeds, supply matching engram_input_ids where Engram is used.

Ordinary backbone execution does not invoke the published dSpark blocks. For explicit draft execution, request output_mtp_features=True and use_cache=True from the backbone, then pass the features and request cache to model.model.forward_spec(input_ids, main_hidden, cache=cache). A continuation supplies the accepted features, the next draft input token per sequence, and start_pos equal to the count already accepted into the draft cache.

Quantize selected projections

GPTQ

Start from a published checkpoint and pass a GPTQ config. Use a nonempty list of unique runtime paths for checkpoint-owned linear projections in layers, vision, or aligner; calibration must exercise every selected projection. Engram and dSpark weights are preserved. This is not whole-model AWQ or a generic full-model GPTQ pass.

from gptqmodel import GPTQModel
from gptqmodel.quantization.config import CalibrationConfig, QuantizeConfig

# Prepare representative unpadded calibration_rows before running this example.
model = GPTQModel.from_pretrained(
    "deepseek-ai/DeepSeek-V4.1-Flash-1017",
    placement="accel:auto",
    quantize_config=QuantizeConfig(bits=4, group_size=128),
)
model.quantize(
    CalibrationConfig(dataset=calibration_rows),
    projections=["layers.1.attn.wq_a", "layers.14.attn.indexer.wq_b"],
)
model.save("deepseek-v41-flash-gptq")
reloaded = GPTQModel.from_quantized("deepseek-v41-flash-gptq", placement="accel:auto")

Calibration runs Engram but disables dSpark. Saved projections use Torch GPTQ v2 kernels on reload; the writer streams unchanged source tensors into the indexed safetensors export. Keep the original shards available through the save and use an empty output directory.

Selected-projection quantization leaves the installed kernels in evaluation mode, so a forward before saving uses the inference path. This applies to both GPTQ and Q4NX EXL3. See projection quantization.

Q4NX EXL3 for routed experts

Use EXL3Config with codebook="q4nx" and a rate of 2.5, 3.0, or 3.5 bits per weight. This path quantizes the published FP4 expert projections layers.N.ffn.experts.E.w1, w3, and w2 on NVIDIA CUDA, using the BF16 activations observed during calibration. Supply CalibrationConfig(dataset=...) with rows that exercise every selected projection.

from gptqmodel import GPTQModel
from gptqmodel.quantization import EXL3Config
from gptqmodel.quantization.config import CalibrationConfig

model = GPTQModel.from_pretrained(
    "deepseek-ai/DeepSeek-V4.1-Flash",
    placement="accel:auto",
    quantize_config=EXL3Config(bits=3.5, codebook="q4nx"),
)
model.quantize(
    CalibrationConfig(dataset=calibration_rows),
    projections=[f"layers.14.ffn.experts.0.w{i}" for i in (1, 3, 2)],
)
model.save("deepseek-v41-flash-q4nx")

The export records each replaced projection's rate and codebook under gptqmodel_v41_projections and saves its trellis, suh, svh, and q4nx marker in indexed safetensors. The loader rejects missing or unexpected Q4NX markers. The remaining weights use the published source format.

Reload with backend="auto" for device-based dispatch, backend="exl3_exllama_v3" for native Q4NX projections on NVIDIA SM80+, or backend="exl3_torch" or "torch" for the Torch path. Native grouped routing requires BF16 input and a homogeneous bank of bias-free, unpadded Q4NX expert projections on NVIDIA SM80+. Gate and up share a rate, while down can use a different rate. Partially converted layers and other ineligible calls use the per-expert loop. Grouped routing requirements

See the checkpoint loader, model forward, projection quantizer, writer, and ownership and runtime flow.

Pinned evidence

The following artifacts come from deepseek-ai/DeepSeek-V4.1-Flash, revision 314113f8a7dadb388215396ba5fbee2c610a04d6, inspected on 2026-11-07:

Artifact What it establishes
config.json deepseek_v41, nested text/vision configs, layer/expert counts, source quantization metadata.
model.safetensors.index.json Exact saved tensor keys and shard membership. Counts below come from this index, without downloading weight shards.
inference/model.py Reference module ownership, expert projection roles, direct parameters, conditional branches, runtime buffers.
inference/convert.py Reference name/format conversion and tensor-parallel sharding. This is not a GPT-QModel converter.
inference/vision.py Vision and aligner ownership.

The config declares 40 text layers, hidden size 5120, 384 routed experts with 6 selected per token, and one shared expert. It also declares 32 vision layers and three next-token prediction layers. The source format declares FP8 with 32-by-32 weight blocks and FP4 experts; stored scale tensors are part of the checkpoint inventory. These facts do not establish GPTQ/AWQ compatibility.

Whole-checkpoint view

The index contains 96,085 tensor keys. Counts include scales and biases; they are not parameter counts, module counts, or tensor element totals.

Saved namespace Tensor keys Coverage responsibility
layers.* 93,415 Backbone decoder: attention, MoE, hyper-connections, optional compression/indexing/Engram.
mtp.* 2,401 Three auxiliary prediction blocks and their additional heads/projections.
vision.* 259 Patch embedding, 32 vision blocks, final vision norm.
aligner.* 4 Vision-to-language projection weights and biases.
embed.weight 1 Token embedding.
norm.weight 1 Final text norm.
head.weight 1 Output head.
image_start, image_end, image_newline 3 Learned image delimiter parameters on the model root.
Total 96,085 Every saved key belongs to an explicit inventory category.

The names below are the actual checkpoint namespace, not an invented HF model.layers.* layout. Bracketed ranges abbreviate repeated numeric segments.

checkpoint
├─ embed.weight
├─ image_start / image_end / image_newline        direct root parameters
├─ vision
│  ├─ patch_embed.proj                           weight + bias
│  ├─ blocks.[0..31]
│  │  ├─ norm1 / norm2                          weight
│  │  ├─ attn.wqkv / attn.wo                    weight + bias
│  │  └─ mlp.w1 / mlp.w2                        weight
│  └─ norm.weight
├─ aligner.w1 / aligner.w2                       weight + bias
├─ layers.[0..39]                               detailed below
├─ norm.weight
├─ head.weight
└─ mtp.[0..2]                                   prediction blocks
   ├─ attn / ffn / attn_norm / ffn_norm / hc_*   block weight families
   ├─ main_norm / norm                          weight
   ├─ main_proj                                weight + scale
   ├─ markov_head.embed / markov_head.head      weight
   └─ confidence_head.proj                     weight

The module-plan implementation currently compiles decoder-relative owners. That does not automatically include vision, aligner, mtp, embeddings, heads, or direct model-root parameters. A full V4.1 integration must give these weights explicit ownership and preservation tests, and extend the public inventory if it is to expose a whole-checkpoint view.

One backbone decoder layer

This is the union of saved backbone-layer paths, not a claim that every optional branch exists in every layer. The index has 50 distinct key templates after normalizing numeric layer and expert indices.

layers.N
├─ hc_attn_fn / hc_attn_base / hc_attn_scale     direct layer parameters
├─ hc_ffn_fn / hc_ffn_base / hc_ffn_scale        direct layer parameters
├─ attn_norm.weight
├─ attn
│  ├─ attn_sink                                direct attention parameter
│  ├─ wq_a                                     weight + scale; query factor A
│  ├─ q_norm.weight
│  ├─ wq_b                                     weight + scale; query factor B
│  ├─ wkv                                      weight + scale; shared KV latent
│  ├─ kv_norm.weight
│  ├─ wo_a / wo_b                              weight + scale; output factors
│  ├─ compressor                               only KV-source layers
│  │  ├─ norm.weight
│  │  ├─ wkv.weight
│  │  └─ wgate.weight                          only ratio > 1
│  └─ indexer                                  only index-source layers
│     ├─ wq_b                                  weight + scale
│     ├─ wk.weight
│     ├─ k_norm.weight
│     └─ weights_proj.weight
├─ engram                                      only layers 1 and 14
│  ├─ embed                                    weight + scale
│  ├─ wkv                                      weight + scale
│  └─ q_weight / k_weight                      direct Engram parameters
├─ ffn_norm.weight
└─ ffn                                         MoE root
   ├─ gate                                     weight + bias + bias_vl
   ├─ experts.[0..383]
   │  ├─ w1                                    weight + scale; gate projection
   │  ├─ w3                                    weight + scale; up projection
   │  └─ w2                                    weight + scale; down projection
   └─ shared_experts
      ├─ w1                                    weight + scale; gate projection
      ├─ w3                                    weight + scale; up projection
      └─ w2                                    weight + scale; down projection
Branch Backbone layers with saved keys
Base attention, routing, routed/shared experts, norms, hyper-connections 0–39
attn.compressor 2, 8, 14, 20
attn.compressor.wgate 2, 8, 14; layer 20 has ratio 1 and no gating projection
attn.indexer 2, 8, 14, 20, 24, 28, 32, 36
engram 1, 14

This makes a layer-zero-only test insufficient. It misses compression, indexing, and Engram even if all its attention and expert projections resolve.

Translating evidence into definition tags

The registered module tree covers the backbone. ffn:moe owns the routed and shared expert projections w1, w3, and w2; ffn.gate:! is the preserved router, not the MLP gate projection. attn:! accounts for the attention sink without excluding its declared projections. The loader maps each layer's six hc_* parameters to the attn_hc and ffn_hc owners. Engram is marked for preservation, and mtp.* is loaded and saved outside the backbone projection plan.

flowchart TD
    INDEX["Indexed safetensors"] --> LOADER["Validate keys and assign placement"]
    LOADER --> DEC["Decoder and vision modules"]
    LOADER --> ENGRAM["Map Engram table and scales"]
    LOADER --> DRAFT["Load separate dSpark owners"]
    DEC --> RUN["Backbone forward"]
    ENGRAM --> RUN
    RUN -->|"Explicit draft call"| DRAFT
    RUN -->|"Calibration"| GPTQ["Pack selected projections"]
    GPTQ --> SAVE["Overlay packed projections on an indexed copy of the source"]
Loading

For module-plan inspection APIs, see Module Plans.

Saved scales versus runtime memory

Example Checkpoint-owned? Treatment
layers.0.attn.wq_a.scale Yes Saved inference metadata associated with wq_a; include in source ownership/conversion audit.
layers.0.ffn.gate.bias_vl Yes Saved routing parameter, even if a text-only run does not exercise image routing.
layers.14.engram.q_weight Yes Direct parameter on engram; absence from a linear-module list is irrelevant.
layers.0.hc_attn_fn Yes Direct decoder-layer parameter; cannot be dropped from coverage.
image_start Yes Direct model-root parameter outside the decoder-only plan.
window_kv_cache, compress_kv_cache No saved keys in this index Runtime attention caches; not model-definition weight obligations.
Compressor kv_state / score_state, generated freqs_cis No saved keys in this index Runtime state or generated positional data; keep separate from checkpoint weights.

The reference converter consumes wo_a.weight and its saved scale to produce a BF16 runtime weight. A missing runtime scale after that transformation is not missing checkpoint coverage if the conversion is accounted for explicitly. Conversely, a newly allocated cache does not become a checkpoint weight because it has tensor storage. Audit provenance, not just Python tensor type.

Reproduce the inventory without loading weights

Download only the pinned index and count its keys:

import json
from collections import Counter
from urllib.request import urlopen

revision = "314113f8a7dadb388215396ba5fbee2c610a04d6"
url = (
    "https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash/resolve/"
    f"{revision}/model.safetensors.index.json"
)
with urlopen(url, timeout=60) as response:
    weight_map = json.load(response)["weight_map"]
counts = Counter(key.split(".", 1)[0] for key in weight_map)
assert len(weight_map) == 96085
assert counts["layers"] == 93415
assert counts["mtp"] == 2401
print(dict(sorted(counts.items())))

Index inspection verifies saved names, not tensor contents, shapes, loader compatibility, quantization accuracy, or a successful inference run. Before claiming support, add the registry contract and a real V4.1 module-plan test, exercise every optional branch and non-decoder family, and validate conversion plus quantize/save/reload against the actual implementation. The current conditional V4.1 test only activates when the upstream config becomes available; it is not evidence that V4.1 already passes.

Clone this wiki locally