如何获取事件';pytorch profiler中的walltime?

如何获取事件';pytorch profiler中的walltime?,time,pytorch,profile,Time,Pytorch,Profile,我使用的是pytorch版本1.8.1+cu102,我想知道活动的开始时间和结束时间 torch.autograd.profiler.FunctionEvent提供了time\u range字段,但其值很奇怪 #%% 进口火炬 将torchvision.models导入为模型 导入时间 打印(火炬版本) # %% model=models.resnet18().cuda() 输入=torch.randn(5,3,224,224).cuda() 使用torch.profiler.profile(

我使用的是pytorch版本1.8.1+cu102,我想知道活动的开始时间和结束时间

torch.autograd.profiler.FunctionEvent
提供了
time\u range
字段,但其值很奇怪

#%%
进口火炬
将torchvision.models导入为模型
导入时间
打印(火炬版本)
# %%
model=models.resnet18().cuda()
输入=torch.randn(5,3,224,224).cuda()
使用torch.profiler.profile(
活动=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.CUDA]
)作为p:
输出=模型(输入)
# %%
事件=p.事件()
打印('begin',min(事件,键=lambda e:e.time\u range.start)。time\u range.start/1000000)
打印('end',max(事件,键=lambda e:e.time\u range.end)。time\u range.end/1000000)
打印('real time',time.time())
第一次运行上面的代码,我得到:

1.8.1+cu102
begin      1615893050.2533033
end        1615893052.6818323
real time  1617705608.1550226
第二次:

1.8.1+cu102
begin      1615893050.2533386
end        1615893052.7069924
real time  1617705746.4107628
事件的开始时间和结束时间没有更改

那么,如何获得事件的正确时间戳呢