Spaces:
Running
Running
File size: 2,081 Bytes
b49bf13 2ad74e3 b49bf13 2ad74e3 b49bf13 | 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 | """Checks that a pinned model bundle cannot silently omit required weights."""
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from model_bundle import PATH_KEYS, resolve_paths
class ModelBundleTests(unittest.TestCase):
def test_complete_bundle_resolves_all_paths(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
values = {key: key for key in PATH_KEYS}
for key, rel in values.items():
path = root / rel
if key == "delta_path":
path.touch()
else:
path.mkdir()
(root / "vicuna_dir" / "config.json").touch()
(root / "vicuna_dir" / "model-00001-of-00001.safetensors").touch()
(root / "imagebind_dir" / "imagebind_huge.pth").touch()
for key in ("image_diffusion_dir", "audio_diffusion_dir", "video_diffusion_dir"):
(root / key / "model_index.json").touch()
manifest = root / "model_manifest.json"
manifest.write_text(json.dumps({"model": "NExT-GPT 7b_tiva_v0", "paths": values}))
with patch.dict(os.environ, {"NEXTGPT_MANIFEST": str(manifest)}):
self.assertEqual(set(resolve_paths()), set(PATH_KEYS))
def test_missing_adapter_is_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
values = {key: key for key in PATH_KEYS}
for key, rel in values.items():
if key != "delta_path":
(root / rel).mkdir()
manifest = root / "model_manifest.json"
manifest.write_text(json.dumps({"model": "NExT-GPT 7b_tiva_v0", "paths": values}))
with patch.dict(os.environ, {"NEXTGPT_MANIFEST": str(manifest)}):
with self.assertRaises(FileNotFoundError):
resolve_paths()
if __name__ == "__main__":
unittest.main()
|