-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from torch import nn | ||
|
||
|
||
class MoELayer(nn.Module): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
"""DON'T USE THIS MODULE: Under development.""" | ||
from abc import ABC | ||
from enum import Enum, auto | ||
|
||
from torch import nn | ||
|
||
class MoERouter(ABC): | ||
|
||
class RouterType(Enum): | ||
"""An enum for router types.""" | ||
|
||
TOP_1 = auto() | ||
TOP_2 = auto() | ||
|
||
|
||
class Router(ABC): | ||
pass | ||
|
||
|
||
class Top1Router(Router, nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, inputs): | ||
pass | ||
|
||
|
||
def get_router(router_type: RouterType) -> Router: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
import torch | ||
|
||
from pipegoose.nn.expert_parallel.routers import RouterType, get_router | ||
|
||
|
||
@pytest.mark.parametrize("router_type", [RouterType.TOP_1]) | ||
def test_topk_router(router_type): | ||
SEQ_LEN = 10 | ||
HIDDEN_DIM = 64 | ||
N_EXPERTS = 5 | ||
|
||
inputs = torch.randn(SEQ_LEN, HIDDEN_DIM) | ||
router = get_router(router_type)( | ||
n_experts=N_EXPERTS, | ||
) | ||
|
||
outputs = router(inputs) | ||
|
||
assert isinstance(outputs, torch.Tensor) |