Skip to content

[Loader] Add values natural order check to layers grouped validation#7498

Open
bukejiyu wants to merge 1 commit intoPaddlePaddle:developfrom
bukejiyu:feat/weight-loading-natural-order
Open

[Loader] Add values natural order check to layers grouped validation#7498
bukejiyu wants to merge 1 commit intoPaddlePaddle:developfrom
bukejiyu:feat/weight-loading-natural-order

Conversation

@bukejiyu
Copy link
Copy Markdown
Collaborator

@bukejiyu bukejiyu commented Apr 20, 2026

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Modifications

修复weight_map value 无序导致加载OOM的问题

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 20, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-20 11:37 CST

📋 Review 摘要

PR 概述:在权重加载的 is_layers_are_grouped 判断中增加对 values(文件名)自然序的检查,避免 keys 按 layer 分组但文件名乱序时使用简单迭代器导致加载顺序错误。
变更范围model_executor/load_weight_utils.py
影响面 TagLoader

📝 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 变量命名 is_keys_orders 语义不够清晰

建议改为 is_keys_groupedare_keys_grouped,与上方的函数名 layers_are_grouped 保持一致,增强可读性:

is_keys_grouped = layers_are_grouped(keys)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants