ImageGenerationModel¶
This section contains the API reference for the distilabel
image generation models, both for the ImageGenerationModel
synchronous implementation, and for the AsyncImageGenerationModel
asynchronous one.
For more information and examples on how to use existing LLMs or create custom ones, please refer to Tutorial - ImageGenerationModel.
base
¶
ImageGenerationModel
¶
Bases: RuntimeParametersModelMixin
, BaseModel
, _Serializable
, ABC
Base class for ImageGeneration
models.
To implement an ImageGeneration
subclass, you need to subclass this class and implement:
- load
method to load the ImageGeneration
model if needed. Don't forget to call super().load()
,
so the _logger
attribute is initialized.
- model_name
property to return the model name used for the LLM.
- generate
method to generate num_generations
per input in inputs
.
Attributes:
Name | Type | Description |
---|---|---|
generation_kwargs |
Optional[RuntimeParameter[dict[str, Any]]]
|
the kwargs to be propagated to either |
_logger |
Logger
|
the logger to be used for the |
Source code in src/distilabel/models/image_generation/base.py
model_name
abstractmethod
property
¶
Returns the model name used for the ImageGenerationModel
.
load()
¶
Method to be called to initialize the ImageGenerationModel
, and its logger.
unload()
¶
get_generation_kwargs()
¶
Returns the generation kwargs to be used for the generation. This method can be overridden to provide a more complex logic for the generation kwargs.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The kwargs to be used for the generation. |
Source code in src/distilabel/models/image_generation/base.py
generate(inputs, num_generations=1, **kwargs)
abstractmethod
¶
Generates images from the provided input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
list[str]
|
the prompt text to generate the image from. |
required |
num_generations
|
int
|
the number of images to generate. Defaults to |
1
|
Returns:
Type | Description |
---|---|
list[list[dict[str, Any]]]
|
A list with a dictionary with the list of images generated. |
Source code in src/distilabel/models/image_generation/base.py
generate_outputs(inputs, num_generations=1, **kwargs)
¶
This method is defined for compatibility with the LLMs
. It calls the generate
method.
Source code in src/distilabel/models/image_generation/base.py
AsyncImageGenerationModel
¶
Bases: ImageGenerationModel
Abstract class for asynchronous ImageGenerationModels
, to benefit from the async capabilities
of each LLM implementation. This class is meant to be subclassed by each ImageGenerationModel
, and the
method agenerate
needs to be implemented to provide the asynchronous generation of
responses.
Attributes:
Name | Type | Description |
---|---|---|
_event_loop |
AbstractEventLoop
|
the event loop to be used for the asynchronous generation of responses. |
Source code in src/distilabel/models/image_generation/base.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
generate_parameters
property
¶
Returns the parameters of the agenerate
method.
Returns:
Type | Description |
---|---|
list[Parameter]
|
A list containing the parameters of the |
generate_parsed_docstring
cached
property
¶
Returns the parsed docstring of the agenerate
method.
Returns:
Type | Description |
---|---|
Docstring
|
The parsed docstring of the |
agenerate(input, num_generations=1, **kwargs)
abstractmethod
async
¶
Generates images from the provided input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
the input text to generate the image from. |
required |
num_generations
|
int
|
the number of images to generate. Defaults to |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
A list with a dictionary with the list of images generated. |
Source code in src/distilabel/models/image_generation/base.py
generate(inputs, num_generations=1, **kwargs)
¶
Method to generate a list of images asynchronously, returning the output
synchronously awaiting for the image of each input sent to agenerate
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
list[str]
|
the list of inputs to generate images for. |
required |
num_generations
|
int
|
the number of generations to generate per input. |
1
|
**kwargs
|
Any
|
the additional kwargs to be used for the generation. |
{}
|
Returns:
Type | Description |
---|---|
list[list[dict[str, Any]]]
|
A list containing the images for each input. |
Source code in src/distilabel/models/image_generation/base.py
__del__()
¶
Closes the event loop when the object is deleted.