Skip to content

Instantly share code, notes, and snippets.

@BloodAxe
Created June 8, 2020 11:11
Show Gist options
  • Save BloodAxe/f9765d29bf7897e8f24b0e23ad988e6c to your computer and use it in GitHub Desktop.
Save BloodAxe/f9765d29bf7897e8f24b0e23ad988e6c to your computer and use it in GitHub Desktop.
def test_loss_profiling():
loss = nn.BCEWithLogitsLoss()
with torch.autograd.profiler.profile(use_cuda=True) as prof:
input = torch.randn((8, 1, 128, 128)).cuda()
input.requires_grad = True
target = torch.randint(1, (8, 1, 128, 128)).cuda().float()
for i in range(10):
l = loss(input, target)
l.backward()
print(prof.key_averages().table(sort_by="self_cpu_time_total"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment