NVIDIA / NVIDIA/Megatron-LM

[QUESTION] Enabling `--fp8-param-gather` during model training with `mxfp8` consumes more GPU memory compared to leaving it disabled.

Open
#2,063 4 comments 0 reactions 1 assignee Claimed by @kunlunl View on GitHub
module: transformer engine question
Dominant language
Python
Stars
17.9k
Forks
4.5k
Avg merge
4d 6h
Merged PRs (30d)
271

Description

# Question
Hi, Megatron team!

On Blackwell GPUs, I loaded a checkpoint trained on Hopper GPUs to continue training. I've noticed that enabling the `--fp8-param-gather` flag actually increases GPU memory usage during training by `mxfp8`. My understanding was that turning on `--fp8-param-gather` should save memory by avoiding the need to keep BF16 copies of parameters in MLP/MoE layers, so overall memory consumption should decrease—not increase.

My environment consists of 1 node with 4 GB200s.

From ckpt:

| Exp | arguments | max allocated(MB) | max reserved(MB) | nvidia-smi(MB) |
|-----|-------------------------------------------------------------------------------------------------------|-------------------|------------------|----------------|
| 1 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer` | 60718 | 60906 | 69689 |
| 2 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--overlap-param-gather`
`--overlap-grad-reduce` | 60718 | 60910 | 69693 |
| 3 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--fp8-param-gather`
`--reuse-grad-buf-for-mxfp8-param-ag` | 65063 | 65188 | 73971 |
| 4 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--overlap-param-gather`
`--overlap-grad-reduce`
`--fp8-param-gather`
`--reuse-grad-buf-for-mxfp8-param-ag` | 65063 | 65182 | 73963 |

From scratch:
| Exp | fp8-related arguments | max allocated(MB) | max reserved(MB) | nvidia-smi(MB) |
|-----|-------------------------------------------------------------------------------------------------------|-------------------|------------------|----------------|
| 1 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--overlap-param-gather`
`--overlap-grad-reduce` | 34764 | 34954 | 55481 |
| 2 | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--overlap-param-gather`
`--overlap-grad-reduce`
`--fp8-param-gather`
`--reuse-grad-buf-for-mxfp8-param-ag` | 34764 | 34954 | 52711 |

Compare from ckpt with from scratch:
| Exp | fp8-related arguments | max allocated(MB) | max reserved(MB) | nvidia-smi(MB) |
|-----|-------------------------------------------------------------------------------------------------------|-------------------|------------------|----------------|
| from ckpt | `--fp8-format e4m3`
`--fp8-recipe mxfp8`
`--moe-router-padding-for-fp8`
`--use-distributed-optimizer`
`--overlap-param-gather`
`--overlap-grad-reduce`
`--fp8-param-gather`
`--reuse-grad-buf-for-mxfp8-param-ag` | 65063 | 65182 | 73963 |
| from scratch | same as above | 34764 | 34954 | 52711 |

# Env
Megatron-LM: https://github.com/NVIDIA/Megatron-LM/tree/core_v0.14.0
TransformerEngine: https://github.com/NVIDIA/TransformerEngine/commit/40c69e75

pytorch collect_env

```
PyTorch version: 2.8.0a0+34c6371d24.nv25.08
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.2 LTS (aarch64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 3.31.6
Libc version: glibc-2.39

Python version: 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.6.47-002.ant8.aarch64-aarch64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: 13.0.48
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA GB200
GPU 1: NVIDIA GB200
GPU 2: NVIDIA GB200
GPU 3: NVIDIA GB200

Nvidia driver version: 580.65.06
cuDNN version: Probably one of the following:
/usr/lib/aarch64-linux-gnu/libcudnn.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_adv.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_cnn.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_engines_precompiled.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_graph.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_heuristic.so.9.12.0
/usr/lib/aarch64-linux-gnu/libcudnn_ops.so.9.12.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 144
On-line CPU(s) list: 0-143
Vendor ID: ARM
Model name: Neoverse-V2
Model: 0
Thread(s) per core: 1
Core(s) per cluster: 72
Socket(s): -
Cluster(s): 2
Stepping: r0p0
Frequency boost: disabled
CPU(s) scaling MHz: 95%
CPU max MHz: 3384.0000
CPU min MHz: 81.0000
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh
L1d cache: 9 MiB (144 instances)
L1i cache: 9 MiB (144 instances)
L2 cache: 144 MiB (144 instances)
L3 cache: 228 MiB (2 instances)
NUMA node(s): 34
NUMA node0 CPU(s): 0-71
NUMA node1 CPU(s): 72-143
NUMA node2 CPU(s):
NUMA node3 CPU(s):
NUMA node4 CPU(s):
NUMA node5 CPU(s):
NUMA node6 CPU(s):
NUMA node7 CPU(s):
NUMA node8 CPU(s):
NUMA node9 CPU(s):
NUMA node10 CPU(s):
NUMA node11 CPU(s):
NUMA node12 CPU(s):
NUMA node13 CPU(s):
NUMA node14 CPU(s):
NUMA node15 CPU(s):
NUMA node16 CPU(s):
NUMA node17 CPU(s):
NUMA node18 CPU(s):
NUMA node19 CPU(s):
NUMA node20 CPU(s):
NUMA node21 CPU(s):
NUMA node22 CPU(s):
NUMA node23 CPU(s):
NUMA node24 CPU(s):
NUMA node25 CPU(s):
NUMA node26 CPU(s):
NUMA node27 CPU(s):
NUMA node28 CPU(s):
NUMA node29 CPU(s):
NUMA node30 CPU(s):
NUMA node31 CPU(s):
NUMA node32 CPU(s):
NUMA node33 CPU(s):
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Not affected
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] mypy_extensions==1.1.0
[pip3] numpy==1.26.4
[pip3] nvidia-cudnn-frontend==1.13.0
[pip3] nvtx==0.2.11
[pip3] onnx==1.18.0
[pip3] onnx-ir==0.1.11
[pip3] onnxscript==0.3.1
[pip3] optree==0.17.0
[pip3] pynvjitlink==0.7.0
[pip3] pytorch-triton==3.3.1+gitc8757738
[pip3] torch==2.8.0a0+34c6371d24.nv25.8
[pip3] torch_tensorrt==2.8.0a0
[pip3] torchao==0.12.0+git
[pip3] torchprofile==0.0.4
[pip3] torchvision==0.23.0a0+428a54c9
[conda] Could not collect
```

# Script to reproduce

script

```shell
#!/bin/bash
set -ex
GPUS_PER_NODE=4

WORLD_SIZE=${WORKER_NUM:-1}
NODE_RANK=${RANK:-0}
MASTER_ADDR=${MASTER_ADDR:-127.0.0.1}
MASTER_PORT=${MASTER_PORT:-20000}
GPU_NUM=$((${GPUS_PER_NODE}*${WORLD_SIZE}))
echo "---> from edl runtime, WORLD_SIZE: ${WORLD_SIZE}, NODE_RANK: ${NODE_RANK}"
LAUNCHER=" \
python3 -m torch.distributed.run \
--nnodes=1 \
--nproc_per_node=$GPUS_PER_NODE \
--node_rank 0 \
--master_addr 127.0.0.1 \
--master_port 20091 \
"

export OMP_NUM_THREADS=1
export NCCL_DEBUG_SUBSYS=INIT # disable aistudio default nccl env
export NCCL_DEBUG=INFO

export TORCH_NCCL_AVOID_RECORD_STREAMS="1"
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
export NCCL_NVLS_ENABLE=0
export NVTE_FUSED_ATTN=1
export NVTE_NORM_FWD_USE_CUDNN=0
export NVTE_NORM_BWD_USE_CUDNN=0

DEVICE_MODEL="gb200"

JOB_DIR="/path/to/mcore_opensource_0.14_ngc2508_deepseek_gqa_fp8_${DEVICE_MODEL}_${GPU_NUM}p_fp8_param_gather"
mkdir -p ${JOB_DIR}
if [ "$RANK" -eq 0 ]; then
cp -r ${0} ${JOB_DIR}
fi
CHECKPOINT_PATH=$JOB_DIR
LOAD_CHECKPOINT_PATH="/path/to/mcore_ea_deepseek_gqa_fp8_h800_4p"
TENSORBOARD_LOGS_PATH=${JOB_DIR}

LOG_PATH="${JOB_DIR}/log_8layer_4p_${NODE_RANK}.txt"

# --moe-router-force-load-balancing
MOE_ARGS=(
--moe-grouped-gemm
--moe-permute-fusion
--moe-token-dispatcher-type alltoall
--num-experts 64
--moe-ffn-hidden-size 2048
--moe-router-score-function sigmoid
--moe-router-topk 8
--moe-router-enable-expert-bias
--moe-router-topk-scaling-factor 2.5
--moe-router-load-balancing-type "seq_aux_loss"
--moe-router-group-topk 4
--moe-router-num-groups 8
--moe-router-dtype "fp32"
--moe-aux-loss-coeff "1e-4"
--moe-router-bias-update-rate 1e-3
--moe-router-pre-softmax
)

FP8_ARGS=(
--fp8-param-gather
--reuse-grad-buf-for-mxfp8-param-ag
--fp8-recipe mxfp8
--fp8-format e4m3
--moe-router-padding-for-fp8
)

GPT_MODEL_ARGS=(
--num-layers 8
--hidden-size 2048
--ffn-hidden-size 5120
--num-attention-heads 16
--num-query-groups 4
--group-query-attention
--mscale 1.0
--mscale-all-dim 1.0
--max-position-embeddings 4096
--make-vocab-size-divisible-by 3232
--position-embedding-type "rope"
--rotary-base 10000
--rotary-percent 1.0
--rotary-scaling-factor 40
--swiglu
--untie-embeddings-and-output-weights
--normalization "RMSNorm"
--norm-epsilon "1e-06"
--disable-bias-linear
--transformer-impl "transformer_engine"
--attention-dropout 0
--hidden-dropout 0
)

TRAINING_ARGS=(
--micro-batch-size 1
--global-batch-size 4
--seq-length "4096"
--weight-decay 0.1
--adam-beta1 0.9
--adam-beta2 0.95
--init-method-std 0.02
--clip-grad 1.0
--bf16
--qk-layernorm
--train-samples 585937500
--lr-decay-samples 584765624
--lr-warmup-samples 1536000
--lr-warmup-init "3.9e-7"
--lr "3.9e-6"
--min-lr "3.9e-7"
--lr-decay-style cosine
--no-check-for-nan-in-loss-and-grad
)

MODEL_PARALLEL_ARGS=(
--tensor-model-parallel-size 1
--expert-model-parallel-size 4
--expert-tensor-parallel-size 1
--context-parallel-size 1
--sequence-parallel
--use-distributed-optimizer
--overlap-grad-reduce
--overlap-param-gather
--disable-gloo-process-groups
)

DATA_ARGS=(
--data-path "/path/to/CC-MAIN-2024-10_merged/CC-MAIN-2024-10_merged"
--tokenizer-type "HuggingFaceTokenizer"
--tokenizer-model "/path/to/DeepSeek-V3-Config"
--split 949,50,1
--dataloader-type "single"
--no-create-attention-mask-in-dataloader
)

EVAL_AND_LOGGING_ARGS=(
--save-interval 10000
--eval-interval 1000
--save $CHECKPOINT_PATH
--load $LOAD_CHECKPOINT_PATH
--no-load-rng
--ckpt-format "torch_dist"
--async-save
--eval-iters 1
--log-interval 1
--log-throughput
--tensorboard-dir $TENSORBOARD_LOGS_PATH
--log-timers-to-tensorboard
--log-memory-to-tensorboard
--log-world-size-to-tensorboard
--log-validation-ppl-to-tensorboard
)

KERNEL_ARGS=(
--attention-backend auto
--no-masked-softmax-fusion
--attention-softmax-in-fp32
--cross-entropy-loss-fusion
--cross-entropy-fusion-impl "native"
)
# --no-bias-swiglu-fusion

CMD="${LAUNCHER} pretrain_gpt.py \
${MOE_ARGS[@]}
${GPT_MODEL_ARGS[@]} \
${TRAINING_ARGS[@]} \
${MODEL_PARALLEL_ARGS[@]} \
${DATA_ARGS[@]} \
${EVAL_AND_LOGGING_ARGS[@]} \
${KERNEL_ARGS[@]} \
${FP8_ARGS[@]} \
"
echo ${CMD}
#${CMD} 2>&1 | tee ${LOG_PATH}

echo "${LOG_PATH}"
nohup ${CMD} > ${LOG_PATH} 2>&1 &
```

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.