Skip to content

Commit 5d5eeb5

Browse files
Merge pull request #2811 from AI-Hypercomputer:qinwen/add_ckpt_mla
PiperOrigin-RevId: 843274677
2 parents 9e16c99 + 6560a08 commit 5d5eeb5

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/MaxText/configs/base.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ key_proj: 'remat'
298298
value_proj: 'remat'
299299
qkv_proj: 'remat'
300300
out_proj: 'remat'
301+
mla_q: 'remat'
302+
mla_kv: 'remat'
301303

302304
optimizer_memory_host_offload: False
303305
parameter_memory_host_offload: False

src/MaxText/configs/types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ class RematAndOffload(BaseModel):
805805
RematLocation.REMAT,
806806
description="Remat policy for the attention output projection.",
807807
)
808+
mla_q: RematLocation = Field(
809+
RematLocation.REMAT,
810+
description="Remat policy for the mla's query projectiont.",
811+
)
812+
mla_kv: RematLocation = Field(
813+
RematLocation.REMAT,
814+
description="Remat policy for the mla's key and value projection.",
815+
)
808816
optimizer_memory_host_offload: bool = Field(False, description="Offload optimizer state to host memory.")
809817
parameter_memory_host_offload: bool = Field(False, description="Offload parameters to host memory.")
810818

@@ -1855,6 +1863,8 @@ def calculate_global_batch_sizes(per_device_batch_size, expansion_factor, num_de
18551863
"query_proj",
18561864
"key_proj",
18571865
"value_proj",
1866+
"mla_kv",
1867+
"mla_q",
18581868
"qkv_proj",
18591869
"out_proj",
18601870
]

src/MaxText/layers/attention_mla.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ def mla_query_projection(self, inputs_q: Array, inputs_positions: Array, model_m
530530
# LoRA path
531531
low_rank_q = self.wq_a(inputs_q, out_sharding=wqa_out_sharding) # [B, L, q_lora_rank]
532532
low_rank_q = self.q_norm(low_rank_q) # RMSNorm on low rank
533+
low_rank_q = checkpoint_name(low_rank_q, "mla_q")
533534
q = self.wq_b(low_rank_q, out_sharding=query_sharding) # [B, L, n_heads * qk_head_dim]
534535

535536
# Split into non-positional and rotary parts.
@@ -668,7 +669,7 @@ def mla_kv_projection(self, inputs: Array, inputs_positions: Array, decoder_segm
668669
low_rank = self.wkv_a(inputs, out_sharding=wkva_out_sharding)
669670
low_rank_main, low_rank_rope = jnp.split(low_rank, [self.kv_lora_rank], axis=-1)
670671
low_rank_main = self.kv_norm(low_rank_main)
671-
672+
low_rank_main = checkpoint_name(low_rank_main, "mla_kv")
672673
# Apply rotary embedding to key_rope.
673674
key_rope = jnp.expand_dims(low_rank_rope, axis=2)
674675
key_rope = self.apply_rotary_embedding(key_rope, inputs_positions=inputs_positions)

0 commit comments

Comments
 (0)