(x)
| 588 | bs, length, width = x.size() |
| 589 | |
| 590 | def shape(x): |
| 591 | # (bs, length, width) --> (bs, length, n_heads, dim_per_head) |
| 592 | x = x.view(bs, -1, self.num_heads, self.dim_per_head) |
| 593 | # (bs, length, n_heads, dim_per_head) --> (bs, n_heads, length, dim_per_head) |
| 594 | x = x.transpose(1, 2) |
| 595 | # (bs, n_heads, length, dim_per_head) --> (bs*n_heads, length, dim_per_head) |
| 596 | x = x.reshape(bs * self.num_heads, -1, self.dim_per_head) |
| 597 | # (bs*n_heads, length, dim_per_head) --> (bs*n_heads, dim_per_head, length) |
| 598 | x = x.transpose(1, 2) |
| 599 | return x |
| 600 | |
| 601 | class_token = x.mean(dim=1, keepdim=True) + self.positional_embedding.to(x.dtype) |
| 602 | x = torch.cat([class_token, x], dim=1) # (bs, length+1, width) |
no test coverage detected