Spaces:
Sleeping
Sleeping
DEPLOY: switch plan to ZeroGPU (Gradio SDK, on-Space inference, no API key)
Browse files
DEPLOY.md
CHANGED
|
@@ -1,35 +1,71 @@
|
|
| 1 |
-
# Deploying SCRYPT to
|
| 2 |
|
| 3 |
-
Target: `build-small-hackathon/scrypt`
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
```bash
|
| 11 |
-
#
|
| 12 |
-
# root-owned on this box and crashes the hf CLI — fix ownership first:
|
| 13 |
sudo chown -R imjonezz:imjonezz ~/.cache/huggingface
|
| 14 |
hf auth login
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
hf repo create build-small-hackathon/scrypt --repo-type space --space-sdk
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
git push space main
|
| 21 |
|
| 22 |
-
|
| 23 |
-
# SCRYPT_API_KEY = an OpenRouter or NVIDIA NIM key for
|
| 24 |
-
# nvidia/nemotron-3-nano-30b-a3b. Without it the Warden is scripted-only.
|
| 25 |
```
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
`/
|
| 30 |
-
|
| 31 |
-
Notes
|
| 32 |
-
- The Space never runs the model locally — `SCRYPT_BACKEND=api` is baked into
|
| 33 |
-
the image; sandboxes are always fabricated there, never mirrored.
|
| 34 |
-
- Model weights, finetune runs, and caches are `.gitignore`d; the push is
|
| 35 |
-
source-only (no LFS needed).
|
|
|
|
| 1 |
+
# Deploying SCRYPT to HuggingFace — ZeroGPU plan
|
| 2 |
|
| 3 |
+
Target: `build-small-hackathon/scrypt`. We deploy on **ZeroGPU** (HF Pro):
|
| 4 |
+
the Warden runs *on the Space itself* — no third-party API key, no OpenRouter.
|
| 5 |
+
The Space becomes self-hosted inference, which also answers "isn't the Warden
|
| 6 |
+
supposed to stay local?" — it is; the Space is just someone else's localhost.
|
| 7 |
|
| 8 |
+
## Hard constraints (verified against HF docs, 2026-06-12)
|
| 9 |
+
|
| 10 |
+
- ZeroGPU Spaces are **Gradio SDK only** — no Docker Spaces. Our gradio.Server
|
| 11 |
+
web layer survives, but it must run inside the Gradio SDK runtime
|
| 12 |
+
(`sdk: gradio` frontmatter + `requirements.txt`), not our Dockerfile.
|
| 13 |
+
- **Hosting under an org requires the org to have ZeroGPU enabled**
|
| 14 |
+
(Team/Enterprise — hackathon orgs often get it granted). Personal PRO
|
| 15 |
+
accounts can host up to 10 ZeroGPU Spaces. → **Decision gate #1, check
|
| 16 |
+
first:** create the Space under `build-small-hackathon` and see if ZeroGPU
|
| 17 |
+
appears in the hardware options. If not: host under your account, transfer
|
| 18 |
+
to the org later (or keep the org Space as a CPU/API mirror).
|
| 19 |
+
- GPU = RTX Pro 6000 Blackwell slice: `large` 48GB VRAM (1× quota) or
|
| 20 |
+
`xlarge` 96GB (2× quota). BF16 30B (~60GB) needs `xlarge`; **4-bit (~18GB)
|
| 21 |
+
fits `large`** — and the local game runs a Q4 GGUF anyway, so 4-bit is
|
| 22 |
+
quality-parity, not a downgrade. Start 4-bit/`large`.
|
| 23 |
+
- Model must be moved to `cuda` at module level (ZeroGPU emulates CUDA at
|
| 24 |
+
startup); GPU attaches only inside `@spaces.GPU(duration=...)` functions.
|
| 25 |
+
Default 60s/call; visitors burn daily quota (2 min unauthenticated /
|
| 26 |
+
5 min free / 40 min PRO) — our calls are ~1.5K-token prefill + short
|
| 27 |
+
generations on a 3.5B-active MoE, i.e. seconds per call. Plenty.
|
| 28 |
+
|
| 29 |
+
## Architecture changes (space/ rework)
|
| 30 |
+
|
| 31 |
+
1. `app.py` stays a Gradio-hosted FastAPI: build a minimal `gr.Blocks` (the
|
| 32 |
+
"engine room" — can be a hidden status page), launch it, and attach our
|
| 33 |
+
routes (`/` CRT page, `/api/whisper`, `/play`, `WS /pty`) to gradio's
|
| 34 |
+
FastAPI app. **Spike risk:** validate custom routes + websocket survive the
|
| 35 |
+
Space proxy in a throwaway ZeroGPU Space before porting everything.
|
| 36 |
+
2. Inference: per-visitor game PTYs are subprocesses and **cannot** call
|
| 37 |
+
`@spaces.GPU` themselves. The main process exposes an internal
|
| 38 |
+
OpenAI-style endpoint (`POST /v1/internal/generate`) whose handler is the
|
| 39 |
+
`@spaces.GPU` generator (transformers + `TextIteratorStreamer`,
|
| 40 |
+
bitsandbytes 4-bit, `trust_remote_code`). Game subprocesses run
|
| 41 |
+
`SCRYPT_BACKEND=api` pointed at `http://127.0.0.1:7860/...` — the existing
|
| 42 |
+
api backend, new base URL. No game-code changes.
|
| 43 |
+
3. Model source: until the finetune ships, load
|
| 44 |
+
`nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16` quantized 4-bit at startup.
|
| 45 |
+
After the merge→export→eval gate passes, upload the merged Warden to
|
| 46 |
+
`build-small-hackathon/warden-nemotron-30b` and point the Space there —
|
| 47 |
+
the Space then runs the *finetuned* Warden.
|
| 48 |
+
4. Keep the root `Dockerfile` (it no longer drives the Space, but stays the
|
| 49 |
+
local/self-host path); frontmatter flips `sdk: docker` → `sdk: gradio` +
|
| 50 |
+
`app_file: space/app.py` + `python_version: 3.12` when we cut over.
|
| 51 |
+
5. `SCRYPT_API_KEY` is **no longer needed** on the Space. Scripted-Warden
|
| 52 |
+
fallback stays as the safety net (quota exhausted / GPU queue too long).
|
| 53 |
+
|
| 54 |
+
## Your steps (interactive auth — run with `!` prefix)
|
| 55 |
|
| 56 |
```bash
|
| 57 |
+
# once: fix the root-owned HF cache that crashes the hf CLI, then login
|
|
|
|
| 58 |
sudo chown -R imjonezz:imjonezz ~/.cache/huggingface
|
| 59 |
hf auth login
|
| 60 |
|
| 61 |
+
# decision gate #1: try creating under the org with Gradio SDK
|
| 62 |
+
hf repo create build-small-hackathon/scrypt --repo-type space --space-sdk gradio
|
| 63 |
+
# then in Space settings → check whether ZeroGPU is offered under Hardware.
|
| 64 |
+
# If not offered: hf repo create scrypt --repo-type space --space-sdk gradio (personal)
|
|
|
|
| 65 |
|
| 66 |
+
git push space main # remote already wired; update URL first if personal
|
|
|
|
|
|
|
| 67 |
```
|
| 68 |
|
| 69 |
+
No secrets to set in the ZeroGPU plan. First build ~5 min (model download
|
| 70 |
+
~17GB happens at first startup). Smoke test: `/` CRT page, `/api/whisper`,
|
| 71 |
+
full run via `/play`, and watch quota burn in the Space's ZeroGPU panel.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|