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

Function check_forward_equal_with_pytorch_double

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

Source from the content-addressed store, hash-verified

28
29@torch.no_grad()
30def check_forward_equal_with_pytorch_double():
31 value = torch.rand(N, S, M, D).cuda() * 0.01
32 sampling_locations = torch.rand(N, Lq, M, L, P, 2).cuda()
33 attention_weights = torch.rand(N, Lq, M, L, P).cuda() + 1e-5
34 attention_weights /= attention_weights.sum(-1,
35 keepdim=True).sum(-2,
36 keepdim=True)
37 im2col_step = 2
38 output_pytorch = ms_deform_attn_core_pytorch(
39 value.double(), shapes, sampling_locations.double(),
40 attention_weights.double()).detach().cpu()
41 output_cuda = MSDeformAttnFunction.apply(value.double(), shapes,
42 level_start_index,
43 sampling_locations.double(),
44 attention_weights.double(),
45 im2col_step).detach().cpu()
46 fwdok = torch.allclose(output_cuda, output_pytorch)
47 max_abs_err = (output_cuda - output_pytorch).abs().max()
48 max_rel_err = ((output_cuda - output_pytorch).abs() /
49 output_pytorch.abs()).max()
50
51 print(
52 f'* {fwdok} check_forward_equal_with_pytorch_double: max_abs_err {max_abs_err:.2e} max_rel_err {max_rel_err:.2e}'
53 )
54
55
56@torch.no_grad()

Callers 1

test.pyFile · 0.85

Calls 4

maxMethod · 0.80
printFunction · 0.50
detachMethod · 0.45

Tested by

no test coverage detected