MCPcopy Create free account
hub / github.com/MotrixLab/MotionDiffuse / forward

Method forward

text2motion/datasets/evaluator_models.py:246–261  ·  view source on GitHub ↗

query (batch, query_dim) key (batch, seq_len, key_dim)

(self, query, key_mat)

Source from the content-addressed store, hash-verified

244 self.W_v.apply(init_weight)
245
246 def forward(self, query, key_mat):
247 '''
248 query (batch, query_dim)
249 key (batch, seq_len, key_dim)
250 '''
251 # print(query.shape)
252 query_vec = self.W_q(query).unsqueeze(-1) # (batch, value_dim, 1)
253 val_set = self.W_v(key_mat) # (batch, seq_len, value_dim)
254 key_set = self.W_k(key_mat) # (batch, seq_len, value_dim)
255
256 weights = torch.matmul(key_set, query_vec) / np.sqrt(self.dim)
257
258 co_weights = self.softmax(weights) # (batch, seq_len, 1)
259 values = val_set * co_weights # (batch, seq_len, value_dim)
260 pred = values.sum(dim=1) # (batch, value_dim)
261 return pred, co_weights
262
263 def short_cut(self, querys, keys):
264 return self.W_q(querys), self.W_k(keys)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected