NVIDIA / NVIDIA/Megatron-LM

[QUESTION] MOE training meet abnormal gradient norm and loss

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

Description

Hello, I am training a MOE model (16B total and 2.5B activated) and below are some tensorboard logs,

**grad norm**
![Image](https://github.com/user-attachments/assets/d9be9c3b-ab20-4d65-9d65-7ef052e3f657)

![Image](https://github.com/user-attachments/assets/55568b17-5592-4e04-8b70-95f4dade3f01)

**Lm loss**
![Image](https://github.com/user-attachments/assets/e9e8ac5f-5acf-42b5-941b-668b274e7084)

![Image](https://github.com/user-attachments/assets/31584462-dd44-44b9-884c-9da3a4233147)

**load_balance_loss**
![Image](https://github.com/user-attachments/assets/614bf749-9ba4-4d78-a8b4-c284bd41b251)

![Image](https://github.com/user-attachments/assets/7ddc1b2a-3f3f-44f9-9059-d14e0c58f34d)

as you can see, as training going on , loss and gradient turns abnormal,here are some key arguments

**the ordinary arguments**

```
--lr 4.2e-4
--min-lr 4.2e-5
--lr-decay-style cosine
--weight-decay 0.1
--adam-beta1 0.9
--adam-beta2 0.95
--clip-grad 1.0
--init-method-std 0.006
--attention-dropout 0.0
--hidden-dropout 0.0
--lr-decay-iters 381469
--lr-warmup-iters 2000
--train-iters 381469
--micro-batch-size 2
--global-batch-size 4800
--num-layers 28
--hidden-size 2048
--num-attention-heads 16
--ffn-hidden-size 10944
--seq-length 4096
--max-position-embeddings 4096
--tensor-model-parallel-size 1
--pipeline-model-parallel-size 2
--context-parallel-size 1
--swiglu
--normalization RMSNorm
--norm-epsilon 1e-6
--use-rotary-position-embeddings
--no-bias-swiglu-fusion
--no-rope-fusion
--position-embedding-type rope
--untie-embeddings-and-output-weights
--rotary-base 10000
--rotary-scaling-factor 40
--kv-channels 128
--bf16
```
**arguments related to MOE**

```
--qk-layernorm
--multi-latent-attention
--transformer-impl transformer_engine
--use-distributed-optimizer
--attention-backend flash
--moe-ffn-hidden-size 1408
--moe-router-topk 6
--num-experts 64
--moe-layer-freq 1
--moe-first-k-dense-replace 1
--moe-aux-loss-coeff 0.001
--moe-shared-expert-intermediate-size 2816
--expert-model-parallel-size 8
--kv-lora-rank 512
--qk-head-dim 128
--qk-pos-emb-head-dim 64
--v-head-dim 128
--moe-token-dispatcher-type alltoall_seq
--moe-grouped-gemm
--moe-router-score-function sigmoid
--moe-router-enable-expert-bias
--moe-router-bias-update-rate 0.001
--moe-router-load-balancing-type seq_aux_loss
```

Can anyone offer some potential reason for the abnormal gradient? Thanks

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.