5-th DL fix

This commit is contained in:
Dobromir Popov
2026-07-06 22:55:01 +03:00
parent 7e7682be47
commit 4bfdc814e2
6 changed files with 126 additions and 78 deletions

View File

@@ -407,11 +407,11 @@ def test_download_shard_uses_huggingface_when_repo_is_assigned(tmp_path, monkeyp
}]
def test_download_shard_races_tracker_model_source_against_huggingface(
def test_download_shard_prefers_tracker_model_source_over_huggingface(
tmp_path,
monkeypatch,
):
"""Tracker-hosted model files can win while HF receives the same allow_patterns."""
"""A working tracker model source is used exclusively — HF is never contacted."""
source_dir = tmp_path / "source"
source_dir.mkdir()
(source_dir / "config.json").write_text("{}")
@@ -473,6 +473,49 @@ def test_download_shard_races_tracker_model_source_against_huggingface(
)
assert (shard_dir / "model-00002-of-00004.safetensors").read_text() == "tracker"
assert hf_calls == []
def test_download_shard_falls_back_to_huggingface_when_tracker_source_fails(
tmp_path,
monkeypatch,
):
"""A dead tracker source falls through to HF with allow_patterns from the source files."""
def failing_urlopen(*args, **kwargs):
raise ConnectionResetError("tracker went away")
monkeypatch.setattr(urllib.request, "urlopen", failing_urlopen)
hf_calls = []
def fake_snapshot_download(**kwargs):
hf_calls.append(kwargs)
local_dir = Path(kwargs["local_dir"])
local_dir.mkdir(parents=True, exist_ok=True)
(local_dir / "model-00002-of-00004.safetensors").write_text("hf")
return str(local_dir)
monkeypatch.setitem(
sys.modules,
"huggingface_hub",
types.SimpleNamespace(snapshot_download=fake_snapshot_download),
)
shard_dir = download_shard(
"tiny-llama",
2,
3,
cache_dir=tmp_path / "cache",
hf_repo="org/tiny-llama-shards",
model_sources=[{
"type": "tracker",
"url": "http://tracker/v1/model-files/download?model=tiny-llama",
"files": ["config.json", "model-00002-of-00004.safetensors"],
}],
progress=False,
)
assert (shard_dir / "model-00002-of-00004.safetensors").read_text() == "hf"
assert hf_calls[0]["allow_patterns"] == ["config.json", "model-00002-of-00004.safetensors"]