Skip to content

Align rope init in lmdeploy#4466

Merged
lvhan028 merged 1 commit intoInternLM:mainfrom
RangiLyu:lcq/rope-init
Mar 26, 2026
Merged

Align rope init in lmdeploy#4466
lvhan028 merged 1 commit intoInternLM:mainfrom
RangiLyu:lcq/rope-init

Conversation

@RangiLyu
Copy link
Contributor

Align all rope initialization with

inv_freq = 1.0 / (self.base**(torch.arange(0, self.dim, 2, dtype=torch.int64).float() / self.dim))

There is a slight difference in numerical precision between CPU and GPU, which leads to inconsistencies between training and inference in RL.

Copilot AI review requested due to automatic review settings March 25, 2026 08:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes RoPE inverse-frequency (inv_freq) initialization across several PyTorch model/backends to match the default rotary embedding implementation, aiming to reduce CPU vs GPU numerical differences that can cause RL training/inference inconsistencies.

Changes:

  • Update Qwen3.5 default RoPE parameter computation to compute inv_freq in float on CPU first, then move to the target device.
  • Update Qwen2-VL / Qwen2.5-VL vision rotary embeddings to follow the same arange(int64) -> float -> move device pattern.
  • Update dlinfer rotary embedding initialization to follow the same pattern before moving to CUDA.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
lmdeploy/pytorch/models/qwen3_5.py Adjusts default RoPE inv_freq initialization to align numerically with the default backend implementation.
lmdeploy/pytorch/models/qwen2_vl.py Aligns vision rotary embedding inv_freq init pattern (CPU float compute, then .to(device)).
lmdeploy/pytorch/models/qwen2_5_vl.py Same alignment for Qwen2.5-VL vision rotary embedding inv_freq.
lmdeploy/pytorch/backends/dlinfer/rotary_embedding.py Aligns dlinfer base rotary embedding inv_freq init pattern (then moves to CUDA).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CUHKSZzxy CUHKSZzxy mentioned this pull request Mar 25, 2026
@lvhan028 lvhan028 merged commit 9d1dda3 into InternLM:main Mar 26, 2026
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants