MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / DotProdWithIdx

Class DotProdWithIdx

pointops2/functions/pointops.py:320–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318attention_step2_v2 = AttentionStep2_v2.apply
319
320class DotProdWithIdx(Function):
321 @staticmethod
322 def forward(ctx, q, index, table, rel_idx):
323 """
324 input: q: (N, h, hdim), index: (M), table: (L, h, hdim, 3), rel_idx: (M, 3)
325 output: output: [M, h]
326 """
327 assert q.is_contiguous() and index.is_contiguous() and table.is_contiguous() and rel_idx.is_contiguous()
328
329 N, h, hdim = q.shape
330 M = index.shape[0]
331
332 output = torch.cuda.FloatTensor(M, h).zero_()
333 pointops_cuda.dot_prod_with_idx_forward_cuda(N, M, h, hdim, q, index, table, rel_idx, output)
334 ctx.save_for_backward(q, index, table, rel_idx)
335 return output
336
337 @staticmethod
338 def backward(ctx, grad_output):
339 """
340 input: grad_output: [M, h]
341 output: (N, h, hdim), None, (L, h, hdim, 3), None
342 """
343 q, index, table, rel_idx = ctx.saved_tensors
344 M, h = grad_output.shape
345 N, _, hdim = q.shape
346 L = table.shape[0]
347
348 grad_output = grad_output.contiguous()
349 assert q.is_contiguous() and index.is_contiguous() and table.is_contiguous() and rel_idx.is_contiguous() and grad_output.is_contiguous()
350
351 # print("back: attn[:5,:5]: ", attn[:5, :5])
352
353 # print("attn.shape: {} v.shape: {}, index0.shape: {}, index1.shape: {}".format(attn.shape, v.shape, index0.shape, index1.shape))
354
355 grad_q = torch.cuda.FloatTensor(N, h, hdim).zero_()
356 grad_table = torch.cuda.FloatTensor(L, h, hdim, 3).zero_()
357
358 # torch.cuda.synchronize()
359 # start = time.time()
360
361 pointops_cuda.dot_prod_with_idx_backward_cuda(N, M, h, hdim, grad_output, q, index, table, rel_idx, grad_q, grad_table)
362
363 # torch.cuda.synchronize()
364 # end = time.time()
365 # print("time v9: {}".format(end - start))
366 # # input()
367
368 return grad_q, None, grad_table, None
369
370dot_prod_with_idx = DotProdWithIdx.apply
371

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected