Skip to content

Guard DeepSpeed imports #37755

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

Merged
merged 7 commits into from
Apr 24, 2025
Merged

Guard DeepSpeed imports #37755

merged 7 commits into from
Apr 24, 2025

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented Apr 24, 2025

What does this PR do?

This PR follows a similar approach as the one taken in accelerate (huggingface/accelerate#1963) to guard the DeepSpeed imports so that we only call import deepspeed when it's needed. The rationale for this is that whenever we run import deepspeed, CUDA is initialised which is (a) slow and (b) interferes with the vllm server when DP=8 and TP=1 (see vllm-project/vllm#17079)

Related to huggingface/trl#3351

Gently pinging @SunMarc for review 🤗

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.

@github-actions github-actions bot marked this pull request as draft April 24, 2025 13:02
Copy link

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@@ -2702,6 +2701,8 @@ def resize_token_embeddings(
# Since we are basically reusing the same old embeddings with new weight values, gathering is required
is_quantized = hasattr(self, "hf_quantizer") and self.hf_quantizer is not None
if is_deepspeed_zero3_enabled() and not is_quantized:
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I am assuming that we do not need an additional is_deepspeed_available() check, but let me know if we do!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we don't need one ! if is_deepspeed_zero3_enabled returns True, deepspeed will be installed

@lewtun lewtun marked this pull request as ready for review April 24, 2025 13:05
@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.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks ! Just a few nits

@@ -2702,6 +2701,8 @@ def resize_token_embeddings(
# Since we are basically reusing the same old embeddings with new weight values, gathering is required
is_quantized = hasattr(self, "hf_quantizer") and self.hf_quantizer is not None
if is_deepspeed_zero3_enabled() and not is_quantized:
Copy link
Member

Choose a reason for hiding this comment

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

Yeah we don't need one ! if is_deepspeed_zero3_enabled returns True, deepspeed will be installed

@SunMarc SunMarc merged commit acdbe62 into main Apr 24, 2025
21 checks passed
@SunMarc SunMarc deleted the lewtun/deepspeed-imports branch April 24, 2025 16:16
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.

3 participants