Migrating from Modal
How a Modal app maps onto Runware Serverless: the decorators, the image definition, and where scaling configuration moves to.
Introduction
Most of a Modal app translates line for line. One thing moves, the thing Modal advertises most: Modal puts infrastructure in your source file, and Runware keeps it out.
Where the configuration went
In Modal, the GPU and the image are arguments to a decorator. On Runware they are arguments to a deploy.
# Modal
@app.cls(gpu="h100", image=image, min_containers=1)
class Model:
...# Runware
runware serverless deploy model.py --id my-app --gpu-type h100 --min-workers 1Your source file cannot declare hardware or scaling. The decorator accepts no arguments for them, the API rejects an attempt to declare them per endpoint, and a code app has no configuration file.
The API owns those values and they are mutable on a live app. You can scale an app from the CLI or the dashboard while it is serving.
A configuration change skips the rebuild, and a code deploy keeps your scaling.
Imports move inside
Modal lets you import at module level, or defer with with image.imports():. Deferring is required here. The build imports your file to find your endpoints, without your dependencies installed, so a module-level import torch fails the build. with imports(): is the direct counterpart, and moving the import into load or into the handler that uses it works just as well. See Serving-time imports.
A minimal app, both ways
# Modal
import modal
app = modal.App("image-tools")
image = modal.Image.debian_slim().pip_install("torch", "diffusers", "fastapi[standard]")
@app.cls(gpu="h100", image=image)
class ImageTools:
@modal.enter()
def load(self):
self.pipe = load_my_pipeline()
@modal.fastapi_endpoint()
def generate(self, prompt: str):
return {"image": self.pipe(prompt).encode()}# Runware
from runware_serverless import endpoint, serve
@serve
class ImageTools:
def load(self) -> None:
self.pipe = load_my_pipeline()
@endpoint
def generate(self, prompt: str) -> dict:
return {"image": self.pipe(prompt).encode()}runware serverless deploy model.py --id image-tools --gpu-type h100 \
--requirement torch --requirement diffusersThe class is the app. Runware has no App object to name and no Image object to build.
--max-workers defaults to 1. Modal's max_containers defaults to no ceiling, so an app that scaled freely there runs on a single worker here, with no error anywhere. Set it on the first deploy. The other defaults are --min-workers 0, --idle-ttl 60 and --scaling-delay 10.
The mapping
| Modal | Runware |
modal.App("name") | --id on the deploy. The app is created by deploying it |
@app.cls(...) | @serve, which accepts encode_response and free_bytes, with no hardware or scaling arguments |
@modal.enter() | A load method, required and named |
@modal.exit() | No equivalent |
@modal.fastapi_endpoint() | @endpoint, which accepts no path |
modal.Image...pip_install(...) | --base-image and --requirement on the deploy |
gpu="h100" | --gpu-type h100 |
min_containers, max_containers | --min-workers, --max-workers, and apps scale afterwards |
modal.Volume | --volume /path. The mount path is the whole identity, there is no name, and it is a node-local cache, not a distributed volume |
modal.Secret | secrets set once, then secrets attach per app |
modal deploy | runware serverless deploy |
modal serve | No equivalent |
Endpoints and paths
Modal lets you name a web endpoint through the decorator. Runware derives the path from the method name, replacing underscores with hyphens, so run_upscale is served at run-upscale.
Renaming a method renames your public endpoint. There is no decorator argument to pin it. Choose method names you are willing to publish, and treat renaming one as a breaking change for your callers.
A class that decorates nothing falls back to serving its predict, so a single-endpoint model can leave the decorator off.
The request body
Modal's simple endpoints take query parameters and map them onto your arguments. Runware requires a POST with an envelope, and your fields go inside payload.
{
"taskId": "6b0c2f4e-8d3a-4c1b-9e7f-2a5d8c1b3e60",
"payload": { "prompt": "a red bicycle" }
}taskId is yours to generate, and it makes retries safe. Sending the same id again returns the existing task, and no second run starts. See Invoking an app.
Your handler still receives the payload fields as keyword arguments, so the shape of the signature carries over. One thing inside it does not.
An omitted optional field arrives as an explicit null, not as a missing key, so a Python default never fires. Re-apply each default in the body, as steps = 4 if steps is None else steps. A positional-only parameter, *args or **kwargs fails the build outright.
Loading weights
@modal.enter() becomes a plain load method, and it is required. The build identifies your class by looking for one that defines load alongside its handlers.
load can run more than once on the same worker. It is retried when the GPU is out of memory at startup, and the retry re-instantiates your class, so both __init__ and load have to be safe to run twice. Modal's @enter runs once per container.
There is no @modal.exit() equivalent. If you rely on one for flushing or cleanup, that logic has to move inside the handler or be dropped.
Typed requests
Annotate a parameter with a Pydantic model and it arrives validated, as an instance, and the model's schema is published as your endpoint's contract.
from pydantic import BaseModel
from runware_serverless import endpoint, serve
class Transcribe(BaseModel):
audio_url: str
language: str | None = None
@endpoint
def transcribe(self, req: Transcribe) -> dict:
return {"text": self.pipe(req.audio_url)}A mismatched body is rejected before a worker is woken. See Writing a model.
Features with no equivalent
There is no equivalent of modal serve, and no live-reloading development loop against the platform. You deploy, and a deploy builds. Iterate against your class locally, since @serve returns it unchanged and your own tests can call the methods directly.
Validation happens at the build. Importing your model file locally does catch the decorator mistakes, because @endpoint and @serve raise at import for an illegal method name, an argument in the parentheses, or a class with nothing to serve. Everything past that, a missing dependency or a signature the platform cannot bind, surfaces as a failed build and not as an error on your machine.
Concurrency inside a container. Modal's @modal.concurrent(max_inputs=...) lets one container take several requests at once. A Runware worker serves one task at a time, so throughput depends only on the worker count. An app that leaned on concurrency needs proportionally more workers here.
No @exit, and no per-endpoint hardware. Every endpoint on an app shares one queue and one worker pool. Two endpoints that need different GPUs are two apps.
One deployment class per file. Helper classes and request models are fine. The build refuses a second class that also defines load alongside endpoints or a predict.
A way to pass an ASGI or WSGI app. @modal.asgi_app, @modal.wsgi_app and @modal.web_server have no counterpart on the code path, which only ever serves methods on a class. If your Modal deployment is a FastAPI or Flask app, move it to a container. Your image runs the server and a container.yaml declares each route. Your server receives the inner payload alone, not the envelope around it.
Porting checklist
- Strip
gpu,imageand scaling arguments out of the decorator and pass them to the deploy command instead - Replace
@app.cls(...)with@serve, and@modal.enter()with aloadmethod - Make
loadand__init__safe to run twice, since an out-of-memory retry re-instantiates the class - Move every heavy import out of the module level, into a
with imports():block or intoloador the handler that uses it - Replace each web endpoint decorator with
@endpoint, and check the method names, since they are now your public paths - Move
pip_installarguments to--requirement, and the base image to--base-image - Decide your mount paths before the first deploy and pass them as
--volume, since anything downloaded at runtime is otherwise refetched on every cold start. Unlike a ModalVolume, the set is fixed when the app is created, so adding one later means a new app - Move
@modal.exit()logic into the handler, or drop it - Re-apply every parameter default inside the handler body, since an omitted field arrives as
null - Update your callers to send the envelope