Skip to content

Conversation

@gante
Copy link
Contributor

@gante gante commented May 6, 2025

What does this PR do?

Our daily CI had >1000 new failures since #37920, on tests that use the max_memory argument in from_pretrained. This is because we now recapture unused reserved GPU memory, which caused us to go beyond the user-defined max_memory. This PR fixes it.

Affected tests, which set max_memory:

  • test_cpu_offload
  • test_disk_offload_bin
  • test_model_parallelism

@github-actions github-actions bot marked this pull request as draft May 6, 2025 16:52
@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2025

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.

@gante gante requested review from Cyrilvallez and ydshieh May 6, 2025 16:52
@gante gante marked this pull request as ready for review May 6, 2025 16:52
@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
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

Looks good to me although not diving into the details 💯 !

@gante gante changed the title [offload] respect max_memory argument [offload] respect max_memory argument when factoring in unused reserved memory May 6, 2025
Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

Ha, this got through the radar indeed! Thanks! Though I believe we can simply check unused_memory when max_memory is set, to keep the exact same behavior

Comment on lines -1298 to +1301
max_memory[device_name] += unused_memory
device_map_kwargs["max_memory"] = max_memory
inferred_max_memory[device_name] += unused_memory
# respect the `max_memory` passed by the user
if max_memory is not None and device_name in max_memory:
inferred_max_memory[device_name] = min(inferred_max_memory[device_name], max_memory[device_name])
Copy link
Member

Choose a reason for hiding this comment

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

Probably easier to check unused_memory only if max_memory is not None and device_name in max_memory no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(chatted on slack)

@gante gante merged commit a9384f8 into huggingface:main May 7, 2025
20 checks passed
@gante gante deleted the respect_max_memory branch May 7, 2025 08:49
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Jun 25, 2025
As discussed internally, since
huggingface/transformers#37982, some multi-GPU
tests started failing because all parameters are loaded onto a single
GPU. This should now be fixed by providing an explicit device_map
instead of relying on "auto".

Furthermore, for an unknown reason, the HQQ test started failing as the
correlation dipped below 0.97 -- to 0.9696 actually. I think this is
close enough to not warrant further investigation. Therefore, I only
decreased the threshold.
BenjaminBossan added a commit to huggingface/peft that referenced this pull request Jul 2, 2025
As discussed internally, since
huggingface/transformers#37982, some multi-GPU
tests started failing because all parameters are loaded onto a single
GPU. This should now be fixed by providing an explicit device_map
instead of relying on "auto".

Furthermore, for an unknown reason, the HQQ test started failing as the
correlation dipped below 0.97 -- to 0.9696 actually. I think this is
close enough to not warrant further investigation. Therefore, I only
decreased the threshold.
efraimdahl pushed a commit to efraimdahl/peft that referenced this pull request Jul 12, 2025
As discussed internally, since
huggingface/transformers#37982, some multi-GPU
tests started failing because all parameters are loaded onto a single
GPU. This should now be fixed by providing an explicit device_map
instead of relying on "auto".

Furthermore, for an unknown reason, the HQQ test started failing as the
correlation dipped below 0.97 -- to 0.9696 actually. I think this is
close enough to not warrant further investigation. Therefore, I only
decreased the threshold.
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.

4 participants