guidellm.backends.backend
Backend interface and registry for generative AI model interactions.
Provides the abstract base class for implementing backends that communicate with generative AI models. Backends handle the lifecycle of generation requests and provide a standard interface for distributed execution across worker processes.
Backend
Bases: RegistryMixin['type[Backend]'], BackendInterface[GenerationRequest, GenerationResponse]
Base class for generative AI backends with registry and lifecycle management.
Provides a standard interface for backends that communicate with generative AI models. Combines the registry pattern for automatic discovery with a defined lifecycle for process-based distributed execution. Backend state must be pickleable for distributed execution across process boundaries.
Backend lifecycle phases: 1. Creation and configuration 2. Process startup - Initialize resources in worker process 3. Validation - Verify backend readiness 4. Request resolution - Process generation requests 5. Process shutdown - Clean up resources
Example: :: @Backend.register("my_backend") class MyBackend(Backend): def init(self, args: MyBackendArgs): super().init(args) self.api_key = args.api_key
async def process_startup(self):
self.client = MyAPIClient(self.api_key)
args = MyBackendArgs(api_key="secret")
backend = Backend.create(args)
Source code in src/guidellm/backends/backend.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
processes_limit property
Returns:
| Type | Description |
|---|---|
int | None | Maximum number of worker processes supported, None if unlimited |
requests_limit property
Returns:
| Type | Description |
|---|---|
int | None | Maximum number of concurrent requests supported globally, None if unlimited |
__init__(args)
Initialize a backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ | The backend type identifier | required |
create(args) classmethod
Create a backend instance based on the backend type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ | The type of backend to create | required | |
kwargs | Additional arguments for backend initialization | required |
Returns:
| Type | Description |
|---|---|
Backend | An instance of a subclass of Backend |
Raises:
| Type | Description |
|---|---|
ValueError | If the backend type is not registered |
Source code in src/guidellm/backends/backend.py
default_model() abstractmethod async
BackendArgs
Bases: PydanticClassRegistryMixin['BackendArgs'], ABC
Base class for backend creation arguments.
This class serves as a base for defining argument models used in the creation of backend instances. It inherits from PydanticClassRegistryMixin to enable automatic registration of subclasses, allowing for flexible and extensible backend configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_discriminator | str | Field name for polymorphic deserialization |
Source code in src/guidellm/backends/backend.py
__pydantic_schema_base_type__() classmethod
Return base type for polymorphic validation hierarchy.
Returns:
| Type | Description |
|---|---|
type[BackendArgs] | Base BackendArgs class for schema validation |