NVIDIA / NVIDIA/Megatron-LM

[BUG] [MLA] k_pos_emb in MLA is not reduced across TP ranks if linear_kv_down_proj is ColumnParallelLinear

Open
#1,699 0 comments 0 reactions 0 assignees View on GitHub
bug module: moe
Dominant language
Python
Stars
17.9k
Forks
4.5k
Avg merge
4d 6h
Merged PRs (30d)
271

Description

**Describe the bug**

https://github.com/NVIDIA/Megatron-LM/blob/e96a358f60c82b8ac8d965d91c3cc4ad0230a4e0/megatron/core/transformer/multi_latent_attention.py#L443

`gather_from_tensor_model_parallel_region` uses `split` for backward. The grad of `kv_compressed` is already reduced by `ColumnParallelLinear` but the grad of `k_pos_emb` is never reduced across TP ranks.

This part of code was introduced by https://github.com/NVIDIA/Megatron-LM/commit/1c425a83136c4f5b5841051fe9a501e3c36a750b

**Analysis**

The `expand` operation [here](https://github.com/NVIDIA/Megatron-LM/blob/e96a358f60c82b8ac8d965d91c3cc4ad0230a4e0/megatron/core/transformer/multi_latent_attention.py#L573-L577) is actually a simplified forward path for:
**k_pos_emb** *(nheads=1, duplicated)* --expand--> **k_pos_emb** *(nheads=N, duplicated)* --scatter--> **k_pos_emb** *(nheads=N/TP, sharded)*

During the backward, the grad of `k_pos_emb` is different across TP ranks and a sum-reduce might be needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.