Download reference/code/Diffulex-mbd-lms/diffulex/moe/topk/base.py from Ouzhang/hku_diffusion_dllm: direct link, hf CLI and curl.
- Browser
- Download file 653 Bytes
-
https://huggingface.co/Ouzhang/hku_diffusion_dllm/resolve/main/reference/code/Diffulex-mbd-lms/diffulex/moe/topk/base.py
- Command line
-
hf download hf://Ouzhang/hku_diffusion_dllm/reference/code/Diffulex-mbd-lms/diffulex/moe/topk/base.py
-
curl -L -o base.py https://huggingface.co/Ouzhang/hku_diffusion_dllm/resolve/main/reference/code/Diffulex-mbd-lms/diffulex/moe/topk/base.py
653 Bytes
| from __future__ import annotations | |
| from abc import ABC, abstractmethod | |
| import torch | |
| import torch.nn as nn | |
| from diffulex.moe.topk.output import TopKOutput | |
| class TopKRouter(nn.Module, ABC): | |
| """Top-k expert selection for MoE inference.""" | |
| def __init__( | |
| self, | |
| top_k: int, | |
| *, | |
| renormalize: bool = True, | |
| scoring_func: str = "softmax", | |
| ) -> None: | |
| super().__init__() | |
| self.top_k = top_k | |
| self.renormalize = renormalize | |
| self.scoring_func = scoring_func | |
| def forward(self, router_logits: torch.Tensor) -> TopKOutput: | |
| raise NotImplementedError | |