"""Download public inputs and restore Vicuna v0 exactly as LMSYS documents.""" import argparse import subprocess import sys import urllib.request from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from model_paths import BASE, DELTA, VICUNA, IMAGEBIND, NEXTGPT, MODEL_ROOT, missing_for_inference def download_file(url: str, dest: Path): dest.parent.mkdir(parents=True, exist_ok=True) temporary = dest.with_suffix(dest.suffix + ".partial") with urllib.request.urlopen(url, timeout=120) as response, temporary.open("wb") as target: while chunk := response.read(8 * 1024 * 1024): target.write(chunk) temporary.replace(dest) def main(): parser = argparse.ArgumentParser() parser.add_argument("--verify-only", action="store_true") args = parser.parse_args() if args.verify_only: missing = missing_for_inference() print("Ready" if not missing else "Missing: " + ", ".join(missing)) return 0 if not missing else 1 from huggingface_hub import snapshot_download MODEL_ROOT.mkdir(parents=True, exist_ok=True) for repo, path in [ ("huggyllama/llama-7b", BASE), ("lmsys/vicuna-7b-delta-v0", DELTA), ]: print(f"Downloading {repo} to {path}", flush=True) snapshot_download( repo_id=repo, allow_patterns=["*.json", "*.model", "*.bin", "*.txt"], local_dir=str(path), local_dir_use_symlinks=False, ) if not (VICUNA / "config.json").is_file() or not any(VICUNA.glob("pytorch_model*.bin")): VICUNA.parent.mkdir(parents=True, exist_ok=True) subprocess.run([ sys.executable, "-m", "fastchat.model.apply_delta", "--base", str(BASE), "--target", str(VICUNA), "--delta", str(DELTA), ], check=True) if not IMAGEBIND.is_file(): download_file("https://dl.fbaipublicfiles.com/imagebind/imagebind_huge.pth", IMAGEBIND) if not NEXTGPT.is_file(): NEXTGPT.parent.mkdir(parents=True, exist_ok=True) snapshot_download( repo_id="ChocoWu/nextgpt_7b_tiva_v0", allow_patterns=["pytorch_model.pt"], local_dir=str(NEXTGPT.parent), local_dir_use_symlinks=False, ) missing = missing_for_inference() if missing: raise RuntimeError("Incomplete checkpoints: " + ", ".join(missing)) print("All required base checkpoints are present.") if __name__ == "__main__": raise SystemExit(main())