Repository navigation
[Dev] Add configurable attention latent normalization epsilon #6204
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| ) | ||
| from megatron.core.transformer.attention import Attention | ||
| from megatron.core.transformer.enums import AttnMaskType | ||
| from megatron.core.transformer.mla_qk_norm_config import QKNormConfigResolver | ||
| from megatron.core.transformer.spec_utils import ModuleSpec, build_module | ||
| from megatron.core.transformer.transformer_config import MLATransformerConfig | ||
| from megatron.core.utils import deprecate_inference_params, get_pg_size, is_te_min_version | ||
|
|
@@ -164,6 +165,8 @@ def __init__( | |
| name=name, | ||
| ) | ||
|
|
||
| layer_classes = QKNormConfigResolver(self.config, submodules).resolve() | ||
|
|
||
| assert not config.add_bias_linear, "add_bias_linear is not supported for AbsorbedMLA" | ||
| assert not ( | ||
| config.tensor_model_parallel_size > 1 and not config.sequence_parallel | ||
|
|
@@ -263,7 +266,7 @@ def __init__( | |
| if self.config.q_lora_rank is None: | ||
| # Not projecting query | ||
| self.linear_q_proj = build_module( | ||
| submodules.linear_q_proj, | ||
| layer_classes["linear_q_proj"], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it need to override in the init func rather than replace the spec directly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know... This is carried over from #4452... This PR needs 4452's mla_qk_norm_config.py. This is how my agent replies to your question:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I see. |
||
| self.config.hidden_size, | ||
| self.config.num_attention_heads * self.q_head_dim, | ||
| config=self.config, | ||
|
|
@@ -309,7 +312,7 @@ def __init__( | |
| ) | ||
|
|
||
| self.linear_q_up_proj = build_module( | ||
| submodules.linear_q_up_proj, | ||
| layer_classes["linear_q_up_proj"], | ||
| self.config.q_lora_rank, | ||
| self.config.num_attention_heads * self.q_head_dim, | ||
| config=self.config, | ||
|
|
@@ -370,7 +373,7 @@ def __init__( | |
|
|
||
| if self._uses_combined_kv_up_projection: | ||
| self.linear_kv_up_proj = build_module( | ||
| submodules.linear_kv_up_proj, | ||
| layer_classes["linear_kv_up_proj"], | ||
|
buptzyb marked this conversation as resolved.
|
||
| self.config.kv_lora_rank, | ||
| self.config.num_attention_heads | ||
| * (self.config.qk_head_dim + self.config.v_head_dim), | ||
|
|
@@ -416,17 +419,17 @@ def __init__( | |
|
|
||
| if self.config.q_lora_rank is not None: | ||
| self.q_layernorm = build_module( | ||
| submodules.q_layernorm, | ||
| layer_classes["q_layernorm"], | ||
| hidden_size=self.config.q_lora_rank, | ||
| config=self.config, | ||
| eps=self.config.layernorm_epsilon, | ||
| eps=self.config.attention_latent_norm_epsilon, | ||
| ) | ||
|
|
||
| self.kv_layernorm = build_module( | ||
| submodules.kv_layernorm, | ||
| layer_classes["kv_layernorm"], | ||
| hidden_size=self.config.kv_lora_rank, | ||
| config=self.config, | ||
| eps=self.config.layernorm_epsilon, | ||
| eps=self.config.attention_latent_norm_epsilon, | ||
| ) | ||
|
|
||
| def get_query_key_value_tensors( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.