| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import copy |
| 5 | import dataclasses |
| 6 | from collections.abc import Generator |
| 7 | from contextlib import contextmanager |
| 8 | from typing import Any |
| 9 | |
| 10 | |
| 11 | @dataclasses.dataclass |
| 12 | class CompilationCounter: |
| 13 | num_models_seen: int = 0 |
| 14 | num_graphs_seen: int = 0 |
| 15 | # including the splitting ops |
| 16 | num_piecewise_graphs_seen: int = 0 |
| 17 | # not including the splitting ops |
| 18 | num_piecewise_capturable_graphs_seen: int = 0 |
| 19 | num_backend_compilations: int = 0 |
| 20 | # Number of gpu_model_runner attempts to trigger CUDAGraphs capture |
| 21 | num_gpu_runner_capture_triggers: int = 0 |
| 22 | # Number of CUDAGraphs captured |
| 23 | num_cudagraph_captured: int = 0 |
| 24 | # InductorAdapter.compile calls |
| 25 | num_inductor_compiles: int = 0 |
| 26 | # EagerAdapter.compile calls |
| 27 | num_eager_compiles: int = 0 |
| 28 | # The number of time vLLM's compiler cache entry was updated |
| 29 | num_cache_entries_updated: int = 0 |
| 30 | # The number of standalone_compile compiled artifacts saved |
| 31 | num_compiled_artifacts_saved: int = 0 |
| 32 | # The number of standalone_compile compiled artifacts loaded from cache |
| 33 | num_compiled_artifacts_loaded: int = 0 |
| 34 | # The number of AOT compile invocations |
| 35 | num_aot_compiles: int = 0 |
| 36 | # The number of AOT compiled artifacts saved to disk |
| 37 | num_aot_artifacts_saved: int = 0 |
| 38 | # The number of AOT compiled artifacts loaded from disk |
| 39 | num_aot_artifacts_loaded: int = 0 |
| 40 | # Number of times a model was loaded with CompilationMode.STOCK_TORCH_COMPILE |
| 41 | stock_torch_compile_count: int = 0 |
| 42 | |
| 43 | def clone(self) -> "CompilationCounter": |
| 44 | return copy.deepcopy(self) |
| 45 | |
| 46 | @contextmanager |
| 47 | def expect(self, **kwargs: Any) -> Generator[None, None, None]: |
| 48 | old = self.clone() |
| 49 | yield |
| 50 | for k, v in kwargs.items(): |
| 51 | assert getattr(self, k) - getattr(old, k) == v, ( |
| 52 | f"{k} not as expected, before it is {getattr(old, k)}" |
| 53 | f", after it is {getattr(self, k)}, " |
| 54 | f"expected diff is {v}" |
| 55 | ) |
| 56 | |
| 57 | |
| 58 | compilation_counter = CompilationCounter() |