Repository navigation
Add Llama4 text model #4536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Llama4 text model #4536
Changes from 16 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d1dc553
Add Llama4 text model
yicycyc a3ede51
Merge upstream/develop into Llama4 support
yicycyc eac6aa9
Merge remote-tracking branch 'upstream/develop' into feat/llama4-migr…
yicycyc a5df5d6
Address Llama4 review feedback
yicycyc b4292e0
fix Llama4 chunked attention padding mask
yicycyc 009a292
Merge branch 'develop' into feat/llama4-migration
yicycyc 66640ad
Add Llama4 CE template and LoRA support
yicycyc b725dbc
Apply Llama4 pre-commit formatting
yicycyc ab2a155
Merge branch 'develop' into feat/llama4-migration
yicycyc de595fe
fix(llama4): preserve auto model mapping
yicycyc 9c37e08
Merge branch 'develop' into feat/llama4-migration
yicycyc 713abde
feat(llama4): add multimodal conditional generation model
yicycyc 363949b
fix(llama4): support guard checkpoint loading and cache
yicycyc 2030b3b
style(llama4): apply pre-commit formatting
yicycyc 16fe9a6
docs(llama4): document Llama Guard 4 support
yicycyc b04f92b
fix(llama4): support cached multimodal generation
yicycyc 54e7d32
fix(llama4): preserve auto loading and generation inputs
yicycyc 73eadc2
Merge branch 'develop' into feat/llama4-migration
yicycyc d35d737
fix(auto): restore path fallback after develop merge
yicycyc f428ebe
fix(llama4): honor hidden-state config defaults
yicycyc eb450bb
fix(llama4): propagate multimodal hidden-state default
yicycyc 3a1e36b
fix(llama4): limit recompute to training
yicycyc 14109a9
fix(llama4): address latest model review
yicycyc ef04699
fix(llama4): honor multimodal projector bias
yicycyc 8cf54f5
refactor(llama4): remove unused attention wrapper
yicycyc 2ecbe2a
Merge remote-tracking branch 'upstream/develop' into merge/llama4
yicycyc f1fd861
[Model] Add Llama4 multimodal processors
yicycyc 198afa3
Merge remote-tracking branch 'upstream/develop' into merge/llama4
yicycyc c36290e
fix(llama4): accept visual token masks during template registration
yicycyc dc3e0a4
fix(llama4): disable cache during training recompute
yicycyc 37661f1
Fix Llama4 text and vision templates, LoRA registration and attention…
yicycyc 362a8ae
Merge develop and reconcile llama4 model registrations
yicycyc bd4d1ee
Merge develop and preserve Llama4 and MiniMax registrations
yicycyc 7890e20
Merge branch 'develop' into feat/llama4-migration
yicycyc 9eb4c1d
style: separate Llama4 and Molmo plugin classes
yicycyc cc08161
fix: restore independent Llama4 and Molmo image plugins
yicycyc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -949,6 +949,27 @@ def _get_gpt_oss_prefix(): | |
| chat_sep="<|eot_id|>", | ||
| ) | ||
|
|
||
| register_template( | ||
| name="llama4", | ||
| format_user=StringFormatter( | ||
| slots=[ | ||
| ("<|header_start|>user<|header_end|>\n\n{{content}}<|eot|>" "<|header_start|>assistant<|header_end|>\n\n") | ||
| ] | ||
| ), | ||
| format_assistant=StringFormatter(slots=["{{content}}"]), | ||
| format_system=StringFormatter(slots=["<|header_start|>system<|header_end|>\n\n{{content}}<|eot|>"]), | ||
| format_function=FunctionFormatter(slots=["{{content}}"], tool_format="llama4"), | ||
| format_observation=StringFormatter( | ||
| slots=[ | ||
| ("<|header_start|>user<|header_end|>\n\n{{content}}<|eot|>" "<|header_start|>assistant<|header_end|>\n\n") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 官方用ipython,而不是user。上面的llama3也是ipython
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修正。工具返回对应的 |
||
| ] | ||
| ), | ||
| format_tools=ToolFormatter(tool_format="llama4"), | ||
| format_prefix=EmptyFormatter(slots=[{"bos_token"}]), | ||
| suffix=["<|eot|>"], | ||
| chat_sep="<|eot|>", | ||
| ) | ||
|
|
||
|
|
||
| # copied from gemma template | ||
| register_template( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils.lazy_import import _LazyModule | ||
|
|
||
| import_structure = { | ||
| "configuration": ["Llama4Config", "Llama4TextConfig", "Llama4VisionConfig"], | ||
| "modeling": [ | ||
| "Llama4TextDecoderLayer", | ||
| "Llama4TextModel", | ||
| "Llama4ForCausalLM", | ||
| "Llama4TextPretrainedModel", | ||
| ], | ||
| "multimodal": ["Llama4ForConditionalGeneration", "Llama4VisionEncoderLayer", "Llama4VisionModel"], | ||
| } | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration import Llama4Config, Llama4TextConfig, Llama4VisionConfig | ||
| from .modeling import ( | ||
| Llama4ForCausalLM, | ||
| Llama4TextDecoderLayer, | ||
| Llama4TextModel, | ||
| Llama4TextPretrainedModel, | ||
| ) | ||
| from .multimodal import ( | ||
| Llama4ForConditionalGeneration, | ||
| Llama4VisionEncoderLayer, | ||
| Llama4VisionModel, | ||
| ) | ||
| else: | ||
| sys.modules[__name__] = _LazyModule( | ||
| __name__, | ||
| globals()["__file__"], | ||
| import_structure, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想问下template没有mm_plugin,组网里没有image_processing/processor,为什么可以跑带图片的多模呢?我用cli的方式hang住了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认当前 PR 尚未提供 Llama4 image processor、processor 和 mm_plugin,因此 PaddleFormers CLI 不能完整执行带图 SFT;此前图文验证使用的是直接构造
pixel_values的模型接口。已将能力表中的 Llama Guard 4 SFT 标记改为 x,避免误报 CLI 能力。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已在 f1fd861 补齐 Llama4 多模态组件链路:新增 Paddle 原生 Llama4ImageProcessor/Llama4ImageProcessorFast、Llama4Processor,注册 AutoImageProcessor/AutoProcessor,并为 llama4 template 增加按 aspect ratio 展开 tile/global patch token 的 mm_plugin。图像预处理遵循 Transformers 的选画布、等比例 resize、右/下 padding、切 tile 及多 tile 时追加 global tile 的顺序;CLI collator 最终只传 pixel_values。新增 7 项单测覆盖单 tile、多 tile、global tile、视觉 token/feature 数一致、占位符校验和 dataset placeholder 展开,均已通过;能力表已恢复 SFT/SFT-LoRA 为支持。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
补充修复:CI 原始日志确认 Llama4Plugin 未声明 masked_tokens,模板注册在导入阶段失败,影响其他训练任务。已在 c36290e 声明该字段并新增实际导入 TEMPLATES 的回归测试,通过后推送;同时合并最新 develop。