generations
ImageGenerationInitKwargs
Bases: TypedDict
Optional keyword arguments accepted by ImageSingleGeneration from template helpers.
Source code in horde_sdk/worker/generations.py
AlchemyGenerationInitKwargs
Bases: TypedDict
Optional keyword arguments accepted by AlchemySingleGeneration factory flows.
Source code in horde_sdk/worker/generations.py
TextGenerationInitKwargs
Bases: TypedDict
Optional keyword arguments accepted by TextSingleGeneration helpers.
Source code in horde_sdk/worker/generations.py
ImageSingleGeneration
Bases: HordeSingleGeneration[bytes]
A single image generation.
Not to be confused with a job, which can contain multiple generations.
Source code in horde_sdk/worker/generations.py
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 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 | |
result_type
property
The type of the result of the generation.
result_ids
property
The unique identifiers for the generations in the batch.
dispatch_result_ids
property
Identifiers supplied by the dispatch source, if any.
generation_failure_count
property
The number of times the generation has failed during any step of the generation process.
errored_states
property
Return a tuple of states which occurred just before an error state and the time they were set.
error_counts
property
Return a dictionary of states and the number of times they occurred before an error state.
requires_post_processing
property
Whether or not the generation requires post-processing.
requires_generation
property
Whether or not the generation requires generation.
requires_safety_check
property
Whether or not the generation requires a safety check.
generation_results
property
Get the result of the generation.
default_generate_progress_transitions
classmethod
default_generate_progress_transitions_no_submit
classmethod
does_class_require_generation
classmethod
does_class_require_safety_check
classmethod
__init__
__init__(
*,
generation_parameters: ImageGenerationParameters,
generation_id: ID_TYPES | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
result_ids: list[ID_TYPES] | None = None,
requires_submit: bool = True,
safety_rules: SafetyRules = default_image_safety_rules,
black_box_mode: bool = False,
state_error_limits: (
Mapping[GENERATION_PROGRESS, int] | None
) = HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS,
strict_transition_mode: bool = HordeWorkerConfigDefaults.DEFAULT_GENERATION_STRICT_TRANSITION_MODE,
extra_logging: bool = False
) -> None
Initialize the generation.
Parameters:
-
generation_parameters(ImageGenerationParameters) –The parameters for the generation.
-
generation_id(str | None, default:None) –The unique identifier for the generation. If None, a random UUID will be generated.
-
dispatch_result_ids(Sequence[str | UUID] | None, default:None) –Result identifiers assigned by dispatch, if available.
-
result_ids(list[ID_TYPES] | None, default:None) –The unique identifiers for the generation. If None, a random UUID will be generated for each result.
-
requires_submit(bool, default:True) –Whether the generation requires submission. Defaults to True.
-
safety_rules(SafetyRules, default:default_image_safety_rules) –The safety rules to apply to the generation. Defaults to default_image_safety_rules from
horde_sdk.safety. -
black_box_mode(bool, default:False) –Whether the generation is in black box mode. This removes all of the intermediate states between starting and finished states. This should only be used when the backend has no observability into the generation process. Defaults to False.
-
state_error_limits(Mapping[GENERATION_PROGRESS, int], default:DEFAULT_STATE_ERROR_LIMITS) –The maximum number of times a generation can be in an error state before it is considered failed. Defaults to HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS.
-
strict_transition_mode(bool, default:DEFAULT_GENERATION_STRICT_TRANSITION_MODE) –Whether or not to enforce strict transition checking. This prevents setting the same state multiple times in a row. Defaults to True.
-
extra_logging(bool, default:False) –Whether or not to enable extra debug-level logging, especially for state transitions. Defaults to True.
Source code in horde_sdk/worker/generations.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 | |
from_template
classmethod
from_template(
template: ImageGenerationParametersTemplate,
*,
generation_id: ID_TYPES | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
base_param_updates: (
BasicImageGenerationParametersTemplate | None
) = None,
additional_param_updates: (
ImageGenerationComponentContainer | None
) = None,
result_ids: Sequence[ID_TYPES] | None = None,
allocator: ResultIdAllocator | None = None,
seed: str = "image",
init_kwargs: ImageGenerationInitKwargs | None = None
) -> ImageSingleGeneration
Instantiate an image generation from a template.
Source code in horde_sdk/worker/generations.py
default_interrupt_states
classmethod
Get the default interrupt states.
register_callback
Register a callback to be called when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The state to register the callback for.
-
callback(Callable[[], None]) –The callback to call when the state is updated.
Source code in horde_sdk/worker/generations_base.py
set_dispatch_result_ids
Bind the generation to the result identifiers supplied by dispatch.
Source code in horde_sdk/worker/generations_base.py
get_generation_progress
get_progress_history
get_last_non_error_state
Get the last non-error state.
Source code in horde_sdk/worker/generations_base.py
get_last_non_error_state_and_time
Get the last non-error state and the time it was set.
Source code in horde_sdk/worker/generations_base.py
is_next_state_valid
Check if the next state is valid.
Source code in horde_sdk/worker/generations_base.py
on_error
on_error(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when an error occurs at any point in the generation process, safety checks, or submission.
This should be reserved for errors which make the current step impossible to complete. For example, if the a sub-process is OOM killed.
Contrast with the add_metadata_entry method, which is used for non-critical errors. If there is no
METADATA_TYPE for the error you encountered, you can use failed_message and failure_exception instead.
Parameters:
-
failed_message(str) –The reason the generation failed.
-
failure_exception(Exception, default:None) –The exception that caused the generation to fail. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ERROR.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_abort
on_abort(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when the generation is aborted.
Parameters:
-
failed_message(str) –The reason the generation was aborted.
-
failure_exception(Exception, default:None) –The exception that caused the generation to be aborted. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ABORTED.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_preloading
on_preloading_complete
on_generation_work_complete
on_generation_work_complete(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
| None
) = None,
) -> GENERATION_PROGRESS
Call when the generation work is complete, such as when inference is done.
This does not mean the generation is finalized, as calling this function means that safety checks and submission may still be pending. Examples of when this function would be called are when comfyui has just returned an image, interrogating an image has just completed or when a text backend has just generated text.
Source code in horde_sdk/worker/generations_base.py
on_generating
on_post_processing
on_post_processing_complete
on_pending_safety_check
Call when the generation is pending safety check.
set_work_result
set_work_result(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
),
) -> None
Set the result of the generation work.
Parameters:
-
result(Any) –The result of the generation work.
Source code in horde_sdk/worker/generations_base.py
on_complete
on_state
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
Source code in horde_sdk/worker/generations_base.py
step
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
is_safety_checking_done_on_all_batch
Check if the safety check is being done on a one-on-all basis.
Returns:
-
bool(bool) –True if the safety check is being done on a one-on-all basis, False otherwise.
Source code in horde_sdk/worker/generations_base.py
get_safety_check_results
Get the results of the safety checks.
Returns:
-
list[SafetyResult | None]–list[SafetyResult | None]: The results of the safety checks for each batch.
Source code in horde_sdk/worker/generations_base.py
on_safety_checking
on_safety_check_complete
Call when the safety check is complete.
Parameters:
-
batch_index(int) –The index of the batch to set the safety check result for. This is 0-indexed and must match the position of the result_ids provided during initialization.
-
safety_result(SafetyResult) –The result of the safety check.
Source code in horde_sdk/worker/generations_base.py
on_pending_submit
on_submitting
Call when an attempt is going to be made to submit the generation.
on_submit_complete
Call when the generation has been successfully submitted.
on_user_requested_abort
Call when the user requests to abort the generation.
on_user_abort_complete
AlchemySingleGeneration
Bases: HordeSingleGeneration[bytes]
A single alchemy generation. Alchemy is generally transformative or analytical in nature.
'Generation' is used more broadly here than in the context of AI generation for the sake of naming consistency.
Generally an input might be an image and the output could be anything, such as the input image upscaled with a model, caption text, or whether the image is NSFW or not (bool).
Not to be confused with a job, which can contain multiple generations.
Source code in horde_sdk/worker/generations.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
generation_parameters
instance-attribute
The parameters for the generation.
result_type
property
The type of the result of the generation.
result_ids
property
The unique identifiers for the generations in the batch.
dispatch_result_ids
property
Identifiers supplied by the dispatch source, if any.
generation_failure_count
property
The number of times the generation has failed during any step of the generation process.
errored_states
property
Return a tuple of states which occurred just before an error state and the time they were set.
error_counts
property
Return a dictionary of states and the number of times they occurred before an error state.
requires_post_processing
property
Whether or not the generation requires post-processing.
requires_generation
property
Whether or not the generation requires generation.
requires_safety_check
property
Whether or not the generation requires a safety check.
generation_results
property
Get the result of the generation.
default_generate_progress_transitions
classmethod
default_generate_progress_transitions_no_submit
classmethod
does_class_require_generation
classmethod
does_class_require_safety_check
classmethod
__init__
__init__(
*,
generation_parameters: SingleAlchemyParameters,
generation_id: str | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
result_ids: list[ID_TYPES] | None = None,
requires_generation: bool = False,
requires_post_processing: bool = True,
requires_safety_check: bool = False,
requires_submit: bool = True,
safety_rules: SafetyRules = default_image_safety_rules,
black_box_mode: bool = False,
state_error_limits: (
Mapping[GENERATION_PROGRESS, int] | None
) = HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS,
strict_transition_mode: bool = HordeWorkerConfigDefaults.DEFAULT_GENERATION_STRICT_TRANSITION_MODE,
extra_logging: bool = False
) -> None
Initialize the generation.
Parameters:
-
generation_parameters(SingleAlchemyParameters) –The parameters for the generation.
-
generation_id(str | None, default:None) –The unique identifier for the generation. If None, a random UUID will be generated.
-
dispatch_result_ids(Sequence[str | UUID] | None, default:None) –Result identifiers assigned by dispatch, if available.
-
result_ids(list[ID_TYPES] | None, default:None) –The unique identifiers for the generation. If None, a random UUID will be generated for each result.
-
requires_generation(bool, default:False) –Whether the generation requires generation. Defaults to False.
-
requires_post_processing(bool, default:True) –Whether the generation requires post-processing. Defaults to True.
-
requires_safety_check(bool, default:False) –Whether the generation requires a safety check. Defaults to False.
-
requires_submit(bool, default:True) –Whether the generation requires submission. Defaults to True.
-
safety_rules(SafetyRules, default:default_image_safety_rules) –The safety rules to apply to the generation. Defaults to default_image_safety_rules from
horde_sdk.safety. -
black_box_mode(bool, default:False) –Whether the generation is in black box mode. This removes all of the intermediate states between starting and finished states. This should only be used when the backend has no observability into the generation process. Defaults to False.
-
state_error_limits(Mapping[GENERATION_PROGRESS, int], default:DEFAULT_STATE_ERROR_LIMITS) –The maximum number of times a generation can be in an error state before it is considered failed. Defaults to HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS.
-
strict_transition_mode(bool, default:DEFAULT_GENERATION_STRICT_TRANSITION_MODE) –Whether or not to enforce strict transition checking. This prevents setting the same state multiple times in a row. Defaults to True.
-
extra_logging(bool, default:False) –Whether or not to enable extra debug-level logging, especially for state transitions. Defaults to True.
Source code in horde_sdk/worker/generations.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
from_template
classmethod
from_template(
template: SingleAlchemyParametersTemplate,
*,
source_image: bytes | str | None = None,
default_form: str | None = None,
generation_id: ID_TYPES | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
result_id: ID_TYPES | None = None,
allocator: ResultIdAllocator | None = None,
seed: str = "alchemy",
init_kwargs: AlchemyGenerationInitKwargs | None = None
) -> AlchemySingleGeneration
Instantiate an alchemy generation from a template.
Source code in horde_sdk/worker/generations.py
default_interrupt_states
classmethod
Get the default interrupt states.
register_callback
Register a callback to be called when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The state to register the callback for.
-
callback(Callable[[], None]) –The callback to call when the state is updated.
Source code in horde_sdk/worker/generations_base.py
set_dispatch_result_ids
Bind the generation to the result identifiers supplied by dispatch.
Source code in horde_sdk/worker/generations_base.py
get_generation_progress
get_progress_history
get_last_non_error_state
Get the last non-error state.
Source code in horde_sdk/worker/generations_base.py
get_last_non_error_state_and_time
Get the last non-error state and the time it was set.
Source code in horde_sdk/worker/generations_base.py
is_next_state_valid
Check if the next state is valid.
Source code in horde_sdk/worker/generations_base.py
on_error
on_error(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when an error occurs at any point in the generation process, safety checks, or submission.
This should be reserved for errors which make the current step impossible to complete. For example, if the a sub-process is OOM killed.
Contrast with the add_metadata_entry method, which is used for non-critical errors. If there is no
METADATA_TYPE for the error you encountered, you can use failed_message and failure_exception instead.
Parameters:
-
failed_message(str) –The reason the generation failed.
-
failure_exception(Exception, default:None) –The exception that caused the generation to fail. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ERROR.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_abort
on_abort(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when the generation is aborted.
Parameters:
-
failed_message(str) –The reason the generation was aborted.
-
failure_exception(Exception, default:None) –The exception that caused the generation to be aborted. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ABORTED.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_preloading
on_preloading_complete
on_generation_work_complete
on_generation_work_complete(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
| None
) = None,
) -> GENERATION_PROGRESS
Call when the generation work is complete, such as when inference is done.
This does not mean the generation is finalized, as calling this function means that safety checks and submission may still be pending. Examples of when this function would be called are when comfyui has just returned an image, interrogating an image has just completed or when a text backend has just generated text.
Source code in horde_sdk/worker/generations_base.py
on_generating
on_post_processing
on_post_processing_complete
on_pending_safety_check
Call when the generation is pending safety check.
set_work_result
set_work_result(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
),
) -> None
Set the result of the generation work.
Parameters:
-
result(Any) –The result of the generation work.
Source code in horde_sdk/worker/generations_base.py
on_complete
on_state
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
Source code in horde_sdk/worker/generations_base.py
step
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
is_safety_checking_done_on_all_batch
Check if the safety check is being done on a one-on-all basis.
Returns:
-
bool(bool) –True if the safety check is being done on a one-on-all basis, False otherwise.
Source code in horde_sdk/worker/generations_base.py
get_safety_check_results
Get the results of the safety checks.
Returns:
-
list[SafetyResult | None]–list[SafetyResult | None]: The results of the safety checks for each batch.
Source code in horde_sdk/worker/generations_base.py
on_safety_checking
on_safety_check_complete
Call when the safety check is complete.
Parameters:
-
batch_index(int) –The index of the batch to set the safety check result for. This is 0-indexed and must match the position of the result_ids provided during initialization.
-
safety_result(SafetyResult) –The result of the safety check.
Source code in horde_sdk/worker/generations_base.py
on_pending_submit
on_submitting
Call when an attempt is going to be made to submit the generation.
on_submit_complete
Call when the generation has been successfully submitted.
on_user_requested_abort
Call when the user requests to abort the generation.
on_user_abort_complete
TextSingleGeneration
Bases: HordeSingleGeneration[str]
A single text generation.
Not to be confused with a job, which can contain multiple generations.
Source code in horde_sdk/worker/generations.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
generation_parameters
instance-attribute
The parameters for the generation.
result_type
property
The type of the result of the generation.
result_ids
property
The unique identifiers for the generations in the batch.
dispatch_result_ids
property
Identifiers supplied by the dispatch source, if any.
generation_failure_count
property
The number of times the generation has failed during any step of the generation process.
errored_states
property
Return a tuple of states which occurred just before an error state and the time they were set.
error_counts
property
Return a dictionary of states and the number of times they occurred before an error state.
requires_post_processing
property
Whether or not the generation requires post-processing.
requires_generation
property
Whether or not the generation requires generation.
requires_safety_check
property
Whether or not the generation requires a safety check.
generation_results
property
Get the result of the generation.
default_generate_progress_transitions
classmethod
default_generate_progress_transitions_no_submit
classmethod
does_class_require_generation
classmethod
does_class_require_safety_check
classmethod
__init__
__init__(
*,
generation_parameters: TextGenerationParameters,
generation_id: ID_TYPES | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
result_ids: list[ID_TYPES] | None = None,
requires_generation: bool = True,
requires_post_processing: bool = False,
requires_safety_check: bool = False,
requires_submit: bool = True,
safety_rules: SafetyRules = default_text_safety_rules,
black_box_mode: bool = False,
state_error_limits: (
Mapping[GENERATION_PROGRESS, int] | None
) = HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS,
strict_transition_mode: bool = HordeWorkerConfigDefaults.DEFAULT_GENERATION_STRICT_TRANSITION_MODE,
extra_logging: bool = False
) -> None
Initialize the generation.
Parameters:
-
generation_parameters(TextGenerationParameters) –The parameters for the generation.
-
generation_id(str | None, default:None) –The unique identifier for the generation. If None, a random UUID will be generated.
-
dispatch_result_ids(Sequence[str | UUID] | None, default:None) –Result identifiers assigned by dispatch, if available.
-
result_ids(list[ID_TYPES] | None, default:None) –The unique identifiers for the generation. If None, a random UUID will be generated for each result.
-
requires_generation(bool, default:True) –Whether the generation requires generation. Defaults to True.
-
requires_post_processing(bool, default:False) –Whether the generation requires post-processing. Defaults to False.
-
requires_safety_check(bool, default:False) –Whether the generation requires a safety check. Defaults to False.
-
requires_submit(bool, default:True) –Whether the generation requires submission. Defaults to True.
-
safety_rules(SafetyRules, default:default_text_safety_rules) –The safety rules to apply to the generation. Defaults to default_text_safety_rules from
horde_sdk.safety. -
black_box_mode(bool, default:False) –Whether the generation is in black box mode. This removes all of the intermediate states between starting and finished states. This should only be used when the backend has no observability into the generation process. Defaults to False.
-
state_error_limits(Mapping[GENERATION_PROGRESS, int], default:DEFAULT_STATE_ERROR_LIMITS) –The maximum number of times a generation can be in an error state before it is considered failed. Defaults to HordeWorkerConfigDefaults.DEFAULT_STATE_ERROR_LIMITS.
-
strict_transition_mode(bool, default:DEFAULT_GENERATION_STRICT_TRANSITION_MODE) –Whether or not to enforce strict transition checking. This prevents setting the same state multiple times in a row. Defaults to True.
-
extra_logging(bool, default:False) –Whether or not to enable extra debug-level logging, especially for state transitions. Defaults to True.
Source code in horde_sdk/worker/generations.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
from_template
classmethod
from_template(
template: TextGenerationParametersTemplate,
*,
generation_id: ID_TYPES | None = None,
dispatch_result_ids: Sequence[ID_TYPES] | None = None,
base_param_updates: (
BasicTextGenerationParametersTemplate | None
) = None,
result_ids: Sequence[ID_TYPES] | None = None,
allocator: ResultIdAllocator | None = None,
seed: str = "text",
init_kwargs: TextGenerationInitKwargs | None = None
) -> TextSingleGeneration
Instantiate a text generation from a template.
Source code in horde_sdk/worker/generations.py
default_interrupt_states
classmethod
Get the default interrupt states.
register_callback
Register a callback to be called when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The state to register the callback for.
-
callback(Callable[[], None]) –The callback to call when the state is updated.
Source code in horde_sdk/worker/generations_base.py
set_dispatch_result_ids
Bind the generation to the result identifiers supplied by dispatch.
Source code in horde_sdk/worker/generations_base.py
get_generation_progress
get_progress_history
get_last_non_error_state
Get the last non-error state.
Source code in horde_sdk/worker/generations_base.py
get_last_non_error_state_and_time
Get the last non-error state and the time it was set.
Source code in horde_sdk/worker/generations_base.py
is_next_state_valid
Check if the next state is valid.
Source code in horde_sdk/worker/generations_base.py
on_error
on_error(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when an error occurs at any point in the generation process, safety checks, or submission.
This should be reserved for errors which make the current step impossible to complete. For example, if the a sub-process is OOM killed.
Contrast with the add_metadata_entry method, which is used for non-critical errors. If there is no
METADATA_TYPE for the error you encountered, you can use failed_message and failure_exception instead.
Parameters:
-
failed_message(str) –The reason the generation failed.
-
failure_exception(Exception, default:None) –The exception that caused the generation to fail. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ERROR.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_abort
on_abort(
*,
failed_message: str,
failure_exception: Exception | None = None
) -> GENERATION_PROGRESS
Call when the generation is aborted.
Parameters:
-
failed_message(str) –The reason the generation was aborted.
-
failure_exception(Exception, default:None) –The exception that caused the generation to be aborted. Defaults to None.
Returns:
-
GENERATION_PROGRESS(GENERATION_PROGRESS) –The new state of the generation, which will be set to
GENERATION_PROGRESS.ABORTED.
Raises:
-
RuntimeError–If the generation has exceeded the maximum number of errors for the current state.
-
RuntimeError–If the generation is in an error state and has no previous state to transition from.
Source code in horde_sdk/worker/generations_base.py
on_preloading
on_preloading_complete
on_generation_work_complete
on_generation_work_complete(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
| None
) = None,
) -> GENERATION_PROGRESS
Call when the generation work is complete, such as when inference is done.
This does not mean the generation is finalized, as calling this function means that safety checks and submission may still be pending. Examples of when this function would be called are when comfyui has just returned an image, interrogating an image has just completed or when a text backend has just generated text.
Source code in horde_sdk/worker/generations_base.py
on_generating
on_post_processing
on_post_processing_complete
on_pending_safety_check
Call when the generation is pending safety check.
set_work_result
set_work_result(
result: (
GenerationResultTypeVar
| Collection[GenerationResultTypeVar]
),
) -> None
Set the result of the generation work.
Parameters:
-
result(Any) –The result of the generation work.
Source code in horde_sdk/worker/generations_base.py
on_complete
on_state
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
Source code in horde_sdk/worker/generations_base.py
step
Call when the generation state is updated.
Parameters:
-
state(GENERATION_PROGRESS) –The new state of the generation.
is_safety_checking_done_on_all_batch
Check if the safety check is being done on a one-on-all basis.
Returns:
-
bool(bool) –True if the safety check is being done on a one-on-all basis, False otherwise.
Source code in horde_sdk/worker/generations_base.py
get_safety_check_results
Get the results of the safety checks.
Returns:
-
list[SafetyResult | None]–list[SafetyResult | None]: The results of the safety checks for each batch.
Source code in horde_sdk/worker/generations_base.py
on_safety_checking
on_safety_check_complete
Call when the safety check is complete.
Parameters:
-
batch_index(int) –The index of the batch to set the safety check result for. This is 0-indexed and must match the position of the result_ids provided during initialization.
-
safety_result(SafetyResult) –The result of the safety check.
Source code in horde_sdk/worker/generations_base.py
on_pending_submit
on_submitting
Call when an attempt is going to be made to submit the generation.
on_submit_complete
Call when the generation has been successfully submitted.
on_user_requested_abort
Call when the user requests to abort the generation.