| 32 | super(SparseLayerNorm, self).__init__(normalized_shape, eps, elementwise_affine) |
| 33 | |
| 34 | def forward(self, input: VarLenTensor) -> VarLenTensor: |
| 35 | nfeats = torch.zeros_like(input.feats) |
| 36 | for k in range(input.shape[0]): |
| 37 | bfeats = input.feats[input.layout[k]] |
| 38 | bfeats = bfeats.permute(1, 0).reshape(1, input.shape[1], -1) |
| 39 | bfeats = super().forward(bfeats) |
| 40 | bfeats = bfeats.reshape(input.shape[1], -1).permute(1, 0) |
| 41 | nfeats[input.layout[k]] = bfeats |
| 42 | return input.replace(nfeats) |
| 43 | |
| 44 | |
| 45 | class SparseGroupNorm32(SparseGroupNorm): |