# PR #2081 完整报告

- 仓库：`THUDM/slime`
- 标题：sync from internal and cleanup
- 合并时间：2026-06-15 14:50
- 原文链接：http://prhub.com.cn/THUDM/slime/pull/2081

---

# 执行摘要

- 一句话：清理并同步内部代码变更
- 推荐动作：该 PR 为常规维护清理，值得快速合入。建议关注后续 PR 中 `apply_chat_template_kwargs` 的实际使用，确保数据一致性。

# 功能与动机

PR 标题为“sync from internal and cleanup”，目的是同步内部仓库的改进并清理已废弃的功能。具体动机包括：移除已弃用的 `--use-slime-router` 标志（该功能已被 SGLang router 替代），以及为 `Sample` 数据类增加新字段以支持更灵活的 chat template 和 per-sample 自定义 reward model 路径。

# 实现拆解

1. **移除已废弃的 SGLang Router 参数 **（`slime/utils/arguments.py`）：删除 `add_router_arguments` 函数及其调用，移除对 `RouterArgs` 的导入，以及在 `slime_validate_args` 中处理 `--use-slime-router` 的废弃警告逻辑。
2. **扩展 `Sample` 数据类 **（`slime/utils/types.py`）：新增两个字段——`apply_chat_template_kwargs`（支持更灵活的 chat template 配置）和 `custom_rm_path`（支持 per-sample 自定义 reward model 路径）。
3. **调整 reward model 路由优先级 **（`slime/rollout/rm_hub/__init__.py`）：在 `async_rm` 函数中，将 `sample.custom_rm_path` 的检查移至 `args.custom_rm_path` 之前，使得 sample 级别的自定义 RM 路径优先于全局配置。
4. **更新测试用例 **（`tests/test_megatron_argument_validation.py`）：在 `make_slime_validate_args` 的默认值中移除 `use_slime_router=False`，以匹配参数列表的变更。

关键文件：
- `slime/utils/arguments.py`（模块 参数解析；类别 source；类型 core-logic；符号 add_router_arguments）: 移除已废弃的 `--use-slime-router` 参数及相关导入和验证逻辑，是本次清理的核心改动。
- `slime/rollout/rm_hub/__init__.py`（模块 奖励模型；类别 source；类型 core-logic）: 修改 reward model 路由优先级，支持 per-sample 自定义 RM 路径。
- `slime/utils/types.py`（模块 数据结构；类别 source；类型 core-logic）: 为 Sample 数据类新增两个字段，支持更灵活的配置。
- `tests/test_megatron_argument_validation.py`（模块 测试；类别 test；类型 test-coverage）: 移除测试中已删除参数 `use_slime_router` 的默认值，保持测试与代码一致。

关键符号：add_router_arguments, async_rm, slime_validate_args

## 关键源码片段

### `slime/utils/arguments.py`

移除已废弃的 `--use-slime-router` 参数及相关导入和验证逻辑，是本次清理的核心改动。

```python
# slime/utils/arguments.py
# 以下为被删除的代码片段（已从文件中移除）
# 删除的导入：
# from sglang_router.launch_router import RouterArgs

# 删除的函数 add_router_arguments：
# def add_router_arguments(parser):
# parser.add_argument(
# "--use-slime-router",
# action="store_true",
# default=False,
# help="Whether to use SlimeRouter for text-based routing instead of SGLang token-based routing",
# )
# RouterArgs.add_cli_args(parser, use_router_prefix=True, exclude_host_port=True)
# return parser

# 在 slime_validate_args 中删除的废弃警告：
# if args.use_slime_router:
# logger.warning(
# "--use-slime-router is deprecated and ignored. slime now always uses sglang_router "
# "built from https://github.com/zhuzilin/sgl-router."
# )
# args.use_slime_router = False

```

### `slime/rollout/rm_hub/__init__.py`

修改 reward model 路由优先级，支持 per-sample 自定义 RM 路径。

```python
# slime/rollout/rm_hub/__init__.py
async def async_rm(args, sample: Sample, **kwargs):
    # Per-sample custom_rm_path (from eval dataset config) takes priority
    if sample.custom_rm_path:
        rm_function = load_function(sample.custom_rm_path)
        return await rm_function(args, sample, **kwargs)

    if args.custom_rm_path is not None:
        rm_function = load_function(args.custom_rm_path)
        return await rm_function(args, sample, **kwargs)
    # ... 后续逻辑不变

```

### `slime/utils/types.py`

为 Sample 数据类新增两个字段，支持更灵活的配置。

```python
# slime/utils/types.py
@dataclass
class Sample:
    """The sample generated"""
    # ... 已有字段 ...
    # 新增字段：
    apply_chat_template_kwargs: dict = field(default_factory=dict)  # 支持更灵活的 chat template 配置
    # ...
    custom_rm_path: str | None = None  # per-sample 自定义 reward model 路径，优先级高于全局 args.custom_rm_path
    # ...

```

# 评论区精华

本 PR 无 review 评论和讨论。

- 暂无高价值评论线程

# 风险与影响

- 风险：风险较低。主要涉及删除已废弃的功能和新增字段：
 - `--use-slime-router` 已被标记为 deprecated，删除后不应影响现有使用 SGLang router 的用户。
 - 新增的 `custom_rm_path` 字段仅在 `async_rm` 中使用，且优先于全局配置，不会破坏现有行为。
 - 新增的 `apply_chat_template_kwargs` 字段仅为数据容器，未在其他地方引用，需要确认后续使用是否一致。
 - 测试覆盖的调整仅移除一个默认值，风险低。
 - 影响：
 - **用户影响**：移除了已废弃的 `--use-slime-router` 命令行参数，用户若仍在使用该参数将报错，但已有废弃警告提示。
 - **系统影响**：reward model 路由优先级变化，sample 级别的 `custom_rm_path` 将覆盖全局设置，使得在 eval dataset 中为每个样本指定不同的 RM 成为可能。
 - **团队影响**：新增 `Sample` 字段需确保下游数据序列化和消费方兼容。
 - 风险标记：废弃功能移除 , 新增数据字段

# 关联脉络

- PR #2057 Allow zero-GPU rollout router startup: 涉及 rollout router 的配置变更，与本 PR 移除的 --use-slime-router 属于同一功能线。