mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-10 00:06:06 +08:00
27 lines
573 B
Python
27 lines
573 B
Python
import torch
|
|
import torch.nn as nn
|
|
|
|
from cacheflow import layernorm_ops
|
|
|
|
|
|
class RMSNorm(nn.Module):
|
|
|
|
def __init__(
|
|
self,
|
|
hidden_size: int,
|
|
eps: float = 1e-6,
|
|
) -> None:
|
|
super().__init__()
|
|
self.weight = nn.Parameter(torch.ones(hidden_size))
|
|
self.variance_epsilon = eps
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
out = torch.empty_like(x)
|
|
layernorm_ops.rms_norm(
|
|
out,
|
|
x,
|
|
self.weight.data,
|
|
self.variance_epsilon,
|
|
)
|
|
return out
|