mirror of
https://github.com/RYDE-WORK/lnp_ml.git
synced 2026-07-21 21:22:05 +08:00
feat: 同步 RAG 融合与训练核心代码(fusion 支持 f_retr、models/trainer/moe/dataset)
This commit is contained in:
parent
3898fb8973
commit
987ecf6386
@ -128,6 +128,7 @@ class ResidualConcatFusion(nn.Module):
|
||||
# 零初始化门控(可学习标量),旁路初始不参与
|
||||
self.g_moe = nn.Parameter(torch.zeros(()))
|
||||
self.g_llm = nn.Parameter(torch.zeros(()))
|
||||
self.g_retr = nn.Parameter(torch.zeros(())) # 检索旁路零初始化门控
|
||||
|
||||
def forward(
|
||||
self,
|
||||
@ -135,6 +136,7 @@ class ResidualConcatFusion(nn.Module):
|
||||
tab: torch.Tensor,
|
||||
f_moe: Optional[torch.Tensor] = None,
|
||||
f_llm: Optional[torch.Tensor] = None,
|
||||
f_retr: Optional[torch.Tensor] = None,
|
||||
return_attn_weights: bool = False,
|
||||
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
|
||||
# 只对真实 token(chem + tab)做注意力池化,旁路不参与 softmax 竞争
|
||||
@ -148,5 +150,7 @@ class ResidualConcatFusion(nn.Module):
|
||||
out = out + self.g_moe * f_moe # 残差 + 零初始化门
|
||||
if f_llm is not None:
|
||||
out = out + self.g_llm * f_llm
|
||||
if f_retr is not None:
|
||||
out = out + self.g_retr * f_retr # 检索旁路,零初始化门保证起点=不开
|
||||
|
||||
return (out, attn) if return_attn_weights else out
|
||||
Loading…
x
Reference in New Issue
Block a user