Skip to content

FP8 on the fine-grained machinery (Fp8Config) - #49777

Draft
IlyasMoutawwakil wants to merge 22 commits into
fg-split/4-machineryfrom
fg-split/5-fp8
Draft

IlyasMoutawwakil wants to merge 22 commits into
fg-split/4-machineryfrom
fg-split/5-fp8

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What and why.

  • Fp8Config and Fp8HfQuantizer: FP8 weights with fp32 or UE8M0 scales over blocks or the whole tensor, with
    dynamic or calibrated activations. quant_method="fp8" routes here. This is the first format on the machinery of
    Fine-grained block-scaled quantization: the shared machinery #49776. MXFP4, NVFP4 and MXFP8 follow in 🚨 MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan #49778, NVFP4 on the fine-grained machinery #49779 and MXFP8 on the fine-grained machinery (Mxfp8Config) #49780.
  • FP8 embedding tables with one per-tensor scale. They exist for tables too big to dequantize. The first user is
    Qwen4Exp's ~95 GiB ple.ple_embedding.ngram_embedding (main code). Its weight_scale is replicated under TP, since
    a (1,) scale cannot follow a vocab-sharded table.
    • A table is a plan entry: FineGrainedConfig(dtype_plan={"ngram_embedding": Fp8Config(weight_block_size=None), ".*": Fp8Config()}). The catch-all never covers an embedding.
    • read_fp8 reads an FP8 checkpoint's modules_to_convert, the dialect of main's FineGrainedFP8Config, into such
      a plan. So Fp8Config has no modules_to_convert.
    • The host gives each member dtype_plan_targets, the patterns that name its modules. A block-scaled member
      converts the embeddings they name. The block-scale rename leaves out every embedding.
  • The reader registry starts here, with read_fp8. A reader turns a checkpoint's quantization_config into the
    configs that load it. ModelOpt and compressed-tensors exports come in Load ModelOpt and compressed-tensors exports on the fine-grained formats #49823, for every format at once.
  • CHECKPOINT_READING_CONFIG_TYPES: a passed config of these types reads the checkpoint's config as its own class.
    FineGrainedFP8Config reads only FP8 checkpoints, not MXFP4 or NVFP4 ones.
  • FineGrainedFP8Config is deprecated when built. Passed explicitly, it still loads through its frozen
    integration. from_dict does not warn, so checkpoints that still map to it load quietly. "mxfp8" keeps that
    mapping and from_config routes it by type to the frozen quantizer until MXFP8 on the fine-grained machinery (Mxfp8Config) #49780.
  • The frozen FP8 integration now pads a trailing partial block on save and load. DeepSeek-V3's (576, 7168)
    kv_a_proj_with_mqa has one. Before, the save left it unquantized and the load raised on the scale grid.
  • DeepSeek-V4 checkpoints still load through the legacy FP8 integration, as on main, until 🚨 MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan #49778. read_fp8 reads
    their checkpoint_format: "deepseek" as FineGrainedFP8Config. DeepseekV4Config.__post_init__ puts that layout
    name, and V4's expert_dtype, into the quantization config it loads with. A config transformers saved names its
    own layout, so it stays as saved: an FP8 model quantized on the fly reloads as FP8.
  • The Mistral conversion scripts swap modules through the quantizer, since the legacy replace helpers are not used
    by Fp8Config.

Depends on. #49776.

How tested. AdaptQuantizationConfigTest in tests/quantization/test_quantizers_utils.py, tests/quantization/fp8 and the shared fine-grained tests that need a real format. The legacy suite
(tests/quantization/finegrained_fp8, tests/kernels/test_finegrained_fp8.py) stays while the legacy path ships.
Slow tiny checkpoints: RUN_SLOW=1 pytest tests/quantization/fp8 -k "Tiny or Checkpoint".

The comments and docstrings that say why each change exists are there for readability. Feel free to ask for any of them to go if it's self-evident.

🤖 Generated with Claude Code

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

IlyasMoutawwakil and others added 21 commits October 23, 2026 13:34
- Fp8Config / Fp8HfQuantizer: FP8 weights with fp32 or UE8M0 scales over
  blocks or the whole tensor, dynamic or calibrated (static) activations;
  quant_method="fp8" now routes here.
- FP8 embedding tables (modules_to_convert): FineGrainedEmbedding, one
  per-tensor scale each, also under FineGrainedConfig.
- The modelopt and compressed-tensors config readers, registered for the
  producers' FP8 exports, with their producer layouts.
- FineGrainedFP8Config is deprecated: passed explicitly it still loads through
  its own frozen integration; finegrained_fp8 warns that it is frozen.
- The Mistral conversion scripts swap modules through the quantizer.
- Tests: the FP8 suite (config, quantize op, chains, quantizer, tiny
  checkpoints, load-path equivalence under TP/EP), the shared fine-grained
  tests that need a real format, and the testers' FP8 fixtures. The machinery
  tests against the test-only formats are superseded and removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restore the legacy kernel tests and `FP8LinearTest`, and drop the import-time warning of the frozen module.
The block-FP8 routing test moves to the `fp8` suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A linear whose shape does not tile the block became an FP8Linear but kept
its uninitialized scale, which made the ue8m0 round-trip test flaky.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rnel

The Hub kernel now reads the right scale for interleaved gate|up rows
(kernels-community/finegrained-kernels#1253), so the old slice recorded the bug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n format

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Block-FP8 gate|up are interleaved on SM100 only, so the tests that check interleaving pin SM100, and a
switch of experts implementation after load now works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A loaded table kept an fp32 scale in a bf16 model, so its rows came out fp32 and the next linear raised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ror messages

The host finds embedding tables with module_kind, as replacement does. FineGrainedEmbedding checks the method
enum. plan_from_config_groups only has internal callers, so it is private.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FineGrainedConfig drops modules_to_convert, which never shipped. A targeted entry opts a table in, so the plan
alone says which modules quantize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nfig hook

DeepseekV4Config moves its experts' dtype and its scale names into its quantization config. The fp8 reader then
picks the integration. PreTrainedConfig needs no adapt hook for one model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s_to_convert

- read_fp8 turns a checkpoint's modules_to_convert into per-tensor table entries.
- The host gives each member the patterns that name its modules, dtype_plan_targets. A block-scaled member converts
  the embeddings they name.
- The block-scale rename leaves out every embedding, so a member needs no other member's tables.
- A reader's skip-list becomes None entries of the plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They come back at the top of the stack, for every format at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the fly a passed Fp8Config quantizes the experts to FP8 too. The model config's expert_dtype describes DeepSeek's
own checkpoints, so it no longer turns a saved FP8 model into MXFP4 experts on reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: deepseek_v4, glm_moe_dsa, ministral3, mistral4, qwen4_exp, finegrained, finegrained_fp8, fp8

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants