Nekochu commited on
Commit
282bfe7
Β·
verified Β·
1 Parent(s): e2c0978

Update gpu-space-cpu/SKILL.md inspired of https://github.com/huggingface/skills/tree/main/skills/huggingface-spaces

Browse files
Files changed (1) hide show
  1. gpu-space-cpu/SKILL.md +10 -6
gpu-space-cpu/SKILL.md CHANGED
@@ -5,15 +5,16 @@ description: Convert GPU HuggingFace Spaces to CPU-only for free tier deployment
5
 
6
  # GPU β†’ CPU Space demo Conversion
7
 
8
- - Free space Tier CPU = 2 CPU cores (vCPUs) + 16GB RAM + 50GB non-persistent disk space
 
9
 
10
  ## Workflow
11
 
12
  1. Grep GPU deps: `@spaces.GPU|bitsandbytes|flash-attn|triton|xformers|auto-gptq|exllama|apex|\.cuda\(|device.*cuda`
13
  2. Remove GPU packages, replace code: `cuda`β†’`cpu`, `float16`β†’`int8`, remove `.half()`, `.cuda()`, `device_map="auto"`
14
- 3. Create: app.py (all logic, prioritize recent built-in gradio [v6+](https://www.gradio.app/guides/gradio-6-migration-guide)), README.md, requirements.txt
15
- 4. Test: `pip install -r requirements.txt && python app.py` and Test API by adding mcp https://www.gradio.app/guides/building-mcp-server-with-gradio
16
- 5. Deploy after local test passes
17
 
18
  ## requirements.txt
19
 
@@ -21,7 +22,9 @@ description: Convert GPU HuggingFace Spaces to CPU-only for free tier deployment
21
  --extra-index-url https://download.pytorch.org/whl/cpu
22
  torch
23
  ```
24
- Never pin transitive deps. No packages.txt (ffmpeg/git/cmake pre-installed).
 
 
25
 
26
  ## README.md
27
 
@@ -32,6 +35,7 @@ emoji: X
32
  sdk: gradio
33
  sdk_version: 6.3.0
34
  app_file: app.py
 
35
  ---
36
  ```
37
 
@@ -40,7 +44,7 @@ app_file: app.py
40
  1. ONNX Runtime (Optimum+OMP_NUM_THREADS=2) INT8 (preferred - onnxruntime fast on CPU)
41
  2. TorchAO
42
  3. torch.quantization.quantize_dynamic
43
- 3. Onnx FP32 is faster than FP16 on CPU
44
 
45
  ## Stop
46
 
 
5
 
6
  # GPU β†’ CPU Space demo Conversion
7
 
8
+ - Free space Tier CPU = 2 CPU cores (vCPUs) + 18GB RAM + 50GB non-persistent disk space
9
+ - RAM is the binding limit (not disk): load large models with `low_cpu_mem_usage=True` (needs `accelerate`) so peak RAM stays ~1Γ— the weights instead of ~2Γ— during load.
10
 
11
  ## Workflow
12
 
13
  1. Grep GPU deps: `@spaces.GPU|bitsandbytes|flash-attn|triton|xformers|auto-gptq|exllama|apex|\.cuda\(|device.*cuda`
14
  2. Remove GPU packages, replace code: `cuda`β†’`cpu`, `float16`β†’`int8`, remove `.half()`, `.cuda()`, `device_map="auto"`
15
+ 3. Create: app.py (all logic, prioritize recent built-in gradio [v6+](https://www.gradio.app/guides/gradio-6-migration-guide)), README.md, requirements.txt. Handlers can run concurrently β€” write outputs to `tempfile.NamedTemporaryFile(...)`, never a fixed path like `output.png` (concurrent calls clobber it and files leak across users); keep module-level globals read-only.
16
+ 4. Test: `pip install -r requirements.txt && python app.py` and test the API by adding MCP (`demo.launch(mcp_server=True)`) https://www.gradio.app/guides/building-mcp-server-with-gradio β€” every API-exposed handler needs a docstring + type hints, otherwise it surfaces as an opaque, unusable MCP tool.
17
+ 5. Deploy after local test passes: `hf upload <id> . --repo-type space` (omit `--repo-type space` and it silently creates a *model* repo instead). On a build failure read `hf spaces logs <id> --build` and fix the **first** error, not the last.
18
 
19
  ## requirements.txt
20
 
 
22
  --extra-index-url https://download.pytorch.org/whl/cpu
23
  torch
24
  ```
25
+ - `torchvision` / `torchaudio` are **not** preinstalled β€” add them (unpinned) if you import them; the index above serves their `+cpu` builds too.
26
+ - Default: never pin transitive deps. Exception: a build-time `ResolutionImpossible` against the Gradio SDK β€” unpin (or bump) the offender, usually `pydantic` / `uvicorn` / `huggingface_hub` / `jinja2`. `gradio[mcp]` specifically needs `uvicorn>=0.31.1` + `pydantic>=2.11.10`.
27
+ - Use packages.txt (ffmpeg/git/cmake pre-installed) instead of docker first.
28
 
29
  ## README.md
30
 
 
35
  sdk: gradio
36
  sdk_version: 6.3.0
37
  app_file: app.py
38
+ short_description: ... # ≀ 60 chars; the Hub rejects longer (undocumented cap)
39
  ---
40
  ```
41
 
 
44
  1. ONNX Runtime (Optimum+OMP_NUM_THREADS=2) INT8 (preferred - onnxruntime fast on CPU)
45
  2. TorchAO
46
  3. torch.quantization.quantize_dynamic
47
+ 4. Onnx FP32 is faster than FP16 on CPU
48
 
49
  ## Stop
50