Network volume example that shares model cache and generated images between GPU and CPU workers.
The GPU worker generates images with Stable Diffusion and writes them to a Runpod network volume. The CPU worker lists or serves those images from the same volume.
uv syncuv run flash loginOr create a .env file with RUNPOD_API_KEY=your_api_key_here.
uv run flash devServer starts at http://localhost:8888
Generate an image (GPU worker):
curl -X POST http://localhost:8888/gpu_worker/runsync \
-H "Content-Type: application/json" \
-d '{"prompt": "a sunset over mountains"}'List generated images (CPU worker):
curl http://localhost:8888/imagesGet a specific image (CPU worker):
curl http://localhost:8888/images/sd_generated_20240101_120000.pngVisit http://localhost:8888/docs for interactive API documentation.
- How to attach a shared
NetworkVolumeto GPU and CPU workers - How to use the GPU worker to write to the volume
- How to read and serve files from the CPU worker
- GPU worker: loads Stable Diffusion, caches weights in
/runpod-volume/models, writes images to/runpod-volume/generated_images - CPU worker: lists images and serves files from
/runpod-volume/generated_images
01_network_volumes/
├── gpu_worker.py # Stable Diffusion worker with @Endpoint
├── cpu_worker.py # List and serve images with Endpoint routes
├── requirements.txt
└── README.md
GPU worker (QB, class-based @Endpoint). Generates an image and saves it to the shared volume.
Request:
{ "prompt": "a sunset over mountains" }Response:
{
"prompt": "string",
"image_path": "string",
"timestamp": "string",
"generation_params": {
"num_inference_steps": 20,
"guidance_scale": 7.5,
"width": 512,
"height": 512
},
"message": "Image generated and saved locally!"
}CPU worker (LB, explicit path). Lists all generated images on the shared volume.
Response:
{ "status": "success", "images": ["sd_generated_20240101_120000.png"] }CPU worker (LB, explicit path). Returns metadata and base64-encoded content for a single image.
- The network volume is defined inline in each worker file and attached to both workers.
- Stable Diffusion weights are cached in the volume so cold starts are faster after the first run.
flash build
flash deploy new production
flash deploy send production