A model worker is a background execution component that pulls requests from a queue and runs model inference. It lets an API keep accepting requests while inference runs separately. section 17.1.4
Figure 17.2 Dataflow with request batching and streaming
Follow the flow from client requests into a queue, through batched model execution, and back to clients as streamed tokens. section 17.1.4
A typical worker coordinates several pieces:
- Collect requests until a batch is full or the oldest request reaches a maximum wait time. section 17.1.4
- Run on a background thread while the API handles incoming requests concurrently. section 17.1.4
FastAPI worker setup
Start model_worker in the application's lifespan, enqueue each request with a unique identifier, and return a StreamingResponse for its results.
