torch_npu.profiler.tensorboard_trace_handler(dir_name, worker_name = None, use_gzip = False)
将采集到的性能数据导出为TensorBoard工具支持的格式。用于构造torch_npu.profiler.profile的on_trace_ready参数。
with torch_npu.profiler.profile( schedule=torch_npu.profiler.schedule(wait=1, warmup=1, active=2, repeat=2, skip_first=10), on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result"), with_stack=True) as prof: for step in range(steps): train_one_step(step, steps, train_loader, model, optimizer, criterion) prof.step()