This file contains hidden or 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
class NgramBlock(nn.Module): | |
requires_input_ids = True | |
def __init__(self, config, ngram): | |
""" | |
parameter size 4d^2 | |
""" | |
super().__init__() | |
self.ln_1 = RMSNorm(config.d_model, eps=1e-5) | |
This file contains hidden or 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
import torch | |
if __name__ == "__main__": | |
N, d = 128, 256 | |
dtype = torch.float32 | |
A = torch.randn((N, N), dtype=dtype).cuda().requires_grad_(True) | |
p = torch.randn((N, ), dtype=dtype).uniform_(0.1, 0.9).cuda().requires_grad_(True) | |
o1 = A @ p | |
o1.sum().backward() |