MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / rotary

Method rotary

sat/dit_video_concat.py:326–346  ·  view source on GitHub ↗
(self, t, **kwargs)

Source from the content-addressed store, hash-verified

324 self.pos_embedding = None
325
326 def rotary(self, t, **kwargs):
327 if self.pnp:
328 t_coords = kwargs["rope_position_ids"][:, :, 0]
329 x_coords = kwargs["rope_position_ids"][:, :, 1]
330 y_coords = kwargs["rope_position_ids"][:, :, 2]
331 mask = (x_coords != -1) & (y_coords != -1) & (t_coords != -1)
332 freqs = torch.zeros([t.shape[0], t.shape[2], t.shape[3]], dtype=t.dtype, device=t.device)
333 freqs[mask] = self.freqs[t_coords[mask], x_coords[mask], y_coords[mask]]
334
335 else:
336
337 def reshape_freq(freqs):
338 frame = t.shape[2]
339 freqs = freqs[:frame].contiguous()
340 freqs = freqs.unsqueeze(0).unsqueeze(0)
341 return freqs
342
343 freqs_cos = reshape_freq(self.freqs_cos)
344 freqs_sin = reshape_freq(self.freqs_sin)
345
346 return t * freqs_cos + rotate_half(t) * freqs_sin
347
348 def position_embedding_forward(self, position_ids, **kwargs):
349 if self.pos_embedding is not None:

Callers 1

attention_fnMethod · 0.95

Calls 1

rotate_halfFunction · 0.70

Tested by

no test coverage detected