wang2226's picture
Beyond Tokens decoding playground: contrastive, guided and parallel decoding
371d90c verified
Raw History Blame Contribute Delete
2.17 kB
"""Create (or update) the Space and upload this folder.
Usage:
python scripts/deploy.py --repo USER/beyond-tokens-decoding [--private] [--hardware zero-a10g] [--message "..."]
Needs a write token (`hf auth login`). Gated models (Llama 3.2, Gemma 3) also need an HF_TOKEN secret on the Space
with access to those repos; add it in the Space settings.
"""
from __future__ import annotations
import argparse
from pathlib import Path
from huggingface_hub import HfApi
ROOT = Path(__file__).resolve().parents[1]
IGNORE = [".venv/*", ".tools/*", "**/__pycache__/*", "__pycache__/*", ".pytest_cache/*", "*.log", ".DS_Store",
"**/.DS_Store", "shots/*"]
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--repo", required=True)
ap.add_argument("--private", action="store_true")
ap.add_argument("--hardware", default="zero-a10g", help="ZeroGPU's flavor id; '' to leave unchanged")
ap.add_argument("--message", default="Deploy the decoding playground")
args = ap.parse_args()
api = HfApi()
# Request the hardware at creation: free accounts may not create Gradio Spaces on cpu-basic,
# but may host ZeroGPU Spaces.
url = api.create_repo(args.repo, repo_type="space", space_sdk="gradio", private=args.private, exist_ok=True,
space_hardware=args.hardware or None)
print("space:", url)
if args.hardware:
try:
api.request_space_hardware(args.repo, args.hardware)
print("hardware requested:", args.hardware)
except Exception as exc: # e.g. account not eligible for ZeroGPU
print(f"could not set hardware {args.hardware!r}: {exc}\n -> choose ZeroGPU in the Space settings")
info = api.upload_folder(repo_id=args.repo, repo_type="space", folder_path=str(ROOT), ignore_patterns=IGNORE,
commit_message=args.message)
print("uploaded:", info.commit_url if hasattr(info, "commit_url") else info)
runtime = api.get_space_runtime(args.repo)
print("runtime:", runtime.stage, "hardware:", runtime.hardware, "requested:", runtime.requested_hardware)
if __name__ == "__main__":
main()