Skip to content

consts

initial_generation_state module-attribute

initial_generation_state = NOT_STARTED

base_generate_progress_transitions module-attribute

base_generate_progress_transitions: dict[
    GENERATION_PROGRESS, list[GENERATION_PROGRESS]
] = {
    NOT_STARTED: [
        PRELOADING,
        GENERATING,
        PENDING_POST_PROCESSING,
        POST_PROCESSING,
        ERROR,
    ],
    PRELOADING: [PRELOADING_COMPLETE, ERROR],
    PRELOADING_COMPLETE: [
        GENERATING,
        PENDING_POST_PROCESSING,
        POST_PROCESSING,
        ERROR,
    ],
    GENERATING: [
        PENDING_POST_PROCESSING,
        POST_PROCESSING,
        PENDING_SAFETY_CHECK,
        SAFETY_CHECKING,
        ERROR,
    ],
    PENDING_POST_PROCESSING: [POST_PROCESSING, ERROR],
    POST_PROCESSING: [
        PENDING_SAFETY_CHECK,
        SAFETY_CHECKING,
        ERROR,
    ],
    PENDING_SAFETY_CHECK: [SAFETY_CHECKING, ERROR],
    SAFETY_CHECKING: [PENDING_SUBMIT, ERROR],
    PENDING_SUBMIT: [SUBMITTING, ERROR],
    SUBMITTING: [SUBMIT_COMPLETE, ERROR],
    SUBMIT_COMPLETE: [COMPLETE],
    COMPLETE: [],
    ABORTED: [REPORTED_FAILED, ERROR],
    REPORTED_FAILED: [],
    ERROR: [ABORTED],
    USER_REQUESTED_ABORT: [USER_ABORT_COMPLETE],
    USER_ABORT_COMPLETE: [],
    ABANDONED: [],
}

A map of the typical transitions between generation states.

black_box_generate_progress_transitions module-attribute

black_box_generate_progress_transitions: dict[
    GENERATION_PROGRESS, list[GENERATION_PROGRESS]
] = {
    NOT_STARTED: [GENERATING, ERROR],
    GENERATING: [
        PENDING_SUBMIT,
        PENDING_SAFETY_CHECK,
        COMPLETE,
        ERROR,
    ],
    PENDING_SAFETY_CHECK: [SAFETY_CHECKING, ERROR],
    SAFETY_CHECKING: [PENDING_SUBMIT, COMPLETE, ERROR],
    PENDING_SUBMIT: [SUBMITTING, ERROR],
    SUBMITTING: [SUBMIT_COMPLETE, COMPLETE, ERROR],
    SUBMIT_COMPLETE: [COMPLETE],
    COMPLETE: [],
    ABORTED: [REPORTED_FAILED, ERROR],
    REPORTED_FAILED: [],
    ERROR: [ABORTED],
    USER_REQUESTED_ABORT: [USER_ABORT_COMPLETE, ABANDONED],
    USER_ABORT_COMPLETE: [],
    ABANDONED: [],
}

base_generate_progress_no_submit_transitions module-attribute

base_generate_progress_no_submit_transitions = (
    generate_transitions(
        base_generate_progress_transitions, skip_submit=True
    )
)

default_image_generate_progress_transitions module-attribute

default_image_generate_progress_transitions = (
    generate_transitions(base_generate_progress_transitions)
)

default_image_generate_progress_no_submit_transitions module-attribute

default_image_generate_progress_no_submit_transitions = (
    generate_transitions(
        base_generate_progress_transitions, skip_submit=True
    )
)

default_alchemy_generate_progress_transitions module-attribute

default_alchemy_generate_progress_transitions = (
    generate_transitions(
        base_generate_progress_transitions,
        can_skip_safety_checks=True,
    )
)

default_alchemy_generate_progress_no_submit_transitions module-attribute

default_alchemy_generate_progress_no_submit_transitions = (
    generate_transitions(
        base_generate_progress_transitions,
        skip_submit=True,
        can_skip_safety_checks=True,
    )
)

default_text_generate_progress_transitions module-attribute

default_text_generate_progress_transitions = (
    generate_transitions(
        base_generate_progress_transitions,
        can_skip_safety_checks=True,
    )
)

default_text_generate_progress_no_submit_transitions module-attribute

default_text_generate_progress_no_submit_transitions = (
    generate_transitions(
        base_generate_progress_transitions,
        skip_submit=True,
        can_skip_safety_checks=True,
    )
)

