[Fix]: Handle div_scale when using Gemini plugin with CPUAdam#6408
Open
Truong5724 wants to merge 1 commit intohpcaitech:mainfrom
Open
[Fix]: Handle div_scale when using Gemini plugin with CPUAdam#6408Truong5724 wants to merge 1 commit intohpcaitech:mainfrom
Truong5724 wants to merge 1 commit intohpcaitech:mainfrom
Conversation
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.
📌 Checklist before creating the PR
[doc/gemini/tensor/...]: A concise descriptionpip install pre-commit && pre-commit install🚨 Issue number
Fixed #6386
📝 What does this PR do?
Problem
colossalai run --nproc_per_node 4 main.pyon Google Colab using the Gemini plugin with CPUAdam (the relevant files and their contents are provided in the issue). The training runs successfully for the first few steps but later fails with anAssertionError.The execution log is shown below:
I also tested with
HybridAdamandFusedAdam, and both worked correctly. This suggests that the issue is specific to theCPUAdamimplementation.In fact, this assertion only exists in
cpu_adam.py, which causes the failure.This check enforces that
div_scalemust remain at its default value (-1), which is too restrictive in practice.In PyTorch, gradient scaling is not automatically handled at the optimizer level, and scaling factors such as
div_scalemay be controlled externally (e.g., by mixed precision or distributed training strategies like Gemini).As a result, enforcing
div_scale == -1prevents valid use cases where a non-default scaling factor is passed, leading to unnecessary failures.Solution
cpu_adam.py:This change allows
div_scaleto be passed without triggering errors, makingCPUAdamcompatible with external gradient scaling mechanisms.I have verified that the training now runs successfully after applying this fix.
💥 Checklist before requesting a review
⭐️ Do you enjoy contributing to Colossal-AI?