(x)
| 1978 | bs, length, width = x.size() |
| 1979 | |
| 1980 | def shape(x): |
| 1981 | # (bs, length, width) --> (bs, length, n_heads, dim_per_head) |
| 1982 | x = x.view(bs, -1, self.num_heads, self.dim_per_head) |
| 1983 | # (bs, length, n_heads, dim_per_head) --> (bs, n_heads, length, dim_per_head) |
| 1984 | x = x.transpose(1, 2) |
| 1985 | # (bs, n_heads, length, dim_per_head) --> (bs*n_heads, length, dim_per_head) |
| 1986 | x = x.reshape(bs * self.num_heads, -1, self.dim_per_head) |
| 1987 | # (bs*n_heads, length, dim_per_head) --> (bs*n_heads, dim_per_head, length) |
| 1988 | x = x.transpose(1, 2) |
| 1989 | return x |
| 1990 | |
| 1991 | class_token = x.mean(dim=1, keepdim=True) + self.positional_embedding.to(x.dtype) |
| 1992 | x = torch.cat([class_token, x], dim=1) # (bs, length+1, width) |
nothing calls this directly
no outgoing calls
no test coverage detected