huggingface-zerogpu
यह क्या करती है
यह स्किल मशीन लर्निंग डेमो बनाने में मदद करती है जो Hugging Face के साझा ZeroGPU हार्डवेयर पर चलते हैं। यह उन डेवलपर्स के लिए है जो चाहते हैं कि उनका Space बिना त्रुटि के GPU इस्तेमाल करे।
कब इस्तेमाल करें
- ✓जब आप ZeroGPU Space पर GPU decorators इस्तेमाल करने वाला कोड लिखते या जाँचते हैं।
- ✓जब आपको ZeroGPU Space के लिए Python संस्करण या requirements सेट करने हों।
- ✓जब ZeroGPU डेमो अपनी समय सीमा, कोटा या प्रक्रिया के नियमों की वजह से विफल हो।
Skill का लिंक
https://github.com/huggingface/skills/blob/main/skills/huggingface-zerogpu/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे ZeroGPU Space में लिखा है कि GPU duration अवैध है। decorator ठीक कीजिए ताकि डेमो चले।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI ZeroGPU के नियम लागू करता है, जैसे प्रक्रिया अलगाव, GPU duration सेटिंग्स और CUDA build की सीमाएँ। समस्या ठीक करने के लिए वह decorator, state संभालने और concurrency की जाँच करता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Hugging Face ZeroGPU
Rules and patterns for ML demos on Hugging Face Spaces with ZeroGPU hardware. Covers @spaces.GPU, duration and quota tuning, process isolation, the CUDA availability model, concurrency safety, and CUDA build constraints.
Scope
This skill is for Gradio SDK Spaces using ZeroGPU hardware. Docker and Static Spaces cannot schedule onto ZeroGPU, and Streamlit apps now run as Docker Spaces — so this skill applies only to Gradio. For general Gradio coding (components, layouts, event listeners), see the huggingface-gradio skill in this repo. The authoritative ZeroGPU docs live at https://huggingface.co/docs/hub/spaces-zerogpu — refer to them for the current backing GPU, runtime version lists, and tier thresholds, all of which change over time.
Reference Files
| Reference | When to read |
|---|---|
references/concurrency.md |
Always read alongside SKILL.md when writing ZeroGPU code — handlers run in parallel by default |
references/how-zerogpu-works.md |
When reasoning about cold-starts, worker reuse, why module-scope warmup does not carry to requests, or why returning CUDA tensors hangs |
references/how-quota-works.md |
When choosing duration values, debugging illegal duration vs quota exceeded errors, or explaining why default 60s blocks short tasks |
references/cuda-and-deps.md |
When installing CUDA-dependent packages (e.g. flash-attn), pinning torch side-cars, or reading wheel filename tags |
Hardware
ZeroGPU exposes two GPU sizes that map to a fraction of the backing card:
size |
Slice of backing GPU | Quota cost |
|---|---|---|
large (default) |
Half | 1x |
xlarge |
Full | 2x |
Default large gives half a physical GPU, so memory bandwidth and compute are significantly lower than the full card's specs. Use xlarge only when the workload genuinely needs the extra memory or compute.
Backing GPU changes without notice. ZeroGPU has already migrated across GPU generations several times; older write-ups may name A100 or H200, but those are outdated. For the current backing GPU and exact per-size VRAM, always check the ZeroGPU docs before sizing workloads.
Basic Pattern
import spaces
import torch
from transformers import pipeline
pipe = pipeline("text-generation", model="...", device="cuda")
@spaces.GPU
def generate(prompt: str) -> str:
return pipe(prompt, max_new_tokens=100)[0]["generated_text"]
Key rules:
- Instantiate models at module scope and call
.to("cuda")eagerly. ZeroGPU handles the actual device mapping transparently (see CUDA availability model below). - Decorate GPU functions with
@spaces.GPU. The decorator is a no-op outside ZeroGPU, so it is safe to keep in all environments. - Set
durationto match the realistic worst-case workload (default 60s). The platform pre-checksrequested durationagainst the user'sremaining quota— not against the actual run time — so a 10-second task left at the 60s default fails withquota exceededas soon as the user's remaining quota drops below 60s. Smaller declareddurationalso ranks higher in the node-level queue. See "Duration and Quota" below. torch.compileis NOT supported. Use PyTorch ahead-of-time compilation (AoTI) (torch 2.8+) instead.- Use
size="xlarge"sparingly. It allocates the full backing GPU, but costs 2x quota and tends to queue longer.
@spaces.GPU(duration=120)
def generate_image(prompt: str):
return pipe(prompt).images[0]
CUDA Availability Model
Real GPU access is only available inside @spaces.GPU-decorated functions. Outside those functions, the GPU is not attached to the process.
However, import spaces monkey-patches torch so that:
torch.cuda.is_available()returnsTrueglobally..to("cuda")/device="cuda"calls at module scope succeed without error.
This is intentional. Module-scope model.to("cuda") calls register tensors with the ZeroGPU backend, which writes them to a disk offload directory at a startup "pack" step and frees the corresponding RAM. When a @spaces.GPU call lands, a forked GPU worker process streams those weights from disk into VRAM via a pinned-memory pipeline. Warm workers (reused across requests on the same GPU slot) keep weights resident on the GPU and skip the disk → V
अक्सर पूछे जाने वाले सवाल
एक आम ZeroGPU त्रुटि कौन सी है?
समय सीमा की त्रुटि, जैसे अवैध duration, एक आम मामला है जिसे स्किल समझाती है।
क्या यह सारा Gradio कोड कवर करती है?
नहीं। सामान्य Gradio काम एक अलग Gradio स्किल कवर करती है।
क्या यह Docker Spaces के लिए काम करती है?
नहीं। यह सिर्फ़ ZeroGPU हार्डवेयर पर Gradio Spaces के लिए है।
जानकारी
लेखक का मूल विवरण
AI demos and GPU compute with Gradio Spaces and Hugging Face Spaces ZeroGPU. Use when writing or reviewing code that uses `@spaces.GPU`, configuring `python_version` or `requirements.txt` for a ZeroGPU Space, or handling ZeroGPU-specific code constraints — pickle-based process isolation, `gr.State` semantics across the worker boundary, no `torch.compile` (use AoTI instead), CUDA wheel-only builds (no `nvcc` at build or runtime), large vs xlarge sizing, and dynamic duration callables. Make sure to use this skill whenever the user mentions ZeroGPU, `@spaces.GPU`, or the `spaces` Python package,
repo: huggingface/skills
लोकप्रियता
- GitHub स्टार
- 11k
- रैंकिंग में स्थान
- #11780
- लाइसेंस
- Apache-2.0
- अपडेट की गई
- 30/10/2026
कमेंट
- …
इस repository की और skills
hf-cli
11kयह आपके एजेंट को hf कमांड लाइन टूल से Hugging Face पर मॉडल, डेटासेट, Spaces, रिपो और लोकल कैश डाउनलोड करने, अपलोड करने और संभालने में मदद करती है।
hf-cloud-aws-context-discovery
11kयह आपके एजेंट को किसी भी क्लाउड काम से पहले AWS प्रोफ़ाइल, क्षेत्र और खाते का विवरण खोजने में मदद करती है, ताकि वह अंदाज़ा लगाकर खाता न चुने।
hf-cloud-python-env-setup
11kयह आपके एजेंट को SageMaker या AWS ऑटोमेशन चलाने से पहले सही Python संस्करण और ताज़ा लाइब्रेरी वाला साफ़ Python वातावरण सेट करने में मदद करती है।
hf-cloud-sagemaker-deployment-planner
11kयह आपके एजेंट को मॉडल को Amazon SageMaker पर डिप्लॉय करने की योजना बनाने में मदद करती है, real-time, serverless, async या batch होस्टिंग में से सही विकल्प चुनकर।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।