update duration for zero gpu
Browse files
app.py
CHANGED
|
@@ -191,7 +191,11 @@ ALWAYS use ZeroGPU for GPU-dependent functions in Gradio apps:
|
|
| 191 |
|
| 192 |
1. Import the spaces module: `import spaces`
|
| 193 |
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
| 194 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
Example usage:
|
| 197 |
```python
|
|
@@ -201,7 +205,7 @@ from diffusers import DiffusionPipeline
|
|
| 201 |
pipe = DiffusionPipeline.from_pretrained(...)
|
| 202 |
pipe.to('cuda')
|
| 203 |
|
| 204 |
-
@spaces.GPU
|
| 205 |
def generate(prompt):
|
| 206 |
return pipe(prompt).images
|
| 207 |
|
|
@@ -212,6 +216,14 @@ gr.Interface(
|
|
| 212 |
).launch()
|
| 213 |
```
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
Functions that typically need @spaces.GPU:
|
| 216 |
- Image generation (text-to-image, image-to-image)
|
| 217 |
- Video generation
|
|
@@ -234,7 +246,11 @@ ALWAYS use ZeroGPU for GPU-dependent functions in Gradio apps:
|
|
| 234 |
|
| 235 |
1. Import the spaces module: `import spaces`
|
| 236 |
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
| 237 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
Example usage:
|
| 240 |
```python
|
|
@@ -244,7 +260,7 @@ from diffusers import DiffusionPipeline
|
|
| 244 |
pipe = DiffusionPipeline.from_pretrained(...)
|
| 245 |
pipe.to('cuda')
|
| 246 |
|
| 247 |
-
@spaces.GPU
|
| 248 |
def generate(prompt):
|
| 249 |
return pipe(prompt).images
|
| 250 |
|
|
@@ -255,6 +271,14 @@ gr.Interface(
|
|
| 255 |
).launch()
|
| 256 |
```
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
Functions that typically need @spaces.GPU:
|
| 259 |
- Image generation (text-to-image, image-to-image)
|
| 260 |
- Video generation
|
|
|
|
| 191 |
|
| 192 |
1. Import the spaces module: `import spaces`
|
| 193 |
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
| 194 |
+
3. Specify appropriate duration based on expected runtime:
|
| 195 |
+
- Quick inference (< 30s): `@spaces.GPU(duration=30)`
|
| 196 |
+
- Standard generation (30-60s): `@spaces.GPU` (default 60s)
|
| 197 |
+
- Complex generation (60-120s): `@spaces.GPU(duration=120)`
|
| 198 |
+
- Heavy processing (120-180s): `@spaces.GPU(duration=180)`
|
| 199 |
|
| 200 |
Example usage:
|
| 201 |
```python
|
|
|
|
| 205 |
pipe = DiffusionPipeline.from_pretrained(...)
|
| 206 |
pipe.to('cuda')
|
| 207 |
|
| 208 |
+
@spaces.GPU(duration=120)
|
| 209 |
def generate(prompt):
|
| 210 |
return pipe(prompt).images
|
| 211 |
|
|
|
|
| 216 |
).launch()
|
| 217 |
```
|
| 218 |
|
| 219 |
+
Duration Guidelines:
|
| 220 |
+
- Shorter durations improve queue priority for users
|
| 221 |
+
- Text-to-image: typically 30-60 seconds
|
| 222 |
+
- Image-to-image: typically 20-40 seconds
|
| 223 |
+
- Video generation: typically 60-180 seconds
|
| 224 |
+
- Audio/music generation: typically 30-90 seconds
|
| 225 |
+
- Model loading + inference: add 10-30s buffer
|
| 226 |
+
|
| 227 |
Functions that typically need @spaces.GPU:
|
| 228 |
- Image generation (text-to-image, image-to-image)
|
| 229 |
- Video generation
|
|
|
|
| 246 |
|
| 247 |
1. Import the spaces module: `import spaces`
|
| 248 |
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
| 249 |
+
3. Specify appropriate duration based on expected runtime:
|
| 250 |
+
- Quick inference (< 30s): `@spaces.GPU(duration=30)`
|
| 251 |
+
- Standard generation (30-60s): `@spaces.GPU` (default 60s)
|
| 252 |
+
- Complex generation (60-120s): `@spaces.GPU(duration=120)`
|
| 253 |
+
- Heavy processing (120-180s): `@spaces.GPU(duration=180)`
|
| 254 |
|
| 255 |
Example usage:
|
| 256 |
```python
|
|
|
|
| 260 |
pipe = DiffusionPipeline.from_pretrained(...)
|
| 261 |
pipe.to('cuda')
|
| 262 |
|
| 263 |
+
@spaces.GPU(duration=120)
|
| 264 |
def generate(prompt):
|
| 265 |
return pipe(prompt).images
|
| 266 |
|
|
|
|
| 271 |
).launch()
|
| 272 |
```
|
| 273 |
|
| 274 |
+
Duration Guidelines:
|
| 275 |
+
- Shorter durations improve queue priority for users
|
| 276 |
+
- Text-to-image: typically 30-60 seconds
|
| 277 |
+
- Image-to-image: typically 20-40 seconds
|
| 278 |
+
- Video generation: typically 60-180 seconds
|
| 279 |
+
- Audio/music generation: typically 30-90 seconds
|
| 280 |
+
- Model loading + inference: add 10-30s buffer
|
| 281 |
+
|
| 282 |
Functions that typically need @spaces.GPU:
|
| 283 |
- Image generation (text-to-image, image-to-image)
|
| 284 |
- Video generation
|