已合并
test(distributed):add test for validate_checkpoint_id, reset, set_up_storage_reader from BroadcastingTorchSaveReader #33733
test(distributed):add test for validate_checkpoint_id, reset, set_up_storage_reader from BroadcastingTorchSaveReader #33733
已合并
xh-zhan创建于 4月14日
xh-zhan
xh-zhan
4月14日

/kind feature

What does this PR do / why do we need it:

本次 PR 为 BroadcastingTorchSaveReader 类中的三个核心 API 新增了单元测试用例,以确保其在 torch_npu 环境下的行为与 PyTorch 原生行为保持一致。

测试用例路径:test/distributed/checkpoint/test_broadcasting_reader.py

API 功能说明:

  • torch.distributed.checkpoint.format_utils.BroadcastingTorchSaveReader.validate_checkpoint_id:纯逻辑 API,用于检查给定的 checkpoint 文件路径是否存在。
  • torch.distributed.checkpoint.format_utils.BroadcastingTorchSaveReader.reset:纯逻辑 API,用于重置 BroadcastingTorchSaveReader 实例的 checkpoint_id 属性,支持更新为新的路径或 None
  • torch.distributed.checkpoint.format_utils.BroadcastingTorchSaveReader.set_up_storage_reader:用于设置存储读取器的元数据及协调者(coordinator)状态。包含协调者身份校验和 checkpoint_id 非空检查。

用例完备性说明:

由于Pytorch社区无上述三个API的测试用例,故本次PR新增用例test_broadcasting_reader.py。本次提交的测试用例覆盖了以下场景,确保 API 的健壮性:

  • validate_checkpoint_id:
    • ✅ 存在的文件路径 → 返回 True
    • ✅ 不存在的文件路径 → 返回 False
  • reset:
    • ✅ 更新为新路径 → checkpoint_id 正确变更
    • ✅ 更新为 Nonecheckpoint_id 正确变更为 None
  • set_up_storage_reader:
    • ✅ 正确设置 is_coordinator 属性
    • ✅ 协调者 rank 不匹配时抛出 AssertionError
    • checkpoint_idNone 时抛出 AssertionError

注:测试中使用 unittest.mock 模拟 torch.distributed.get_rank,以在单进程环境下验证分布式协调者校验逻辑,避免对真实多进程环境的依赖。

适配方案:

经分析,这三个 API 均为纯 Python 逻辑,不依赖任何 NPU 特定算子或硬件特性。本次提交 无需对 API 本身进行任何代码适配,仅增加单元测试以完成 NPU 环境下的兼容性验证。

Which issue(s) this PR fixes:

Fixes #1680

Special notes for your reviewers:

  1. 测试文件路径test/distributed/checkpoint/test_broadcasting_reader.py
  2. 本地验证结果:所有测试用例已在昇腾 NPU 环境下成功运行,且本地2.6.0,2.7.1,2.8.0,2.9.0,2.10.0,2.11.0版本下都运行成功,输出如下:
    Ran 7 tests in 0.011s
    OK
  3. 命名规范:测试文件命名符合 torch-npu 仓库规范(test_ 开头 + 核心关键词),文件内添加了完整 API 名称和测试维度注释,便于后续检索和维护。
  4. 需合入的分支v2.6.0, v2.7.1, v2.8.0, v2.9.0, v2.10.0, v2.11.0, master(根据赛事文档要求)。
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 xh-zhan 的贡献)
xh-zhanxh-zhan
4月14日 创建了 pull request,commit c3b1aa6d
xh-zhanxh-zhan
4月14日 关联了issue:[API一致性] BroadcastingTorchSaveReader的下三个API:validate_checkpoint_id、reset、set_up_storage_reader无需NPU适配
ascend-robot
ascend-robot成员
4月14日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
test 李伟, yuhaiyan (2/2) 李伟 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

xh-zhan, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
4月14日 添加了label:ascend-cla/no
此处折叠了50条消息 查看更多
liwei386成员
4月17日 评论:

/approve

likedislike
ascend-robotascend-robot成员
4月17日 添加了label:approvedlgtm
ascend-robot
ascend-robot成员
4月17日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 李伟.
Reviewers who wrote a comment of /lgtm are: 李伟, yuhaiyan.

likedislike
ascend-robotascend-robot成员
4月17日 合入了pull request
ascend-robot
ascend-robot成员
4月17日 评论:

In response to this:

/sync v2.6.0 v2.7.1 v2.8.0 v2.9.0 v2.10.0 v2.11.0 master

@xh-zhan

同步操作执行结果:

Branch Status Pull Request
v2.6.0 推送分支失败
v2.7.1 推送分支失败
v2.8.0 推送分支失败
v2.9.0 推送分支失败
v2.10.0 推送分支失败
v2.11.0 推送分支失败
master 同步失败:请手动创建 PR 进行同步,我们会继续完善分支之间同步操作,尽量避免同步失败的情况
likedislike