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

Method forward

pointops2/functions/pointops.py:448–482  ·  view source on GitHub ↗

input: q: (N, h, hdim), index_q: (M), k: (N, h, hdim), index_k: (M), table_q: (L, h, hdim, 3), table_k: (L, h, hdim, 3), rel_idx: (M, 3) output: output: [M, h]

(ctx, q, index_q_offsets, n_max, k, index_k, table_q, table_k, rel_idx)

Source from the content-addressed store, hash-verified

446class DotProdWithIdx_v3(Function):
447 @staticmethod
448 def forward(ctx, q, index_q_offsets, n_max, k, index_k, table_q, table_k, rel_idx):
449 """
450 input: q: (N, h, hdim), index_q: (M), k: (N, h, hdim), index_k: (M), table_q: (L, h, hdim, 3), table_k: (L, h, hdim, 3), rel_idx: (M, 3)
451 output: output: [M, h]
452 """
453 assert q.is_contiguous() and index_q_offsets.is_contiguous() and k.is_contiguous() and index_k.is_contiguous() and table_q.is_contiguous() and table_k.is_contiguous() and rel_idx.is_contiguous()
454
455 N, h, hdim = q.shape
456 M = index_k.shape[0]
457 L = table_q.shape[0]
458 assert table_k.shape[0] == L
459
460 # # obtain the mapping from block_idx to m_idx
461 # rel_idx_merge = rel_idx[:, 0] + rel_idx[:, 1] * L + rel_idx[:, 2] * (L ** 2) #[M, ]
462 # sorted_values, sort_indices = torch.sort(rel_idx_merge)
463 # _, counts = torch.unique_consecutive(sorted_values, return_counts=True)
464 # rel_idx_offsets = torch.cumsum(counts, dim=-1) #[T,]
465 # rel_idx_offsets = torch.cat([torch.zeros(1, dtype=torch.long).cuda(), rel_idx_offsets], 0) #[T+1,]
466 # n_max = counts.max()
467 # T = counts.shape[0]
468
469 # print("M: {}, L: {}, n_max: {}, T: {}".format(M, L, n_max, T))
470 # print("rel_idx_merge.shape: {}, sorted_values.shape: {}".format(rel_idx_merge.shape, sorted_values.shape))
471 # print("counts.shape: {}".format(counts.shape))
472
473 # print("M: {}, L: {}, n_max: {}".format(M, L, n_max))
474
475 output = torch.cuda.FloatTensor(M, h).zero_()
476 # pointops_cuda.dot_prod_with_idx_forward_cuda(N, M, h, hdim, q, index, table, rel_idx, output)
477 pointops_cuda.dot_prod_with_idx_forward_cuda_v3(N, M, h, hdim, n_max, q, index_q_offsets, k, index_k, table_q, table_k, rel_idx, output)
478
479 ctx.n_max = n_max
480 # ctx.T = T
481 ctx.save_for_backward(q, index_q_offsets, k, index_k, table_q, table_k, rel_idx)
482 return output
483
484 @staticmethod
485 def backward(ctx, grad_output):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected