Skip to content

fix rms_norm #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix rms_norm #945

wants to merge 4 commits into from

Conversation

SangChengC
Copy link
Contributor

No description provided.

Copy link

@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.

Summary of Changes

Hello @SangChengC, 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 refactors the RMS normalization usage within the Llama model's inference components. It standardizes the RMSNorm operation by migrating to a shared, potentially optimized, rms_norm kernel and adapts the function calls to its updated signature, ensuring consistency and correctness in the normalization process.

Highlights

  • RMSNorm Implementation Update: The RMS normalization function used across the Llama model's inference layers has been updated. The previous rmsnorm_forward function, specific to Llama, has been replaced with a more general rms_norm function, now imported from lightllm.models.vit.triton_kernel.rms_norm_vit. This suggests a consolidation or improvement of the underlying kernel.
  • RMSNorm Function Signature Change: The updated rms_norm function now requires the use_custom_tensor_mananger=True argument. Additionally, in transformer_layer_infer.py, the out argument, which previously allowed specifying an explicit output tensor, has been removed from the function calls to rms_norm in both _att_norm and _ffn_norm.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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

@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

The pull request replaces the rmsnorm_forward function with rms_norm from the vit model in the llama model. The import paths and the hardcoded use_custom_tensor_mananger=True should be double checked.

@@ -8,7 +8,7 @@
from lightllm.models.llama.layer_weights.pre_and_post_layer_weight import LlamaPreAndPostLayerWeight
from einops import rearrange
from lightllm.models.llama.infer_struct import LlamaInferStateInfo
from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward
from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm

Choose a reason for hiding this comment

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

high

The import path seems incorrect. This change imports rms_norm from the vit model, but the file name indicates it should be for llama. Double check this import.

Suggested change
from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm
from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward

@@ -14,7 +14,7 @@
from lightllm.models.llama.triton_kernel.token_attention_nopad_att1 import token_att_fwd, token_att_fwd_int8k
from lightllm.models.llama.triton_kernel.token_attention_nopad_softmax import token_softmax_fwd
from lightllm.models.llama.triton_kernel.token_attention_nopad_reduceV import token_att_fwd2, token_att_fwd2_int8v
from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward
from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm

Choose a reason for hiding this comment

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

high

The import path seems incorrect. This change imports rms_norm from the vit model, but the file name indicates it should be for llama. Double check this import.

Suggested change
from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm
from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward

@@ -25,7 +25,7 @@ def __init__(self, network_config, mode):
return

def _norm(self, input, infer_state, layer_weight: LlamaPreAndPostLayerWeight) -> torch.Tensor:
return rmsnorm_forward(input, layer_weight.final_norm_weight_, eps=self.eps_)
return rms_norm(input, layer_weight.final_norm_weight_, eps=self.eps_, use_custom_tensor_mananger=True)

Choose a reason for hiding this comment

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

medium

Consider whether use_custom_tensor_mananger=True should be a configurable parameter or determined based on the execution environment, rather than being hardcoded.

return rms_norm(input, layer_weight.final_norm_weight_, eps=self.eps_)

@@ -135,14 +135,14 @@ def _att_norm(
self, input, infer_state: LlamaInferStateInfo, layer_weight: LlamaTransformerLayerWeight
) -> torch.Tensor:
out = self.alloc_tensor(input.shape, input.dtype)
rmsnorm_forward(input, weight=layer_weight.att_norm_weight_.weight, eps=self.eps_, out=out)
rms_norm(input, weight=layer_weight.att_norm_weight_.weight, eps=self.eps_, use_custom_tensor_mananger=True)

Choose a reason for hiding this comment

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

medium

Consider whether use_custom_tensor_mananger=True should be a configurable parameter or determined based on the execution environment, rather than being hardcoded.

rms_norm(input, weight=layer_weight.att_norm_weight_.weight, eps=self.eps_)

return out

def _ffn_norm(
self, input, infer_state: LlamaInferStateInfo, layer_weight: LlamaTransformerLayerWeight
) -> torch.Tensor:
out = self.alloc_tensor(input.shape, input.dtype)
rmsnorm_forward(input, weight=layer_weight.ffn_norm_weight_.weight, eps=self.eps_, out=out)
rms_norm(input, weight=layer_weight.ffn_norm_weight_.weight, eps=self.eps_, use_custom_tensor_mananger=True)

Choose a reason for hiding this comment

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

medium

Consider whether use_custom_tensor_mananger=True should be a configurable parameter or determined based on the execution environment, rather than being hardcoded.

rms_norm(input, weight=layer_weight.ffn_norm_weight_.weight, eps=self.eps_)

@SangChengC SangChengC force-pushed the fix_rms_norm branch 3 times, most recently from f432e97 to 45e2878 Compare June 27, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant