update model

This commit is contained in:
gongjy 2024-10-20 15:13:58 +08:00
parent 00e09efb5b
commit 3ff66f7221

View File

@ -27,15 +27,11 @@ class RMSNorm(torch.nn.Module):
return output * self.weight
def precompute_pos_cis(dim: int, end: int, theta: float = 10000.0, train_len: int = 512):
def precompute_pos_cis(dim: int, end: int, theta: float = 10000.0):
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
t = torch.arange(end, device=freqs.device) # type: ignore
freqs = torch.outer(t, freqs).float() # type: ignore
pos_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64
# # 计算缩放因子
# scale = train_len / end
# # 缩放旋转嵌入实现线性的长度外推注释掉不用是因为小模型依赖pos_cis拟合严重直接做线性外推效果并不好
# pos_cis = pos_cis * scale
return pos_cis