feat(m2): Collator — JSONL → wrapper raw batch (T2.5)

- src/tsmm/data/collator.py: Collator maps JSONL sample dicts to the wrapper
  batch contract {series [B,max_T,max_C], attributes, timestamps, events,
  question, answer}. Variable-T pad/truncate, variable-C pad, NaN→fill.
  Variable-text padding/attention_mask deferred to the wrapper's per-sample
  splice + max_seq padding.
- tests/test_collator.py: 11 tests. End-to-end Collator→Wrapper fwd+bwd+generate
  verified (loss finite, peak 2.32 GB, generate emits text). 91 tests passing.
This commit is contained in:
张宗平
2026-06-30 02:14:47 +00:00
parent aec8fd5ef1
commit 7e1df76e3e
3 changed files with 201 additions and 1 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
- [x] 2.2 Projector `model/projector.py``Linear(256→896)+LayerNorm`(验证:输出 `[B,n_patches,896]` 对齐 Qwen2.5-0.5B hidden
- [x] 2.3 多模态拼接 `model/multimodal.py`Qwen tokenizer tokenize 文本部分,TS token 作 inputs_embeds 插入 `[属性][时间戳][TS tok][事件][问题][回答][EOS]`,统一构造 inputs_embeds+attention_mask+labels(仅回答段非 -100)(验证:8 项单测过——seq_len ≤1024、mask 全 1、回答段 label 非 -100、TS token 计入序列、无 NaN、超长左截断)。spec 澄清:训练拼回答+EOS,用 `len(tokenizer)` 构建嵌入表以容纳 special tokens。
- [x] 2.4 训练/推理封装 `model/wrapper.py``MultimodalTSModel` 组合 Encoder+Projector+LLM+LoRA 挂载开关,`forward` 返 loss、`generate` 返文本,支持 `freeze_llm`(阶段①)/`enable_lora(r=16)`(阶段②)(验证:端到端 forward+backward 跑通、grad 流入 Encoder/Projector、generate 出文本、阶段①峰值 1.87GB ≪5GB 设计预算)。spec 澄清:wrapper 既接收原始 batch(series+文本列表)走端到端,也兼容预拼接 inputs_embedsencoder/projector fp32,输出投影到 LLM dtype(bf16)。
- [ ] 2.5 Collator `data/collator.py`JSONL→batch 张量,处理变长 Cpadding+mask)与变长文本padding+attention_mask)(验证:batch=4 张量形状一致无 NaN
- [x] 2.5 Collator `data/collator.py`JSONL→wrapper 原始 batchseries 张量 + attributes/timestamps/events/question/answer 文本列表),处理变长 Tpadding/trunc 到 max_T)与变长 Cpadding 到 max_C)、NaN→fill变长文本 padding/attention_mask 由 wrapper 逐样本 splice+max_seq 填充处理(验证:11 项单测过;端到端 Collator→Wrapper fwd+bwd+generate 跑通
- [ ] 2.6 M2 出口验证:单 batch 前向+反向在 3060 跑通,loss 有限且下降趋势,阶段①模式峰值显存 ~5GB
## 3. M3 · 阶段①对齐训练