Skip to content
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

allow to set mxied_precision in accelerate config when using a given deepspeed config #3385

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

XiaobingSuper
Copy link
Contributor

What does this PR do?

Fixes #3360 (comment).

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@@ -1335,7 +1335,6 @@ def _deepspeed_config_checks(self):
"ACCELERATE_DEEPSPEED_OFFLOAD_PARAM_NVME_PATH",
"ACCELERATE_DEEPSPEED_OFFLOAD_OPTIMIZER_NVME_PATH",
"ACCELERATE_DEEPSPEED_ZERO3_SAVE_16BIT_MODEL",
"ACCELERATE_MIXED_PRECISION",
Copy link
Contributor Author

@XiaobingSuper XiaobingSuper Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ds config doesn't have such an attribute, and it only works when calling(https://github.com/huggingface/accelerate/blob/main/src/accelerate/accelerator.py#L351)

def set_mixed_precision(self, mixed_precision):
ds_config = self.deepspeed_config
kwargs = {
"fp16.enabled": mixed_precision == "fp16",
# When training in fp8, we still rely on bf16 autocast for the core mixed precision
"bf16.enabled": mixed_precision in ("bf16", "fp8"),
}
if mixed_precision == "fp16":
if "fp16" not in ds_config:
ds_config["fp16"] = {"enabled": True, "auto_cast": True}
elif mixed_precision in ("bf16", "fp8"):
if "bf16" not in ds_config:
ds_config["bf16"] = {"enabled": True}
if mixed_precision == "fp8" and self.enable_msamp:
if "msamp" not in ds_config:
ds_config["msamp"] = {"enabled": True, "opt_level": self.msamp_opt_level}
if mixed_precision != "no":
diff_dtype = "bf16" if mixed_precision == "fp16" else "fp16"
if str(ds_config.get(diff_dtype, {}).get("enabled", "False")).lower() == "true":
raise ValueError(
f"`--mixed_precision` arg cannot be set to `{mixed_precision}` when `{diff_dtype}` is set in the DeepSpeed config file."
)
for dtype in ["fp16", "bf16"]:
if dtype not in ds_config:
ds_config[dtype] = {"enabled": False}
self.fill_match("fp16.enabled", must_match=False, **kwargs)
self.fill_match("bf16.enabled", must_match=False, **kwargs)
, for the case which the mixed_precision flag is not aligned with the deepspeed config, there will raise error:
image

@XiaobingSuper XiaobingSuper changed the title allow to set mxied_precision in accelerate config given a using deepspeed config allow to set mxied_precision in accelerate config when using a given deepspeed config Feb 7, 2025
@XiaobingSuper XiaobingSuper force-pushed the xiaobing/accelerate_config branch 2 times, most recently from 7552c3e to be09963 Compare February 7, 2025 08:59
@HuggingFaceDocBuilderDev

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.

@XiaobingSuper XiaobingSuper force-pushed the xiaobing/accelerate_config branch from be09963 to a43dec6 Compare February 12, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FP8 training can't works with deepspeed
2 participants