Prhub

#25294 [SMG] Support regular worker discovery alongside PD workers in IGW mode

原始 PR 作者 Gruner-atero 合并时间 2026-05-21 07:23 文件变更 3 提交数 3 评论 5 代码增减 +162 / -9

执行摘要

支持 IGW 模式下 PD 与常规 worker 混合服务发现

当使用 --pd-disaggregation 时,服务发现只接受 pods 匹配 prefill_selector 或 decode_selector。匹配 --selector 的 pods 被静默丢弃,使得无法从同一路由器同时服务多个模型(一些通过 PD,一些通过常规路由)。在 IGW 模式下,路由基础设施已支持混合调度,但服务发现缺少对应能力。见 PR #25294 描述。

该 PR 值得阅读,尤其展示了如何在不大幅新增 CLI 参数的情况下,通过组合现有参数实现功能扩展。同时代码中针对配置误用的告警机制也是良好的实践。对于需要部署混合模型路由的场景,这是一个关键的缺失填补。

讨论亮点

Reviewer alexnails 指出两个问题:

  • should_include() 中,当 prefill_selectordecode_selector 均为空时,原逻辑会在告警后直接返回 false,导致 matches_regular 分支不可达。建议通过提前检查 igw_mode && !config.selector.is_empty() 来修正,使得该配置下依然能发现常规 worker。开发者已采纳并修复。
  • 告警逻辑最初只写在 main.rs 的二进制入口,而 Python 绑定的 start() 方法缺少等价的检查。建议抽取辅助方法在两个入口同时调用。开发者后续在 ServiceDiscoveryConfig 上增加了 warn_if_misconfigured(),并在两入口统一调用,问题已解决。

实现拆解

实现分为三步:

  1. 数据结构扩展:在 ServiceDiscoveryConfig 中新增 igw_mode: bool 字段,默认 false,确保向后兼容。
  2. 核心服务发现逻辑调整:修改 PodInfo::should_include(),在 pd_mode=trueigw_mode=true 时,额外检查 selector 是否匹配 Pod,若匹配则归入 Regular 类型。同时调整原有空 selector 判断逻辑,避免早期返回阻挡常规 worker 发现。新增 warn_if_misconfigured() 方法,当 pd_modeselector 已设但 igw_mode 未启用时,输出告警日志。
  3. 入口集成:在 main.rsbindings/python/src/lib.rs 的配置构造处,将 self.enable_igw 传入 igw_mode,构造后调用 warn_if_misconfigured() 统一告警。所有变更均不引入新 CLI 参数,重用已有 --selector--enable-igw
文件 模块 状态 重要度
sgl-model-gateway/src/service_discovery.rs 模型网关 modified 8.89
sgl-model-gateway/src/main.rs 模型网关 modified 5.98
sgl-model-gateway/bindings/python/src/lib.rs Python 绑定 modified 5.44

关键符号

warn_if_misconfigured should_include

关键源码片段

sgl-model-gateway/src/service_discovery.rs data-contract

核心文件,实现服务发现配置扩展、should_include 多模式判断、配置告警以及大量单元测试。

// ServiceDiscoveryConfig 新增 igw_mode 字段,当启用 IGW 时允许同时发现常规 worker
impl ServiceDiscoveryConfig {
    pub fn warn_if_misconfigured(&self) {
        // 若 PD 模式已开启但未启用 IGW,且设置了 --selector,则发出告警
        if self.pd_mode && !self.igw_mode && !self.selector.is_empty() {
            warn!(
                "--selector is set in PD mode without IGW mode enabled; \
                regular worker discovery alongside PD workers requires IGW mode, \
                selector will be ignored"
            );
        }
    }
}impl PodInfo {
    pub fn should_include(pod: &Pod, config: &ServiceDiscoveryConfig) -> bool {
        if config.pd_mode {
            // 当 prefill 和 decode selector 都为空时,仅在 IGW+selector 模式下不提前返回
            if config.prefill_selector.is_empty() && config.decode_selector.is_empty() {
                if !(config.igw_mode && !config.selector.is_empty()) {
                    warn!("PD mode enabled but both prefill_selector and decode_selector are empty");
                    return false;
                }
            }
            let matches_pd = Self::matches_selector(pod, &config.prefill_selector)
                || Self::matches_selector(pod, &config.decode_selector);
            // IGW 模式下,额外匹配 --selector 对应的常规 worker
            let matches_regular = config.igw_mode
                && !config.selector.is_empty()
                && Self::matches_selector(pod, &config.selector);
            matches_pd || matches_regular
        } else {
            // 常规非 PD 模式,与原有逻辑一致
            if config.selector.is_empty() {
                warn!("Regular mode enabled but selector is empty");
                return false;
            }
            Self::matches_selector(pod, &config.selector)
        }
    }
}

评论区精华

matches_regular 在 prefill/decode selector 同时为空时不可达 正确性

alexnails 指出当 prefill_selector 和 decode_selector 均为空时,原始代码直接返回 false,导致后续的 matches_regular 分支无法执行。建议在返回前检查是否因 IGW+selector 模式而需要继续发现常规 worker。

结论:开发者修改了条件判断,当 prefill/decode 都为空但 igw_mode 和 selector 非空时不再提前返回,修复了不可达问题。 · 已解决

告警信息在 Python 绑定的入口缺失 设计

alexnails 注意到二进制入口(main.rs)有配置告警,但 Python 绑定的 start() 方法没有等价检查,可能导致 Python 用户得不到提示。建议抽取 helper 使两者一致。

结论:开发者创建了 warn_if_misconfigured 方法放置于 ServiceDiscoveryConfig,并在两个入口处统一调用,确保告警全覆盖。 · 已解决

风险与影响

风险较低。首先,igw_mode 默认 false,现有 PD 模式行为保持不变,向后兼容。其次,当 pd_mode=trueigw_mode=trueselector 未设置时,告警会提示用户。如果用户误用(PD+IGW 但未设置 selector),常规 worker 不会被发现,但系统不会崩溃。另外,测试覆盖了多种组合,包括只有 PD selector、混合 IGW+selector、纯 IGW 模式等。潜在风险:如果用户已经在 PD 模式下通过一些非预期的 selector 匹配到 pod,但 igw_mode=false,那么这些 pod 现在依然会被忽略,但之前也是忽略的,所以无变化。总体而言,风险可控。

影响范围限于 sgl-model-gateway 模块的部署场景。对于使用了 --pd-disaggregation--enable-igw 的用户,现在可以通过复用 --selector 来发现常规 worker,使得同一路由器可以同时路由 PD 和非 PD 模型。没有性能影响,因为只是服务发现阶段的逻辑扩展。团队和用户需要了解新增的行为,但无需更改现有配置即可享受新能力(只需添加 --enable-igw--selector)。

配置变更影响服务发现行为 向后兼容风险(igw_mode 默认 false) 告警日志可能误导无 IGW 用户

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论