Skip to content

vllm.benchmarks.sweep.sla_sweep

SLA_CRITERIA module-attribute

SLACriterionBase dataclass

Bases: ABC

Source code in vllm/benchmarks/sweep/sla_sweep.py
@dataclass
class SLACriterionBase(ABC):
    target: float

    @abstractmethod
    def validate(self, actual: float) -> bool:
        """Return `True` if this criterion is met; otherwise `False`."""
        raise NotImplementedError

    @abstractmethod
    def format_cond(self, lhs: str) -> str:
        raise NotImplementedError

    def print_and_validate(
        self,
        metrics: dict[str, float],
        metrics_key: str,
    ) -> bool:
        metric = metrics[metrics_key]
        result = self.validate(metric)

        cond = self.format_cond(f"{metrics_key} = {metric:.2f}")
        print(f"Validating SLA: {cond} | " + ("PASSED" if result else "FAILED"))

        return result

target instance-attribute

target: float

__init__

__init__(target: float) -> None

format_cond abstractmethod

format_cond(lhs: str) -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
@abstractmethod
def format_cond(self, lhs: str) -> str:
    raise NotImplementedError

print_and_validate

print_and_validate(
    metrics: dict[str, float], metrics_key: str
) -> bool
Source code in vllm/benchmarks/sweep/sla_sweep.py
def print_and_validate(
    self,
    metrics: dict[str, float],
    metrics_key: str,
) -> bool:
    metric = metrics[metrics_key]
    result = self.validate(metric)

    cond = self.format_cond(f"{metrics_key} = {metric:.2f}")
    print(f"Validating SLA: {cond} | " + ("PASSED" if result else "FAILED"))

    return result

validate abstractmethod

validate(actual: float) -> bool

Return True if this criterion is met; otherwise False.

Source code in vllm/benchmarks/sweep/sla_sweep.py
@abstractmethod
def validate(self, actual: float) -> bool:
    """Return `True` if this criterion is met; otherwise `False`."""
    raise NotImplementedError

SLAGreaterThan dataclass

Bases: SLACriterionBase

Source code in vllm/benchmarks/sweep/sla_sweep.py
@dataclass
class SLAGreaterThan(SLACriterionBase):
    @override
    def validate(self, actual: float) -> bool:
        return actual > self.target

    @override
    def format_cond(self, lhs: str) -> str:
        return f"{lhs}>{self.target:.2f}"

__init__

__init__(target: float) -> None

format_cond

format_cond(lhs: str) -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def format_cond(self, lhs: str) -> str:
    return f"{lhs}>{self.target:.2f}"

validate

validate(actual: float) -> bool
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def validate(self, actual: float) -> bool:
    return actual > self.target

SLAGreaterThanOrEqualTo dataclass

Bases: SLACriterionBase

Source code in vllm/benchmarks/sweep/sla_sweep.py
@dataclass
class SLAGreaterThanOrEqualTo(SLACriterionBase):
    @override
    def validate(self, actual: float) -> bool:
        return actual >= self.target

    @override
    def format_cond(self, lhs: str) -> str:
        return f"{lhs}>={self.target:.2f}"

__init__

__init__(target: float) -> None

format_cond

format_cond(lhs: str) -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def format_cond(self, lhs: str) -> str:
    return f"{lhs}>={self.target:.2f}"

validate

validate(actual: float) -> bool
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def validate(self, actual: float) -> bool:
    return actual >= self.target

SLALessThan dataclass

Bases: SLACriterionBase

Source code in vllm/benchmarks/sweep/sla_sweep.py
@dataclass
class SLALessThan(SLACriterionBase):
    @override
    def validate(self, actual: float) -> bool:
        return actual < self.target

    @override
    def format_cond(self, lhs: str) -> str:
        return f"{lhs}<{self.target:.2f}"

__init__

__init__(target: float) -> None

format_cond

format_cond(lhs: str) -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def format_cond(self, lhs: str) -> str:
    return f"{lhs}<{self.target:.2f}"

validate

validate(actual: float) -> bool
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def validate(self, actual: float) -> bool:
    return actual < self.target

