interface / externals / image_generation / img_gen_server.py
Stable Diffusion XL Lightning server. Runs on a Mac (MPS) or Jetson (CUDA) box.
Endpoints
| Method · Path | Behaviour |
|---|---|
| POST /generate · POST / · POST /v1/images/generations | Body: {"prompt", "negative_prompt", "steps"}. Steps clamped 3-8. Guidance 1.5. 832×1216 output. Returns {"time": float, "data": [{"b64_json": ...}]}. |
Model & scheduler
StableDiffusionXLPipelinefromjuggernaut_xl_lightning.safetensors.EulerDiscreteSchedulerwith trailing timestep — required for Lightning models.torch.float16for memory.
Lifespan
asynccontextmanager loads the pipeline on startup, enables CPU offload + VAE slicing, runs a warmup pass. Garbage-collects + clears MPS/CUDA cache between generations. Sets PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 for Mac.
Dependencies
diffusers(StableDiffusionXLPipeline, EulerDiscreteScheduler)torch(float16, mps.empty_cache)PIL