Spaces:
Running
Running
File size: 2,519 Bytes
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 52 53 54 55 56 57 58 | """Resolve the pinned, public FP16 NExT-GPT v0 inference resources."""
from __future__ import annotations
import json
import os
from pathlib import Path
REPO_ID = "nemoyu/nlp-chapter6-nextgpt-models"
REVISION = "bf8511b150742466477c4342027d9cc1480c23d4"
PATH_KEYS = (
"vicuna_dir", "imagebind_dir", "delta_path",
"image_diffusion_dir", "audio_diffusion_dir", "video_diffusion_dir",
)
def resolve_paths() -> dict[str, Path]:
"""Use a local manifest for testing, otherwise fetch the pinned Hub snapshot."""
override = os.environ.get("NEXTGPT_MANIFEST")
if override:
manifest = Path(override).expanduser().absolute()
else:
from huggingface_hub import snapshot_download
snapshot = snapshot_download(
repo_id=REPO_ID, revision=REVISION,
allow_patterns=["model_manifest.json", "models/**"],
token=False, max_workers=5,
)
manifest = Path(snapshot) / "model_manifest.json"
if not manifest.is_file():
raise FileNotFoundError(f"Model manifest is missing: {manifest}")
data = json.loads(manifest.read_text(encoding="utf-8"))
if data.get("model") != "NExT-GPT 7b_tiva_v0":
raise ValueError("The selected bundle does not identify NExT-GPT 7b_tiva_v0")
entries = data.get("paths", {})
paths = {}
for key in PATH_KEYS:
value = entries.get(key)
if not isinstance(value, str) or not value:
raise ValueError(f"Model manifest is missing {key}")
path = (manifest.parent / value).resolve()
if not path.exists():
raise FileNotFoundError(f"Model bundle component {key} is missing: {path}")
paths[key] = path
if not (paths["vicuna_dir"] / "config.json").is_file():
raise FileNotFoundError("Restored Vicuna config is missing")
if not any(paths["vicuna_dir"].glob("model*.safetensors")) and not any(
paths["vicuna_dir"].glob("pytorch_model*.bin")
):
raise FileNotFoundError("Restored Vicuna weights are missing")
if not (paths["imagebind_dir"] / "imagebind_huge.pth").is_file():
raise FileNotFoundError("ImageBind checkpoint is missing")
if not paths["delta_path"].is_file():
raise FileNotFoundError("NExT-GPT checkpoint is missing")
for key in ("image_diffusion_dir", "audio_diffusion_dir", "video_diffusion_dir"):
if not (paths[key] / "model_index.json").is_file():
raise FileNotFoundError(f"{key} pipeline configuration is missing")
return paths
|