You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8007a54
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+251Lines changed: 251 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,30 @@ rp flash dev main.py # live dev session: edit, re-run, logs stream back
69
69
rp flash deploy # deploy production endpoints
70
70
```
71
71
72
+
Functions keep their Python identity: `chat.remote(...)` runs in the cloud, `await chat.remote.aio(...)` is the async form, `chat.local(...)` runs in-process. See [`examples/apps`](examples/apps) for runnable examples and [docs.runpod.io](https://docs.runpod.io) for the full guide.
73
+
74
+
Queue `.remote()` calls request a synchronous result and poll the same job if the server's wait window expires. Fast results need no client-side polling. Dev sessions use a short sync window to keep worker logs responsive. Use `.spawn()` for an asynchronous job handle. A transport failure before receiving a job ID raises an error without resubmitting the work.
datacenter-local storage. Apps resolve names and choose a datacenter compatible
80
+
with every resource sharing the volume. `GlobalVolume(name_or_id, create=True)`
81
+
references global storage without a datacenter constraint. Both inherit from
82
+
the abstract `Volume` base, resolve by name or ID, and create missing storage
83
+
when provisioning remote compute. Set `create=False` to require existing storage.
84
+
Global-volume lookup and creation use GraphQL; network volumes use REST.
85
+
86
+
Declare attachments with `mounts={"/path": volume}`. Tasks support one network
87
+
and one global volume at distinct, non-overlapping paths. Queue and API resources
88
+
support one volume at `/runpod-volume`; global storage requires a GPU endpoint.
89
+
90
+
Inside worker code, `volume.path` returns the configured mount path. The runtime
91
+
binds declared references and resolved IDs before importing user code. Access
92
+
raises if the volume is unmounted or has multiple bindings. Evaluate `.path`
93
+
inside remote functions, not during local module discovery. Calling `.local()`
94
+
does not mount remote storage on the client machine.
95
+
72
96
## Sandboxes
73
97
74
98
Sandboxes are an access-controlled preview. An authorized account and a
@@ -222,6 +246,233 @@ You can also test your worker locally before deploying it to Runpod. This is use
222
246
python my_worker.py --rp_serve_api
223
247
```
224
248
249
+
### Worker Fitness Checks
250
+
251
+
Fitness checks allow you to validate your worker environment at startup before processing jobs. If any check fails, the worker exits immediately, allowing your orchestrator to restart it.
252
+
253
+
```python
254
+
# my_worker.py
255
+
256
+
import runpod
257
+
import torch
258
+
259
+
# Register fitness checks using the decorator
260
+
@runpod.serverless.register_fitness_check
261
+
defcheck_gpu_available():
262
+
"""Verify GPU is available."""
263
+
ifnot torch.cuda.is_available():
264
+
raiseRuntimeError("GPU not available")
265
+
266
+
@runpod.serverless.register_fitness_check
267
+
defcheck_disk_space():
268
+
"""Verify sufficient disk space."""
269
+
import shutil
270
+
stat = shutil.disk_usage("/")
271
+
free_gb = stat.free / (1024**3)
272
+
if free_gb <10:
273
+
raiseRuntimeError(f"Insufficient disk space: {free_gb:.2f}GB free")
274
+
275
+
defhandler(job):
276
+
job_input = job["input"]
277
+
# Your handler code here
278
+
return {"output": "success"}
279
+
280
+
# Fitness checks run before handler initialization (production only)
281
+
runpod.serverless.start({"handler": handler})
282
+
```
283
+
284
+
**Key Features:**
285
+
- Supports both synchronous and asynchronous check functions
286
+
- Hardware checks run at the first Serverless `import runpod`; processes it launches inherit the result via `RUNPOD_EARLY_FITNESS_CHECKS_DONE` and skip the pass
287
+
- Local tests and non-worker imports remain exempt; network readiness and custom checks run at worker start
288
+
- Successful early checks are reused at worker start unless their configuration changes
289
+
- Runs before handler initialization and job processing begins
290
+
- Any check failure exits with code 1 (worker marked unhealthy)
291
+
292
+
See [Worker Fitness Checks](https://github.com/runpod/runpod-python/blob/main/docs/serverless/worker_fitness_checks.md) documentation for more examples and best practices.
293
+
294
+
### Network-Volume Warm Cache
295
+
296
+
When a network volume is attached, `VolumeCache` warms local directories (such as a model cache) across cold starts — hydrating them on startup and syncing new files back on exit — so a repeated multi-GB model download becomes a one-time cost per endpoint. It is stdlib-only and best-effort.
297
+
298
+
```python
299
+
from runpod.serverless import VolumeCache
300
+
301
+
with VolumeCache(dirs=["/root/.cache/huggingface"]):
302
+
model = load_model()
303
+
```
304
+
305
+
See [Network-Volume Warm Cache](https://github.com/runpod/runpod-python/blob/main/docs/serverless/volume_cache.md) documentation for configuration and details.
306
+
307
+
## 📚 | REST API v2 Wrapper
308
+
309
+
Use the API wrapper to manage Runpod resources through REST API v2.
0 commit comments