MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / check_forward_equal_with_pytorch_float

Function check_forward_equal_with_pytorch_float

models/aios/ops/test.py:57–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55
56@torch.no_grad()
57def check_forward_equal_with_pytorch_float():
58 value = torch.rand(N, S, M, D).cuda() * 0.01
59 sampling_locations = torch.rand(N, Lq, M, L, P, 2).cuda()
60 attention_weights = torch.rand(N, Lq, M, L, P).cuda() + 1e-5
61 attention_weights /= attention_weights.sum(-1,
62 keepdim=True).sum(-2,
63 keepdim=True)
64 im2col_step = 2
65 output_pytorch = ms_deform_attn_core_pytorch(
66 value, shapes, sampling_locations, attention_weights).detach().cpu()
67 output_cuda = MSDeformAttnFunction.apply(value, shapes, level_start_index,
68 sampling_locations,
69 attention_weights,
70 im2col_step).detach().cpu()
71 fwdok = torch.allclose(output_cuda, output_pytorch, rtol=1e-2, atol=1e-3)
72 max_abs_err = (output_cuda - output_pytorch).abs().max()
73 max_rel_err = ((output_cuda - output_pytorch).abs() /
74 output_pytorch.abs()).max()
75
76 print(
77 f'* {fwdok} check_forward_equal_with_pytorch_float: max_abs_err {max_abs_err:.2e} max_rel_err {max_rel_err:.2e}'
78 )
79
80
81def check_gradient_numerical(channels=4,

Callers 1

test.pyFile · 0.85

Calls 4

maxMethod · 0.80
printFunction · 0.50
detachMethod · 0.45

Tested by

no test coverage detected