Skip to content

Fix low_cpu_mem_usage Flag Conflict with DeepSpeed Zero 3 in from_pretrained for Models with keep_in_fp32_modules" - #27762

Merged
asartran merged 1 commit into
huggingface:mainfrom
kotarotanahashi:fix-cpu-mem-usage-for-zero3
Dec 15, 2023
Merged

asartran merged 1 commit into
huggingface:mainfrom
kotarotanahashi:fix-cpu-mem-usage-for-zero3

Conversation

@kotarotanahashi

@kotarotanahashi kotarotanahashi commented Nov 29, 2023 •

Copy link
Copy Markdown
Contributor

Summary

This pull request addresses a compatibility issue in the from_pretrained method. Specifically, when using models with keep_in_fp32_modules not set to None (e.g., BLIP2, T5) in conjunction with DeepSpeed's Zero 3, an unexpected error occurs due to the improper handling of the low_cpu_mem_usage.

Problem Description

Currently, in the from_pretrained method, the low_cpu_mem_usage flag is set to True if use_keep_in_fp32_modules is True and accelerate is available. This logic does not account for the incompatibility with DeepSpeed Zero 3. When Zero 3 is enabled, setting low_cpu_mem_usage to True can lead to unexpected errors.

Proposed Change

I propose to modify the condition to check whether DeepSpeed Zero3 is enabled. The low_cpu_mem_usage should be set to True only if Accelerate is available and DeepSpeed Zero3 is not enabled. The revised code snippet is:

if is_accelerate_available() and not is_deepspeed_zero3_enabled():
    low_cpu_mem_usage = True

This change prevents the low_cpu_mem_usage flag from being incorrectly set in scenarios where DeepSpeed Zero 3 is in use, thereby avoiding the aforementioned issue.

for `low_cpu_mem_usage` with DeepSpeed Zero3

@pacman100 pacman100 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @kotarotanahashi for fixing this bug!

@asartran asartran left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing!

@asartran
asartran merged commit 29a1c1b into huggingface:main Dec 15, 2023
iantbutler01 pushed a commit to BismuthCloud/transformers that referenced this pull request Dec 16, 2023
…pretrained` for Models with `keep_in_fp32_modules`" (huggingface#27762)

Fix `from_pretrained` Logic
for `low_cpu_mem_usage` with DeepSpeed Zero3
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