verl icon indicating copy to clipboard operation
verl copied to clipboard

[Bug] [fully async] Meet torch.AcceleratorError: CUDA error: invalid argument when compute old_log_probs

Open qbei-i opened this issue 8 months ago • 5 comments

System Info

----------Python Info---------- Version : 3.12.12 Compiler : GCC 11.4.0 Build : ('main', 'Oct 10 2025 08:52:57') Arch : ('64bit', 'ELF') ------------Pip Info----------- Version : 26.0.1 Directory : /usr/local/lib/python3.12/dist-packages/pip vllm : 0.12.0 sglang : not found. ray : 2.54.0 torch : 2.9.0+cu129 ----------verl Info----------- Version : 0.8.0.dev Directory : /volume/posttrain/users/qbei/code/verl/verl Commit Hash : 96f5e9a12a3e2d0b57c54e1029dd14657b48f7da ----------Platform Info---------- Platform : Linux-5.15.0-94-generic-x86_64-with-glibc2.35 system : Linux node : ray-debug-0 release : 5.15.0-94-generic version : #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 ----------Environment---------- CUDA Runtime : 12.9 CUDA Compiler : Cuda compilation tools, release 12.9, V12.9.86 ----------System Info---------- CPU Memory : 2009.19 GB GPU Count : 8 GPU 1 Type : NVIDIA H20 GPU 1 Memory : 95.58 GB GPU 2 Type : NVIDIA H20 GPU 2 Memory : 95.58 GB GPU 3 Type : NVIDIA H20 GPU 3 Memory : 95.58 GB GPU 4 Type : NVIDIA H20 GPU 4 Memory : 95.58 GB GPU 5 Type : NVIDIA H20 GPU 5 Memory : 95.58 GB GPU 6 Type : NVIDIA H20 GPU 6 Memory : 95.58 GB GPU 7 Type : NVIDIA H20 GPU 7 Memory : 95.58 GB GPU 8 Type : NVIDIA H20 GPU 8 Memory : 95.58 GB

Information

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

Tasks

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

Reproduction

  1. using verl/experimental/fully_async_policy/shell/grpo_30b_a3b_base_math_megatron_96_32_mis.sh
  2. add config algorithm.rollout_correction.bypass_mode=False to close bypass model
  3. run and get follow output
verl/verl/experimental/fully_async_policy/megatron_utils.py", line 91, in restore_megatron_model_from_cpu
buffer.param_data.data.copy_(buffer_state["param_data"].to(buffer.param_data.device))
torch.AcceleratorError: CUDA error: invalid argument
Search for `cudaErrorInvalidValue' in https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html for more information.
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.

Expected behavior

this bug happend in https://github.com/verl-project/verl/blob/main/verl/experimental/fully_async_policy/fully_async_trainer.py#L443C13-L447C75 when close bypass_mode

qbei-i avatar Mar 05 '26 05:03 qbei-i

Got it. I'll check it out ASAP.

ArronHZG avatar Mar 13 '26 11:03 ArronHZG

https://github.com/verl-project/verl/issues/4285

ArronHZG avatar Mar 13 '26 11:03 ArronHZG

#4285

hi, as #4285 mentioned, it goes fine with upgrade to torch==2.8.0. But It's 2.9.0 in my case. Also I will try it.

qbei-i avatar Mar 14 '26 00:03 qbei-i

This CUDA error: invalid argument during old_log_probs computation with bypass_mode=False is typically caused by a memory access violation in the weight restoration path.

The issue occurs when:

  1. bypass_mode=False triggers the full model restoration from CPU buffers
  2. The param_data.copy_ operation fails due to device mismatch or invalid memory layout

Debugging steps:

  1. Check buffer-device consistency:
# Before line 91 in megatron_utils.py
assert buffer.param_data.device == buffer_state["param_data"].device, "Device mismatch"
  1. Enable CUDA debug mode:
export CUDA_LAUNCH_BLOCKING=1
export TORCH_USE_CUDA_DSA=1
  1. Verify buffer shapes match:
assert buffer.param_data.shape == buffer_state["param_data"].shape, "Shape mismatch"

The PyTorch 2.9.0 vs 2.8.0 difference suggests a CUDA backend behavior change. Consider filing an issue with the PyTorch team as well.

As a temporary workaround, stick with bypass_mode=True which avoids this restoration path.

Kirrito-k423 avatar Mar 17 '26 11:03 Kirrito-k423

Hit the same crash. The root cause is that save_model_to_cpu / restore_model_from_cpu in verl/experimental/separation/engine_workers.py don't account for the actor model being offloaded.

When param_offload=True, megatron buffers have storage().resize_(0) applied. restore_megatron_model_from_cpu then runs buffer.param_data.data.copy_(...) into a 0-storage tensor → CUDA invalid argument.

Four conditions must all hold to crash:

  1. strategy=megatron
  2. actor.megatron.param_offload=True
  3. bypass_mode=False with trigger_parameter_sync_step>1 (so the else branch in _compute_old_log_prob actually calls restore_model_from_cpu(1))
  4. checkpoint_engine.backend=nccl

Condition 4 is what surfaces the bug. The nccl path of update_weights early-returns after get_per_tensor_param, which loads the model to GPU but doesn't offload back. The next save_model_to_cpu(1) thus captures real param data. One iteration later the
model is offloaded again by compute_log_prob / update_actor, and restore_model_from_cpu(1) crashes on copy into 0-storage.

There's also a silent correctness issue worth fixing in the same patch: when save runs on an offloaded model, copy_megatron_model_to_cpu skips all buffers via if buffer.param_data.storage().size() > 0, producing empty snapshots. The
matching restore guard if "param_data" in buffer_state then makes restore a no-op. In configs where this happens every iteration (e.g. non-nccl backends), the v1 anchor is never actually applied — decoupled PPO / MIS silently degrades to on-policy PPO with no error.

Suggested fix: make save/restore in engine_workers.py offload-aware — detect storage==0, load to GPU before invoking the
strategy handler, offload back afterwards. Scope stays inside DetachActorWorker, the underlying megatron utils don't need
changes, FSDP path is unaffected.

I have a local patch along these lines that fixes both the crash and the silent MIS issue. Happy to send a PR. cc @ArronHZG

lizipao avatar Apr 13 '26 14:04 lizipao