norm.py 426 Bytes
Newer Older
Haotian Tang's avatar
Haotian Tang committed
1
2
3
4
import torch
from torch import nn
import awq_inference_engine

Casper Hansen's avatar
Casper Hansen committed
5
class FasterTransformerRMSNorm(nn.Module):
Haotian Tang's avatar
Haotian Tang committed
6
7
8
9
10
11
12
13
14
    def __init__(self, weight, eps=1e-6):
        super().__init__()
        self.weight = weight
        self.variance_epsilon = eps

    def forward(self, x):
        output = torch.empty_like(x)
        awq_inference_engine.layernorm_forward_cuda(x, self.weight, output, self.variance_epsilon)
        return output