aitune.dynamo.worker
Dynamo worker — serve AITune-tuned models as Dynamo endpoints.
Module Contents
Classes
Functions
Data
API
Base class for AITune Dynamo workers (power-user API).
Subclass, override :meth:setup and :meth:serve, then call :meth:run.
Called after the Dynamo endpoint is registered.
Override to call register_model or perform post-startup work.
Parameters:
The :class:DistributedRuntime instance.
The registered Dynamo :class:Endpoint object.
Start serving. Blocks until SIGTERM/SIGINT.
Parameters:
Enable NATS JetStream for KV cache events.
Handle one request. Async generator — yield response chunks.
Parameters:
Incoming request payload.
Raises:
NotImplementedError: Must be overridden by subclasses.
Initialize the model. Called once before serving starts.
Raises:
NotImplementedError: Must be overridden by subclasses.
Configuration for the high-level :func:dynamo_worker entrypoint.
Parameters:
Modality type. One of "image", "video", "embedding".
HuggingFace model ID or local path passed to register_model.
Optional adapter fn(DynamoRequest) -> dict. The dict is
unpacked as **kwargs when calling the user function. If None
and the user passed a plain callable (not nn.Module), the raw
Dynamo request object is passed as the sole positional argument.
Dynamo service namespace. Default: "aitune".
Component name within the namespace. Default: "backend".
Endpoint name within the component. Default: "generate".
Enable NATS JetStream for KV cache events. Default: False.
Name advertised to the Dynamo frontend. Defaults to model_path.
Bases: DynamoWorker
Internal worker built from a DynamoWorkerConfig. Not part of public API.
From version 1.3.0 dynamo introduces a new WorkerType enum and made it required.
Register this worker with the Dynamo frontend.
Deserialize request, run user function in executor, pack and yield response.
No-op: the model is already initialized before dynamo_worker() is called.
Return (ModelInput, ModelType, request_class) for type_.
All imports are deferred because dynamo is optional.
Parameters:
Modality type string ("image", "video", "embedding").
Returns: tuple
Tuple of (ModelInput enum value, ModelType enum value, request Pydantic class).
Import dynamo runtime dependencies, raising a clear error if absent.
Returns: tuple
Tuple of (DistributedRuntime class, dynamo_worker decorator, uvloop module).
Raises:
ImportError: Whenai-dynamo-runtimeoruvloopis not installed.
Convert a user function’s return value to the Dynamo wire-format dict.
Parameters:
Return value from the user’s inference function.
Worker configuration (used for model name and type).
Returns: dict
A dict ready to yield to the Dynamo runtime.
Raises:
TypeError: When result cannot be converted for config.type.
Low-level runtime loop. Call setup() once, serve until SIGTERM/SIGINT.
Parameters:
Zero-argument initializer called before serving starts.
Async generator serve(request) -> AsyncIterable[response].
Dynamo service namespace.
Component name within the namespace.
Endpoint name within the component.
Enable NATS JetStream for KV cache events.
Optional async callable invoked after endpoint registration.
Serve a tuned model as a Dynamo worker endpoint.
The minimal path to serving after ait.tune() or ait.load():
- Build a :class:
DynamoWorkerConfigfor your modality. - Call this function. It blocks until SIGTERM/SIGINT.
Startup validation happens before any Dynamo runtime is started.
Modality-specific request deserialization, register_model, sync-to-async
wrapping, and response packing are handled automatically.
Parameters:
A torch.nn.Module (requires config.mapping) or any
callable. If callable and config.mapping is None, the raw
Dynamo request object is passed as the sole argument.
Worker configuration including modality type, model path, and optional request adapter.
Raises:
ValueError: Ifconfig.typeis not a supported P0 modality, or if atorch.nn.Moduleis passed without amapping.ImportError: Ifai-dynamo-runtimeis not installed.