|
26 | 26 | from helion._testing import skipIfXPU |
27 | 27 | from helion.autotuner.base_search import PopulationBasedSearch |
28 | 28 | from helion.autotuner.base_search import PopulationMember |
| 29 | +from helion.autotuner.benchmark_job import BenchmarkJob |
29 | 30 | from helion.autotuner.benchmark_job import RebenchmarkJob |
30 | 31 | from helion.autotuner.benchmark_job import _load_args |
31 | 32 | from helion.autotuner.benchmark_pool import PoolBenchmarkManager |
@@ -238,6 +239,73 @@ def test_pool_mode_reports_disabled_worker_reason(self) -> None: |
238 | 239 | assert reason is not None |
239 | 240 | self.assertIn("disabled", reason) |
240 | 241 |
|
| 242 | + def test_benchmark_isolated_routes_each_fn_to_owner_worker(self) -> None: |
| 243 | + # Isolated benchmarking should route each config to its precompile owner. |
| 244 | + class FakePoolManager: |
| 245 | + def __init__(self) -> None: |
| 246 | + self.calls: list[tuple[int, object, float]] = [] |
| 247 | + |
| 248 | + def worker_index_for_fn(self, fn: object) -> int: |
| 249 | + return 2 if fn is fake_fn_a else 1 |
| 250 | + |
| 251 | + def run_job_on_worker( |
| 252 | + self, |
| 253 | + worker_index: int, |
| 254 | + job: object, |
| 255 | + timeout: float, |
| 256 | + ) -> float: |
| 257 | + self.calls.append((worker_index, job, timeout)) |
| 258 | + return float(worker_index) |
| 259 | + |
| 260 | + class FakeLog: |
| 261 | + def warning(self, *_args: object, **_kwargs: object) -> None: |
| 262 | + pass |
| 263 | + |
| 264 | + def debug(self, *_args: object, **_kwargs: object) -> None: |
| 265 | + pass |
| 266 | + |
| 267 | + def fake_fn_a() -> None: |
| 268 | + pass |
| 269 | + |
| 270 | + def fake_fn_b() -> None: |
| 271 | + pass |
| 272 | + |
| 273 | + pool = FakePoolManager() |
| 274 | + provider = cast("Any", LocalBenchmarkProvider.__new__(LocalBenchmarkProvider)) |
| 275 | + provider.settings = Settings( |
| 276 | + autotune_precompile="pool", |
| 277 | + autotune_benchmark_timeout=10, |
| 278 | + ) |
| 279 | + provider.config_spec = SimpleNamespace(backend=None) |
| 280 | + provider.mutated_arg_indices = [] |
| 281 | + provider._precompile_args_path = "args.pt" |
| 282 | + provider._pool_manager = pool |
| 283 | + provider._benchmark_worker = None |
| 284 | + provider._autotune_metrics = SimpleNamespace(num_compile_failures=0) |
| 285 | + provider.log = FakeLog() |
| 286 | + provider._serialize_fn_for_worker = lambda _fn: SerializedCompiledFunction( |
| 287 | + function_name="fake_fn", |
| 288 | + source_code="def fake_fn(): pass", |
| 289 | + filename=None, |
| 290 | + module_name=None, |
| 291 | + ) |
| 292 | + |
| 293 | + result = provider.benchmark_isolated( |
| 294 | + [fake_fn_a, fake_fn_b], |
| 295 | + warmup=25, |
| 296 | + rep=100, |
| 297 | + desc="verify", |
| 298 | + ) |
| 299 | + |
| 300 | + self.assertEqual(result, [2.0, 1.0]) |
| 301 | + self.assertEqual([call[0] for call in pool.calls], [2, 1]) |
| 302 | + self.assertTrue(all(isinstance(call[1], BenchmarkJob) for call in pool.calls)) |
| 303 | + self.assertTrue(all(call[2] == 10.0 for call in pool.calls)) |
| 304 | + for _, job, _ in pool.calls: |
| 305 | + assert isinstance(job, BenchmarkJob) |
| 306 | + self.assertEqual(job.warmup, 25) |
| 307 | + self.assertEqual(job.rep, 100) |
| 308 | + |
241 | 309 | def test_rebenchmark_uses_worker_pool(self) -> None: |
242 | 310 | # Full-effort rebenchmarking should run on the worker that precompiled the config. |
243 | 311 | class FakePoolManager: |
|
0 commit comments