Mixin for forward_list operation on list of tensors.
| 7 | |
| 8 | |
| 9 | class ListForwardMixin(object): |
| 10 | """Mixin for forward_list operation on list of tensors.""" |
| 11 | |
| 12 | def forward(self, x: Tensor): |
| 13 | raise NotImplementedError |
| 14 | |
| 15 | def forward_list(self, x_list: List[Tensor]) -> List[Tensor]: |
| 16 | x_flat, shapes, num_tokens = cat_keep_shapes(x_list) |
| 17 | x_flat = self.forward(x_flat) |
| 18 | return uncat_with_shapes(x_flat, shapes, num_tokens) |
| 19 | |
| 20 | |
| 21 | class Mlp(nn.Module, ListForwardMixin): |
nothing calls this directly
no outgoing calls
no test coverage detected