增加internlm3的支持#4167
Conversation
|
Thanks for your contribution! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #4167 +/- ##
==========================================
Coverage ? 34.15%
==========================================
Files ? 467
Lines ? 87868
Branches ? 0
==========================================
Hits ? 30008
Misses ? 57860
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ("gemma3_text", "Gemma3TextConfig"), | ||
| ("glm4v_moe", "Glm4vMoeConfig"), | ||
| ("glm_ocr", "GlmOcrConfig"), | ||
| ("internlm3", "InternLM3Config"), |
There was a problem hiding this comment.
需要在auto/modeling.py也添加InternLM3,否则通过 AutoModelForCausalLM.from_pretrained() 加载会失败,在 MAPPING_NAMES 中添加 ("InternLM3", "intern_lm3")
| @@ -0,0 +1,110 @@ | |||
| # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | |||
| @@ -0,0 +1,44 @@ | |||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | |||
| @@ -0,0 +1,347 @@ | |||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | |||
| # Copyright 2020 The HuggingFace Team. All rights reserved. | |||
There was a problem hiding this comment.
是否有引用 hf 代码,如果没有的话,建议删掉这行
|
1、Copyright 年份错误 |
liuhao2638
left a comment
There was a problem hiding this comment.
本轮已完成复查,发现 1 个需要修正后再合入的训练模板问题,另有 1 个配置默认值一致性问题。具体细节已放在行级评论里。
| register_template( | ||
| name="internlm3", | ||
| format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]), | ||
| format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]), |
There was a problem hiding this comment.
这里把 <|im_end|>\n 放进了 format_assistant,同时下面的 chat_sep 和 suffix 也都是同一个结束符。Template._encode() 会在非最后一轮 assistant 后追加 chat_sep,SFTDataset 还会在末尾再追加 suffix,因此使用 template: internlm3 做 SFT 时会训练出重复的 <|im_end|> 分隔符,和上游 chat template 不一致。建议和已有 qwen/qwen3 模板一样,让 assistant formatter 只包含响应文本,结束符统一由 chat_sep/suffix 处理。
| format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]), | |
| format_assistant=StringFormatter(slots=["{{content}}"]), |
| intermediate_size=11008, | ||
| num_hidden_layers=32, | ||
| num_attention_heads=32, | ||
| num_key_value_heads=32, | ||
| hidden_act="silu", | ||
| max_position_embeddings=32768, | ||
| initializer_range=0.02, | ||
| rms_norm_eps=1e-6, | ||
| use_cache=True, | ||
| tie_word_embeddings=False, | ||
| rope_theta=10000.0, | ||
| rope_scaling=None, | ||
| qkv_bias=False, | ||
| attention_dropout=0.0, | ||
| bias=False, | ||
| head_dim=None, |
There was a problem hiding this comment.
InternLM3Config() 的默认值目前不是 InternLM3-8B 的结构:公开的 internlm/internlm3-8b-instruct 配置是 intermediate_size=10240、num_hidden_layers=48、num_key_value_heads=2、rms_norm_eps=1e-5、rope_theta=50000000、动态 RoPE factor 6、head_dim=128。这里的默认值仍接近 Llama/Qwen 形状,但类说明又写着默认会得到 InternLM3-8B;用户直接实例化默认 config 或缺省 config 转换时会得到不兼容的模型结构。请把默认值和文档默认值同步到实际 InternLM3-8B 配置。
| intermediate_size=11008, | |
| num_hidden_layers=32, | |
| num_attention_heads=32, | |
| num_key_value_heads=32, | |
| hidden_act="silu", | |
| max_position_embeddings=32768, | |
| initializer_range=0.02, | |
| rms_norm_eps=1e-6, | |
| use_cache=True, | |
| tie_word_embeddings=False, | |
| rope_theta=10000.0, | |
| rope_scaling=None, | |
| qkv_bias=False, | |
| attention_dropout=0.0, | |
| bias=False, | |
| head_dim=None, | |
| intermediate_size=10240, | |
| num_hidden_layers=48, | |
| num_attention_heads=32, | |
| num_key_value_heads=2, | |
| hidden_act="silu", | |
| max_position_embeddings=32768, | |
| initializer_range=0.02, | |
| rms_norm_eps=1e-5, | |
| use_cache=True, | |
| tie_word_embeddings=False, | |
| rope_theta=50000000.0, | |
| rope_scaling={"factor": 6.0, "rope_type": "dynamic"}, | |
| qkv_bias=False, | |
| attention_dropout=0.0, | |
| bias=False, | |
| head_dim=128, |
risemeup1111
left a comment
There was a problem hiding this comment.
已复查最新提交,上一轮关于 internlm3 SFT 模板结束符重复和默认配置不一致的问题已经修复;CI 当前通过,未发现新的阻塞问题。
|
需要解决ci报错的代码规范问题 |
PaddleFormers Log Analysis
日志分析报告
失败的测试case: 根本原因分析: 两个 case 均在 修复建议:
🔄 每次 Re-run 后自动更新 |
|
仍然存在代码风格问题,建议本地在commit前运行pre-commit,修复代码风格问题再提交 |
Resolve conflicts in template.py, transformers/__init__.py and auto/configuration.py by keeping both internlm3 and gemma4_moe/phi4 entries.
risemeup1111
left a comment
There was a problem hiding this comment.
已复查最新提交,上一轮 Nyanpasu 提出的 P1 模板问题仍保持已修复状态,默认配置问题也已同步。新提交里只发现一个非阻塞的 .gitignore 仓库级忽略项清理建议,细节见行级评论;当前 CI 仍在运行中,建议等检查完成后再合入。
| checkpoints | ||
| .claude | ||
| /test/ | ||
| /tmp/ | ||
| .roo/ | ||
| .flake8 | ||
| AGENTS.md | ||
| ms-swift-4.0.2 | ||
| paconvert-lm3 | ||
| phi4-code-convert | ||
| phi4-code-raw | ||
| raw-internlm2 | ||
| raw-internlm2_5 | ||
| raw-internlm3 | ||
| log/ | ||
| .agents/ | ||
| .infcode No newline at end of file |
There was a problem hiding this comment.
处理要求:请针对该评论进行回复(同意并已修改请回复 Done,不同意请说明理由)。
这组新增 ignore 项看起来是本地开发/转换工具目录(如 .claude、.roo、AGENTS.md、raw-internlm3 等),而不是 PaddleFormers 项目通用产物。提交到仓库级 .gitignore 后,所有贡献者都会默认忽略同名根目录/文件,例如后续如果需要提交 AGENTS.md、/test/ 或 /tmp/ 下的项目文件会被 Git 隐藏。建议仓库级规则只保留项目通用产物;个人环境和临时模型目录放到本机 .git/info/exclude 或全局 gitignore。
| checkpoints | |
| .claude | |
| /test/ | |
| /tmp/ | |
| .roo/ | |
| .flake8 | |
| AGENTS.md | |
| ms-swift-4.0.2 | |
| paconvert-lm3 | |
| phi4-code-convert | |
| phi4-code-raw | |
| raw-internlm2 | |
| raw-internlm2_5 | |
| raw-internlm3 | |
| log/ | |
| .agents/ | |
| .infcode | |
| checkpoints |
There was a problem hiding this comment.
已看到最新提交把这些仓库级 ignore 项移除了,代码侧已经满足这条建议。按前面 P3 的处理要求,还请在本线程回复 Done,我就可以把这条视为已完成。
There was a problem hiding this comment.
确认,代码侧和回复都已满足这条 P3 建议,我这边按已完成处理。
risemeup1111
left a comment
There was a problem hiding this comment.
已复查最新提交,上一轮 .gitignore 的代码侧修改已经到位;我已在原线程说明还需要作者回复 Done 作为 P3 处理完成信号。当前 CI 仍在运行中,本轮未新增行级问题。
risemeup1111
left a comment
There was a problem hiding this comment.
已复查,前面提出的 .gitignore 清理建议已通过最新提交处理,并且作者已在对应线程回复确认。此前关于 internlm3 模板和默认配置的问题也保持已修复状态;本轮未发现新的阻塞问题。
PR类型
新增模型支持,增加internlm3支持
特别注意
internlm3的版本有点特殊,其依赖的transformers特性在4.53.0-5.x之间。transformers不能太老或者太新,transformers有些特性出现了一下后续又被删除了。而且即使强行修改lm3原版代码,通过patch 的方式绕过一些依赖,原版也无法实现精确推理。所以,建议使用确定的transformers 的4.53.0版本测试
相关模型权重下载
推理和token对齐
tests/transformers/intern_lm3/test_modeling.py中的test_torch_paddle_model_alignment中前20个logits值对齐 < 1e-2,top 10 token一致。tests/transformers/intern_lm3/test_modeling.py中的test_paddle_model_load_and_infer方法有@slow标记,可以实现8b规模的情况下,直接加载hg上的原始权重,并推理出和transformers版本上一样的output。训练对齐
使用ms-swift【一样需要切换到transformers 的4.53.0版本】,指令如下:
swift sft \ --model "$MODEL_PATH" \ --model_type internlm3 \ --tuner_type full \ --template internlm3 \ --custom_register_path "$REGISTER_SCRIPT" \ --dataset "$TRAIN_DATA" \ --max_length 512 \ --per_device_train_batch_size 1 \ --learning_rate 1e-5 \ --max_steps 500 \ --warmup_steps 5 \ --gradient_accumulation_steps 4 \ --num_train_epochs 1 \ --bf16 true \ --seed 23 \ --output_dir "$OUTPUT_DIR" \ --logging_steps 1 \ --save_strategy no \ --gradient_checkpointing true \ --freeze_parameters_ratio 1.0 \ --trainable_parameters model.layers.0 model.layers.1 model.layers.2 \ --ddp_find_unused_parameters true \ 2>&1 | tee "$OUTPUT_DIR/training.log"ms-swift的注册模板代码如下:
paddleformers cli的配置在
tests/config/ci/interlm3_sft.yaml结果如下: