# Deploying to Hugging Face Spaces The app is a standard Gradio `app.py`, so it deploys to Spaces as-is. Pick a model in `config.yaml` (`repo_id` + `filename`) and it's downloaded on startup. > Local dev uses **uv** (`uv sync`, CPU `llama-cpp-python`, no torch/spaces). HF Spaces > builds from **`requirements.txt`**, which ships the **ZeroGPU CUDA stack** by default. > The app auto-selects the runtime: ZeroGPU when HF sets `SPACES_ZERO_GPU`, otherwise the > plain `LlamaRuntime`. No code change needed to move between the options below. ## Option A — ZeroGPU (default; keeps the llama.cpp / Llama Champion badge) `requirements.txt` is already set up for this (the llama-cpp-python maintainer's recipe): prebuilt CUDA `llama-cpp-python` from the cu124 index, `torch==2.8.0` (ships the CUDA libs llama.cpp links against), `hf_transfer`, and `spaces`. 1. Create a **Gradio** Space and select **ZeroGPU** hardware in Settings (needs a PRO or Team/Enterprise plan). ZeroGPU is Gradio-only — we comply. 2. Keep `python_version: "3.12"` in the `README.md` frontmatter (already set) — the prebuilt CUDA wheels target 3.12. 3. Set `model.repo_id`/`filename` in `config.yaml` to the GGUF to test (e.g. Nemotron Nano 9B v2 or MiniCPM4-8B). `flash_attn` and `gpu_duration` there tune the GPU path. 4. Push. The model downloads on the Space CPU at startup; on each message the GPU is attached inside `@spaces.GPU`, where the `Llama` model is built with all layers offloaded (`ZeroGpuLlamaRuntime` in `engine/runtime.py`). **Tradeoff:** ZeroGPU releases the GPU after every call, so the model reloads each turn (a few seconds on the Blackwell card + generation). Fine for A/B **testing**. If turns feel slow, use a smaller model / lower `n_ctx` / `max_tokens`, or Option B. ## Option B — Plain paid GPU Space (snappiest for a public demo) A persistent GPU (e.g. Nvidia L4/T4) loads the model **once** and keeps it warm — no per-turn reload. The app picks `LlamaRuntime` automatically here (no `SPACES_ZERO_GPU`). 1. Upgrade the Space to a GPU; keep the CUDA `llama-cpp-python` from `requirements.txt`. 2. Set `model.n_gpu_layers: -1` in `config.yaml` to offload all layers at startup. ## Option C — CPU Space (free, small models only) Swap `requirements.txt` to the CPU stack (drop `torch`, `spaces`, and the two `--extra-index-url` lines; plain `llama-cpp-python`). Slower; best for ≤4B models. ## Local ```bash uv sync # one-time setup uv run python app.py # uses config.yaml model SECOND_DEGREE_FAKE=1 uv run python app.py # no model, heuristic NPC (UI dev) SECOND_DEGREE_ZEROGPU=1 uv run python app.py # force the ZeroGPU path (needs spaces + CUDA wheel) ```