Skip to content

Quantize the tiny DeepSeek-V3 and GPT-OSS models like their references (FP8, MXFP4) - #8058

Merged
qgallouedec merged 19 commits into
mainfrom
quantized-tiny-models
Nov 9, 2026
Merged

qgallouedec merged 19 commits into
mainfrom
quantized-tiny-models

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Three tiny models have quantized references but were not quantized: DeepSeek-R1 and R1-0528 ship FP8 weights, gpt-oss-20b ships MXFP4 experts. The scripts now quantize the random weights the same way and write the checkpoint in the reference layout (transformers' FP8 quantizer rejects the 576-row kv_a_proj_with_mqa, and its MXFP4 save path hardcodes gpt-oss-20b's shapes), so the tiny models load like the real ones, dequantized by TRL since #8070. DeepSeek widens to 128 (the FP8 activation block), gpt-oss to 32 (the MXFP4 block).


Note

Medium Risk
Changes quantized tiny Hub artifacts and broad test matrix behavior (xfail/skip/revisions); DeepSeek tests stay red until upstream FP8 dequant is fixed, but runtime trainer code is mostly test and script tooling.

Overview
Tiny-model generators for DeepSeek-V3 (R1 and 0528) and GPT-OSS now write Hub checkpoints in the same FP8 / MXFP4 layouts as the real models—manual block quantization and safetensors save, reload for smoke tests, then push_dir_to_hub. DeepSeek configs widen to 128-wide blocks; gpt-oss uses 32-wide expert blocks.

scripts/generate_tiny_models/_common.py gains dtype checking from a raw state dict, push_dir_to_hub, and a --revision flag to append commits to an existing Hub PR (documented in the README).

Tests point at unpinned Hub PR refs for the three tiny quant models; MoE LoRA/PEFT coverage moves from gpt-oss to tiny-Qwen3MoeForCausalLM (fused experts need transformers ≥5). DeepSeek cases are xfail until transformers#49873; gpt-oss is gated at 5.23.0 for float32 expert dequant; fused-head and aux-loss tests load via create_model_from_path so MXFP4 weights dequantize like trainers do.

Reviewed by Cursor Bugbot for commit 82f6631. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T21:34:31.469239Z 902f2f1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the 🔧 maintenance CI, tooling, tests, or repo upkeep label Nov 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 902f2f1149

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bot-ci-comment

bot-ci-comment Bot commented Nov 1, 2026

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.

@qgallouedec qgallouedec changed the title Quantize the tiny DeepSeek-V3 and GPT-OSS models like their references (FP8, MXFP4) [WIP] Quantize the tiny DeepSeek-V3 and GPT-OSS models like their references (FP8, MXFP4) Nov 1, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread tests/test_utils.py Resolved
Comment thread tests/test_dpo_trainer.py Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread tests/test_utils.py Resolved
@qgallouedec qgallouedec changed the title [WIP] Quantize the tiny DeepSeek-V3 and GPT-OSS models like their references (FP8, MXFP4) Quantize the tiny DeepSeek-V3 and GPT-OSS models like their references (FP8, MXFP4) Nov 2, 2026
@qgallouedec
qgallouedec requested a review from AmineDiro November 3, 2026 05:12
Comment thread scripts/generate_tiny_models/README.md Outdated
6. Runs `print_config_diff` — prints every flat-key difference between the reference Hub config and the tiny model's config (for debugging scale-downs).
7. Pushes the model, tokenizer/processor, generation config, and model card to the Hub in a single commit.

When the reference checkpoint is quantized (DeepSeek-R1 in FP8, gpt-oss in MXFP4), the script quantizes the random weights the same way, writes the checkpoint itself in the reference's layout, loads it back for the smoke test, and pushes the directory with `push_dir_to_hub`. Loading these tiny models needs a GPU with FP8 support, or the `kernels` package for MXFP4 (transformers dequantizes to bf16 without it).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a GPU with FP8 support,

Is this always true ? we dont do software quantization in transformers 🤔 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, without a GPU with FP8 support, transformers dequantizes the checkpoint to bf16 on load, like MXFP4 without kernels. Let's be precise

@qgallouedec
qgallouedec requested a review from AmineDiro November 9, 2026 10:09

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 82f6631. Configure here.

Comment thread tests/test_sft_trainer.py Resolved
@qgallouedec

Copy link
Copy Markdown
Member Author

merging this one, it's been waiting for a while, it's only tests changes

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

Labels

🔧 maintenance CI, tooling, tests, or repo upkeep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants