已合并
【API】Add custom validation cases for HealthCheckServer APIs #34493
【API】Add custom validation cases for HealthCheckServer APIs #34493
已合并
Jinfan Liu创建于 4月27日
Jinfan Liu
Jinfan Liu
4月27日

环境信息
操作系统:AlmaLinux 8.10
架构:aarch64
CANN 软件版本:8.5.0
安装的软件版本:torch 2.7.1+cpu、torch-npu 2.7.1.post2

一、4 个 API 功能如下:

1. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer
elastic agent 健康检查服务的接口类。构造函数接收 alive_callback、port、timeout,并将三项配置保存到实例属性 _alive_callback、_port、_timeout,供后续 health check server 实现复用。当前社区实现是 noop health check server,不创建 socket、不启动后台线程、不访问设备资源。

2. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer.start
健康检查服务启动入口。当前社区实现保持 noop 行为,只通过 health_check_server logger 输出 WARNING 日志 No health check server started。该接口用于保持 elastic agent 健康检查启动链路的统一调用形态。

3. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer.stop
健康检查服务停止入口。当前社区实现保持 noop 行为,只通过 health_check_server logger 输出 INFO 日志 Stopping noop health check server.。该接口不维护额外运行状态,也不释放外部资源。

4. torch.distributed.elastic.agent.server.health_check_server.create_healthcheck_server
模块级 factory 函数。函数接收 alive_callback、port、timeout,返回 HealthCheckServer(alive_callback, port, timeout)。该函数的核心语义是返回类型固定、三项参数原样透传、创建阶段不执行 alive_callback。

二、社区用例对这 4 个 API 的验证完整性分析

搜索了官方 test 目录,搜了 HealthCheckServer、health_check_server、create_healthcheck_server,没有搜到,说明 4 个 API 没有直接测试用例。

1. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer
官方 test 目录未发现直接构造 HealthCheckServer 并校验 _alive_callback、_port、_timeout 的用例,也未发现构造阶段不触发 callback 的断言。构造参数保存和无副作用构造语义缺少直接覆盖。

2. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer.start
官方 test 目录未发现调用 start() 并校验 logger 名称、日志级别、日志内容的用例。当前 noop start 的外部可观察行为缺少直接覆盖。

3. torch.distributed.elastic.agent.server.health_check_server.HealthCheckServer.stop
官方 test 目录未发现调用 stop() 并校验 logger 名称、日志级别、日志内容的用例,也未发现 stop() 重复调用稳定性的验证。当前 noop stop 的外部可观察行为和幂等调用语义缺少直接覆盖。

4. torch.distributed.elastic.agent.server.health_check_server.create_healthcheck_server
官方 test 目录未发现调用 create_healthcheck_server() 并校验返回类型、alive_callback/port/timeout 参数透传、创建阶段不触发 callback 的用例。factory 函数的类型约束、参数传递和无副作用创建语义缺少直接覆盖。

三、NPU 适配

3.1 API 适配
这 4 个 API 属于 torch.distributed.elastic.agent.server.health_check_server 控制面逻辑。
这些 API 不执行 Tensor 计算,不涉及 NPU kernel、算子适配、计算图构建、精度对比、CANN runtime 或 HCCL 通信。

3.2 测试用例适配
本 PR 在 torch-npu test 目录新增自定义测试文件:
- test/distributed/elastic/agent/server/test_healthcheckserver_api.py

测试文件覆盖以下用例:
1. test_init:直接构造 HealthCheckServer(alive_callback, 0, 30),校验 _alive_callback、_port、_timeout 与入参一致,并校验构造阶段没有调用 alive_callback。
2. test_create_healthcheck_server:调用 create_healthcheck_server(alive_callback, 0, 45),校验返回对象是 HealthCheckServer,校验 alive_callback、port、timeout 原样传入实例,并校验 factory 阶段没有调用 alive_callback。
3. test_start_logs_warning:调用 start(),使用 assertLogs 捕获 torch.distributed.elastic.agent.server.health_check_server logger 的 WARNING 记录,校验只产生 1 条日志,且 message 精确等于 No health check server started。
4. test_stop_logs_info:调用 stop(),使用 assertLogs 捕获 torch.distributed.elastic.agent.server.health_check_server logger 的 INFO 记录,校验只产生 1 条日志,且 message 精确等于 Stopping noop health check server.。
5. test_start_stop_lifecycle_safe:按 start() -> stop() 顺序执行完整生命周期调用,校验 noop 实现不抛异常,覆盖常规调用链。
6. test_stop_idempotent:执行 start() 后连续调用 stop() 三次,校验重复 stop() 不抛异常,覆盖停止接口的幂等调用场景。


3.3 文档修改
本测试 PR 不修改 docs 文件。docs 支持项由独立 docs PR 补齐。

四、运行日志

python test/distributed/elastic/agent/server/test_healthcheckserver_api.py

...W0428 12:03:19.530000 11291 torch_npu_2.7.1/lib/python3.11/site-packages/torch/distributed/elastic/agent/server/health_check_server.py:48] No health check server started
.W0428 12:03:19.531000 11291 torch_npu_2.7.1/lib/python3.11/site-packages/torch/distributed/elastic/agent/server/health_check_server.py:48] No health check server started
..
----------------------------------------------------------------------
Ran 6 tests in 1.376s

OK
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Jinfan Liu 的贡献)
Jinfan LiuJinfan Liu
4月27日 创建了 pull request,commit 852a6317
ascend-robot
ascend-robot成员
4月27日 评论:

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 李伟, AACAES (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

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

likedislike
ascend-robotascend-robot成员
4月27日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
4月27日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.8.0
v2.10.0
v2.7.1
v2.9.0
v2.11.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
此处折叠了75条消息 查看更多
AACAES成员
4月29日 评论:

/lgtm

likedislike
liwei386成员
4月29日 评论:

/approve

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

Review Guide

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

likedislike
ascend-robotascend-robot成员
4月29日 合入了pull request