Repository navigation
Write the tiny Mistral Large 4 FP8 checkpoint in the reference layout - #8239
albertvillanova wants to merge 1 commit into
Conversation
|
The CI model has been regenerated and the corresponding Hub PR is open. It needs to be merged once this PR is approved: |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
mangeshraut712
left a comment
There was a problem hiding this comment.
The in-script FP8 conversion is a reasonable way to avoid needing an FP8 GPU at load time, but a couple of edges will corrupt or change the checkpoint:
-
All-zero blocks become NaN. For a block whose
amaxis 0,torch.log2(blocks.abs().amax(dim=(1, 3)) / torch.finfo(torch.float8_e4m3fn).max)
is
-inf,exp2is 0, andblocks / scaleis0/0→ NaN before thefloat8_e4m3fncast. Tiny or structured-init weights can easily have a zero tile. I’d clamp the scale to a minimum of 1 (or skip / write a zero scale) whenamax == 0. -
The fp32 restore for the router and RoPE scale was dropped. The previous code forced
layer.mlp.gate.weightandrotary_emb.alphato float32 because “the reference keeps [them] in fp32”. Those names are not infp8_weights, so they now staybfloat16frommodel.to(dtype=torch.bfloat16). Ifcheck_dtype_patterndoes not cover them, the published tiny checkpoint will silently disagree with the reference dtypes. -
view(rows // 32, 32, cols // 32, 32)throws if a matched weight is not divisible by 32.hidden_size/intermediate_size/moe_intermediate_sizeare, but if awq/indexer.wq_bever comes out 32×16 (e.g. fromkv_lora_rankorindex_head_dim), the script crashes instead of skipping or padding. A divisibility check with a clear error would help.
|
Tested with |
qgallouedec
left a comment
There was a problem hiding this comment.
Thanks, confirmed on my side
This PR writes the FP8 checkpoint of the tiny Mistral Large 4 model in the layout of
mistralai/Mistral-Large-4-1T-A52B, instead of quantizing it at load.Part of #7137.
Motivation
When the model is quantized at load and saved by transformers, the file stores fused expert scales named
weight_scale_invnext to per-expert weights. The script also cast the router and the RoPEalphato F32. The reference stores per-expertqscale_weightscales and keeps both tensors in BF16.Changes
qscale_weight(F32).gate.weightandlerope.alphain BF16, like the reference.quantization_config, with onlyweight_block_sizescaled down.Dry run at transformers 5.22.0: the checkpoint matches the reference names and dtypes, it reloads with the per-expert scales merged, and the smoke test passes. The dtype check in the script compares against the consolidated reference once #8238 is merged.
Note
Low Risk
Changes are confined to the tiny-model generation script and checkpoint export path, not runtime inference or core library logic.
Overview
The tiny Mistral Large 4 generator no longer relies on
FineGrainedFP8Configand load-time quantization. It saves a BF16 checkpoint, rewrites selected linear weights inmodel.safetensorstofloat8_e4m3fnin 32×32 blocks with per-block power-of-twoqscale_weighttensors (matching the reference consolidated layout), restoresquantization_configwith shrunkweight_block_size, reloads from disk for the smoke test, and uploads viapush_dir_to_hubinstead of hub-push on the in-memory quantized model.Router
gate.weightand RoPEalphaare no longer upcast to FP32 during export, aligning dtypes with the reference checkpoint naming and scale conventions.Reviewed by Cursor Bugbot for commit faff858. Bugbot is set up for automated code reviews on this repo. Configure here.