finalized_generation_states module-attribute

finalized_generation_states = {
    SUBMIT_COMPLETE,
    REPORTED_FAILED,
    USER_ABORT_COMPLETE,
    ABANDONED,
}

WORKER_ERRORS

Bases: StrEnum

The reason a job faulted.

Source code in horde_sdk/worker/consts.py
class WORKER_ERRORS(StrEnum):
    """The reason a job faulted."""

    UNHANDLED_EXCEPTION = auto()
    """An error not otherwise specified occurred."""
    UNHANDLED_EXCEPTION_FROM_BACKEND = auto()
    """An error was caught originating from within the backend."""
    SYSTEM_OUT_OF_MEMORY = auto()
    """The system ran out of memory."""
    GPU_OUT_OF_MEMORY = auto()
    """The GPU ran out of memory."""
    NETWORK_ISSUE = auto()
    """There was a network issue, such as a timeout or a connection error."""
    SAFEGUARD_TIMEOUT = auto()
    """A reasonable time limit was exceeded, such as a model taking too long to load or generate."""

UNHANDLED_EXCEPTION class-attribute instance-attribute

UNHANDLED_EXCEPTION = auto()

An error not otherwise specified occurred.

UNHANDLED_EXCEPTION_FROM_BACKEND class-attribute instance-attribute

UNHANDLED_EXCEPTION_FROM_BACKEND = auto()

An error was caught originating from within the backend.

SYSTEM_OUT_OF_MEMORY class-attribute instance-attribute

SYSTEM_OUT_OF_MEMORY = auto()

The system ran out of memory.

GPU_OUT_OF_MEMORY class-attribute instance-attribute

GPU_OUT_OF_MEMORY = auto()

The GPU ran out of memory.

NETWORK_ISSUE class-attribute instance-attribute

NETWORK_ISSUE = auto()

There was a network issue, such as a timeout or a connection error.

SAFEGUARD_TIMEOUT class-attribute instance-attribute

SAFEGUARD_TIMEOUT = auto()

A reasonable time limit was exceeded, such as a model taking too long to load or generate.

GENERATION_PROGRESS

Bases: StrEnum

The state of a generation.

Source code in horde_sdk/worker/consts.py
class GENERATION_PROGRESS(StrEnum):
    """The state of a generation."""

    NOT_STARTED = auto()
    """The generation has not started."""
    ERROR = auto()
    """An error occurred during generation. The most recent step will be retried up to a certain number of times."""
    PRELOADING = auto()
    """The generation is preloading any models to RAM/VRAM. Preloading is skipped if the models are already loaded."""
    PRELOADING_COMPLETE = auto()
    """The generation has completed preloading."""
    GENERATING = auto()
    """The generation is in progress. This will also preload if that step did not yet occur."""
    GENERATION_COMPLETE = auto()
    """The generation has completed generating the data, but may still need post-processing or safety checks."""
    PENDING_POST_PROCESSING = auto()
    """The generation has completed and is pending post-processing."""
    POST_PROCESSING = auto()
    """The generation is post-processing the generated data."""
    POST_PROCESSING_COMPLETE = auto()
    """The generation has completed post-processing and is pending safety check."""
    PENDING_SAFETY_CHECK = auto()
    """The generation was created and is pending safety check."""
    SAFETY_CHECKING = auto()
    """The generation is being safety checked."""
    SAFETY_CHECK_COMPLETE = auto()
    """The generation has completed safety check and is pending submission."""
    PENDING_SUBMIT = auto()
    """The generation has completed safety check and is pending submission."""
    SUBMITTING = auto()
    """The generation is pending submission."""
    SUBMIT_COMPLETE = auto()
    """The generation has been successfully submitted."""
    COMPLETE = auto()
    """The generation is completely finished and no further steps are required."""
    ABORTED = auto()
    """The generation has failed because one or more steps failed too many times. An attempt to notify the API will
    be made."""
    REPORTED_FAILED = auto()
    """The generation has been reported as failed to the API."""
    USER_REQUESTED_ABORT = auto()
    """The generation was aborted by the submitting user's request."""
    USER_ABORT_COMPLETE = auto()
    """The generation was aborted (by user's request) and the API has been notified accordingly."""
    ABANDONED = auto()
    """The generation failed and the API could not be notified. It has simply been discarded.

    Note that this can lead to a worker being put into maintenance mode if too many generations are abandoned
    within a certain time frame.
    """

    @staticmethod
    def is_state_complete(progress: GENERATION_PROGRESS) -> bool:
        """Check if the generation is complete."""
        return progress in {
            GENERATION_PROGRESS.COMPLETE,
            GENERATION_PROGRESS.ABORTED,
            GENERATION_PROGRESS.REPORTED_FAILED,
            GENERATION_PROGRESS.USER_ABORT_COMPLETE,
            GENERATION_PROGRESS.ABANDONED,
        }

    @staticmethod
    def is_state_failing(progress: GENERATION_PROGRESS) -> bool:
        """Check if the generation is failing."""
        return progress in {
            GENERATION_PROGRESS.ERROR,
            GENERATION_PROGRESS.ABORTED,
            GENERATION_PROGRESS.REPORTED_FAILED,
            GENERATION_PROGRESS.USER_REQUESTED_ABORT,
            GENERATION_PROGRESS.ABANDONED,
        }

    @staticmethod
    def is_state_pending(progress: GENERATION_PROGRESS) -> bool:
        """Check if the generation is pending."""
        return progress in {
            GENERATION_PROGRESS.NOT_STARTED,
            GENERATION_PROGRESS.PRELOADING_COMPLETE,
            GENERATION_PROGRESS.PENDING_POST_PROCESSING,
            GENERATION_PROGRESS.PENDING_SAFETY_CHECK,
            GENERATION_PROGRESS.PENDING_SUBMIT,
        }

NOT_STARTED class-attribute instance-attribute

NOT_STARTED = auto()

The generation has not started.

ERROR class-attribute instance-attribute

ERROR = auto()

An error occurred during generation. The most recent step will be retried up to a certain number of times.

PRELOADING class-attribute instance-attribute

PRELOADING = auto()

The generation is preloading any models to RAM/VRAM. Preloading is skipped if the models are already loaded.

PRELOADING_COMPLETE class-attribute instance-attribute

PRELOADING_COMPLETE = auto()

The generation has completed preloading.

GENERATING class-attribute instance-attribute

GENERATING = auto()

The generation is in progress. This will also preload if that step did not yet occur.

GENERATION_COMPLETE class-attribute instance-attribute

GENERATION_COMPLETE = auto()

The generation has completed generating the data, but may still need post-processing or safety checks.

PENDING_POST_PROCESSING class-attribute instance-attribute

PENDING_POST_PROCESSING = auto()

The generation has completed and is pending post-processing.

POST_PROCESSING class-attribute instance-attribute

POST_PROCESSING = auto()

The generation is post-processing the generated data.

POST_PROCESSING_COMPLETE class-attribute instance-attribute

POST_PROCESSING_COMPLETE = auto()

The generation has completed post-processing and is pending safety check.

PENDING_SAFETY_CHECK class-attribute instance-attribute

PENDING_SAFETY_CHECK = auto()

The generation was created and is pending safety check.

SAFETY_CHECKING class-attribute instance-attribute

SAFETY_CHECKING = auto()

The generation is being safety checked.

SAFETY_CHECK_COMPLETE class-attribute instance-attribute

SAFETY_CHECK_COMPLETE = auto()

The generation has completed safety check and is pending submission.

PENDING_SUBMIT class-attribute instance-attribute

PENDING_SUBMIT = auto()

The generation has completed safety check and is pending submission.

SUBMITTING class-attribute instance-attribute

SUBMITTING = auto()

The generation is pending submission.

SUBMIT_COMPLETE class-attribute instance-attribute

SUBMIT_COMPLETE = auto()

The generation has been successfully submitted.

COMPLETE class-attribute instance-attribute

COMPLETE = auto()

The generation is completely finished and no further steps are required.

ABORTED class-attribute instance-attribute

ABORTED = auto()

The generation has failed because one or more steps failed too many times. An attempt to notify the API will be made.

REPORTED_FAILED class-attribute instance-attribute

REPORTED_FAILED = auto()

The generation has been reported as failed to the API.

USER_REQUESTED_ABORT class-attribute instance-attribute

USER_REQUESTED_ABORT = auto()

The generation was aborted by the submitting user's request.

USER_ABORT_COMPLETE class-attribute instance-attribute

USER_ABORT_COMPLETE = auto()

The generation was aborted (by user's request) and the API has been notified accordingly.

ABANDONED class-attribute instance-attribute

ABANDONED = auto()

The generation failed and the API could not be notified. It has simply been discarded.

Note that this can lead to a worker being put into maintenance mode if too many generations are abandoned within a certain time frame.

is_state_complete staticmethod

is_state_complete(progress: GENERATION_PROGRESS) -> bool

Check if the generation is complete.

Source code in horde_sdk/worker/consts.py
@staticmethod
def is_state_complete(progress: GENERATION_PROGRESS) -> bool:
    """Check if the generation is complete."""
    return progress in {
        GENERATION_PROGRESS.COMPLETE,
        GENERATION_PROGRESS.ABORTED,
        GENERATION_PROGRESS.REPORTED_FAILED,
        GENERATION_PROGRESS.USER_ABORT_COMPLETE,
        GENERATION_PROGRESS.ABANDONED,
    }

is_state_failing staticmethod

is_state_failing(progress: GENERATION_PROGRESS) -> bool

Check if the generation is failing.

Source code in horde_sdk/worker/consts.py
@staticmethod
def is_state_failing(progress: GENERATION_PROGRESS) -> bool:
    """Check if the generation is failing."""
    return progress in {
        GENERATION_PROGRESS.ERROR,
        GENERATION_PROGRESS.ABORTED,
        GENERATION_PROGRESS.REPORTED_FAILED,
        GENERATION_PROGRESS.USER_REQUESTED_ABORT,
        GENERATION_PROGRESS.ABANDONED,
    }

is_state_pending staticmethod

is_state_pending(progress: GENERATION_PROGRESS) -> bool

Check if the generation is pending.

Source code in horde_sdk/worker/consts.py
@staticmethod
def is_state_pending(progress: GENERATION_PROGRESS) -> bool:
    """Check if the generation is pending."""
    return progress in {
        GENERATION_PROGRESS.NOT_STARTED,
        GENERATION_PROGRESS.PRELOADING_COMPLETE,
        GENERATION_PROGRESS.PENDING_POST_PROCESSING,
        GENERATION_PROGRESS.PENDING_SAFETY_CHECK,
        GENERATION_PROGRESS.PENDING_SUBMIT,
    }

JobState

Bases: StrEnum

The state of a job.

Source code in horde_sdk/worker/consts.py
class JobState(StrEnum):
    """The state of a job."""

    QUEUED = auto()
    """The job has been received and is waiting to be processed."""
    PREPARING = auto()
    """The job is being prepared for processing."""
    GENERATING = auto()
    """The job is in the process of generating."""
    PENDING_SAFETY_CHECK = auto()
    """The job was generated and is pending safety check."""
    PENDING_SUBMIT = auto()
    """The job is pending submission."""
    WAITING_ON_NETWORK = auto()
    """The job is waiting on network IO."""
    SUCCESSFULLY_COMPLETED = auto()
    """The job finished successfully."""
    FAULTED = auto()
    """The job faulted. Faulted jobs are ones which failed catastrophically and will not be retried.

    Note: This is different from a generation faulting, which can be submitted as a faulted generation.
    """

QUEUED class-attribute instance-attribute

QUEUED = auto()

The job has been received and is waiting to be processed.

PREPARING class-attribute instance-attribute

PREPARING = auto()

The job is being prepared for processing.

GENERATING class-attribute instance-attribute

GENERATING = auto()

The job is in the process of generating.

PENDING_SAFETY_CHECK class-attribute instance-attribute

PENDING_SAFETY_CHECK = auto()

The job was generated and is pending safety check.

PENDING_SUBMIT class-attribute instance-attribute

PENDING_SUBMIT = auto()

The job is pending submission.

WAITING_ON_NETWORK class-attribute instance-attribute

WAITING_ON_NETWORK = auto()

The job is waiting on network IO.

SUCCESSFULLY_COMPLETED class-attribute instance-attribute

SUCCESSFULLY_COMPLETED = auto()

The job finished successfully.

FAULTED class-attribute instance-attribute

FAULTED = auto()

The job faulted. Faulted jobs are ones which failed catastrophically and will not be retried.

Note: This is different from a generation faulting, which can be submitted as a faulted generation.

HordeWorkerConfigDefaults

Default values for HordeWorkerJobConfig.

Source code in horde_sdk/worker/consts.py
class HordeWorkerConfigDefaults:
    """Default values for HordeWorkerJobConfig."""

    DEFAULT_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS: int = 3
    """The default maximum number of consecutive times a job can fail to submit to the API before it is marked as
    faulted. This is used to prevent a job from being retried indefinitely and to prevent a job from being submitted
    well after it would have likely have been marked stale by the API.

    Jobs which are faulted are *abandoned* and no further attempts are made to submit any generations in the job nor to
    notify the API that the job failed.
    """

    DEFAULT_JOB_SUBMIT_RETRY_DELAY: float = 2.0
    """The default delay in seconds between retries to submit a job to the API after submit issues."""

    UNREASONABLE_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS: int = 10
    """The highest number of consecutive failed job submits allowed in any configuration.

    This is used internally to the sdk as a final safeguard to prevent mistakes in configuration.
    """

    DEFAULT_MAX_GENERATION_FAILURES: int = 3
    """The default maximum number of times a generation can fail before it is abandoned.

    **Note:** *Generations* which fail are reported to the API as failed, but the job itself is not
    necessarily *faulted*. If notifying the API of a failed generation fails the number of times specified by
    `max_consecutive_failed_job_submits`, then the job is marked as faulted and is abandoned.
    """

    UNREASONABLE_MAX_GENERATION_FAILURES: int = 10
    """The highest number of generation failures allowed in any configuration.

    This is used internally to the sdk as a final safeguard to prevent mistakes in configuration.
    """

    DEFAULT_STATE_ERROR_LIMITS: ClassVar[dict[GENERATION_PROGRESS, int]] = {
        GENERATION_PROGRESS.PRELOADING: 3,
        GENERATION_PROGRESS.GENERATING: 3,
        GENERATION_PROGRESS.POST_PROCESSING: 3,
        GENERATION_PROGRESS.SAFETY_CHECKING: 3,
        GENERATION_PROGRESS.SUBMITTING: 10,
        GENERATION_PROGRESS.USER_REQUESTED_ABORT: 10,
    }

    DEFAULT_UPLOAD_TIMEOUT: float = 10.0
    DEFAULT_MAX_RETRIES: int = 10
    DEFAULT_RETRY_DELAY: float = 1.0

    DEFAULT_RESULT_IMAGE_FORMAT: str = "WebP"
    DEFAULT_RESULT_IMAGE_QUALITY: int = 95
    DEFAULT_RESULT_IMAGE_PIL_METHOD: int = 6

    DEFAULT_GENERATION_STRICT_TRANSITION_MODE: bool = True

DEFAULT_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS class-attribute instance-attribute

DEFAULT_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS: int = 3

The default maximum number of consecutive times a job can fail to submit to the API before it is marked as faulted. This is used to prevent a job from being retried indefinitely and to prevent a job from being submitted well after it would have likely have been marked stale by the API.

Jobs which are faulted are abandoned and no further attempts are made to submit any generations in the job nor to notify the API that the job failed.

DEFAULT_JOB_SUBMIT_RETRY_DELAY class-attribute instance-attribute

DEFAULT_JOB_SUBMIT_RETRY_DELAY: float = 2.0

The default delay in seconds between retries to submit a job to the API after submit issues.

UNREASONABLE_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS class-attribute instance-attribute

UNREASONABLE_MAX_CONSECUTIVE_FAILED_JOB_SUBMITS: int = 10

The highest number of consecutive failed job submits allowed in any configuration.

This is used internally to the sdk as a final safeguard to prevent mistakes in configuration.

DEFAULT_MAX_GENERATION_FAILURES class-attribute instance-attribute

DEFAULT_MAX_GENERATION_FAILURES: int = 3

The default maximum number of times a generation can fail before it is abandoned.

Note: Generations which fail are reported to the API as failed, but the job itself is not necessarily faulted. If notifying the API of a failed generation fails the number of times specified by max_consecutive_failed_job_submits, then the job is marked as faulted and is abandoned.

UNREASONABLE_MAX_GENERATION_FAILURES class-attribute instance-attribute

UNREASONABLE_MAX_GENERATION_FAILURES: int = 10

The highest number of generation failures allowed in any configuration.

This is used internally to the sdk as a final safeguard to prevent mistakes in configuration.

DEFAULT_STATE_ERROR_LIMITS class-attribute

DEFAULT_STATE_ERROR_LIMITS: dict[
    GENERATION_PROGRESS, int
] = {
    PRELOADING: 3,
    GENERATING: 3,
    POST_PROCESSING: 3,
    SAFETY_CHECKING: 3,
    SUBMITTING: 10,
    USER_REQUESTED_ABORT: 10,
}

DEFAULT_UPLOAD_TIMEOUT class-attribute instance-attribute

DEFAULT_UPLOAD_TIMEOUT: float = 10.0

DEFAULT_MAX_RETRIES class-attribute instance-attribute

DEFAULT_MAX_RETRIES: int = 10

DEFAULT_RETRY_DELAY class-attribute instance-attribute

DEFAULT_RETRY_DELAY: float = 1.0

DEFAULT_RESULT_IMAGE_FORMAT class-attribute instance-attribute

DEFAULT_RESULT_IMAGE_FORMAT: str = 'WebP'

DEFAULT_RESULT_IMAGE_QUALITY class-attribute instance-attribute

DEFAULT_RESULT_IMAGE_QUALITY: int = 95

DEFAULT_RESULT_IMAGE_PIL_METHOD class-attribute instance-attribute

DEFAULT_RESULT_IMAGE_PIL_METHOD: int = 6

DEFAULT_GENERATION_STRICT_TRANSITION_MODE class-attribute instance-attribute

DEFAULT_GENERATION_STRICT_TRANSITION_MODE: bool = True

REQUESTED_BACKEND_CONSTRAINTS

Bases: StrEnum

What constraints on backends to use were requested by the user/server.

Source code in horde_sdk/worker/consts.py
class REQUESTED_BACKEND_CONSTRAINTS(StrEnum):
    """What constraints on backends to use were requested by the user/server."""

    ANY = auto()
    """Any backend is acceptable."""

    SPECIFIED = auto()
    """Only the specified backend is acceptable."""

    DEFAULT_IMAGE = auto()
    """Only the default image backend is acceptable."""

    DEFAULT_TEXT = auto()
    """Only the default text backend is acceptable."""

    DEFAULT_AUDIO = auto()
    """Only the default audio backend is acceptable."""

    DEFAULT_VIDEO = auto()
    """Only the default video backend is acceptable."""

    DEFAULT_ALCHEMY = auto()
    """Only the default alchemy backend is acceptable."""

    NO_CUSTOM = auto()
    """Only official backends are acceptable."""

    ONLY_CUSTOM = auto()
    """Only custom backends are acceptable."""

ANY class-attribute instance-attribute

ANY = auto()

Any backend is acceptable.

SPECIFIED class-attribute instance-attribute

SPECIFIED = auto()

Only the specified backend is acceptable.

DEFAULT_IMAGE class-attribute instance-attribute

DEFAULT_IMAGE = auto()

Only the default image backend is acceptable.

DEFAULT_TEXT class-attribute instance-attribute

DEFAULT_TEXT = auto()

Only the default text backend is acceptable.

DEFAULT_AUDIO class-attribute instance-attribute

DEFAULT_AUDIO = auto()

Only the default audio backend is acceptable.

DEFAULT_VIDEO class-attribute instance-attribute

DEFAULT_VIDEO = auto()

Only the default video backend is acceptable.

DEFAULT_ALCHEMY class-attribute instance-attribute

DEFAULT_ALCHEMY = auto()

Only the default alchemy backend is acceptable.

NO_CUSTOM class-attribute instance-attribute

NO_CUSTOM = auto()

Only official backends are acceptable.

ONLY_CUSTOM class-attribute instance-attribute

ONLY_CUSTOM = auto()

Only custom backends are acceptable.

REQUESTED_SOURCE_IMAGE_FALLBACK_CHOICE

Bases: StrEnum

The choice for what to do when a requested source image couldn't be parsed or is otherwise unusable.

Source code in horde_sdk/worker/consts.py
class REQUESTED_SOURCE_IMAGE_FALLBACK_CHOICE(StrEnum):
    """The choice for what to do when a requested source image couldn't be parsed or is otherwise unusable."""

    TXT2IMG_FALLBACK = auto()
    """Use txt2img instead if the source image is unusable."""

    ABANDON = auto()
    """Abandon the generation if the source image is unusable."""

    USE_WHITE_IMAGE = auto()
    """Use a white image if the source image is unusable."""

    USE_BLACK_IMAGE = auto()
    """Use a black image if the source image is unusable."""

    USE_NOISE_IMAGE = auto()
    """Use a noise image if the source image is unusable."""

TXT2IMG_FALLBACK class-attribute instance-attribute

TXT2IMG_FALLBACK = auto()

Use txt2img instead if the source image is unusable.

ABANDON class-attribute instance-attribute

ABANDON = auto()

Abandon the generation if the source image is unusable.

USE_WHITE_IMAGE class-attribute instance-attribute

USE_WHITE_IMAGE = auto()

Use a white image if the source image is unusable.

USE_BLACK_IMAGE class-attribute instance-attribute

USE_BLACK_IMAGE = auto()

Use a black image if the source image is unusable.

USE_NOISE_IMAGE class-attribute instance-attribute

USE_NOISE_IMAGE = auto()

Use a noise image if the source image is unusable.

CHAIN_EDGE_KIND

Bases: StrEnum

The known chain edges.

Source code in horde_sdk/worker/consts.py
class CHAIN_EDGE_KIND(StrEnum):
    """The known chain edges."""

    CUSTOM = auto()
    """A custom chain edge."""

    RESULTING_IMAGE_AS_SOURCE = auto()
    """The resulting image of the previous generation is used as the source for the next generation."""

    RESULTING_TEXT_AS_PROMPT = auto()
    """The resulting text of the previous generation is used as the prompt for the next generation."""

    RESULTING_IMAGE_AS_MASK = auto()
    """The resulting image of the previous generation is used as the mask for the next generation."""

    RESULTING_IMAGE_AS_CONTROL_MAP = auto()
    """The resulting image of the previous generation is used as the control map for the next generation."""

    IMAGE_TO_ALCHEMY_UPSCALE = auto()
    """The resulting image from image generation is used as the source for alchemy upscaling."""

    IMAGE_TO_ALCHEMY_FACEFIX = auto()
    """The resulting image from image generation is used as the source for alchemy face fixing."""

    ALCHEMY_TO_ALCHEMY = auto()
    """The resulting image from one alchemy operation is used as the source for another alchemy operation."""

    TEXT_TO_IMAGE_PROMPT = auto()
    """The resulting text from text generation is used as the prompt for image generation."""

CUSTOM class-attribute instance-attribute

CUSTOM = auto()

A custom chain edge.

RESULTING_IMAGE_AS_SOURCE class-attribute instance-attribute

RESULTING_IMAGE_AS_SOURCE = auto()

The resulting image of the previous generation is used as the source for the next generation.

RESULTING_TEXT_AS_PROMPT class-attribute instance-attribute

RESULTING_TEXT_AS_PROMPT = auto()

The resulting text of the previous generation is used as the prompt for the next generation.

RESULTING_IMAGE_AS_MASK class-attribute instance-attribute

RESULTING_IMAGE_AS_MASK = auto()

The resulting image of the previous generation is used as the mask for the next generation.

RESULTING_IMAGE_AS_CONTROL_MAP class-attribute instance-attribute

RESULTING_IMAGE_AS_CONTROL_MAP = auto()

The resulting image of the previous generation is used as the control map for the next generation.

IMAGE_TO_ALCHEMY_UPSCALE class-attribute instance-attribute

IMAGE_TO_ALCHEMY_UPSCALE = auto()

The resulting image from image generation is used as the source for alchemy upscaling.

IMAGE_TO_ALCHEMY_FACEFIX class-attribute instance-attribute

IMAGE_TO_ALCHEMY_FACEFIX = auto()

The resulting image from image generation is used as the source for alchemy face fixing.

ALCHEMY_TO_ALCHEMY class-attribute instance-attribute

ALCHEMY_TO_ALCHEMY = auto()

The resulting image from one alchemy operation is used as the source for another alchemy operation.

TEXT_TO_IMAGE_PROMPT class-attribute instance-attribute

TEXT_TO_IMAGE_PROMPT = auto()

The resulting text from text generation is used as the prompt for image generation.

generate_transitions

generate_transitions(
    base_transitions: dict[
        GENERATION_PROGRESS, list[GENERATION_PROGRESS]
    ],
    skip_submit: bool = False,
    can_skip_safety_checks: bool = False,
    supports_safety_only: bool = False,
) -> dict[GENERATION_PROGRESS, list[GENERATION_PROGRESS]]

Generate transitions with optional modifications.

Parameters:

  • base_transitions (dict[GENERATION_PROGRESS, list[GENERATION_PROGRESS]]) –

    The base transitions to modify.

  • skip_submit (bool, default: False ) –

    Whether to skip submit transitions. Defaults to False.

  • can_skip_safety_checks (bool, default: False ) –

    Whether to skip safety check transitions can be skipped. Defaults to False.

  • supports_safety_only (bool, default: False ) –

    Whether to allow transition directly to safety check without going through generation or post-processing. Defaults to False.

Source code in horde_sdk/worker/consts.py
def generate_transitions(
    base_transitions: dict[GENERATION_PROGRESS, list[GENERATION_PROGRESS]],
    skip_submit: bool = False,
    can_skip_safety_checks: bool = False,
    supports_safety_only: bool = False,
) -> dict[GENERATION_PROGRESS, list[GENERATION_PROGRESS]]:
    """Generate transitions with optional modifications.

    Args:
        base_transitions (dict[GENERATION_PROGRESS, list[GENERATION_PROGRESS]]): The base transitions to modify.
        skip_submit (bool, optional): Whether to skip submit transitions. Defaults to False.
        can_skip_safety_checks (bool, optional): Whether to skip safety check transitions can be skipped.
            Defaults to False.
        supports_safety_only (bool, optional): Whether to allow transition directly to safety check
            without going through generation or post-processing. Defaults to False.
    """
    transitions = deepcopy(base_transitions)

    if can_skip_safety_checks:
        for state in [
            GENERATION_PROGRESS.GENERATING,
            GENERATION_PROGRESS.POST_PROCESSING,
        ]:
            transitions[state].append(
                GENERATION_PROGRESS.PENDING_SUBMIT,
            )

    if skip_submit:
        for state in [
            GENERATION_PROGRESS.PENDING_SUBMIT,
            GENERATION_PROGRESS.SUBMITTING,
            GENERATION_PROGRESS.SUBMIT_COMPLETE,
        ]:
            transitions.pop(state, None)

        for transition_values in transitions.values():
            for transition_value in transition_values:
                found_transition_to_remove = False
                if transition_value in [
                    GENERATION_PROGRESS.PENDING_SUBMIT,
                    GENERATION_PROGRESS.SUBMITTING,
                    GENERATION_PROGRESS.SUBMIT_COMPLETE,
                ]:
                    transition_values.remove(transition_value)
                    found_transition_to_remove = True

            if found_transition_to_remove:
                transition_values.append(
                    GENERATION_PROGRESS.COMPLETE,
                )
    if supports_safety_only:
        for state in [
            GENERATION_PROGRESS.NOT_STARTED,
            GENERATION_PROGRESS.PRELOADING_COMPLETE,
        ]:
            if state in transitions:
                transitions[state].append(GENERATION_PROGRESS.PENDING_SAFETY_CHECK)

    return transitions

validate_generation_progress_transitions

validate_generation_progress_transitions(
    progress_transitions: Mapping[
        GENERATION_PROGRESS, Iterable[GENERATION_PROGRESS]
    ],
) -> bool

Validate the generation progress transitions.

Parameters:

Returns:

  • bool ( bool ) –

    True if the transitions are valid, False otherwise.

Source code in horde_sdk/worker/consts.py
def validate_generation_progress_transitions(
    progress_transitions: Mapping[GENERATION_PROGRESS, Iterable[GENERATION_PROGRESS]],
) -> bool:
    """Validate the generation progress transitions.

    Args:
        progress_transitions (Mapping[GENERATION_PROGRESS, Iterable[GENERATION_PROGRESS]]):
            The transitions to validate

    Returns:
        bool: True if the transitions are valid, False otherwise.
    """
    parent_states: set[GENERATION_PROGRESS] = set(progress_transitions.keys())
    target_states: set[GENERATION_PROGRESS] = set()
    for transitions in progress_transitions.values():
        target_states.update(transitions)

    if not target_states.issubset(parent_states):
        logger.error(
            f"Invalid generation progress transitions: "
            f"target states {target_states - parent_states} are not in parent states {parent_states}",
        )
        return False

    if not all(isinstance(state, GENERATION_PROGRESS) for state in parent_states):
        logger.error(
            "Invalid generation progress transitions: not all parent states are instances of GENERATION_PROGRESS",
        )
        return False

    if not all(isinstance(state, GENERATION_PROGRESS) for state in target_states):
        logger.error(
            "Invalid generation progress transitions: not all target states are instances of GENERATION_PROGRESS",
        )
        return False

    return True