Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use device_map="auto" in single file tests to support large models on limited GPU memory#13816

Merged
sayakpaul merged 5 commits into
huggingface:mainfrom
jiqing-feng:flux
Jun 11, 2026
Merged

Use device_map="auto" in single file tests to support large models on limited GPU memory#13816
sayakpaul merged 5 commits into
huggingface:mainfrom
jiqing-feng:flux

Conversation

@jiqing-feng

Copy link
Copy Markdown
Contributor

Problem

Single file loading tests (SingleFileTesterMixin) used device=torch_device or device_map=torch_device, forcing the entire model onto a single GPU. For large models like FLUX.1-dev (~12B params, ~24GB in bf16), this fails on single 24GB GPUs — especially test_single_file_model_config which loads two models simultaneously.

Changes

tests/models/testing_utils/single_file.py

  • test_single_file_model_config: device=torch_devicedevice_map="auto"
  • test_single_file_model_parameters: device_map=str(torch_device) / device=torch_devicedevice_map="auto"
  • test_single_file_loading_with_device_map: device_map=torch_devicedevice_map="auto"

tests/models/transformers/test_models_transformer_flux.py

  • TestFluxSingleFile: added torch_dtype = torch.bfloat16 to halve memory usage

tests/single_file/test_model_flux_transformer_single_file.py

  • test_device_map_cudatest_device_map_auto: device_map="cuda"device_map="auto", added torch_dtype=torch.bfloat16

Why device_map="auto" instead of CPU offload

enable_model_cpu_offload() is a pipeline-level API, not available for individual model from_single_file loading. device_map="auto" is the model-level solution — accelerate automatically places weights on GPU and offloads the rest to CPU RAM when GPU memory is insufficient.

@github-actions github-actions Bot added size/M PR with diff < 200 LOC tests and removed size/M PR with diff < 200 LOC labels May 27, 2026
Signed-off-by: jiqing-feng <[email protected]>
@github-actions github-actions Bot added the size/S PR with diff < 50 LOC label May 27, 2026
@jiqing-feng

Copy link
Copy Markdown
Contributor Author

Hi @sayakpaul . Would you please review this PR? Thanks!

@sayakpaul sayakpaul requested a review from DN6 May 27, 2026 09:20
@jiqing-feng

Copy link
Copy Markdown
Contributor Author

The failed CI ("LoRA tests with PEFT main") is unrelated to this PR. The same failure is happening across other PRs as well. It appears to be a flaky/known issue with PEFT main. All other 12 checks pass.

@yao-matrix

Copy link
Copy Markdown
Contributor

@DN6 , could you pls help take a second look? Thx.

@jiqing-feng

Copy link
Copy Markdown
Contributor Author

Hi @DN6 . The failed CI is not related to my changes. Would you please review the PR? Thanks!

@jiqing-feng

Copy link
Copy Markdown
Contributor Author

Hi @DN6 . Please let me know what need to be changed before merging this PR. Thanks!

@jiqing-feng

Copy link
Copy Markdown
Contributor Author

The failed CI is not related to my changes.

@jiqing-feng

Copy link
Copy Markdown
Contributor Author

Hi @sayakpaul . I already got the approval. Please let me know what need to be changed before merging. Thanks!

@sayakpaul

Copy link
Copy Markdown
Member

Why do you folks keep pinging multiple maintainers multiple times on multiple PRs?

@jiqing-feng

Copy link
Copy Markdown
Contributor Author

Hi @sayakpaul, apologies for the repeated pings — that wasn't my intention to spam you or the team. I just wanted to keep this small test-only PR from going stale, but I completely understand it adds noise on your end.

I'll hold off on further pings and wait patiently. The PR is already approved by DN6 and the only failing CI ("LoRA tests with PEFT main") is an unrelated flaky failure seen across other PRs. Please take your time, and thanks a lot for your work maintaining the project.

@sayakpaul

Copy link
Copy Markdown
Member

Failing tests are unrelated.

@sayakpaul sayakpaul merged commit 784fa62 into huggingface:main Jun 11, 2026
11 of 13 checks passed
DN6 pushed a commit that referenced this pull request Jul 1, 2026
…on limited GPU memory (#13816)

* fix flux tests OOM on 24G GPU

Signed-off-by: jiqing-feng <[email protected]>

* revert wrong change

Signed-off-by: jiqing-feng <[email protected]>

---------

Signed-off-by: jiqing-feng <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR with diff < 50 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants