-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select the DeepSpeedCPUOptimizer based on the original optimizer class. #3255
base: main
Are you sure you want to change the base?
Conversation
Thanks for this update. Just wondering aloud: If the optimizer is neither Adam, nor Adagrad, nor Lion, what would be the right thing to do? As is, Adam is used, is that correct? |
@BenjaminBossan By default, I have kept the Adam as it was for everyone torch optimizer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! Overall I'm a fan, however let's abstract this out to a util func to keep the Accelerator a bit more readable
src/accelerate/accelerator.py
Outdated
# For DeepSpeedCPUAdagrad | ||
if compare_versions("deepspeed", ">=", "0.5.5"): | ||
# Check if the optimizer is PyTorch's Adagrad. | ||
is_ada = isinstance(optimizer, torch.optim.Adagrad) | ||
# If not, and bitsandbytes is available, | ||
# # check if the optimizer is the 32-bit bitsandbytes Adagrad. | ||
if is_bnb_available() and not is_ada: | ||
import bitsandbytes.optim as bnb_opt | ||
|
||
is_ada = ( | ||
isinstance(optimizer, (bnb_opt.Adagrad, bnb_opt.Adagrad32bit)) | ||
and optimizer.optim_bits == 32 | ||
) | ||
if is_ada: | ||
from deepspeed.ops.adagrad import DeepSpeedCPUAdagrad | ||
|
||
optimizer_class = DeepSpeedCPUAdagrad | ||
|
||
# For DeepSpeedCPULion | ||
if is_bnb_available(min_version="0.38.0") and compare_versions("deepspeed", ">=", "0.11.0"): | ||
from bitsandbytes.optim import Lion, Lion32bit | ||
|
||
if isinstance(optimizer, (Lion, Lion32bit)) and optimizer.optim_bits == 32: | ||
from deepspeed.ops.lion import DeepSpeedCPULion | ||
|
||
optimizer_class = DeepSpeedCPULion | ||
|
||
optimizer = optimizer_class(optimizer.param_groups, **defaults) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit bulky for the Accelerator
, can we abstract this out to a deepspeed util of map_pytorch_optim_to_deepspeed
?
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. |
@muellerzr What do you think of it like this? |
What does this PR do?
For DeepSpeed optimizer offloading, select the appropriate optimizer based on the original optimizer class.
Who can review?