fix: probe HF cache before model_info for local-only GGUF saves (#7481)
Always resolve tokenizer.model from the local Hub cache before calling model_info, and skip Hub metadata when the tokenizer was loaded with local_files_only or offline env vars. Fixes Codex review on PR #7482.
This commit is contained in:
parent
222a416480
commit
b41bbbef7d
4 changed files with 91 additions and 28 deletions
|
|
@ -95,8 +95,6 @@ def test_real_cached_unsloth_helpers_offline(monkeypatch):
|
|||
_offline_env(monkeypatch)
|
||||
_block_network(monkeypatch)
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
from unsloth.models.loader_utils import _load_pretrained_tokenizer_fast
|
||||
from unsloth.save import _has_tokenizer_model
|
||||
|
||||
|
|
@ -106,4 +104,4 @@ def test_real_cached_unsloth_helpers_offline(monkeypatch):
|
|||
cache_dir = str(CACHE_ROOT / "hub"),
|
||||
)
|
||||
assert tok.vocab_size > 0
|
||||
assert _has_tokenizer_model(SimpleNamespace(name_or_path = REPO, tokenizer = None)) is True
|
||||
assert _has_tokenizer_model(tok) is True
|
||||
|
|
|
|||
|
|
@ -180,3 +180,39 @@ def test_has_tokenizer_model_offline_skips_model_info(tmp_path, monkeypatch):
|
|||
with patch("huggingface_hub.HfApi.model_info") as model_info:
|
||||
model_info.side_effect = AssertionError("model_info must not run offline")
|
||||
assert _has_tokenizer_model(tok, token = None) is False
|
||||
|
||||
|
||||
def test_has_tokenizer_model_probes_cache_before_model_info(tmp_path, monkeypatch):
|
||||
from unsloth.save import _TOKENIZER_MODEL_CACHE, _has_tokenizer_model
|
||||
|
||||
snap = _write_gemma4_cache(tmp_path)
|
||||
(snap / "tokenizer.model").write_bytes(b"sp-model")
|
||||
monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)
|
||||
monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)
|
||||
monkeypatch.setenv("HF_HUB_CACHE", str(tmp_path))
|
||||
_TOKENIZER_MODEL_CACHE.clear()
|
||||
|
||||
tok = SimpleNamespace(name_or_path = _REPO)
|
||||
|
||||
with patch("huggingface_hub.HfApi.model_info") as model_info:
|
||||
model_info.side_effect = AssertionError("model_info must not run when cache hit")
|
||||
assert _has_tokenizer_model(tok, token = None) is True
|
||||
|
||||
|
||||
def test_has_tokenizer_model_local_files_only_skips_model_info(tmp_path, monkeypatch):
|
||||
from unsloth.save import _TOKENIZER_MODEL_CACHE, _has_tokenizer_model
|
||||
|
||||
_write_gemma4_cache(tmp_path)
|
||||
monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)
|
||||
monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)
|
||||
monkeypatch.setenv("HF_HUB_CACHE", str(tmp_path))
|
||||
_TOKENIZER_MODEL_CACHE.clear()
|
||||
|
||||
tok = SimpleNamespace(
|
||||
name_or_path = _REPO,
|
||||
init_kwargs = {"local_files_only": True},
|
||||
)
|
||||
|
||||
with patch("huggingface_hub.HfApi.model_info") as model_info:
|
||||
model_info.side_effect = AssertionError("model_info must not run with local_files_only")
|
||||
assert _has_tokenizer_model(tok, token = None) is False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue