Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
|
@@ -7,4 +7,49 @@ sdk: static
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
# ZeroGPU
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# ZeroGPU Spaces
|
| 11 |
+
|
| 12 |
+
*ZeroGPU* is a new kind of hardware for Spaces.
|
| 13 |
+
|
| 14 |
+
It has two goals :
|
| 15 |
+
- Provide **free GPU access** for Spaces
|
| 16 |
+
- Allow Spaces to run on **multiple GPUs**
|
| 17 |
+
|
| 18 |
+
This is achieved by making Spaces efficiently hold and release GPUs as needed
|
| 19 |
+
(as opposed to a classical GPU Space that holds exactly one GPU at any point in time)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Compatibility
|
| 23 |
+
|
| 24 |
+
*ZeroGPU* Spaces should mostly be compatible with any PyTorch-based GPU Space.<br>
|
| 25 |
+
Compatibilty with high level HF libraries like `transformers` or `diffusers` is slightly more guaranteed<br>
|
| 26 |
+
That said, ZeroGPU Spaces are not as broadly compatible as classical GPU Spaces and you might still encounter unexpected bugs
|
| 27 |
+
|
| 28 |
+
Also, for now, ZeroGPU Spaces only work with the **Gradio SDK**
|
| 29 |
+
|
| 30 |
+
# Usage
|
| 31 |
+
|
| 32 |
+
In order to make your Space work with ZeroGPU you need to **decorate** the Python functions that actually require a GPU with `@spaces.GPU`<br>
|
| 33 |
+
During the time when a decorated function is invoked, the Space will be attributed a GPU, and it will release it upon completion of the function.<br>
|
| 34 |
+
Here is a practical example :
|
| 35 |
+
|
| 36 |
+
```diff
|
| 37 |
+
+import spaces
|
| 38 |
+
from diffusers import DiffusionPipeline
|
| 39 |
+
|
| 40 |
+
pipe = DiffusionPipeline.from_pretrained(...)
|
| 41 |
+
pipe.to('cuda')
|
| 42 |
+
|
| 43 |
+
+@spaces.GPU
|
| 44 |
+
def generate(prompt):
|
| 45 |
+
return pipe(prompt).images
|
| 46 |
+
|
| 47 |
+
gr.Interface(
|
| 48 |
+
fn=generate,
|
| 49 |
+
inputs=gr.Text(),
|
| 50 |
+
outputs=gr.Gallery(),
|
| 51 |
+
).launch()
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
1. We first `import spaces` (importing it first might prevent some issues but is not mandatory)
|
| 55 |
+
2. Then we decorate the `generate` function by adding a `@spaces.GPU` line before its definition
|