SLALessThanOrEqualTo dataclass

Bases: SLACriterionBase

Source code in vllm/benchmarks/sweep/sla_sweep.py
@dataclass
class SLALessThanOrEqualTo(SLACriterionBase):
    @override
    def validate(self, actual: float) -> bool:
        return actual <= self.target

    @override
    def format_cond(self, lhs: str) -> str:
        return f"{lhs}<={self.target:.2f}"

__init__

__init__(target: float) -> None

format_cond

format_cond(lhs: str) -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def format_cond(self, lhs: str) -> str:
    return f"{lhs}<={self.target:.2f}"

validate

validate(actual: float) -> bool
Source code in vllm/benchmarks/sweep/sla_sweep.py
@override
def validate(self, actual: float) -> bool:
    return actual <= self.target

SLASweep

Bases: list['SLASweepItem']

Source code in vllm/benchmarks/sweep/sla_sweep.py
class SLASweep(list["SLASweepItem"]):
    @classmethod
    def read_json(cls, filepath: os.PathLike):
        with open(filepath, "rb") as f:
            records = json.load(f)

        return cls.from_records(records)

    @classmethod
    def from_records(cls, records: list[dict[str, str]]):
        if not isinstance(records, list):
            raise TypeError(
                f"The SLA sweep should be a list of dictionaries, "
                f"but found type: {type(records)}"
            )

        return cls(SLASweepItem.from_record(record) for record in records)

from_records classmethod

from_records(records: list[dict[str, str]])
Source code in vllm/benchmarks/sweep/sla_sweep.py
@classmethod
def from_records(cls, records: list[dict[str, str]]):
    if not isinstance(records, list):
        raise TypeError(
            f"The SLA sweep should be a list of dictionaries, "
            f"but found type: {type(records)}"
        )

    return cls(SLASweepItem.from_record(record) for record in records)

read_json classmethod

read_json(filepath: PathLike)
Source code in vllm/benchmarks/sweep/sla_sweep.py
@classmethod
def read_json(cls, filepath: os.PathLike):
    with open(filepath, "rb") as f:
        records = json.load(f)

    return cls.from_records(records)

SLASweepItem

Bases: dict[str, SLACriterionBase]

Source code in vllm/benchmarks/sweep/sla_sweep.py
class SLASweepItem(dict[str, SLACriterionBase]):
    @classmethod
    def from_record(cls, record: dict[str, str]):
        sla_criteria: dict[str, SLACriterionBase] = {}

        for metric_key, metric_value in record.items():
            for op_key in SLA_CRITERIA:
                if metric_value.startswith(op_key):
                    sla_criteria[metric_key] = SLA_CRITERIA[op_key](
                        float(metric_value.removeprefix(op_key))
                    )
                    break
            else:
                raise ValueError(
                    f"Invalid operator for "
                    f"SLA constraint '{metric_key}={metric_value}'. "
                    f"Valid operators are: {sorted(SLA_CRITERIA)}",
                )

        return cls(sla_criteria)

    def as_text(self, sep: str = ", ") -> str:
        return sep.join(v.format_cond(k) for k, v in self.items())

as_text

as_text(sep: str = ', ') -> str
Source code in vllm/benchmarks/sweep/sla_sweep.py
def as_text(self, sep: str = ", ") -> str:
    return sep.join(v.format_cond(k) for k, v in self.items())

from_record classmethod

from_record(record: dict[str, str])
Source code in vllm/benchmarks/sweep/sla_sweep.py
@classmethod
def from_record(cls, record: dict[str, str]):
    sla_criteria: dict[str, SLACriterionBase] = {}

    for metric_key, metric_value in record.items():
        for op_key in SLA_CRITERIA:
            if metric_value.startswith(op_key):
                sla_criteria[metric_key] = SLA_CRITERIA[op_key](
                    float(metric_value.removeprefix(op_key))
                )
                break
        else:
            raise ValueError(
                f"Invalid operator for "
                f"SLA constraint '{metric_key}={metric_value}'. "
                f"Valid operators are: {sorted(SLA_CRITERIA)}",
            )

    return cls(sla_criteria)