Why GPU OOM when save ckpt?
experiment settings
- model: Qwen3-32b
- batch_size: 512
- GPU:H20(96G) * 128
- context:64k
- backend:Vllm & megatron
- framework:rllm + verl 0.5.0
Params
'megatron': {'context_parallel_size': 2, 'dist_checkpointing_path': None, 'expert_model_parallel_size': 1, 'expert_tensor_parallel_size': None, 'grad_offload': True, 'optimizer_offload': True, 'override_ddp_config': {}, 'override_transformer_config': {'recompute_granularity': 'full', 'recompute_method': 'uniform', 'recompute_modules': ['core_attn'], 'recompute_num_layers': 1}, 'param_offload': True, 'pipeline_model_parallel_size': 1, 'seed': 42, 'sequence_parallel': True, 'tensor_model_parallel_size': 8, 'use_dist_checkpointing': False, 'use_distributed_optimizer': True, 'use_mbridge': False, 'virtual_pipeline_model_parallel_size': None},
Problem
When saving ckpt, i meet nccl error with cuda oom:
File "/workshop/rllm/verl/verl/workers/megatron_workers.py", line 650, in save_checkpoint self.checkpoint_mananager.save_checkpoint( File "/workshop/rllm/verl/verl/utils/checkpoint/megatron_checkpoint_manager.py", line 394, in save_checkpoint async_save_request = save_dist_checkpointing( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/workshop/rllm/verl/verl/utils/megatron/dist_checkpointing.py", line 35, in save_dist_checkpointing async_save_request = dist_checkpointing.save( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/Megatron-LM/megatron/core/dist_checkpointing/serialization.py", line 414, in save sharded_strategy.save(sharded_state_dict, checkpoint_dir) File "/root/Megatron-LM/megatron/core/dist_checkpointing/strategies/fully_parallel.py", line 97, in save self.apply_saving_parallelization(sharded_state_dict) File "/root/Megatron-LM/megatron/core/dist_checkpointing/strategies/fully_parallel.py", line 121, in apply_saving_parallelization precomputed_distribution = determine_main_replica_uniform_distribution( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/Megatron-LM/megatron/core/dist_checkpointing/exchange_utils.py", line 215, in determine_main_replica_uniform_distribution torch.distributed.all_gather_object( File "/usr/local/lib/python3.12/dist-packages/torch/distributed/c10d_logger.py", line 81, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/distributed_c10d.py", line 3039, in all_gather_object all_gather(object_size_list, local_size, group=group) File "/usr/local/lib/python3.12/dist-packages/torch/distributed/c10d_logger.py", line 81, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/distributed_c10d.py", line 3728, in all_gather work = group.allgather([tensor_list], [tensor]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ torch.distributed.DistBackendError: NCCL error in: /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:3356, unhandled cuda error (run with NCCL_DEBUG=INFO for details), NCCL version 2.26.2 ncclUnhandledCudaError: Call to CUDA function failed. Last error: Cuda failure 2 'out of memory'
GPU OOM during checkpoint saving with Megatron is typically caused by the all_gather_object operation in distributed checkpointing. This operation temporarily gathers metadata from all ranks, which can spike memory usage.
Solutions:
- Use async checkpointing:
megatron.use_dist_checkpointing=True
megatron.dist_checkpointing_path=/path/to/checkpoint
-
Enable CPU offloading before save: The checkpoint save operation needs to gather full model state. With
param_offload=Trueandoptimizer_offload=True, ensure parameters are on CPU before the all_gather. -
Reduce checkpoint frequency: For large models (Qwen3-32B with 64k context), checkpoint saving is memory-intensive. Consider saving less frequently or using a separate checkpoint node.
-
Check NCCL buffer size:
export NCCL_BUFFSIZE=4194304 # 4MB buffer
The determine_main_replica_uniform_distribution function is the bottleneck - it needs to coordinate across all 128 GPUs. For models this large, consider sharded checkpoint format or reducing world size during save.
中文:
从目前公开信息看,这个 OOM 更像是 Megatron checkpoint 保存阶段的分布式保存/容量问题,而不是可以直接按超时或已解决关闭的问题。你贴出的栈在 Megatron-LM 的 dist_checkpointing fully-parallel save 中进入 all_gather_object 后报 CUDA OOM;verl 当前代码里 verl/utils/megatron/dist_checkpointing.py 仍是通过 Megatron dist_checkpointing.save(...) + FullyParallelSaveStrategyWrapper 保存分布式 checkpoint。另见 verl/utils/checkpoint/megatron_checkpoint_manager.py:保存时会按 model/optimizer/extra 调度 dist checkpoint 写入;docs/advance/checkpoint.rst 也说明 use_dist_checkpointing 只控制 Megatron 模型分片是否写入 model/dist_ckpt/,而 optimizer/LR scheduler 和 RNG/extra 仍会走 dist_checkpointing。
为了继续判断这是当前版本仍存在的问题、配置问题,还是 Megatron-LM/PyTorch/NCCL 在该规模下的保存峰值问题,能否补充这些信息?
- 在最新 verl main 或最近 release 上是否仍可复现?原始报告使用的是 verl 0.5.0。
- 完整的
checkpoint.save_contents、checkpoint.async_save、actor_rollout_ref.actor.megatron.use_mbridge、actor_rollout_ref.actor.megatron.use_dist_checkpointing配置。 - OOM 发生前各 rank 的可用显存,以及是否是在保存
model、optimizer还是extra/rng_state阶段触发。 - 如果可行,请尝试一次只保存较小内容集来定位峰值来源,例如临时去掉
optimizer或extra,或只保存模型权重,并贴出结果。
English:
Based on the public evidence, this looks more like a Megatron checkpoint-save distributed-save/capacity issue than something we can safely close as stale or already fixed. The stack trace reaches Megatron-LM dist_checkpointing fully-parallel save and fails in all_gather_object with CUDA OOM. In current verl, verl/utils/megatron/dist_checkpointing.py still calls Megatron dist_checkpointing.save(...) through FullyParallelSaveStrategyWrapper. Also, verl/utils/checkpoint/megatron_checkpoint_manager.py schedules dist checkpoint writes for model, optimizer, and extra; docs/advance/checkpoint.rst documents that use_dist_checkpointing only controls Megatron model shards under model/dist_ckpt/, while optimizer/LR scheduler and RNG/extra still go through dist_checkpointing.
To determine whether this still reproduces on current verl, is configuration-related, or is a Megatron-LM/PyTorch/NCCL peak-memory limitation at this scale, could you provide:
- Whether this reproduces on latest verl main or a recent release; the original report used verl 0.5.0.
- The full
checkpoint.save_contents,checkpoint.async_save,actor_rollout_ref.actor.megatron.use_mbridge, andactor_rollout_ref.actor.megatron.use_dist_checkpointingsettings. - Per-rank free GPU memory right before checkpoint save, and whether the failure happens while saving
model,optimizer, orextra/rng_state. - If possible, one isolation run with a smaller save content set, for example temporarily removing
optimizerorextra, or saving only model weights, and the result.
This response was generated by a scheduled Codex GPT5.5 issue processing task.