(x)
| 1310 | bs, length, width = x.size() |
| 1311 | |
| 1312 | def shape(x): |
| 1313 | # (bs, length, width) --> (bs, length, n_heads, dim_per_head) |
| 1314 | x = x.view(bs, -1, self.num_heads, self.dim_per_head) |
| 1315 | # (bs, length, n_heads, dim_per_head) --> (bs, n_heads, length, dim_per_head) |
| 1316 | x = x.transpose(1, 2) |
| 1317 | # (bs, n_heads, length, dim_per_head) --> (bs*n_heads, length, dim_per_head) |
| 1318 | x = x.reshape(bs * self.num_heads, -1, self.dim_per_head) |
| 1319 | # (bs*n_heads, length, dim_per_head) --> (bs*n_heads, dim_per_head, length) |
| 1320 | x = x.transpose(1, 2) |
| 1321 | return x |
| 1322 | |
| 1323 | class_token = x.mean(dim=1, keepdim=True) + self.positional_embedding.to(x.dtype) |
| 1324 | x = torch.cat([class_token, x], dim=1) # (bs, length+1, width) |
no test coverage detected