Skip to content

Fix local LoRA weight auto-discovery in offline mode#14204

Merged
sayakpaul merged 2 commits into
huggingface:mainfrom
fropych:fix-local-lora-offline-auto-discovery
Jul 16, 2026
Merged

Fix local LoRA weight auto-discovery in offline mode#14204
sayakpaul merged 2 commits into
huggingface:mainfrom
fropych:fix-local-lora-offline-auto-discovery

Conversation

@fropych

@fropych fropych commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #14195

_best_guess_weight_name() currently checks local_files_only and HF_HUB_OFFLINE before determining whether the supplied path is a local file or directory. As a result, local LoRA weights without an explicit weight_name are rejected in offline mode before Diffusers inspects the local filesystem.

This PR moves the offline-mode guard after the local file and directory checks. With this change:

  • a direct local LoRA file works in offline mode;
  • a local directory can auto-discover its LoRA weight file with either HF_HUB_OFFLINE=1 or local_files_only=True;
  • a remote repository ID without weight_name still raises the existing offline-mode error;
  • model_info() is not called in offline mode.

Checking os.path.isfile() and os.path.isdir() only accesses the local filesystem and cannot trigger a Hub request, so this preserves the network restrictions of offline mode. There are no public API changes.

Coordination: #14195 and the related discussion in #14198.

Tests

The regression tests cover local files, local directories, both offline controls, remote repository IDs without weight_name, the absence of model_info() calls, and the existing behavior for zero or multiple matching files.

$ .venv/bin/python -m pytest -q tests/lora/test_lora_loader_utils.py
......                                                                   [100%]
6 passed in 0.05s

$ PATH=".venv/bin:$PATH" make style
All checks passed!
1999 files left unchanged

$ PATH=".venv/bin:$PATH" make fix-copies
Passed

$ PATH=".venv/bin:$PATH" make quality
All checks passed!
1999 files already formatted

AI assistance

This PR received substantial assistance from OpenAI Codex. I identified and reproduced the original problem, defined the expected behavior and regression cases, and made the final contribution decisions. Codex was used to inspect the repository instructions and related history, implement the minimal fix, add regression tests, run the relevant checks, perform the final self-review, and help draft the PR description. The final diff and test results were presented to me before submission.

Final self-review

  • Blocking issues: None.
  • Non-blocking issues: None.
  • Dead code: None introduced; all new test helpers and constants are used.
  • Documentation impact: No documentation update is needed. This is a focused bug fix with no public API or default changes, and remote repository behavior remains unchanged.
  • Verdict: READY.
  • Fix before submitting: Nothing.
  • Leave for the actual review: Nothing.

Before submitting

Who can review?

@sayakpaul

Comment thread tests/lora/test_lora_loader_utils.py Outdated

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@fropych
fropych marked this pull request as ready for review July 16, 2026 09:19
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@sayakpaul
sayakpaul merged commit cca8af2 into huggingface:main Jul 16, 2026
34 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline mode rejects local LoRA files and directories without weight_name

3 participants