[megatron] 2/n towards Kimi K2.6: INT4 -> BF16 masters dequantization tool - #2019
Draft
avigyabb wants to merge 1 commit into
Draft
[megatron] 2/n towards Kimi K2.6: INT4 -> BF16 masters dequantization tool#2019avigyabb wants to merge 1 commit into
avigyabb wants to merge 1 commit into
Conversation
… tool Streaming converter for compressed-tensors pack-quantized INT4 checkpoints into plain BF16 HF checkpoints, producing the master weights that trainer.policy.model.fake_int4_qat.bf16_base_path loads. For models whose BF16 originals were never released (Kimi K2-Thinking / K2.6), the dequant is the only valid master: under the (scale_divisor=7.0, q_min=-7) convention, fake-quantize of a dequant is the identity bit-for-bit. - Shard-by-shard streaming with lazy cross-shard companion lookup and ~5GB buffered output shards + rewritten index; quantization_config is stripped from config.json and sidecar files are copied through. - --verify off|sample|full checks each sampled module's dequant is a fixed point of the QAT grid (stored weight_scale reproduced, fake-quant identity); fails by design on llm-compressor RTN (/7.5) checkpoints, whose dequant is not valid as QAT masters. - CPU tests pin unpack/dequant bit-exactness against the real Kimi-K2.6 and Qwen3.6-INT4-RTN golden slices from _fake_int4_qat_golden.py, plus end-to-end conversion, verify-rejection, and zero-point rejection. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Avi Basnet <avigyabb@stanford.edu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Follow-up to #1862 (fake-INT4 QAT). Adds a streaming converter that turns a compressed-tensors pack-quantized INT4 checkpoint into a plain BF16 HF checkpoint — producing the master weights that
trainer.policy.model.fake_int4_qat.bf16_base_pathloads.For models whose BF16 originals were never released (Kimi K2-Thinking / K2.6), the dequantized INT4 weights are the only valid masters: under the
(scale_divisor=7.0, q_min=-7)convention, fake-quantize of a dequant is the identity bit-for-bit, so training from the dequant reproduces the served grid exactly.Implementation
skyrl/backends/skyrl_train/workers/megatron/dequantize_int4_checkpoint.py:weight_scalecan live in a different shard than itsweight_packed); buffers ~5GB output shards and rewrites the safetensors index, so the 1T-scale Kimi conversion runs in bounded memory on a CPU node.dequantize()bit-for-bit (nibblejof each int32 = codej+ 8; group multiply in the scale dtype).quantization_configis stripped fromconfig.json; sidecar files are copied.--verify off|sample|full: each sampled module's dequant must be a fixed point of the QAT grid (recomputedweight_scaleequals the stored one, fake-quantize is the identity). Fails by design on llm-compressor RTN (/7.5) checkpoints, whose dequant is not valid as QAT masters — those need the original BF16 release.weight_zero_point/weight_g_idx(symmetric group quantization only).Usage:
uv run --isolated -m skyrl.backends.skyrl_train.workers.megatron.dequantize_int4_checkpoint \ <int4_checkpoint_dir> <bf16_masters_dir> --verify sampleTests
CPU-only, no compressed-tensors dependency:
moonshotai/Kimi-K2.6andQwen3.6-35B-A3B-INT4-RTNgolden slices from_fake_int4_qat_golden.py(the Kimi slice converts end-to-end with--verify fulland reproduces the served grid).test_fake_int4_qat.pysuite still passes.Remaining work (next steps in this series)
KimiK25ForConditionalGeneration(vision tower strip, analogous to the Qwen3.5 LM-only bridge).🤖 Generated with Claude Code