Prhub

#42968 [Feature] Add `--cpu-distributed-timeout-seconds` CLI Option for CPU Process Group Timeout

原始 PR 作者 fangyuchu 合并时间 2026-05-22 06:42 文件变更 4 提交数 4 评论 7 代码增减 +33 / -1

执行摘要

为 CPU 通信组新增独立超时配置项

vLLM 初始化分设备(NCCL)和 CPU(gloo)两种进程组用于分布式执行。现有的 --distributed-timeout-seconds 仅作用于设备通信(见 PR#36047)。而 CPU 进程组仍依赖 PyTorch 硬编码的 1800 秒默认超时。通过引入 --cpu-distributed-timeout-seconds,运维人员可为 CPU 侧协调配置更短的超时,在不影响 NCCL 超时语义的前提下实现快速故障恢复。

该 PR 设计清晰,命名合理,向后兼容,建议合并。读者可关注其参数命名讨论和工具函数提取模式,体现的“独立关注点分离”设计值得借鉴。

讨论亮点
  • 命名讨论tlrmchlsmth):建议将 --gloo-timeout-seconds 改为 --cpu-distributed-timeout-seconds 以保持通用性。hmellor 赞同,作者接受并修改。
  • 重构建议SageMoore):建议消除两处重复的配置读取逻辑,提取为 get_cpu_distributed_timeout_or_none 工具函数。作者采纳并实现。
  • 超时传递争议gemini-code-assist):指出直接传递 timeout=None 可能覆盖 PyTorch 默认行为。作者回应称 timeout=None 与省略参数等价,最终版本保留直接传递方式。

实现拆解

  1. 配置定义:在 vllm/config/parallel.pyParallelConfig 类中新增 cpu_distributed_timeout_seconds: int | None = None 字段,并添加文档字符串说明默认使用 Gloo 的 1800 秒。

  2. CLI 注册与值传递:在 vllm/engine/arg_utils.pyEngineArgs 中添加同名属性,并在 add_cli_args 中注册 --cpu-distributed-timeout-seconds 参数;在 create_engine_config 中将该值传入 ParallelConfig 构造函数。

  3. 工具函数提取:在 vllm/distributed/utils.py 中新增 get_cpu_distributed_timeout_or_none() 函数,通过当前 vLLM 配置读取超时秒数并返回 timedelta | None;同时修改 stateless_init_torch_distributed_process_group,在 backend 为 gloo 时调用此函数并覆盖该分支的默认 timeout。

  4. 集成到分布式组初始化:在 vllm/distributed/parallel_state.pyGroupCoordinator.__init__ 中导入并使用同一工具函数,将返回的超时值传递给 torch.distributed.new_group(..., timeout=timeout),从而控制所有 gloo 后端的进程组超时。

未添加自动化测试,但通过手动注入 sleep 验证了超时生效。

文件 模块 状态 重要度
vllm/config/parallel.py 并行配置 modified 5.07
vllm/engine/arg_utils.py 引擎参数 modified 5.48
vllm/distributed/parallel_state.py 分布式状态 modified 5.84
vllm/distributed/utils.py 分布式工具 modified 6.7

关键符号

get_cpu_distributed_timeout_or_none stateless_init_torch_distributed_process_group GroupCoordinator.__init__

关键源码片段

vllm/distributed/parallel_state.py dependency-wiring

在 `GroupCoordinator` 初始化中实际应用超时到 gloo 组,是运行时生效的关键点。

# 在 GroupCoordinator.__init__ 中,创建 gloo 进程组时应用独立超时
from vllm.distributed.utils import get_cpu_distributed_timeout_or_nonetimeout = get_cpu_distributed_timeout_or_none()for ranks in group_ranks:
    device_group = torch.distributed.new_group(
        ranks, backend=torch_distributed_backend
    )
    with suppress_stdout():
        # 将超时参数传给 gloo 后端;None 表示使用 PyTorch 默认(1800 秒)
        cpu_group = torch.distributed.new_group(
            ranks, backend="gloo", timeout=timeout
        )
vllm/distributed/utils.py core-logic

新增核心工具函数 `get_cpu_distributed_timeout_or_none`,并修改了 `stateless_init_torch_distributed_process_group` 中的 gloo 超时逻辑,是复用关键。

def get_cpu_distributed_timeout_or_none() -> timedelta | None:
    """
    从全局 vLLM 配置中读取 CPU 分布式超时秒数,
    若配置存在且设置了值则返回 timedelta,否则返回 None。
    """
    # 延迟导入以避免循环依赖
    from vllm.config import get_current_vllm_config_or_none
    vllm_config = get_current_vllm_config_or_none()
    if vllm_config is None:
        return None
    timeout_seconds = vllm_config.parallel_config.cpu_distributed_timeout_seconds
    # 仅当显式设置时才返回 timedelta
    return timedelta(seconds=timeout_seconds) if timeout_seconds is not None else None# 在 stateless_init_torch_distributed_process_group 中使用
timeout = _get_default_timeout(backend)
# 对 gloo 后端尝试使用独立的 CPU 超时
if backend == "gloo":
    gloo_timeout = get_cpu_distributed_timeout_or_none()
    if gloo_timeout is not None:
        timeout = gloo_timeout

评论区精华

参数命名讨论:gloo vs cpu-distributed 设计

`tlrmchlsmth` 提出疑问:是否应该直接复用 `--distributed-timeout-seconds`?若需分开,建议使用 `--cpu-distributed-timeout-seconds` 更通用。

结论:决定采用 `--cpu-distributed-timeout-seconds`,以保持与设备超时解耦并适应未来可能的后端。 · 已解决

提取工具函数消除重复 设计

`SageMoore` 建议在 `vllm/distributed/utils.py` 中添加 `get_cpu_distributed_timeout_or_none` 函数,集中管理配置读取,避免在 parallel_state.py 和 utils.py 中重复。

结论:作者接受建议,提取出函数并替换两处调用。 · 已解决

传递 timeout=None 的影响 正确性

`gemini-code-assist` 指出直接传递 `timeout=gloo_timeout`(可能为 None)可能在不同 PyTorch 版本下覆盖默认超时,建议只在非 None 时传递。

结论:作者解释 `timeout=None` 与省略参数在 `new_group` 中行为一致,维持原设计。代码审查者未进一步反对。 · 已解决

风险与影响

  • 向后兼容:低风险。新参数默认 None,不影响现有逻辑。
  • 误配置风险:若设置过短超时(如 1 秒),在高延迟环境(如多节点)中可能引发非预期的超时,但这属于用户操作问题。
  • 维护一致性:未来若引入更多通信后端(如 NCCL 的其他变体),需要确保与之类似的独立超时参数保持一致设计。
  • 用户:进行多节点分布式部署、使用 CPU 通信进行协调的用户(如 DP 元数据交换)可获得更灵活的故障恢复配置。
  • 系统:不影响正常的推理性能;仅在故障时影响超时检测速度。
  • 团队:新增一个 CLI 选项和一个内部工具函数,维护负担较小。
向后兼容保障 超时覆盖默认行为 新增配置项

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论