Compare commits

...
Sign in to create a new pull request.

5 commits

Author SHA1 Message Date
Daniel Han
1d46c655b4 Harden HfFileSystem glob: fix Windows path splitting, add try/except
- Use str.rsplit("/", 1) instead of os.path.split to extract filenames
  from HfFileSystem paths. HfFileSystem always returns POSIX-style paths,
  but os.path.split uses the OS separator, so on Windows the entire path
  was returned as the "filename" and the config name comparison always
  failed.
- Wrap the HfFileSystem().glob() call in try/except to gracefully handle
  network failures (offline mode, timeouts, unreachable Hub). On failure
  both_exist stays False, which is the safe default.
2026-04-06 12:07:57 +00:00
Daniel Han
b83d57ff34 Merge remote-tracking branch 'origin/main' into pr-4852-head 2026-04-06 10:27:47 +00:00
Daniel Han
30db8f3935 Remove test file from main PR - moved to separate PR
Tests for the glob skip guard belong in their own PR to keep
the loader change minimal and reviewable.
2026-04-05 03:12:22 +00:00
pre-commit-ci[bot]
c50591b1a2 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-04-05 03:12:22 +00:00
Roland Tannous
dac1b60cd7 fix: skip redundant HfFileSystem().glob() calls in loader.py
Guard the SUPPORTS_LLAMA32 glob blocks with `is_model and is_peft` so
the HfFileSystem HTTP call is only made when both configs could actually
exist. This prevents indefinite hangs on slow/unreliable networks since
the glob result is redundant when either AutoConfig or PeftConfig
already failed to load.
2026-04-05 03:12:22 +00:00

View file

@ -508,7 +508,7 @@ class FastLanguageModel(FastLlamaModel):
model_type = model_types
# New transformers need to check manually.
if SUPPORTS_LLAMA32:
if SUPPORTS_LLAMA32 and is_model and is_peft:
# Check if folder exists locally
if os.path.isdir(model_name):
exist_adapter_config = os.path.exists(
@ -517,14 +517,19 @@ class FastLanguageModel(FastLlamaModel):
exist_config = os.path.exists(os.path.join(model_name, "config.json"))
both_exist = exist_adapter_config and exist_config
else:
# Because HfFileSystem assumes linux paths, we need to set the path with forward slashes, even on Windows.
files = HfFileSystem(token = token).glob(f"{model_name}/*.json")
files = list(os.path.split(x)[-1] for x in files)
if (
sum(x == "adapter_config.json" or x == "config.json" for x in files)
>= 2
):
both_exist = True
# HfFileSystem returns POSIX paths; use str.rsplit to extract
# filenames correctly on all platforms (os.path.split uses the
# OS separator which breaks on Windows).
try:
files = HfFileSystem(token = token).glob(f"{model_name}/*.json")
files = [x.rsplit("/", 1)[-1] for x in files]
if (
sum(x == "adapter_config.json" or x == "config.json" for x in files)
>= 2
):
both_exist = True
except Exception:
pass
if not is_model and not is_peft:
error = autoconfig_error if autoconfig_error is not None else peft_error
@ -1282,7 +1287,7 @@ class FastModel(FastBaseModel):
os.environ["UNSLOTH_DISABLE_STATIC_GENERATION"] = "1"
# New transformers need to check manually.
if SUPPORTS_LLAMA32:
if SUPPORTS_LLAMA32 and is_model and is_peft:
# Check if folder exists locally
if os.path.isdir(model_name):
exist_adapter_config = os.path.exists(
@ -1291,13 +1296,19 @@ class FastModel(FastBaseModel):
exist_config = os.path.exists(os.path.join(model_name, "config.json"))
both_exist = exist_adapter_config and exist_config
else:
files = HfFileSystem(token = token).glob(f"{model_name}/*.json")
files = list(os.path.split(x)[-1] for x in files)
if (
sum(x == "adapter_config.json" or x == "config.json" for x in files)
>= 2
):
both_exist = True
# HfFileSystem returns POSIX paths; use str.rsplit to extract
# filenames correctly on all platforms (os.path.split uses the
# OS separator which breaks on Windows).
try:
files = HfFileSystem(token = token).glob(f"{model_name}/*.json")
files = [x.rsplit("/", 1)[-1] for x in files]
if (
sum(x == "adapter_config.json" or x == "config.json" for x in files)
>= 2
):
both_exist = True
except Exception:
pass
if not is_model and not is_peft:
error = autoconfig_error if autoconfig_error is not None else peft_error