[Enhancement] Improve ProfilerHook beaviour when using a relative (or empty) dir_name (#2119)

* Add default dir_name and make non-absolute dir_name relative to runner.work_dir

* Add log message and change default dir name
pull/2125/head^2
GPhilo 2022-07-18 13:40:59 +02:00 committed by GitHub
parent b58c84c6f0
commit 0092699fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -1,4 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import warnings
from typing import Callable, List, Optional, Union
@ -131,6 +132,15 @@ class ProfilerHook(Hook):
raise ImportError('please run "pip install '
'torch-tb-profiler" to install '
'torch_tb_profiler')
if 'dir_name' not in trace_cfg:
trace_cfg['dir_name'] = osp.join(runner.work_dir,
'tf_tracing_logs')
elif not osp.isabs(trace_cfg['dir_name']):
trace_cfg['dir_name'] = osp.join(runner.work_dir,
trace_cfg['dir_name'])
runner.logger.info(
'tracing files of ProfilerHook will be saved to '
f"{trace_cfg['dir_name']}.")
_on_trace_ready = torch.profiler.tensorboard_trace_handler(
**trace_cfg)
else: