Conversation
When using `from_config()` with DeepSpeed ZeRO-3, `_init_weights()` silently operated on partitioned empty tensors, making custom initialization a no-op. Parameters retained PyTorch's default kaiming_uniform_ instead of the intended initialization, causing abnormally large gradients and loss. The fix suppresses init during construction via `no_init_weights()`, then re-initializes module-by-module using `GatheredParameters` so each module's parameters are gathered before init runs. Co-Authored-By: Masahiro Tanaka <tohtana@users.noreply.github.com>
Member
Author
|
@bot /style |
Contributor
|
Style fix bot fixed some files and pushed the changes. |
|
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. |
winglian
approved these changes
Feb 24, 2026
5 tasks
zvik
pushed a commit
to zvik/transformers
that referenced
this pull request
Mar 1, 2026
* fix zero3 init config * Fix ZeRO-3 weight initialization in `_from_config()` When using `from_config()` with DeepSpeed ZeRO-3, `_init_weights()` silently operated on partitioned empty tensors, making custom initialization a no-op. Parameters retained PyTorch's default kaiming_uniform_ instead of the intended initialization, causing abnormally large gradients and loss. The fix suppresses init during construction via `no_init_weights()`, then re-initializes module-by-module using `GatheredParameters` so each module's parameters are gathered before init runs. Co-Authored-By: Masahiro Tanaka <tohtana@users.noreply.github.com> * Apply repo consistency fixes --------- Co-authored-by: Masahiro Tanaka <tohtana@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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?
Supersedes #43847
When using zero3 + from_config, the model was incorrectly initialized as we were not gathering the params. Added a test also.
cc @tohtana