FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix offline loading of sharded checkpoints by Subodh-17 · Pull Request #14971 · huggingface/diffusers · GitHub

Repository navigation

Fix offline loading of sharded checkpoints - #14971

Open
Subodh-17 wants to merge 1 commit into
huggingface:mainfrom
Subodh-17:fix/hf-hub-offline-sharded-checkpoint
Open

Subodh-17 wants to merge 1 commit into
huggingface:mainfrom
Subodh-17:fix/hf-hub-offline-sharded-checkpoint

Conversation

Copy link
Copy Markdown

What does this PR do?

Fixes an issue where ModelMixin.from_pretrained() could fail to load a fully cached sharded checkpoint when HF_HUB_OFFLINE=1.

When loading sharded checkpoints, _get_checkpoint_shard_files() could still call the Hugging Face Hub metadata API unless local_files_only=True was explicitly passed. In offline mode this caused an OfflineModeIsEnabled error even though all required checkpoint files were already available in the local cache.

This change makes HF_HUB_OFFLINE imply local_files_only for sharded checkpoint loading, preventing unnecessary Hub metadata requests in offline mode.

Which issue does this fix?

Fixes #14952

Motivation and context

Users running Diffusers in offline environments should be able to load cached sharded checkpoints without requiring network access.

The existing local_files_only behavior already supported this use case when explicitly enabled. This change makes the behavior consistent with the HF_HUB_OFFLINE environment setting.

What are the changes?

  • Treat HF_HUB_OFFLINE as equivalent to local_files_only=True in _get_checkpoint_shard_files().
  • Add a regression test verifying that a cached sharded checkpoint can be loaded successfully while offline.
  • Verify that the loaded offline model has the same parameters as the initially cached model.

Tests

Focused regression test:

  • pytest tests/models/test_modeling_common.py::TestModelUtils::test_hf_hub_offline_with_sharded_checkpoint
    • 1 passed

Existing related test:

  • pytest tests/models/test_modeling_common.py::TestModelUtils::test_local_files_only_with_sharded_checkpoint
    • 1 passed

Also verified:

  • git diff --check passes.

Final self-review

  • The change is limited to the reported issue.
  • The implementation uses the existing HF_HUB_OFFLINE behavior rather than introducing a new configuration mechanism.
  • A regression test was added for the reported offline sharded-checkpoint scenario.
  • The test verifies that model parameters remain identical when loading from the cache in offline mode.
  • Existing related sharded-checkpoint behavior remains covered by its existing test.
  • No unrelated files or formatting changes were introduced.
  • The commit is signed off with DCO.

Signed-off-by: Subodh Bansode <subodh171011@gmail.com>
github-actions Bot added fixes-issue size/S PR with diff < 50 LOC tests utils and removed size/S PR with diff < 50 LOC fixes-issue labels Oct 6, 2026

Copy link
Copy Markdown
Author

The TruffleHog Secret Scanning check is failing on 4 unverified AzureSasToken findings, but none are introduced by this PR.

I compared the PR diff against origin/main:

  • PR diff findings: 0
  • The PR changes only:
    • src/diffusers/utils/hub_utils.py
    • tests/models/test_modeling_common.py
  • No credential/token-like content was introduced by these changes.
  • The reported findings are pre-existing repository-history findings.
  • TruffleHog reports 0 verified secrets.

I have therefore left the implementation unchanged rather than modifying unrelated repository content to address the scan result.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant


Back | FazBrowse Home | New Git URL