-
Notifications
You must be signed in to change notification settings - Fork 293
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
fix rms_norm #945
Conversation
There was a problem hiding this 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_forwardfunction, specific to Llama, has been replaced with a more generalrms_normfunction, now imported fromlightllm.models.vit.triton_kernel.rms_norm_vit. This suggests a consolidation or improvement of the underlying kernel. - RMSNorm Function Signature Change: The updated
rms_normfunction now requires theuse_custom_tensor_mananger=Trueargument. Additionally, intransformer_layer_infer.py, theoutargument, which previously allowed specifying an explicit output tensor, has been removed from the function calls torms_normin both_att_normand_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
-
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. ↩
There was a problem hiding this 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.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm | |
| from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| from lightllm.models.vit.triton_kernel.rms_norm_vit import rms_norm | |
| from lightllm.models.llama.triton_kernel.rmsnorm import rmsnorm_forward |
|
|
||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) -> 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) -> 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f432e97 to
45e2878
Compare
No description provided.