Skip to content

Commit 31952db

Browse files
Make single GPU benchmarking 5x more efficient (#2390)
* Use SerialRunner if only one CUDA device is available. Signed-off-by: Weilin Xu <weilin.xu@intel.com> * Resolve PLR6201. Signed-off-by: Weilin Xu <weilin.xu@intel.com> * Update CHANGELOG. Signed-off-by: Weilin Xu <weilin.xu@intel.com> * Keep the same logging level in benchmarking. Signed-off-by: Weilin Xu <weilin.xu@intel.com> --------- Signed-off-by: Weilin Xu <weilin.xu@intel.com> Co-authored-by: Samet Akcay <samet.akcay@intel.com>
1 parent c00e101 commit 31952db

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2121

2222
### Fixed
2323

24+
- Make single GPU benchmarking 5x more efficient by [mzweilin](https://github.com/mzweilin) in https://github.com/openvinotoolkit/anomalib/pull/2390
25+
2426
### New Contributors
2527

2628
**Full Changelog**:

src/anomalib/pipelines/benchmark/pipeline.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ def _setup_runners(args: dict) -> list[Runner]:
2020
accelerators = args["accelerator"] if isinstance(args["accelerator"], list) else [args["accelerator"]]
2121
runners: list[Runner] = []
2222
for accelerator in accelerators:
23-
if accelerator == "cpu":
24-
runners.append(SerialRunner(BenchmarkJobGenerator("cpu")))
25-
elif accelerator == "cuda":
26-
runners.append(ParallelRunner(BenchmarkJobGenerator("cuda"), n_jobs=torch.cuda.device_count()))
27-
else:
23+
if accelerator not in {"cpu", "cuda"}:
2824
msg = f"Unsupported accelerator: {accelerator}"
2925
raise ValueError(msg)
26+
device_count = torch.cuda.device_count()
27+
if device_count <= 1:
28+
runners.append(SerialRunner(BenchmarkJobGenerator(accelerator)))
29+
else:
30+
runners.append(ParallelRunner(BenchmarkJobGenerator(accelerator), n_jobs=device_count))
3031
return runners

src/anomalib/utils/logging.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ def redirect_logs(log_file: str) -> None:
7474
"""
7575
Path(log_file).parent.mkdir(exist_ok=True, parents=True)
7676
logger_file_handler = logging.FileHandler(log_file)
77-
root_logger = logging.getLogger()
78-
root_logger.setLevel(logging.DEBUG)
7977
format_string = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
80-
logging.basicConfig(format=format_string, level=logging.DEBUG, handlers=[logger_file_handler])
78+
logging.basicConfig(format=format_string, handlers=[logger_file_handler])
8179
logging.captureWarnings(capture=True)
8280
# remove other handlers from all loggers
8381
loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]

0 commit comments

Comments
 (0)