[Feature] Support glm yarn scaling rope#7893
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-22 12:24:25
📋 Review 摘要
PR 概述:为 GLM 模型新增 Yarn RoPE 缩放支持,并将 GptOssScalingRotaryEmbedding 重命名为 YarnScalingRotaryEmbedding
变更范围:fastdeploy/model_executor/layers/rotary_embedding.py
影响面 Tag:[OP]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | rotary_embedding.py:362 |
rope_scaling["original_max_position_embeddings"] 直接字典访问,缺少字段时抛 KeyError |
| 📝 PR 规范 | — | 标题拼写错误;PR 描述各 section 均为空,Checklist 全未勾选 |
📝 PR 规范检查
存在两处规范问题:①标题存在拼写错误("Supoort" → "Support");②PR body 的 Motivation、Modifications、Usage or Command、Accuracy Tests 各节均为空,Checklist 条目全部未勾选。
标题建议(可直接复制):
[Feature] Support GLM Yarn scaling RoPE
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
为 GLM 系列模型(`architecture.startswith("Glm")`)新增 Yarn RoPE 缩放支持。当模型配置中 `rope_scaling.rope_type`(或 `type`)为 `"yarn"` 时,自动切换到 `YarnScalingRotaryEmbedding` 而非默认的 `GlmRotaryEmbedding`,以支持超出原始训练长度的推理场景。同时将 `GptOssScalingRotaryEmbedding` 重命名为语义更通用的 `YarnScalingRotaryEmbedding`。
## Modifications
- `fastdeploy/model_executor/layers/rotary_embedding.py`
- 将 `GptOssScalingRotaryEmbedding` 类重命名为 `YarnScalingRotaryEmbedding`
- 在 `get_rope_impl` 的 `Glm` 分支中,增加对 `rope_scaling.rope_type == "yarn"` 的检测逻辑,命中时实例化 `YarnScalingRotaryEmbedding` 并传入 `factor`、`mscale`、`beta_fast`、`beta_slow` 等参数
- `GptOss` 分支使用重命名后的 `YarnScalingRotaryEmbedding`
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.总体评价
GLM Yarn RoPE 支持的整体实现思路正确,条件判断层次清晰;但存在一个 KeyError 安全风险需在合入前修复,同时 PR 描述需补全以便后续可追溯。
| original_max_position_embeddings=rope_scaling["original_max_position_embeddings"], | ||
| scale=rope_scaling["factor"], | ||
| mscale=rope_scaling.get("mscale", 1.0), | ||
| beta_fast=rope_scaling.get("beta_fast", 32), |
There was a problem hiding this comment.
🔴 Bug rope_scaling["original_max_position_embeddings"] 直接字典访问,存在 KeyError 风险。
当前条件只验证了 "factor" in rope_scaling,但未检查 "original_max_position_embeddings" 是否存在。若用户的 rope_scaling 配置中缺少该字段,运行时会直接抛出 KeyError 导致服务崩溃。
建议修复(使用 .get() + 显式报错):
original_max_pos = rope_scaling.get("original_max_position_embeddings")
if original_max_pos is None:
raise ValueError(
"rope_scaling must contain 'original_max_position_embeddings' when rope_type is 'yarn'"
)
rotary_emb_layer = YarnScalingRotaryEmbedding(
rotary_dim=yarn_rotary_dim,
base=base,
original_max_position_embeddings=original_max_pos,
...
)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7893 +/- ##
==========================================
Coverage ? 63.62%
==========================================
Files ? 462
Lines ? 64484
Branches ? 9881
==========================================
Hits ? 41029
Misses ? 20674
Partials ? 2781
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
支持GLM 256K 长上下文推理
Modifications
Usage or Command
Accuracy Tests
结果
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.