[Hunyuan]: add Hunyuan Dense V1 causal language model support - #4767
[Hunyuan]: add Hunyuan Dense V1 causal language model support#4767KissrainKlein wants to merge 12 commits into
Conversation
|
Thanks for your contribution! |
PaddleFormers Log Analysis
日志分析报告
失败的测试 case: 根本原因分析: PR 新增 Hunyuan Dense V1 模型,引入了三类问题:
修复建议:
🔄 每次 Re-run 后自动更新 |
|
建议在PaddleFormers/paddleformers/datasets/template/template.py中增加hunyuan模版,可参考: |
|
paddleformers/transformers/glm4/modeling.py和tests/transformers/glm4/test_glm4.py中的所有中文注释都需要改成英文或者直接删除 |
risemeup1111
left a comment
There was a problem hiding this comment.
已复查,当前还有需要修正的阻塞点,细节都在行内评论里。另有一条非行级的范围建议:
优先级:P3 非行级:
glm4目录也被带进了这次 diff,但auto/configuration.py/auto/modeling.py/ 顶层导出还没接上,和当前标题/描述的 Hunyuan 范围也不一致。请确认这部分是否要一起合入;如果要合入,请补齐注册和说明,否则建议拆到独立 PR。处理要求:请针对该评论进行回复(同意并已修改请回复 Done,不同意请说明理由)。
|
|
||
|
|
||
| # Exact Hugging Face architecture name used by Hunyuan Dense V1 checkpoints. | ||
| HunYuanDenseV1ForCausalLM = HunyuanForCausalLM |
There was a problem hiding this comment.
优先级:P1
这里目前只补了 HunYuanDenseV1ForCausalLM,但 auto/modeling.py 会按最长前缀把 HunYuanDenseV1ForCausalLM 解析成 HunYuanDenseV1Model。现在这个别名不存在,所以 AutoModel.from_pretrained() 遇到 Hunyuan Dense V1 checkpoint 时会直接找不到类。处理要求:请针对该评论修复并提交新的 commit。
建议至少补一个:
HunYuanDenseV1Model = HunyuanModel如果还要支持 pipe / 任务头,再在对应类定义后补同名 alias。
| "hunyuan.modeling": [ | ||
| "HunyuanModel", | ||
| "HunyuanPretrainedModel", | ||
| "HunyuanForCausalLM", | ||
| "HunYuanDenseV1ForCausalLM", | ||
| "HunyuanForCausalLMPipe", | ||
| ], |
There was a problem hiding this comment.
优先级:P2
这里的顶层 lazy import 还是只暴露了基础模型和 CausalLM,HunyuanForSequenceClassification / HunyuanForTokenClassification / HunyuanSentenceEmbedding 仍然无法从 paddleformers.transformers 直接导入。既然这次 PR 已经新增了这些类,建议把它们也加进顶层导出;paddleformers/transformers/hunyuan/__init__.py 里最好同步一份。处理要求:请针对该评论进行回复(同意并已修改请回复 Done,不同意请说明理由)。
| "hunyuan.modeling": [ | |
| "HunyuanModel", | |
| "HunyuanPretrainedModel", | |
| "HunyuanForCausalLM", | |
| "HunYuanDenseV1ForCausalLM", | |
| "HunyuanForCausalLMPipe", | |
| ], | |
| "hunyuan.modeling": [ | |
| "HunyuanModel", | |
| "HunyuanPretrainedModel", | |
| "HunyuanForCausalLM", | |
| "HunYuanDenseV1ForCausalLM", | |
| "HunyuanForCausalLMPipe", | |
| "HunyuanForSequenceClassification", | |
| "HunyuanForTokenClassification", | |
| "HunyuanSentenceEmbedding", | |
| "HunyuanForCausalLMFleet", | |
| "HunyuanForCausalLMPipeFleet", | |
| ], |
|
需要解决代码冲突 |
| class HunyuanForCausalLMPipe(HunyuanForCausalLM): | ||
| config_class = HunyuanConfig | ||
| _decoder_layer_cls = HunyuanDecoderLayer | ||
| _get_tensor_parallel_mappings = HunyuanModel._get_tensor_parallel_mappings |
There was a problem hiding this comment.
这里在模块导入阶段读取 HunyuanModel._get_tensor_parallel_mappings,但该方法既没有在 Hunyuan 模型中定义,也不在 PretrainedModel 基类中提供。因此加载 paddleformers.transformers.hunyuan.modeling(包括顶层 lazy import 首次访问 Hunyuan)会在类定义时直接抛出 AttributeError,整个 Hunyuan 实现无法导入。请为 HunyuanModel 实现实际的 tensor-parallel mapping(并覆盖所需权重布局),或移除该引用并提供正确的 pipe 映射。
risemeup1111
left a comment
There was a problem hiding this comment.
| 序号 | 位置 | 优先级 | 状态 |
|---|---|---|---|
| 1 | hunyuan/modeling.py:1236 | 🚧 | |
| 2 | hunyuan/modeling.py:1230 | 🚧 | |
| 3 | transformers/init.py:211 | 🚧 |


本 PR 完成 Hunyuan Dense V1 从 Transformers 到 PaddleFormers 的迁移,包含组网、前向精度、前 10 token 生成对齐、GSM8K 训练 loss 曲线对比和模型单测验证。
1. 模型实现与注册
paddleformers/transformers/hunyuan/configuration.pypaddleformers/transformers/hunyuan/modeling.pypaddleformers/transformers/hunyuan/tokenizer.pypaddleformers/transformers/hunyuan/tokenizer_fast.pyhunyuan_v1_dense配置识别,并完成AutoConfig、AutoModel、AutoModelForCausalLM注册。2. 前向精度对齐
Hunyuan-0.5B-Instructrtol=1e-3, atol=1e-2的allclose。2.6464462e-051.9950181e-063. 生成前向进度对齐
相同权重、greedy decoding(
do_sample=False)和max_new_tokens=32下,使用 5 个中英文 prompt 验证生成前向进度:case1:
HF first 10 new token ids: [120029, 185, 3125, 270, 3890, 558, 14746, 507, 17687, 2842]
Paddle first 10 new token ids: [120029, 185, 3125, 270, 3890, 558, 14746, 507, 17687, 2842]
case2:
HF first 10 new token ids: [120029, 185, 3125, 270, 3890, 14116, 58131, 1668, 292, 2733]
Paddle first 10 new token ids: [120029, 185, 3125, 270, 3890, 14116, 58131, 1668, 292, 2733]
case3:
HF first 10 new token ids: [120029, 185, 56520, 11, 252, 2388, 316, 14053, 356, 252]
Paddle first 10 new token ids: [120029, 185, 56520, 11, 252, 2388, 316, 14053, 356, 252]
case4:
HF first 10 new token ids: [120029, 185, 3890, 3030, 1115, 2150, 507, 16, 10, 16]
Paddle first 10 new token ids: [120029, 185, 3890, 3030, 1115, 2150, 507, 16, 10, 16]
case5:
HF first 10 new token ids: [120029, 185, 3125, 270, 3890, 14116, 1824, 507, 7331, 12523]
Paddle first 10 new token ids: [120029, 185, 3125, 270, 3890, 14116, 1824, 507, 7331, 12523]
4. 训练 loss 曲线对比
4.2857143e-10。2.35067931262.35830187800.77519954680.94775789980.16269181785. 模型单测
新增
tests/transformers/hunyuan/test_modeling.py,覆盖:input_ids/inputs_embeds等价前向;