Repository navigation
Commit a38d38d
DeepSeek-V4 B2: block-FP8 / packed-FP4 weight-loading + expert-emission primitives
Real DeepSeek-V4-flash routed experts are FP4-packed in int8 (E2M1, block-32,
UE8M0 micro-scales) and its projections are block-FP8 (E4M3 weight + 2D UE8M0
[128,128] block scales). QuantizationConfig.from_transformers treated
quant_method='fp8' as ordinary per-tensor fp8 and returned None, so the model
built bf16 and rejected the packed [2048,2048] expert against the logical
[2048,4096] initializer with a confusing "Weight shape mismatch".
Add a clean, breaking quantized-tensor descriptor + load contract
(mobius.integrations._block_quant), classified by tensor properties (never by
model name):
- BlockQuantScheme: property parser over quantization_config + expert_dtype.
- QuantizedTensorDescriptor: logical + packed shape, qtype, block geometry,
scale name/dtype/shape/layout, byte counts, routed/shared role.
- classify_tensor / validate_descriptor: distinguish ORDINARY, BLOCK_FP8,
FP4_PACKED, UNSUPPORTED; logical-vs-packed shape, scale pairing, wrong/
missing/orphan scale all fail closed. No dequantization, no copy-to-float.
- read_raw_tensor_bytes / LazyRawTensor: byte-exact, header-only, bounded
lazy per-shard loading (one tensor resident).
- stack_expert_bank / PackedExpertBank: byte-exact expert-major bank packing
(reusable lowering primitive; ragged banks are a hard error).
- runtime_representation_gap / plan_routed_expert_bank: the emission gate.
nxrt's BlockFormat accepts only interleaved llama.cpp block_mxfp4 + iq*;
it has no block-FP8 format and no planar-FP4 bank layout, so both families
typed-reject with BlockQuantExportError naming the exact ABI gap instead of
emitting an unrunnable node. No dense fallback.
Route block-scaled fp8 / fp4-expert checkpoints through the typed blocker in
QuantizationConfig.from_transformers (property-guarded: per-tensor fp8 without
weight_block_size still returns None). This moves the real-checkpoint failure
from a shape-mismatch to a precise, actionable BlockQuantExportError.
Tests use the real quantization_config + a measured slice of the checkpoint
index metadata plus tiny synthetic packed safetensors (real I8 / F8_E4M3 /
F8_E8M0 dtypes): classification, logical-vs-packed validation, byte
preservation, scale pairing (missing/duplicate/orphan/wrong), shared vs routed,
bounded lazy load, byte-exact bank stacking, and the emission typed-reject.
An opt-in suite exercises the mounted checkpoint headers directly.
Co-authored-by: Copilot <[email protected]>1 parent cec78d2 commit a38d38d
3 files changed
Lines changed: 1434 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
77 | 109 | | |
78 | 110 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
82 | 114 | | |
83 | 115 | | |
84 | 116 | | |
| |||
0 commit comments