Skip to content
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

[BUG or ENHANCEMENT] Update qk_layernorm. #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ftgreat
Copy link
Collaborator

@ftgreat ftgreat commented Sep 10, 2024

With current qk_layernorm implement training did not converge.
One shared qk_layernorm acts on every head, however qk_layernorm should affect all heads.
So just enlarge the shape of qk_layernorm weights, training converges as expected.

image

List some models using qk_layernorm for references:

  1. https://github.com/mlfoundations/open_lm/blob/main/open_lm/model.py#L131 used in DCLM-7B
  2. https://github.com/huggingface/transformers/blob/main/src/transformers/models/olmoe/modeling_olmoe.py#L394-L395 used in OLMoE

Signed-off-by: ldwang <[email protected]>
@@ -360,7 +360,7 @@ def __init__(
if submodules.q_layernorm is not None:
self.q_layernorm = build_module(
submodules.q_layernorm,
hidden_size=self.hidden_size_per_attention_head,
hidden_size=self.query_projection_size,
Copy link
Collaborator

@heavyrain-lzy heavyrain-lzy Sep 10, 2024

Choose a reason for hiding this comment

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

Thanks for your contribution. According to my understanding, the difference between the origin code and your code is as follows:

  • origin code: normalize the every single head individually
  • new code: normalize all the heads together

According to the input_layernormhttps://github.com/NVIDIA/Megatron-LM/blob/bbecd0812ffc9a90eef472fda91c60eead3f417f/megatron/core/transformer/transformer_layer.py#L111, we should normalize all the heads together. Maybe you can add an issue in Megatron-LM to recheck it.
I think you are right.
LGTM.

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.

2 participants