Phase 8: Serverless GPU Deployment & Infrastructure · 50 min · Python · fal.ai · Replicate
The Concept
Platform 1: fal.ai
fal.ai provides managed GPU infrastructure with 600+ pre-deployed models:
import fal.client
# Direct model call — model is already deployed
result = fal.client.subscribe(
"fal-ai/flux/schnell",
arguments={
"prompt": "a mountain landscape at sunset",
"image_size": {"width": 1024, "height": 1024},
"num_inference_steps": 4,
},
)
print(result["images"][0]["url"])
Key Features
| Feature | Details |
|---|
| GPU types | H100, H200, B200 (1000s available) |
| Models | 600+ pre-deployed (FLUX, SDXL, Kling, Wan, etc.) |
| Billing | Per-second (minimum charge varies by model) |
| Cold start | ~3-5s for warm models, ~15-30s for cold |
| Queue API | Built-in queue with automatic retries |
| Custom models | Deploy your own via fal.ai Queue + function |
Pros & Cons
| Pros | Cons |
|---|
| Easiest to use — models pre-deployed | Less control over inference pipeline |
| Per-second billing (pay only for compute) | Limited to fal.ai's model catalog (for managed) |
| 600+ models available instantly | Custom model deployment requires more setup |
| Queue API with automatic retries | No ComfyUI support (use RunPod for that) |
| Global edge network | Vendor lock-in |
Platform 2: replicate
Replicate lets you deploy any model as a Docker container:
import replicate
output = replicate.run(
"black-forest-labs/flux-schnell",
input={"prompt": "a mountain landscape", "width": 1024, "height": 1024},
)
print(output[0])
Key Features
| Feature | Details |
|---|
| GPU types | T4, A100, H100 (shared/dedicated) |
| Models | Community + official models, push your own |
| Billing | Per-second (based on GPU type) |
| Cold start | ~10-30s (Docker container spin-up) |
| Custom models | Push any Docker container with a predict.py |
| API | Simple REST API, Python/JS SDKs |
Pros & Cons
| Pros | Cons |
|---|
| Deploy any model as Docker container | Slower cold starts than fal.ai |
| Simple API (run any model in 2 lines) | Fewer GPU options than fal.ai |
| Community model marketplace | Per-second billing but minimum charges |
| Good for prototyping | Less control than Modal |
| Push your own model | No ComfyUI support |
Platform 3: modal
Modal provides serverless Python with GPU access:
import modal
app = modal.App("flux-generation")
image = (modal.Image.debian_slim()
.pip_install("diffusers", "torch", "transformers")
.run_commands("huggingface-cli download black-forest-labs/FLUX.1-schnell"))
@app.function(image=image, gpu="A100", min_containers=0)
def generate(prompt: str) -> bytes:
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell")
image = pipe(prompt, num_inference_steps=4).images[0]
import io
buf = io.BytesIO()
image.save(buf, format="PNG")
return buf.getvalue()
# Execute
with app.run():
result = generate.remote("a mountain landscape")
Key Features
| Feature | Details |
|---|
| GPU types | T4, A100, H100 (per-second billing) |
| Models | Any HuggingFace model, custom weights |
| Billing | Per-second (compute) + per-second (idle containers) |
| Cold start | ~15-60s (Docker build + model download) |
| Custom models | Full Python control — install any package |
| Auto-scaling | Scales from 0 to N containers |
| min_containers | Keep warm containers to reduce cold starts |
Pros & Cons
| Pros | Cons |
|---|
| Full control (any Python package, any model) | More setup than fal.ai/Replicate |
| Auto-scaling (scale to zero) | Cold starts can be slow |
| Per-second billing | Need to manage image builds |
| Any GPU type | No pre-deployed models |
| Best for custom pipelines | No ComfyUI support |
Which serverless GPU platform is best for deploying a custom ComfyUI workflow with custom nodes?
RunPod Serverless is specifically designed for ComfyUI deployment. It provides: (1) ComfyUI Docker templates — pre-built images with ComfyUI installed, (2) Custom handler support — write a Python handler that receives jobs, executes ComfyUI workflows, and returns results, (3) GPU marketplace — choose from H100, A100, RTX 4090, etc., (4) Worker pool management — scale workers up/down based on queue length. fal.ai doesn't support ComfyUI. Modal could work but requires more setup. Replicate doesn't support ComfyUI.
Platform 4: RunPod serverless
RunPod Serverless provides GPU marketplace with custom Docker templates:
# RunPod handler (handler.py)
def handler(job):
input_data = job["input"]
prompt = input_data["prompt"]
# Execute ComfyUI workflow
result = execute_comfyui(prompt)
return {"output_url": result["url"]}
# Deploy: push Docker image to RunPod, create serverless endpoint
# API: POST to endpoint, poll for results
Key Features
| Feature | Details |
|---|
| GPU types | RTX 4090, A100, H100, H200 (marketplace) |
| Models | Bring your own Docker image |
| Billing | Per-second (GPU + storage) |
| Cold start | ~10-30s (Docker container spin-up) |
| Custom models | Full Docker control — any model, any framework |
| ComfyUI | First-class support (templates, handlers) |
| Worker pools | Scale workers based on queue length |
Pros & Cons
| Pros | Cons |
|---|
| ComfyUI first-class support | More manual setup than fal.ai |
| Full Docker control | Need to manage Docker images |
| GPU marketplace (choose any GPU) | No pre-deployed models |
| Worker pool management | API less polished than fal.ai |
| Best for ComfyUI deployment | Need to write custom handlers |
Comparison matrix
| Feature | fal.ai | Replicate | Modal | RunPod |
|---|
| Ease of use | High | High | Medium | Medium |
| Control | Low | Medium | High | High |
| Pre-deployed models | 600+ | Community | None | None |
| Custom models | Yes (Queue) | Yes (Docker) | Yes (Python) | Yes (Docker) |
| ComfyUI | No | No | No | Yes |
| GPU types | H100/H200/B200 | T4/A100/H100 | T4/A100/H100 | 4090/A100/H100 |
| Billing | Per-second | Per-second | Per-second | Per-second |
| Cold start | 3-15s | 10-30s | 15-60s | 10-30s |
| Auto-scaling | Yes | Yes | Yes | Yes |
| Scale to zero | Yes | Yes | Yes | Yes |
| Best for | Quick deployment | Prototyping | Custom pipelines | ComfyUI |
Decision framework
Need a pre-deployed model quickly? → fal.ai (600+ models, 3s cold start)
Prototyping with community models? → Replicate (simple API, Docker-based)
Custom Python pipeline with full control? → Modal (any package, any model)
Deploying ComfyUI workflows? → RunPod (ComfyUI templates, handlers)
Need the cheapest GPU? → RunPod (marketplace, RTX 4090 for images)
Need B200 GPUs? → fal.ai (latest GPUs, largest fleet)