mstar.utils.fp8_block#
FP8 block-scale checkpoints: the quantization_config they declare, and their weights dequantized; the scale
layout of cuBLASLt’s block-scaled GEMMs (MXFP8, NVFP4).
A block-scale checkpoint (DeepSeek-V3’s format, GLM-5.x’s) stores each linear weight as e4m3 with one fp32
weight_scale_inv per weight_block_size block. Triton-free, so a model’s config can import it on a
CPU-only install; the activation quantizer that feeds the block-scale GEMMs is quant_fp8.
Functions
|
Pair fp8 |
|
Dequantize one 2-D fp8 weight: |
|
|
|
Length of the flat scales of |
|
The inverse of |
Classes
|
One block-scaled matrix |
|
The fields of an HF fp8 |
- class mstar.utils.fp8_block.BlockQuant(data, scale, tensor_scale=None)[source]#
Bases:
NamedTupleOne block-scaled matrix
[rows, K // packing].scaleis flat in the GEMM’s swizzled layout;tensor_scaleis NVFP4’s second level, a[1]fp32 (None under MXFP8).
- class mstar.utils.fp8_block.Fp8BlockQuantConfig(weight_block_size=(128, 128), fmt='e4m3', activation_scheme='dynamic', ignore=<factory>)[source]#
Bases:
objectThe fields of an HF fp8
quantization_configa block-scale checkpoint carries.- Parameters:
- classmethod from_hf_config_dict(quant)[source]#
- Parameters:
quant (dict | None)
- Return type:
Fp8BlockQuantConfig | None
- mstar.utils.fp8_block.dequant_fp8_block_stream(weights, quant_config, out_dtype=torch.bfloat16, keep_fp8=None)[source]#
Pair fp8
.weightkeys with.weight_scale_invand dequantize.
- mstar.utils.fp8_block.dequantize_fp8_block_weight(weight_fp8, scale_inv, block_size=(128, 128), out_dtype=torch.bfloat16)[source]#
Dequantize one 2-D fp8 weight:
w[i, j] * scale_inv[i//bo, j//bi].
- mstar.utils.fp8_block.swizzle_block_scales(scales)[source]#
[rows, k_blocks]-> the flat 32x4x4 layout of the cuBLAS block scaling factors: 128x4 tiles of 512 elements, rowr, blockjof a tile at(r % 32) * 16 + (r // 32) * 4 + j.