Docs/Build

Setup, snapshots & handlers

Separate initialization from request execution so the expensive ready state can be reused.

Initialize with @app.setup

The setup function runs on the builder. Load weights, initialize your model, and return the state needed by the handler. That state is captured at the snapshot boundary and reused after restore.

Python
@app.setupdef load():    from my_model import load_model    return load_model()

Respect the snapshot boundary

Objects retained across setup must be checkpointable. Do not keep open sockets, pipes, or host file descriptors in the returned state. Open external connections inside the handler or reconnect lazily.

The SDK checks common invalid objects and raises SnapshotBoundaryError. This check is a useful early diagnostic; successful validation does not replace a successful snapshot build.

Serve with @app.handler

The first argument receives the object returned by setup. The request carries the input for this invocation. Keep model loading out of the handler, and return the result your client expects.

Python
@app.handlerdef transcribe(model, request):    return model(request["audio"])

Inspect the captured state

Use snapshots to list published artifacts and their restore information. Use logs to investigate initialization or checkpoint failures. Restore latency depends on model state and placement; it is not a universal fixed number.

Terminal / reference
infimal apps snapshots asr-emotion-checkpoint4200
infimal apps logs asr-emotion-checkpoint4200 --limit 100