feat(m2): Projector Linear(256→896)+LayerNorm (T2.2)

- src/tsmm/model/projector.py: Projector (Linear + LayerNorm).
- tests/test_projector.py: 5 tests (shape, Qwen hidden alignment,
  LayerNorm present, gradient flow, no-NaN).
- 66 tests passing.
This commit is contained in:
张宗平
2026-06-30 00:17:47 +00:00
parent 545802d62c
commit f20c2db803
3 changed files with 58 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
"""Projector (T2.2): maps TS tokens from encoder dim to LLM hidden dim.
``Linear(d → h)`` + ``LayerNorm``. Output feeds as soft tokens into the LLM
``inputs_embeds`` (see ``model/multimodal.py``, T2.3).
Design ref: §2.2 — Projector = Linear(256→896) + LayerNorm.
"""
from __future__ import annotations
import torch
from torch import nn
class Projector(nn.Module):
def __init__(self, in_dim: int = 256, out_dim: int = 896) -> None:
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.norm = nn.LayerNorm(out_dim)
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: [..., in_dim] → [..., out_dim]
return self.norm(self.linear(x))