Commit Graph

74 Commits

Author SHA1 Message Date
Serendipity 7b429cf7fb feat: torch.compile 全模型 + dynamic=True(告知编译器形状可变,避免重编译) 2026-06-13 14:37:38 +08:00
Serendipity 480a81a033 fix: torch.compile mode 改为 default(避免 CUDA Graph 因 N 变化重编译) 2026-06-13 14:20:14 +08:00
Serendipity a74af49456 feat: torch.compile 单独编译 Expert.forward(fc1→relu→fc2 融合)
- 仅编译 Expert.forward,不碰 MoE 循环和 attention
- 纯静态函数无分支,编译成功率高
- 替代 2:4 稀疏方案
2026-06-13 14:20:01 +08:00
Serendipity 4dbee83097 feat: 2:4 非结构化稀疏仅裁剪 Expert FFN(不碰 attention/gate)
- 合规:单个权重置零,矩阵形状不变
- 只裁剪 8层×8expert×2fc = 128 个 Expert Linear
- lambda forward 直调 sparse matmul,绕开 nn.Linear 兼容问题
2026-06-13 14:09:42 +08:00
Serendipity 788ca96d50 revert: 移除 INT8 量化和 k=1 补偿,回到稳定版 58.49 2026-06-13 14:05:19 +08:00
Serendipity 96462444f6 feat: INT8 动态量化所有 Linear 层(torch.ao.quantization)
- 仅量化 Linear 权重(不影响 Embedding)
- INT8 权重读带宽减半 vs FP16
- try-except 保护:CUDA 后端不可用时回退 FP16
2026-06-13 13:53:45 +08:00
Serendipity c081620ffd feat: MoE Top-1 路由 + (p1+p2) 权重补偿
- 仅路由到 Top-1 expert(节省 50% FFN 计算)
- gate 输出 top-2 概率,用 p1+p2 作为输出权重
- 近似 k=2 的输出幅度,避免 PCOC 偏移
- 是参数调整修正,非方案本身错误
2026-06-13 13:32:04 +08:00
Serendipity da37245a9b perf: SMoE 消除 GPU 同步 + CTRModel 去冗余 reshape
1. SMoE: 移除 if not mask.any()(64次GPU→CPU同步/forward)
   - k=2时每个expert都分到token,检查从不跳过
   - 改用 token_idx.numel()==0 判断(元数据操作,不同步)
2. SMoE: out_flat reshape 提到循环外(省7次重复)
3. CTRModel: encoder_output.reshape().squeeze() → .squeeze()
2026-06-13 13:16:01 +08:00
Serendipity 7e0876c671 revert: RepEncoder 批量 embedding 查表(94.3s vs 92.5s,略慢)
回退到稳定版:FP16 + Flash Attention + inference_mode(57.45 分)
2026-06-13 13:05:14 +08:00
Serendipity 9128b60e9d perf: RepEncoder 批量 embedding 查表(28 次 kernel launch → 1 次)
所有 slot 的 sign id 合并为一次 embedding lookup,再按 slot 拆分做 segment_reduce。
数学等价,纯 GPU 算子优化。
2026-06-13 12:36:25 +08:00
Serendipity e69ba714e5 revert: 移除 2:4 稀疏(PCOC 2.067 + 耗时反增 265s,to_sparse_semi_structured 与 nn.Linear 不兼容)
回退到稳定版:FP16 + Flash Attention + inference_mode(57.45 分)
2026-06-13 12:34:29 +08:00
Serendipity 43b0c6c92a feat: 2:4 结构化稀疏(A800 原生加速,所有 Linear 层权重剪枝)
- 每 4 个连续权重保留幅度最大的 2 个(50% 稀疏度)
- torch.sparse.to_sparse_semi_structured 硬件加速 matmul
- 权重形状不变,属参数级剪枝,合规
- try-except 保护:稀疏化失败时回退 dense 权重
2026-06-13 12:20:40 +08:00
Serendipity 1cf1024368 revert: 移除 torch.compile(default 模式也因动态 batch 形状导致编译开销 > 收益)
保留 inference_mode + FP16 + Flash Attention(当前最优 56.98 分)
2026-06-13 12:07:28 +08:00
Serendipity faedab5245 revert: MoE k=1 → k=2(PCOC 从 1.059 炸到 2.075,Top-1 破坏输出校准)
保留 inference_mode + torch.compile(default)
2026-06-13 11:50:30 +08:00
Serendipity f7e1fbfbdc feat: inference_mode + torch.compile(default)
- torch.no_grad() → torch.inference_mode()(禁梯度+禁版本追踪,更快)
- torch.compile(mode='default'):纯算子融合,不用 CUDA Graph,兼容动态 batch 形状
2026-06-12 22:11:35 +08:00
Serendipity feb71be5bd feat: MoE Top-1 gating(每个 token 仅激活 1 个 expert,FFN 计算减半)
- SMoE 默认 k=2 → k=1(属于稀疏优化,规则允许)
- TransformerEncoder 8 层全部改用 Top-1 gating
- forward 针对 k=1 走快速路径(避免二维 mask 和加权累加)
2026-06-12 22:04:34 +08:00
Serendipity bc6e8307c5 revert: 移除 torch.compile(动态 batch 形状导致反复重编译,反而慢于不编译)
Sequence Packing 使每个 batch 序列长度不同,CUDA Graph 需反复重编译。
Flash Attention + FP16 是目前最优组合(94.5s, 56.98 分)。
2026-06-12 22:02:40 +08:00
Serendipity 61bab9d0e3 fix: build_env.sh 简化为纯净版本(避免 CUDA 预热导致异常) 2026-06-12 21:55:09 +08:00
Serendipity 574399e8ac feat: Flash Attention + torch.compile(第二版优化方案)
- scaled_dot_product 替换为 F.scaled_dot_product_attention(自动启用 Flash Attention)
- load_model 中添加 torch.compile(mode='reduce-overhead')
- build_env.sh: 预热 torch inductor,避免编译耗时计入推理
2026-06-12 21:39:43 +08:00
Serendipity c53a936e81 revert: requirements.txt 还原为原始完整依赖列表 2026-06-12 21:24:22 +08:00
Serendipity 47545efd43 fix: RepEncoder forward 中 Embedding FP32 输出显式转为后续层 dtype
修复 FP16 量化后 dtype 不匹配:Embedding 保留 FP32 时,forward 输出需 .to(target_dtype) 对齐后续 LayerNorm/Linear
2026-06-12 21:22:06 +08:00
Serendipity 03bab0f7e5 chore: 更新 notebook 环境和文档
- main.ipynb: 更新 kernel 配置(Python 3.13)
- README.md: 更新项目说明
- 论文/HSTU.md: 移除(已被 PDF 版本替代)
2026-06-12 20:51:14 +08:00
Serendipity 4ee08adff5 feat: 接口对齐 + FP16 量化(第一版优化方案)
- CTRUserDataset → CTRTestSeqDataset,构造参数对齐评测接口
- load_model 签名修正:ckpt_path 作为第一参数
- FP16 量化:model.half() + Embedding 保留 FP32
- move_batch_to_device 自动 FP32→FP16 转换
- 缓存时预转 FP16,减少推理循环开销
- requirements.txt 精简(去除 nvidia-* 包)
- build_env.sh 标准化(set -e + pip install)
- CLAUDE.md 更新开发命令、代码架构、关键接口说明
2026-06-12 20:47:12 +08:00
Serendipity d0bbb8f3e2 chore: 初始化 CTI 推理优化项目
- baseline infer.py + requirements.txt + build_env.sh
- GRAB / HSTU 两篇核心论文
- 比赛规则和提交接口说明
- 项目 CLAUDE.md
2026-06-03 13:49:30 +08:00