forked from programasweights/programasweights-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime_registry_sdk.py
More file actions
81 lines (66 loc) · 2.37 KB
/
Copy pathtest_runtime_registry_sdk.py
File metadata and controls
81 lines (66 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import annotations
import json
from pathlib import Path
import pytest
from programasweights import cache
RUNTIME = {
"runtime_id": "gpt2-q8_0",
"manifest_version": 1,
"display_name": "GPT-2 124M (Q8_0)",
"interpreter": "gpt2",
"adapter_format": "gguf_lora",
"local_sdk": {
"supported": True,
"base_model": {
"provider": "huggingface",
"repo": "programasweights/GPT2-GGUF-Q8_0",
"file": "gpt2-q8_0.gguf",
"url": "https://example.com/gpt2-q8_0.gguf",
"sha256": None,
},
"n_ctx": 2048,
},
"js_sdk": {
"supported": True,
"base_model": {
"provider": "huggingface",
"repo": "programasweights/GPT2-GGUF-Q8_0",
"file": "gpt2-q8_0.gguf",
"url": "https://example.com/gpt2-q8_0.gguf",
"sha256": None,
},
"prefix_cache_supported": True,
},
}
@pytest.fixture(autouse=True)
def _cache_dir(tmp_path, monkeypatch):
monkeypatch.setenv("PAW_CACHE_DIR", str(tmp_path / "cache"))
def test_resolve_runtime_manifest_prefers_embedded_manifest():
meta = {
"interpreter": "gpt2",
"runtime_id": "gpt2-q8_0",
"runtime": RUNTIME,
}
resolved = cache.resolve_runtime_manifest(meta, offline=True)
assert resolved["runtime_id"] == "gpt2-q8_0"
cached = cache.get_cached_runtime_manifest("gpt2-q8_0")
assert cached["runtime_id"] == "gpt2-q8_0"
def test_resolve_runtime_manifest_uses_legacy_fallback_when_offline():
meta = {
"interpreter": "gpt2",
"runtime_id": "gpt2-q8_0",
}
resolved = cache.resolve_runtime_manifest(meta, offline=True)
assert resolved is not None
assert resolved["runtime_id"] == "gpt2-q8_0"
assert resolved["local_sdk"]["base_model"]["file"] == "gpt2-q8_0.gguf"
def test_get_base_model_path_uses_runtime_manifest(tmp_path, monkeypatch):
target = tmp_path / "cache" / "base_models" / "gpt2-q8_0.gguf"
def fake_download(url: str, dest: Path):
assert url == "https://example.com/gpt2-q8_0.gguf"
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_bytes(b"gguf")
monkeypatch.setattr(cache, "_download_file", fake_download)
path = cache.get_base_model_path("gpt2", runtime_manifest=RUNTIME)
assert path == target
assert path.read_bytes() == b"gguf"