verl icon indicating copy to clipboard operation
verl copied to clipboard

grad_norm always equals 0 when training with megatron + lora

Open rtz1998 opened this issue 11 months ago • 3 comments

System Info

----------Python Info----------

Version : 3.12.11

Compiler : GCC 11.4.0

Build : ('main', 'Jun 4 2025 08:56:18')

Arch : ('64bit', 'ELF')

------------Pip Info-----------

Version : 25.2

Directory : /usr/local/lib/python3.12/dist-packages/pip

vllm : 0.11.0

sglang : not found.

ray : 2.49.2

torch : 2.8.0+cu128

----------verl Info-----------

Version : 0.7.0.dev

Directory : *

Commit Hash : b96b53a349046c0a43eb2df4f0977f4e7fc79a16

----------Platform Info----------

Platform : Linux-5.16.20-1-bzl-generic-x86_64-with-glibc2.35

system : Linux

node : pd-yangbao-s-tra-axmqijnrz6bc-tfjob-worker-0

release : 5.16.20-1-bzl-generic

version : #1 SMP PREEMPT Sat Oct 8 07:21:26 UTC 2022

----------Environment----------

CUDA Runtime : 12.8

CUDA Compiler : Cuda compilation tools, release 12.8, V12.8.93

----------System Info----------

CPU Memory : 2014.28 GB

GPU Count : 1

GPU 1 Type : NVIDIA A800-SXM4-80GB

GPU 1 Memory : 80.00 GB

Information

  • [ ] The official example scripts
  • [x] My own modified scripts

Tasks

  • [ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [x] My own task or dataset (give details below)

Reproduction

Here is a partial bash script: grad_norm always equals 0 when training with megatron + lora

bash s python3 -m verl.trainer.main_ppo
--config-path=config
--config-name='ppo_megatron_trainer.yaml'
data.train_files=**
data.val_files=**
data.train_batch_size=${total_bs}
data.max_prompt_length=8192
data.max_response_length=4096
data.filter_overlong_prompts=True
data.truncation='error'
actor_rollout_ref.model.path=${HF_model_path}
actor_rollout_ref.model.lora.rank=64
actor_rollout_ref.model.lora.alpha=64
actor_rollout_ref.model.lora.type=canonical_lora
actor_rollout_ref.model.lora.target_modules=[linear_q,linear_k,linear_v,linear_proj,linear_fc1_up,linear_fc1_gate,linear_fc2]
actor_rollout_ref.model.use_remove_padding=True
actor_rollout_ref.rollout.n=${n_resp_per_prompt}
algorithm.adv_estimator=${adv_estimator}
algorithm.use_kl_in_reward=${use_kl_in_reward}
actor_rollout_ref.actor.use_kl_loss=${use_kl_loss}
actor_rollout_ref.actor.kl_loss_type=${kl_loss_type}
actor_rollout_ref.actor.kl_loss_coef=${kl_loss_coef}
actor_rollout_ref.actor.clip_ratio_low=${clip_ratio_low}
actor_rollout_ref.actor.clip_ratio_high=${clip_ratio_high}
actor_rollout_ref.actor.clip_ratio_c=10.0
+actor_rollout_ref.model.override_config.max_position_embeddings=32768
actor_rollout_ref.actor.use_dynamic_bsz=True
actor_rollout_ref.actor.ppo_max_token_len_per_gpu=12288
actor_rollout_ref.actor.optim.lr=3e-5
actor_rollout_ref.actor.ppo_mini_batch_size=${train_prompt_mini_bsz}
actor_rollout_ref.actor.megatron.param_offload=${actor_offload}
actor_rollout_ref.actor.megatron.optimizer_offload=${actor_offload}
actor_rollout_ref.actor.megatron.grad_offload=${actor_offload}
actor_rollout_ref.actor.megatron.pipeline_model_parallel_size=${train_pp}
actor_rollout_ref.actor.megatron.tensor_model_parallel_size=${train_tp}
actor_rollout_ref.actor.megatron.use_mbridge=$USE_MBRIDGE
actor_rollout_ref.actor.megatron.vanilla_mbridge=False
actor_rollout_ref.actor.megatron.use_dist_checkpointing=$USE_DIST_CKPT
actor_rollout_ref.actor.megatron.override_transformer_config.recompute_method=uniform
actor_rollout_ref.actor.megatron.override_transformer_config.recompute_granularity=full
actor_rollout_ref.actor.megatron.override_transformer_config.recompute_num_layers=1
actor_rollout_ref.actor.entropy_coeff=0
actor_rollout_ref.actor.loss_agg_mode=${loss_agg_mode}
actor_rollout_ref.actor.policy_loss.loss_mode=${loss_mode}
actor_rollout_ref.actor.policy_loss.ppo_kl_coef=${ppo_kl_coef}
actor_rollout_ref.rollout.gpu_memory_utilization=0.6
actor_rollout_ref.rollout.tensor_model_parallel_size=${gen_tp}
actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=20
actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=12288
actor_rollout_ref.rollout.enable_chunked_prefill=True
actor_rollout_ref.rollout.max_num_batched_tokens=12288
actor_rollout_ref.rollout.temperature=${temperature}
actor_rollout_ref.rollout.top_p=${top_p}
actor_rollout_ref.rollout.top_k=${top_k}
actor_rollout_ref.rollout.val_kwargs.temperature=${val_temperature}
actor_rollout_ref.rollout.val_kwargs.top_p=${val_top_p}
actor_rollout_ref.rollout.val_kwargs.top_k=${top_k}
actor_rollout_ref.rollout.val_kwargs.do_sample=False
actor_rollout_ref.rollout.val_kwargs.n=1
actor_rollout_ref.rollout.name=vllm
actor_rollout_ref.ref.megatron.pipeline_model_parallel_size=${train_pp}
actor_rollout_ref.ref.megatron.tensor_model_parallel_size=${train_tp}
actor_rollout_ref.ref.megatron.param_offload=${ref_offload}
actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=12288
actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=20
custom_reward_function.path=**
reward_model.reward_manager=dapo
+reward_model.reward_kwargs.overlong_buffer_cfg.enable=${enable_overlong_buffer}
+reward_model.reward_kwargs.overlong_buffer_cfg.len=${overlong_buffer_len}
+reward_model.reward_kwargs.overlong_buffer_cfg.penalty_factor=${overlong_penalty_factor}
+reward_model.reward_kwargs.overlong_buffer_cfg.log=False
+reward_model.reward_kwargs.max_resp_len=12288
trainer.critic_warmup=0
trainer.logger=['console','tensorboard']
trainer.n_gpus_per_node=2
trainer.nnodes=1
trainer.save_freq=2
trainer.default_local_dir=**
trainer.test_freq=2
trainer.total_epochs=15 $@

Expected behavior

During training, the grad norm value is not 0, and the reward is significantly improved.

rtz1998 avatar Dec 15 '25 03:12 rtz1998

Did you resolve the issue?

cm8908 avatar Dec 22 '25 04:12 cm8908

Did you resolve the issue?

for https://github.com/volcengine/verl/pull/4566

rtz1998 avatar Dec 24 '25 03:12 rtz1998

Now PEFT recompute fix has been merged into Megatron-Bridge main branch, you can install via python3 -m pip install --no-deps --no-build-isolation git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@953aabf

HollowMan6 avatar Dec 28 '25 14:12 HollowMan6