Repository navigation
Keep the parameters a model names for fp32 in fp32 under ZeRO-3 - #8843
Draft
pengdurice wants to merge 1 commit into
Draft
pengdurice wants to merge 1 commit into
pengdurice wants to merge 1 commit into
Conversation
Signed-off-by: pengdurice <pengduhit@gmail.com>
This branch has not been deployed
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.
Keep the parameters a model names for fp32 in fp32 under ZeRO-3
Follows: #8699 (merged), which kept the listed buffers in fp32 and left the listed parameters to this PR.
Summary
Hugging Face transformers models name the tensors that must stay in fp32 (
_keep_in_fp32_modules_strict, and_keep_in_fp32_modulesfor fp16). #8699 addeddata_types.keep_in_fp32_modules(default"auto": the model's ownlists) and kept the listed buffers in fp32 under ZeRO-3. Listed parameters were still trained in bf16, because
ZeRO-3 flattens each sub-group into one buffer of one dtype. Examples of listed parameters: DeepSeek-V4's
hyper-connection weights, attention sinks and norms; gpt-oss's attention sinks.
This PR lets ZeRO-3 (without parameter offload) hold partitions of two dtypes, so listed parameters are stored,
gathered, updated and checkpointed in fp32 next to the bf16 or fp16 ones.
Duplicate check
Searched open and recent pull requests on 2026-10-15 ("keep_in_fp32", "fp32 modules", "mixed dtype"): only #8699
(merged, buffers). #8686 (reconstruction of shared-submodule parameters in ZeRO checkpoints) is unrelated.
The change
deepspeed/runtime/keep_in_fp32.pykeep_tensors_in_fp32(module, pattern, include_params=True)converts matching parameters too; a ZeRO-3 parameter is converted in its partition (ds_tensor), so later gathers return fp32 and a later checkpoint load writes exact fp32 valuesdeepspeed/runtime/zero/partition_parameters.py__init__(when its fp32 list is complete), its already-partitioned parameters are converted in place, before any checkpoint is loaded; with parameter offload only buffers are keptdeepspeed/runtime/zero/stage3.pydeepspeed/runtime/engine.pydocs/_pages/config-json.mddata_types.keep_in_fp32_modulesnow covers parameters (ZeRO-3) and bufferstests/unit/v1/half_precision/test_keep_in_fp32_modules.pyMeasured
DeepSeek-V4-Flash, first 4 layers, ZeRO-3, bf16, 1 node: 54 listed parameters and 1 buffer are
fp32 and exact after loading (bf16 before); the run without a list is bitwise equal to master over 20 steps; with the
list the mean loss differs from master by -0.0063 (lower on 15 of 20 steps). Throughput and memory were not
measured separately; the listed parameters are norms, sinks and small mixing weights, a small share of each model.
Tests
TestZeroInitKeepsParamsFp32::test_loaded_values_survivezero.Init, listed parameters keep exact fp32 checkpoint values after loadingTestZero3TrainsKeptParamsInFp32::test_update_below_bf16_resolution_is_kept(zero.Init on/off, contiguous gradients on/off, optimizer offload on/off, gradient accumulation 1/2)TestZero3TrainsKeptParamsInFp32::test_all_reduce_fetchTestZero3TrainsKeptParamsInFp32::test_checkpoint_round_tripTestZero3TrainsKeptParamsInFp32::test_param_offload_keeps_only_buffersTestZero3Fp16KeptParams::test_fp16_trainsTestStagesBelowThreeKeptParamsHardware: 1 node of 8 H200 (driver 580.126.09), torch 2.8.0+cu126, pytest 9.1.1.
pre-commit run --filespasses on every changed file. Regression runs at the time of the first version: identical pass counts with and without the change ontest_zero,test_offload_statesandtests/unit/runtime/zero.Compatibility
AI assistance
This change, its tests and this description were prepared with AI assistance (Claude).