-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOCS][docs/zeta/nn/modules/fused_dropout_layernorm.md]
- Loading branch information
Kye
committed
Dec 20, 2023
1 parent
c851c73
commit 3dc6384
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
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,52 @@ | ||
import torch | ||
from torch import nn | ||
from zeta.nn.modules.rms_norm import RMSNorm | ||
from zeta.nn.modules.residual import Residual | ||
|
||
|
||
class Mamba(nn.Module): | ||
def __init__( | ||
self, | ||
vocab_size: int, | ||
dim: int, | ||
depth: int, | ||
bias: bool = False, | ||
*args, | ||
**kwargs, | ||
): | ||
super().__init__() | ||
self.embedding = nn.Embedding(vocab_size, dim) | ||
self.layers = nn.ModuleList( | ||
[ | ||
Residual(self.rmsnorm, nn.Linear(dim, dim, bias=bias)) | ||
for _ in range(depth) | ||
] | ||
) | ||
self.rmsnorm = RMSNorm(dim) | ||
self.linear = nn.Linear(dim, vocab_size, bias=bias) | ||
self.linear.weight = self.embedding.weight | ||
|
||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
x = self.embedding(x) | ||
|
||
for layer in self.layers: | ||
x = layer(x) | ||
|
||
x = self.rmsnorm(x) | ||
logits = self.linear(x) | ||
|
||
return logits | ||
|
||
|
||
# class MambaBlock(nn.Module): | ||
# def __init__( | ||
# self, | ||
# dim, | ||
# inner_dim, | ||
# bias: bool = False, | ||
# conv_bias=None, | ||
# dim_conv=None, | ||
# *args, | ||
# **kwargs, | ||
# ): | ||
# super().__init__() |