(enabled=False,
clear_previous=True,
skip_first=10,
wait=5,
warmup=5,
active=10,
repeat=5,
record_dir=f"data/record/{cfg.exp_name}", # constructed in the same way
record_shapes=True,
profile_memory=True,
with_stack=True,
with_flops=True,
with_modules=True,
)
| 26 | |
| 27 | |
| 28 | def setup_profiler(enabled=False, |
| 29 | clear_previous=True, |
| 30 | skip_first=10, |
| 31 | wait=5, |
| 32 | warmup=5, |
| 33 | active=10, |
| 34 | repeat=5, |
| 35 | record_dir=f"data/record/{cfg.exp_name}", # constructed in the same way |
| 36 | record_shapes=True, |
| 37 | profile_memory=True, |
| 38 | with_stack=True, |
| 39 | with_flops=True, |
| 40 | with_modules=True, |
| 41 | ): |
| 42 | if enabled: |
| 43 | log(yellow(f"Profiling results will be saved to: {blue(record_dir)}")) |
| 44 | if clear_previous: |
| 45 | log(red(f'Removing profiling result in: {blue(record_dir)}')) |
| 46 | os.system(f'rm -rf {record_dir}') |
| 47 | global profiler |
| 48 | profiler = profile(schedule=schedule(skip_first=skip_first, |
| 49 | wait=wait, |
| 50 | warmup=warmup, |
| 51 | active=active, |
| 52 | repeat=repeat, |
| 53 | ), |
| 54 | activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], |
| 55 | on_trace_ready=torch.profiler.tensorboard_trace_handler(record_dir), |
| 56 | record_shapes=record_shapes, |
| 57 | profile_memory=profile_memory, |
| 58 | with_stack=with_stack, # sometimes with_stack causes segmentation fault |
| 59 | with_flops=with_flops, |
| 60 | with_modules=with_modules |
| 61 | ) |
| 62 | |
| 63 | # # MARK: modification of global config, is this good? |
| 64 | # cfg.runner_cfg.epoch = 1 |
| 65 | # cfg.runner_cfg.ep_iter = skip_first + repeat * (wait + warmup + active) |
no test coverage detected