Skip to content

[Diffusion] Restruct and clean Diffusion rotary embedding#19064

Merged
BBuf merged 2 commits intomainfrom
restruct_rotary_embedding
Feb 21, 2026
Merged

[Diffusion] Restruct and clean Diffusion rotary embedding#19064
BBuf merged 2 commits intomainfrom
restruct_rotary_embedding

Conversation

@BBuf
Copy link
Collaborator

@BBuf BBuf commented Feb 20, 2026

Motivation

rotary_embedding.py had grown to 1029 lines and was difficult to navigate. This PR splits it into a rotary_embedding/ package with logically grouped sub-modules. No logic changes — this is a pure code reorganization.

And I removed 4 unused funcs: get_meshgrid_nd, get_nd_rotary_pos_embed, _rotate_neox, _rotate_gptj

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @BBuf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the maintainability and readability of the Diffusion rotary embedding module by restructuring its codebase. The previously large rotary_embedding.py file has been broken down into a more organized package structure, separating different concerns into dedicated sub-modules. Additionally, several functions that were no longer in use have been removed, contributing to a cleaner codebase. These changes are purely organizational and do not alter the existing logic or behavior of the rotary embedding functionalities.

Highlights

  • Code Reorganization: The monolithic rotary_embedding.py file, which had grown to over 1000 lines, has been refactored into a new rotary_embedding/ package. This improves modularity and navigability by splitting functionalities into dedicated sub-modules.
  • Modular Structure: Core functionalities are now distributed across _base.py (for base embedding classes), _factory.py (for factory functions and caches), _mrope.py (for multi-dimensional rotary embeddings), and _utils.py (for utility functions).
  • Unused Code Removal: Four unused functions, namely get_meshgrid_nd, get_nd_rotary_pos_embed, _rotate_neox, and _rotate_gptj, have been removed, contributing to a cleaner and more efficient codebase.
  • No Logic Changes: The pull request explicitly states that these changes are purely organizational and do not introduce any modifications to the existing logic or behavior of the rotary embedding functionalities.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding.py
    • Removed the original monolithic rotary embedding file.
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding/init.py
    • Added to establish the new rotary_embedding package and define its public interface.
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding/_base.py
    • Added to encapsulate the base RotaryEmbedding and LinearScalingRotaryEmbedding classes.
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding/_factory.py
    • Added to manage the factory functions get_rope and get_rotary_pos_embed along with their internal caches.
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding/_mrope.py
    • Added to house the OneDRotaryEmbedding and NDRotaryEmbedding classes, and related helper functions.
  • python/sglang/multimodal_gen/runtime/layers/rotary_embedding/_utils.py
    • Added to provide helper functions for applying rotary embeddings and FlashInfer integration.
Activity
  • No specific review comments or activity beyond the initial pull request creation have been recorded.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of refactoring the large rotary_embedding.py file into a more manageable package structure. The code is now better organized and easier to navigate. I've found a couple of minor issues related to dead code that was carried over from the original file. Addressing these will further improve the codebase's cleanliness. Overall, this is a solid improvement.

@BBuf
Copy link
Collaborator Author

BBuf commented Feb 20, 2026

/tag-and-rerun-ci

@BBuf BBuf merged commit 66497ab into main Feb 21, 2026
108 of 117 checks passed
@BBuf BBuf deleted the restruct_rotary_embedding branch February 21, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants