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

Method forward

pointops2/functions/pointops.py:144–164  ·  view source on GitHub ↗

input: q: (N, h, C//h), k: (N, h, C//h), index0: (M), index1: (M) output: output: [N, h, C//h]

(ctx, q, k, index1, index0_offsets, n_max)

Source from the content-addressed store, hash-verified

142class AttentionStep1_v2(Function):
143 @staticmethod
144 def forward(ctx, q, k, index1, index0_offsets, n_max):
145 """
146 input: q: (N, h, C//h), k: (N, h, C//h), index0: (M), index1: (M)
147 output: output: [N, h, C//h]
148 """
149 assert q.is_contiguous() and k.is_contiguous() and index0_offsets.is_contiguous() and index1.is_contiguous()
150 assert n_max <= 1024
151
152 N_q, h, C_div_h = q.shape
153 N_k = k.shape[0]
154 M = index1.shape[0]
155 C = int(C_div_h * h)
156
157 output = torch.cuda.FloatTensor(M, h).zero_()
158 pointops_cuda.attention_step1_forward_cuda_v2(N_k, M, h, C, n_max, q, k, index0_offsets, index1, output)
159 ctx.N_q = N_q
160 ctx.N_k = N_k
161 ctx.C = C
162 ctx.n_max = n_max
163 ctx.save_for_backward(q, k, index0_offsets, index1)
164 return output
165
166 @staticmethod
167 def backward(ctx, grad_output):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected