horde_sdk.generation_parameters.image.sampler_work¶
Typed sampler trajectory, accounting, and execution-ceiling semantics.
A trajectory step describes progress through a denoising schedule. A sampler work unit instead describes the marginal inference work of one ordinary first-order model evaluation at the same payload. Work units deliberately are not exact neural-function-evaluation counts or wall-clock time: fixed higher-order samplers have terminal-step special cases, and adaptive samplers choose their own iteration count.
The module keeps those meanings separate. Atomic guarantees describe individual backend behaviors; cumulative execution contracts give workers one discoverable conformance version to advertise.
Critical public members:
- Worker conformance is identified by
SamplerExecutionContractVersion. SAMPLER_WORK_PROFILESdefines marginal work for every sampler.maximum_sampler_workreturns a finite ceiling only when the advertised execution contract proves one.
__all__
module-attribute
¶
__all__ = [
"BOUNDED_DPM_ADAPTIVE_V1",
"LATEST_SAMPLER_EXECUTION_CONTRACT_VERSION",
"SAMPLER_EXECUTION_CONTRACTS",
"SAMPLER_WORK_PROFILES",
"AdaptiveSamplerExecutionPolicy",
"AdaptiveSamplerWorkProfile",
"FixedRateSamplerWorkProfile",
"SamplerExecutionContract",
"SamplerExecutionContractVersion",
"SamplerExecutionGuarantee",
"SamplerWorkCeiling",
"SamplerWorkEstimate",
"SamplerWorkEstimationPolicy",
"SamplerWorkProfile",
"SamplerWorkUnitCount",
"TrajectoryStepCount",
"estimate_sampler_work",
"get_sampler_execution_contract",
"get_sampler_work_profile",
"maximum_adaptive_solver_iterations",
"maximum_sampler_work",
"maximum_trajectory_steps_for_work_budget",
"minimum_common_sampler_execution_contract_version",
]
BOUNDED_DPM_ADAPTIVE_V1
module-attribute
¶
BOUNDED_DPM_ADAPTIVE_V1: Final[
AdaptiveSamplerExecutionPolicy
] = AdaptiveSamplerExecutionPolicy(
guarantee=SamplerExecutionGuarantee.BOUNDED_DPM_ADAPTIVE_V1,
sampler=KNOWN_IMAGE_SAMPLERS.k_dpm_adaptive,
iteration_multiplier_numerator=5,
iteration_multiplier_denominator=4,
)
The canonical finite execution policy for DPM adaptive.
SAMPLER_EXECUTION_CONTRACTS
module-attribute
¶
SAMPLER_EXECUTION_CONTRACTS: Mapping[
SamplerExecutionContractVersion,
SamplerExecutionContract,
] = MappingProxyType(
{
SamplerExecutionContractVersion.V1: SamplerExecutionContract(
version=SamplerExecutionContractVersion.V1,
guarantees=frozenset(
{
SamplerExecutionGuarantee.BOUNDED_DPM_ADAPTIVE_V1
}
),
)
}
)
All SDK-defined sampler execution contracts, ordered by their cumulative version.
LATEST_SAMPLER_EXECUTION_CONTRACT_VERSION
module-attribute
¶
LATEST_SAMPLER_EXECUTION_CONTRACT_VERSION: Final[
SamplerExecutionContractVersion
] = SamplerExecutionContractVersion.V1
The most recent sampler execution contract defined by this SDK release.
SAMPLER_WORK_PROFILES
module-attribute
¶
SAMPLER_WORK_PROFILES: Mapping[
KNOWN_IMAGE_SAMPLERS, SamplerWorkProfile
] = MappingProxyType(
{
KNOWN_IMAGE_SAMPLERS.k_lms: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.k_heun: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.k_euler: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.k_euler_a: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.k_dpm_2: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.k_dpm_2_a: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.k_dpm_fast: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.k_dpm_adaptive: AdaptiveSamplerWorkProfile(),
KNOWN_IMAGE_SAMPLERS.k_dpmpp_2s_a: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.k_dpmpp_2m: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.dpmsolver: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.k_dpmpp_sde: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.lcm: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.DDIM: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.uni_pc: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.uni_pc_bh2: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.dpmpp_2m_sde: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.dpmpp_3m_sde: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.ddpm: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.deis: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.ipndm: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.res_multistep: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.gradient_estimation: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.heunpp2: FixedRateSamplerWorkProfile(
3
),
KNOWN_IMAGE_SAMPLERS.er_sde: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.sa_solver: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.euler_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.euler_ancestral_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.exp_heun_2_x0: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.exp_heun_2_x0_sde: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.dpmpp_2s_ancestral_cfg_pp: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.dpmpp_2m_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.dpmpp_2m_sde_heun: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.ipndm_v: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.res_multistep_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.res_multistep_ancestral: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.res_multistep_ancestral_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.gradient_estimation_cfg_pp: FixedRateSamplerWorkProfile(
1
),
KNOWN_IMAGE_SAMPLERS.seeds_2: FixedRateSamplerWorkProfile(
2
),
KNOWN_IMAGE_SAMPLERS.seeds_3: FixedRateSamplerWorkProfile(
3
),
KNOWN_IMAGE_SAMPLERS.sa_solver_pece: FixedRateSamplerWorkProfile(
2
),
}
)
One work profile for every SDK sampler.
SamplerWorkProfile ¶
TrajectoryStepCount
dataclass
¶
Represents a positive number of requested denoising-schedule steps.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
__post_init__ ¶
Reject values that cannot represent an API image-generation request.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
SamplerWorkUnitCount
dataclass
¶
Represents a non-negative count of first-order-equivalent marginal sampler work units.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
__post_init__ ¶
Reject negative or boolean work-unit counts.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
FixedRateSamplerWorkProfile
dataclass
¶
Represents a sampler whose marginal work is a fixed multiple of trajectory steps.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
marginal_work_units_per_trajectory_step
instance-attribute
¶
__post_init__ ¶
Require a usable positive marginal rate.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
AdaptiveSamplerWorkProfile
dataclass
¶
Represents a sampler whose trajectory length does not determine its actual iteration count.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
SamplerExecutionGuarantee ¶
Bases: StrEnum
Identify one atomic sampler execution behavior contained by cumulative contracts.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
BOUNDED_DPM_ADAPTIVE_V1
class-attribute
instance-attribute
¶
DPM adaptive stops after ceil(5 / 4 * trajectory_steps) solver iterations.
SamplerExecutionContractVersion ¶
Bases: StrEnum
Identify a cumulative SDK-defined sampler execution behavior contract.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
V1
class-attribute
instance-attribute
¶
Require every execution guarantee introduced by sampler execution contract 1.0.
SamplerExecutionContract
dataclass
¶
Represents a cumulative set of sampler execution guarantees a backend can implement.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
AdaptiveSamplerExecutionPolicy
dataclass
¶
Represents the exact iteration ceiling promised by an adaptive execution guarantee.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
__init__ ¶
__init__(
guarantee: SamplerExecutionGuarantee,
sampler: KNOWN_IMAGE_SAMPLERS,
iteration_multiplier_numerator: int,
iteration_multiplier_denominator: int,
) -> None
__post_init__ ¶
Require an exact positive rational multiplier.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
SamplerWorkEstimationPolicy
dataclass
¶
Represents service-owned estimates for work that is not trajectory-derived.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
adaptive_sampler_work_units
instance-attribute
¶
__init__ ¶
__init__(
adaptive_sampler_work_units: Mapping[
KNOWN_IMAGE_SAMPLERS, SamplerWorkUnitCount
],
) -> None
__post_init__ ¶
Freeze and validate the adaptive estimate map.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
SamplerWorkEstimate
dataclass
¶
Represents a request's trajectory length and service-accounting work estimate.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
__init__ ¶
__init__(
sampler: KNOWN_IMAGE_SAMPLERS,
trajectory_steps: TrajectoryStepCount,
work_units: SamplerWorkUnitCount,
) -> None
SamplerWorkCeiling
dataclass
¶
Represents a finite upper bound guaranteed by the selected execution contract.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
__init__ ¶
__init__(
sampler: KNOWN_IMAGE_SAMPLERS,
trajectory_steps: TrajectoryStepCount,
work_units: SamplerWorkUnitCount,
execution_guarantee: SamplerExecutionGuarantee | None,
) -> None
get_sampler_work_profile ¶
Return the work profile for sampler.
Parameters:
-
sampler(KNOWN_IMAGE_SAMPLERS) –Sampler whose marginal work profile is required.
Returns:
-
SamplerWorkProfile–The sampler's fixed-rate or adaptive work profile.
Raises:
-
KeyError–If the profile registry has drifted from the sampler enum.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
get_sampler_execution_contract ¶
get_sampler_execution_contract(
version: SamplerExecutionContractVersion,
) -> SamplerExecutionContract
Return the sampler execution contract identified by version.
Parameters:
-
version(SamplerExecutionContractVersion) –Stable execution contract version advertised by a worker.
Returns:
-
SamplerExecutionContract–The cumulative contract associated with the version.
Raises:
-
KeyError–If the SDK's version enum and execution-contract registry have drifted.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
minimum_common_sampler_execution_contract_version ¶
minimum_common_sampler_execution_contract_version(
versions: Collection[
SamplerExecutionContractVersion | None
],
) -> SamplerExecutionContractVersion | None
Return the newest contract guaranteed by every represented backend path.
Contract versions are cumulative. A missing version therefore makes the combined profile legacy, while combining newer and older contracts yields the older shared contract.
Parameters:
-
versions(Collection[SamplerExecutionContractVersion | None]) –Contract versions for every backend path represented by a worker profile.
Returns:
-
SamplerExecutionContractVersion | None–The newest shared contract, or
Nonewhen any path is legacy.
Raises:
-
ValueError–If
versionsis empty.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
estimate_sampler_work ¶
estimate_sampler_work(
*,
sampler: KNOWN_IMAGE_SAMPLERS,
trajectory_steps: TrajectoryStepCount,
estimation_policy: SamplerWorkEstimationPolicy
) -> SamplerWorkEstimate
Return estimated service-accounting work without claiming an execution ceiling.
Parameters:
-
sampler(KNOWN_IMAGE_SAMPLERS) –Sampler selected by the request.
-
trajectory_steps(TrajectoryStepCount) –Requested denoising-schedule length.
-
estimation_policy(SamplerWorkEstimationPolicy) –Service-owned adaptive work estimates.
Returns:
-
SamplerWorkEstimate–The request's typed trajectory and estimated work values.
Raises:
-
ValueError–If an adaptive sampler has no service estimate.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
maximum_adaptive_solver_iterations ¶
maximum_adaptive_solver_iterations(
*,
trajectory_steps: TrajectoryStepCount,
execution_policy: AdaptiveSamplerExecutionPolicy = BOUNDED_DPM_ADAPTIVE_V1
) -> int
Return the exact integer iteration ceiling for an adaptive execution policy.
Parameters:
-
trajectory_steps(TrajectoryStepCount) –Requested denoising-schedule length.
-
execution_policy(AdaptiveSamplerExecutionPolicy, default:BOUNDED_DPM_ADAPTIVE_V1) –Adaptive policy whose rational ceiling is enforced.
Returns:
-
int–Maximum permitted solver iterations, rounded upward.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
maximum_sampler_work ¶
maximum_sampler_work(
*,
sampler: KNOWN_IMAGE_SAMPLERS,
trajectory_steps: TrajectoryStepCount,
execution_contract_version: (
SamplerExecutionContractVersion | None
),
adaptive_work_units_per_iteration: int | None = None
) -> SamplerWorkCeiling | None
Return a finite work ceiling when the backend contract proves one.
Parameters:
-
sampler(KNOWN_IMAGE_SAMPLERS) –Sampler selected by the request.
-
trajectory_steps(TrajectoryStepCount) –Requested denoising-schedule length.
-
execution_contract_version(SamplerExecutionContractVersion | None) –Cumulative execution contract advertised by the backend.
-
adaptive_work_units_per_iteration(int | None, default:None) –Work units consumed by each adaptive solver iteration.
Returns:
-
SamplerWorkCeiling | None–A typed finite ceiling, or
Nonewhen no finite ceiling is guaranteed.
Raises:
-
ValueError–If adaptive work per iteration is missing or invalid for a bounded contract.
Source code in horde_sdk/generation_parameters/image/sampler_work.py
maximum_trajectory_steps_for_work_budget ¶
maximum_trajectory_steps_for_work_budget(
*,
sampler: KNOWN_IMAGE_SAMPLERS,
requested_trajectory_steps: TrajectoryStepCount,
work_budget: SamplerWorkUnitCount,
estimation_policy: SamplerWorkEstimationPolicy
) -> TrajectoryStepCount | None
Return the largest requested trajectory length within an estimated-work budget.
An adaptive service estimate is request-independent. Reducing requested steps therefore cannot make an over-budget adaptive request fit; callers must reject it without changing sampler identity.
Parameters:
-
sampler(KNOWN_IMAGE_SAMPLERS) –Sampler selected by the request.
-
requested_trajectory_steps(TrajectoryStepCount) –Requested denoising-schedule length.
-
work_budget(SamplerWorkUnitCount) –Maximum estimated work the service permits.
-
estimation_policy(SamplerWorkEstimationPolicy) –Service-owned adaptive work estimates.
Returns:
-
TrajectoryStepCount | None–The largest permitted trajectory length, or
Nonewhen step reduction cannot fit the budget.