(
self,
num_experts: int,
in_features: int,
out_features: int,
group_size: int = 32,
)
| 5814 | """Model using quantized SwitchLinear for expert selection + matmul.""" |
| 5815 | |
| 5816 | def __init__( |
| 5817 | self, |
| 5818 | num_experts: int, |
| 5819 | in_features: int, |
| 5820 | out_features: int, |
| 5821 | group_size: int = 32, |
| 5822 | ): |
| 5823 | super().__init__() |
| 5824 | from executorch.backends.mlx.llm.quantization import quantize_model_ |
| 5825 | from executorch.backends.mlx.llm.switch import SwitchLinear |
| 5826 | |
| 5827 | self.switch = SwitchLinear(in_features, out_features, num_experts) |
| 5828 | quantize_model_( |
| 5829 | nn.ModuleDict({"switch": self.switch}), |
| 5830 | qlinear_config="4w", |
| 5831 | qlinear_group_size=group_size, |
| 5832 | ) |
| 5833 | self.switch.pack() |
| 5834 | |
| 5835 | def forward(self, x: torch.Tensor, indices: torch.Tensor) -> torch.Tensor: |
| 5836 | return self.switch(x, indices) |
nothing calls this directly
no test coverage detected