Skip to content

vllm.benchmarks.sweep.plot

PlotBinner dataclass

Source code in vllm/benchmarks/sweep/plot.py
@dataclass
class PlotBinner:
    var: str
    bin_size: float

    @classmethod
    def parse_str(cls, s: str):
        for op_key in PLOT_BINNERS:
            if op_key in s:
                key, value = s.split(op_key)
                return PLOT_BINNERS[op_key](key, float(value.removeprefix(op_key)))
        else:
            raise ValueError(
                f"Invalid operator for plot binner '{s}'. "
                f"Valid operators are: {sorted(PLOT_BINNERS)}",
            )

    def apply(self, df: "pd.DataFrame") -> "pd.DataFrame":
        """Applies this binner to a DataFrame."""
        df = df.copy()
        df[self.var] = df[self.var] // self.bin_size * self.bin_size
        return df

apply

apply(df: DataFrame) -> DataFrame

Applies this binner to a DataFrame.

Source code in vllm/benchmarks/sweep/plot.py
def apply(self, df: "pd.DataFrame") -> "pd.DataFrame":
    """Applies this binner to a DataFrame."""
    df = df.copy()
    df[self.var] = df[self.var] // self.bin_size * self.bin_size
    return df

PlotFilterBase dataclass

Bases: ABC

Source code in vllm/benchmarks/sweep/plot.py
@dataclass
class PlotFilterBase(ABC):
    var: str
    target: str

    @classmethod
    def parse_str(cls, s: str):
        for op_key in PLOT_FILTERS:
            if op_key in s:
                key, value = s.split(op_key)
                return PLOT_FILTERS[op_key](
                    key,
                    value.removeprefix(op_key).strip("'").strip('"'),
                )
        else:
            raise ValueError(
                f"Invalid operator for plot filter '{s}'. "
                f"Valid operators are: {sorted(PLOT_FILTERS)}",
            )

    @abstractmethod
    def apply(self, df: "pd.DataFrame") -> "pd.DataFrame":
        """Applies this filter to a DataFrame."""
        raise NotImplementedError

apply abstractmethod

apply(df: DataFrame) -> DataFrame

Applies this filter to a DataFrame.

Source code in vllm/benchmarks/sweep/plot.py
@abstractmethod
def apply(self, df: "pd.DataFrame") -> "pd.DataFrame":
    """Applies this filter to a DataFrame."""
    raise NotImplementedError

_convert_inf_nan_strings

_convert_inf_nan_strings(
    data: list[dict[str, object]],
) -> list[dict[str, object]]

Convert string values "inf", "-inf", and "nan" to their float equivalents.

This handles the case where JSON serialization represents inf/nan as strings.

Source code in vllm/benchmarks/sweep/plot.py
def _convert_inf_nan_strings(data: list[dict[str, object]]) -> list[dict[str, object]]:
    """
    Convert string values "inf", "-inf", and "nan" to their float equivalents.

    This handles the case where JSON serialization represents inf/nan as strings.
    """
    converted_data = []
    for record in data:
        converted_record = {}
        for key, value in record.items():
            if isinstance(value, str):
                if value in ["inf", "-inf", "nan"]:
                    converted_record[key] = float(value)
                else:
                    converted_record[key] = value
            else:
                converted_record[key] = value
        converted_data.append(converted_record)
    return converted_data