[Loader] Add values natural order check to layers grouped validation#7498
Open
bukejiyu wants to merge 1 commit intoPaddlePaddle:developfrom
Open
[Loader] Add values natural order check to layers grouped validation#7498bukejiyu wants to merge 1 commit intoPaddlePaddle:developfrom
bukejiyu wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-20 11:37 CST
📋 Review 摘要
PR 概述:在权重加载的 is_layers_are_grouped 判断中增加对 values(文件名)自然序的检查,避免 keys 按 layer 分组但文件名乱序时使用简单迭代器导致加载顺序错误。
变更范围:model_executor/load_weight_utils.py
影响面 Tag:Loader
📝 PR 规范检查
PR 描述中 Motivation 和 Modifications 章节均未填写,建议补充变更动机和修改说明,方便后续维护者理解。
描述建议(可直接复制):
Motivation
当
model.safetensors.index.json中的 keys 按 layer 分组、但 values(文件名)未按自然序排列时,safetensors_weights_iterator按 sorted files 遍历会导致权重加载顺序与预期不一致,需回退到safetensors_weights_iterator_ordered逐 key 加载。Modifications
- 新增
values_are_naturally_ordered函数,检查 weight_map 的 values 是否按自然序排列。- 将
is_layers_are_grouped的判断条件从仅检查 keys 分组改为同时检查 keys 分组和 values 自然序。
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | load_weight_utils.py:541 |
变量命名 is_keys_orders 语义不清晰 |
总体评价
逻辑正确且有实际意义——补全了原有判断的盲区。变更范围小且安全,仅有一处命名建议。
| keys = list(weight_map.keys()) | ||
| is_layers_are_grouped = layers_are_grouped(keys) | ||
| values = list(weight_map.values()) | ||
| is_keys_orders = layers_are_grouped(keys) |
There was a problem hiding this comment.
🟡 建议 变量命名 is_keys_orders 语义不够清晰
建议改为 is_keys_grouped 或 are_keys_grouped,与上方的函数名 layers_are_grouped 保持一致,增强可读性:
is_keys_grouped = layers_are_grouped(keys)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Modifications
修复weight_map value 无序导致加载OOM的问题
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.