# PR #23894 完整报告

- 仓库：`sgl-project/sglang`
- 标题：Support --model as alias for --model-path in CLI
- 合并时间：2026-04-29 08:23
- 原文链接：http://prhub.com.cn/sgl-project/sglang/pull/23894

---

# 执行摘要

- 一句话：支持 --model 作为 --model-path 的 CLI 别名
- 推荐动作：该 PR 改动简单直接，无需精读。可合并用于提升 CLI 用户体验。

# 功能与动机

PR 标题和 commit message 明确指出：允许用户使用 `--model` 作为 `--model-path` 的别名，匹配其他流行 serving 框架的惯例，提升 CLI 易用性和用户迁移体验。

# 实现拆解

1. **修改参数匹配逻辑**：在 `python/sglang/cli/utils.py` 的 `get_model_path` 函数中（第 106 行），将 `if arg == "--model-path"` 改为 `if arg in ("--model-path", "--model")`，同时在第 110 行，将 `elif arg.startswith("--model-path=")` 扩展为 `elif arg.startswith("--model-path=") or arg.startswith("--model=")`，从而支持等号赋值形式。
2. **无其他配套变更**：本次改动未涉及文档、测试或配置更新，改动范围局限在源码内。

关键文件：
- `python/sglang/cli/utils.py`（模块 CLI；类别 source；类型 core-logic）: 唯一被修改的文件，核心变更在 get_model_path 函数，支持 --model 作为 --model-path 的别名。

关键符号：get_model_path

## 关键源码片段

### `python/sglang/cli/utils.py`

唯一被修改的文件，核心变更在 get_model_path 函数，支持 --model 作为 --model-path 的别名。

```python
# python/sglang/cli/utils.py

def get_model_path(extra_argv):
    # Find the model_path argument
    model_path = None
    for i, arg in enumerate(extra_argv):
        # 支持 --model-path 和 --model 两种 flag
        if arg in ("--model-path", "--model"):
            if i + 1 < len(extra_argv):
                model_path = extra_argv[i + 1]
                break
        # 同时支持等号赋值形式，如 --model=xxx 或 --model-path=xxx
        elif arg.startswith("--model-path=") or arg.startswith("--model="):
            model_path = arg.split("=", 1)[1]
            break

    if model_path is None:
        if any(h in extra_argv for h in ["-h", "--help"]):
            raise Exception(
                "Usage: sglang serve --model-path <model-name-or-path> [additional-arguments]

"
                "This command can launch either a standard language model server or a diffusion model server.\n"
                "The server type is determined by the --model-path.\n"
            )
        else:
            raise Exception(
                "Error: --model-path is required. "
                "Please provide the path to the model."
            )
    return model_path

```

# 评论区精华

PR 无 review 评论讨论。

- 暂无高价值评论线程

# 风险与影响

- 风险：风险极低。改动仅两行，在 CLI 参数解析中增加一个逻辑分支，不改变原有 `--model-path` 的行为，不会影响内部核心逻辑或性能。但需注意，若已有模型名称恰好以 `--model=` 开头（极不可能），可能产生误匹配。
- 影响：影响范围极小。仅对使用 CLI 启动服务时通过 `--model` 参数传递模型路径的用户有正面影响；现有 `--model-path` 用户不受影响。无需考虑回滚或兼容性。
- 风险标记：暂无

# 关联脉络

- 暂无明显关联 PR