aitune.torch.tune_strategy.mixin.performance_validation_mixin

View as Markdown

Performance validation mixin for tune strategy.

Module Contents

Classes

NameDescription
PerformanceValidationMixinTuneStrategy mixin that validates each backend against a TorchEager throughput baseline.
PerformanceValidationMixinResultThroughput and speedup result for a single backend.

Functions

NameDescription
fmt_speedup_msgReturns the full speedup summary line with module/backend fields.
fmt_speedup_msg_shortReturns a compact speedup line without module/backend fields.

API

class aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin(
args = (),
min_speedup_threshold_percent: float = 1.0,
kwargs = {}
)

Bases: TuneStrategy

TuneStrategy mixin that validates each backend against a TorchEager throughput baseline.

When performance validation is enabled, profiles TorchEager during _pre_tune with the strategy profiling config narrowed to the resolved batch size (from graph_spec.get_max_batch_size()) to establish a baseline. For every candidate backend, profiles with the same task-local profiling config and appends a PerformanceValidationMixinResult. Backends with speedup below the configured threshold are rejected.

_baseline_backend
Backend | None = None
_baseline_throughput
float | None = None
_performance_validation_enabled
bool = True
_resolved_batch_size
int | None = None
perf_validation_results
list[PerformanceValidationMixinResult] = []
aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin._build_validate_and_check_perf(
module: torch.nn.Module,
name: str,
device: torch.device,
cache_dir: pathlib.Path,
raise_on_failure: bool = False

Build, correctness-validate, then profile and check throughput against baseline.

Returns the built backend, or None when correctness fails (raise_on_failure=False) or performance check rejects it (speedup below threshold).

aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin._log_baseline_selected(
) -> None

Emit an explicit message when the TorchEager baseline is the selected backend.

aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin._post_tune(
name: str,
)

Emits a speedup line after tuning completes.

aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin._pre_tune(
module: torch.nn.Module,
name: str,
device: torch.device,
cache_dir: pathlib.Path
)

Runs pre-tune setup and profiles TorchEager when performance validation is enabled.

aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixin._profiling_config_for_batch_size(
batch_size: int,
batching: bool | None = None

Returns the strategy profiling config narrowed to one validation batch size.

Enables or disables TorchEager baseline profiling and candidate performance checks.

class aitune.torch.tune_strategy.mixin.performance_validation_mixin.PerformanceValidationMixinResult(
backend_description: str,
throughput: float,
baseline_throughput: float,
speedup: float,
passed: bool
)
Dataclass

Throughput and speedup result for a single backend.

backend_description
str
baseline_throughput
float
passed
bool
speedup
float
throughput
float
aitune.torch.tune_strategy.mixin.performance_validation_mixin.fmt_speedup_msg(
speedup: float,
detail: str,
name: str,
backend_desc: str
) -> str

Returns the full speedup summary line with module/backend fields.

aitune.torch.tune_strategy.mixin.performance_validation_mixin.fmt_speedup_msg_short(
speedup: float,
detail: str
) -> str

Returns a compact speedup line without module/backend fields.