MCPcopy Index your code
hub / github.com/pytorch/tutorials / benchmark_with_profiler

Function benchmark_with_profiler

intermediate_source/pinmem_nonblock.py:171–192  ·  view source on GitHub ↗
(
    pinned,
    streamed,
)

Source from the content-addressed store, hash-verified

169
170# Our profiler: profiles the `inner` function and stores the results in a .json file
171def benchmark_with_profiler(
172 pinned,
173 streamed,
174) -> None:
175 torch._C._profiler._set_cuda_sync_enabled_val(True)
176 wait, warmup, active = 1, 1, 2
177 num_steps = wait + warmup + active
178 rank = 0
179 with torch.profiler.profile(
180 activities=[
181 torch.profiler.ProfilerActivity.CPU,
182 torch.profiler.ProfilerActivity.CUDA,
183 ],
184 schedule=torch.profiler.schedule(
185 wait=wait, warmup=warmup, active=active, repeat=1, skip_first=1
186 ),
187 ) as prof:
188 for step_idx in range(1, num_steps + 1):
189 inner(streamed=streamed, pinned=pinned)
190 if rank is None or rank == 0:
191 prof.step()
192 prof.export_chrome_trace(f"trace_streamed{int(streamed)}_pinned{int(pinned)}.json")
193
194
195######################################################################

Callers 1

pinmem_nonblock.pyFile · 0.85

Calls 2

stepMethod · 0.80
innerFunction · 0.70

Tested by

no test coverage detected