(
self,
q: torch.Tensor,
k: torch.Tensor,
v: torch.Tensor,
)
| 61 | |
| 62 | |
| 63 | def forward( |
| 64 | self, |
| 65 | q: torch.Tensor, |
| 66 | k: torch.Tensor, |
| 67 | v: torch.Tensor, |
| 68 | ) -> torch.Tensor: |
| 69 | # torch.Size([128, 4, 16, 32]) |
| 70 | q, k, v = (rearrange(x, 'n b h d -> b h n d') for x in (q, k, v)) |
| 71 | |
| 72 | q, k = self.la_feature_map_fn(q, flatten=(self.la_mode != 'parallel')), self.la_feature_map_fn(k, flatten=(self.la_mode != 'parallel')) |
| 73 | |
| 74 | # expects q: B, H, T, K |
| 75 | if self.la_mode in ['chunk', 'fused_chunk']: |
| 76 | output, _ = self._la_impl(q, k, v, normalize=True, scale=1) |
| 77 | elif self.la_mode == 'parallel': |
| 78 | assert q.shape[-1] <= 128 |
| 79 | output, _ = self._la_impl(q, k, v, self.la_eps, True, True) |
| 80 | |
| 81 | output = rearrange(output, 'b h n d -> n b (h d)') |
| 82 | return output |
nothing calls this directly
no outgoing calls
no test coverage detected