OwnerSunshine530
cdc2dd490b
feat: Triton varlen因果flash attention(块对角,单kernel,消逐块调用+mask构造开销)
...
每program处理(用户段query块,head),只遍历段内<=该块的key(因果),在线softmax,
fp16读写fp32累加。CONFIG.attn=triton(默认仍chunked);_triton_block_meta每batch算一次
block→段映射8层复用;_resolve_attn在无triton/CPU时回退chunked。等价测试+bench --attn triton。
数学等价(FlashAttention同类,规则允许),不改组网。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-17 00:14:53 +08:00
OwnerSunshine530
4ea6d57a07
feat: movedev_rep — 在move_batch_to_device(不计时/主进程/有模型有数据)算rep,model跳过embedding
...
collate_rep 评测端回退(疑num_workers>0子进程无模型)。move_batch_to_device官方明确不计入、
在主进程model(batch)之前调用→有CUDA+_MODEL_REF+batch数据,避开数据访问/调用顺序/子进程三大坑。
rep逐位等价。bench --no-movedev-rep 对照。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-16 19:37:34 +08:00
OwnerSunshine530
e1ad26867e
feat: collate_rep — 在collate_fn(定义上不计时)就地算RepEncoder存batch[rep],model跳过embedding
...
collate 在两次model(batch)之间运行(取下一batch),永不在计时窗口;且必有数据、必在
load_model之后。比load_model预计算(3连回退)可靠。rep逐位等价(同rep_encoder同batch)。
load_model设_MODEL_REF供collate用;forward优先用batch[rep]。bench重排load_model先于建batch
以本地复现;默认collate_rep=True,--no-collate-rep对照。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-16 18:49:55 +08:00
OwnerSunshine530
9042655fed
fix: 修OOM — load_model预计算改流式只加载测试用户+直接逐item算(不建Dataset)+算完释放
...
评测异常根因:load_model全量load_sample_files与评测自身数据双倍内存OOM。
改:_load_test_user_items流式过滤(仅测试用户~1.5M)、build_rep_cache直接从item_dict
逐item算(省掉user_items~8GB拷贝)、算完del+gc。bench加--eval-precompute本地真跑
load_model这条路验证不OOM。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-16 12:19:30 +08:00
OwnerSunshine530
2004ad6bb8
feat: 预计算RepEncoder缓存,model(batch)按logid gather跳过embedding层
...
不计时的load_model里(或bench从batches)预计算所有item的context-free RepEncoder向量,
排序存(sorted_logids,emb);model(batch)用searchsorted gather、缺失回退现算。逐位等价。
预期 model(batch) 48s->~37s->~70。CONFIG.precompute_rep(eval默认True);bench --precompute-rep。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 17:06:56 +08:00
OwnerSunshine530
6625666010
feat: sparse_pool 选项 — (段×唯一)稀疏矩阵乘做池化,避免materialize[M,emb]
...
针对 profile 的 dedup展开(15%)+segment_reduce(6.6%)。段内高重复(slot19)塌缩
为单个带权项。CONFIG.sparse_pool;bench --sparse-pool;等价测试已加。默认关,待验证。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 15:15:13 +08:00
OwnerSunshine530
2268fa6cf3
feat: dedup_embedding 选项 — 查表前对sign去重(slot19等高重复),减少大表随机访存
...
profile显示embedding查表现为头号瓶颈(32%)。torch.unique去重后只查唯一sign
再按逆索引展开,数学逐位等价(AUC不变),省最贵的大表随机gather。bench --dedup-emb。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 14:07:23 +08:00
OwnerSunshine530
3d28f61a98
feat: 分块SDPA注意力(--attn chunked),按用户边界切块降O(S²)
...
每块~chunk_users个用户、块内因果SDPA(评测端已验证、无嵌套开销),sum(块S²)
远小于总S²。仅1次同步读切分边界。之前本地bs=16快13%被MoE同步吃掉,现MoE
同步已消除,切块红利应全露出。CONFIG.attn=chunked/chunk_users;等价测试已加。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 13:13:13 +08:00
OwnerSunshine530
adc99b5b41
feat: emb_fp16 选项(Embedding表转FP16,查表带宽减半);bench --emb-fp16
...
embedding查表是显存带宽瓶颈(profile 16%);FP16表读一半字节。按token量算应
能等比例翻译到评测。代价:embedding权重存FP16微小精度损失,须先测AUC。默认关。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 12:26:55 +08:00
OwnerSunshine530
7791674a32
feat: 嵌套张量变长 flash 注意力(--attn varlen),统一 CONFIG.attn 分发
...
每用户当独立序列、is_causal 块对角因果,一个 flash 内核处理一 batch 内所有
用户,无稠密mask/无padding浪费/开销远低于FlexAttention。CONFIG.attn∈
{sdpa(默认),flex,varlen};bench --attn varlen;test_equiv 加 varlen 等价测试。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 09:06:11 +08:00
OwnerSunshine530
9eaf5f5511
fix: Phase B 实测回归(flex+dense慢5-6x),默认回退 sdpa+loop;bench 加 --profile
...
实测 A800:sdpa+loop=15.15s,flex+dense=98s,+compile=82s。模型是开销瓶颈
非算力瓶颈(30TFLOP应0.15s却跑15s),FlexAttention解决的算力问题非此处瓶颈、
反增开销。默认改回已验证最快的 sdpa+loop。新增 bench --profile 用 torch.profiler
定位真正的开销来源(算子级)。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-15 00:25:53 +08:00
OwnerSunshine530
c1d8b91fb2
feat(Phase B): FlexAttention 块对角注意力 + MoE 稠密向量化
...
- scaled_dot_product 分发:block_mask->FlexAttention(每用户仅自身序列内因果,
避免对~14000长拼接序列做O(S²)稠密注意力);否则SDPA稠密(回退/对照)。
- CTRModel.build_block_mask 构造块对角因果mask;_use_flex 在SM80+自动启用。
- SMoE 稠密向量化(einsum批量算所有expert后按top-k gather),消除Python循环/同步;
保留 _smoe_forward_loop 作数值等价对照。CONFIG.vectorize_moe 可切。
- load_model 加可选 torch.compile。
- tests/test_equiv.py:MoE稠密vs循环、Flex vs稠密SDPA 数值等价(无pytest依赖)。
- bench.py 加 --attn/--moe/--compile 便于A800上对比测速。
需 A800(SM80) 实测;CPU/V100 自动回退 SDPA。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 23:30:59 +08:00
OwnerSunshine530
0a971e67ac
fix: 缓存改用文本CSV(逐行写)替代pickle,避免容器cgroup OOM静默杀进程
...
pickle.dump 150万记录的memo瞬间撑爆容器内存上限被杀;改为流式逐行写
保留的历史行到 cache_filtered_history.csv,读回用 load_sample_files。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 22:47:17 +08:00
OwnerSunshine530
8855a75cc3
fix: 缓存直接写+fsync,去掉会误删的写后校验
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 22:32:59 +08:00
OwnerSunshine530
e7b542a389
fix: 缓存原子写+fsync+校验,diag 先打印再缓存(防卡住看不到诊断)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 22:07:48 +08:00
OwnerSunshine530
8328327497
fix: bench 缓存改用 pickle(torch.load 在 overlay fs 报 Errno 38)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 21:47:21 +08:00
OwnerSunshine530
4257df795f
feat: bench.py 加 --diag 诊断模式(序列长度分布 + sign-id 超界比例)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 21:38:50 +08:00
OwnerSunshine530
c0c23ad224
fix: bench.py 只保留测试用户数据(流式过滤+磁盘缓存),解决 OOM 与 16min 重载
...
不同用户被因果mask隔离,过滤非测试用户对测试样本AUC/PCOC零影响。
流式加载只持有测试用户记录,避免 CTRTestSeqDataset 构造期 OOM;
过滤结果缓存到 bench_filtered_cache.pt,后续秒级复用。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 21:12:15 +08:00
OwnerSunshine530
8c1d1cbaa5
feat: bench.py 加命令行参数,支持子进程方式跑(绕开内核torch限制)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 19:53:21 +08:00
OwnerSunshine530
ab9c624167
fix: bench.py 在 import torch 前补上 baseline 的 libraries 路径
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 19:46:21 +08:00
OwnerSunshine530
9d5a5a52f2
feat: infer.py 接入 CONFIG 实验开关 + 新增 bench.py 测量闭环
...
- infer.py: 模块级 CONFIG(fp16/keep_fp32_modules/expert_merge/
merge_threshold/signid_mode/sync_timing),默认值=当前最优行为;
load_model 按 CONFIG 控制半精度/FP32敏感层/expert合并;
RepEncoder 支持 clamp/modulo 两种 sign-id 处理;
新增 _force_fp32_io 钩子让敏感层在FP16模型里以FP32 IO 计算。
- bench.py: 设置 CONFIG → 跑推理 → cuda.synchronize 真实计时 →
_cal_score 打印 AUC/PCOC/延迟/总分,支持配置/batch扫描。不进提交包。
- EXPERIMENTS.md: 实验记录表。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-14 16:48:38 +08:00