Skip to content

guidellm.scheduler.constraints.args

Kind-discriminated constraint argument schemas for benchmark configuration.

ConstraintArgs

Bases: PydanticClassRegistryMixin['ConstraintArgs']

Base class for constraint configuration arguments.

Uses PydanticClassRegistryMixin to enable polymorphic deserialization based on the kind field. Each registered subclass represents a specific constraint type with its own parameters.

Attributes:

Name Type Description
schema_discriminator str

Field name for polymorphic deserialization

Source code in src/guidellm/scheduler/constraints/args.py
class ConstraintArgs(PydanticClassRegistryMixin["ConstraintArgs"]):
    """
    Base class for constraint configuration arguments.

    Uses ``PydanticClassRegistryMixin`` to enable polymorphic deserialization
    based on the ``kind`` field. Each registered subclass represents a specific
    constraint type with its own parameters.

    :cvar schema_discriminator: Field name for polymorphic deserialization
    """

    model_config = ConfigDict(
        extra="forbid",
        serialize_by_alias=True,
        ser_json_bytes="base64",
        val_json_bytes="base64",
    )

    schema_discriminator: ClassVar[str] = "kind"

    @classmethod
    def __pydantic_schema_base_type__(cls) -> type[ConstraintArgs]:
        """
        Return base type for polymorphic validation hierarchy.

        :return: Base ConstraintArgs class for schema validation
        """
        if cls.__name__ == "ConstraintArgs":
            return cls

        return ConstraintArgs

    kind: str = Field(
        description="Constraint type discriminator for polymorphic serialization",
    )

    stopping_scope: Literal["current", "all"] = Field(
        default="current",
        description=(
            "Whether triggering this constraint should stop only the current "
            "benchmark ('current') or also halt escalation to subsequent "
            "rates/streams ('all')."
        ),
    )

    @property
    def constraint_key(self) -> str:
        """
        The key to use when inserting into the constraints dict.

        Defaults to ``kind``, but subclasses may override if the factory
        registry key differs from the args kind.

        :return: Registry key for this constraint type
        """
        return self.kind

constraint_key property

The key to use when inserting into the constraints dict.

Defaults to kind, but subclasses may override if the factory registry key differs from the args kind.

Returns:

Type Description
str

Registry key for this constraint type

__pydantic_schema_base_type__() classmethod

Return base type for polymorphic validation hierarchy.

Returns:

Type Description
type[ConstraintArgs]

Base ConstraintArgs class for schema validation

Source code in src/guidellm/scheduler/constraints/args.py
@classmethod
def __pydantic_schema_base_type__(cls) -> type[ConstraintArgs]:
    """
    Return base type for polymorphic validation hierarchy.

    :return: Base ConstraintArgs class for schema validation
    """
    if cls.__name__ == "ConstraintArgs":
        return cls

    return ConstraintArgs