ms-swift icon indicating copy to clipboard operation
ms-swift copied to clipboard

VLLM INFERENCE ERROR WHILE TRAINING WITH GRPO (FORWARD CONTEXT )

Open tejeshbhalla opened this issue 1 year ago • 8 comments

Describe the bug While training with grpo the process crashes out with wierd error from vllm saying AssertionError: Forward context is not set. Please use set_forward_context

and a whole traceback forwarding to a specific file in vllm asking to set it

tejeshbhalla avatar Apr 09 '25 04:04 tejeshbhalla

link here's an issue reference

tejeshbhalla avatar Apr 09 '25 04:04 tejeshbhalla

any repro scripts?

hjh0119 avatar Apr 09 '25 09:04 hjh0119

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 NPROC_PER_NODE=7 swift rlhf --rlhf_type grpo --model /root/highspeedstorage/ft-volume//mistral-4-2-2025 --train_type lora --dataset ms-swift/all_processed_logs4.jsonl --torch_dtype bfloat16 --num_train_epochs 1 --max_length 80000 --per_device_train_batch_size 1 --per_device_eval_batch_size 1 --gradient_accumulation_steps 1 --eval_steps 100 --save_steps 10 --learning_rate 1e-6 --save_total_limit 2 --logging_steps 100 --output_dir output --warmup_ratio 0.05 --dataloader_num_workers 4 --max_completion_length 32000 --reward_funcs accuracy format repetition --num_generations 7 --system "" --use_vllm true --vllm_gpu_memory_utilization 0.95 --vllm_max_model_len 80000 --deepspeed zero3_offload --temperature 1 --top_p 1.0 --top_k 80 --log_completions true --num_infer_workers 1 --async_generate true --move_model_batches 7 --offload_optimizer true --offload_model true --gc_collect_after_offload true --lora_rank 128 --lora_alpha 256 --model_type mistral_2501 --rope_scaling dynamic

tejeshbhalla avatar Apr 09 '25 09:04 tejeshbhalla

TRACEBACK LOGS -

all_impl [125/1823] [rank0]: return self._call_impl(*args, **kwargs) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl[rank0]: return forward_call(*args, **kwargs) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/vllm/model_executor/models/llama.py", line 206, in forward [rank0]: attn_output = self.attn(q, k, v, kv_cache, attn_metadata) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl [rank0]: return self._call_impl(*args, **kwargs) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl[rank0]: return forward_call(*args, **kwargs) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/vllm/attention/layer.py", line 190, in forward [rank0]: torch.ops.vllm.unified_attention_with_output( [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/torch/_ops.py", line 1116, in __call__ [rank0]: return self._op(*args, **(kwargs or {})) [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/vllm/attention/layer.py", line 335, in unified_attention_with_output [rank0]: forward_context: ForwardContext = get_forward_context() [rank0]: File "/root/dataDisk/.venv/lib/python3.10/site-packages/vllm/forward_context.py", line 42, in get_forward_context [rank0]: assert _forward_context is not None, ( [rank0]: AssertionError: Forward context is not set. Please use set_forward_contextto set the forward context. terminate called after throwing an instance of 'c10::Error' what(): CUDA error: an illegal memory access was encountered 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 withTORCH_USE_CUDA_DSAto enable device-side assertions.

tejeshbhalla avatar Apr 09 '25 09:04 tejeshbhalla

I am also getting this AssertionError: Forward context is not set. Please use set_forward_context to set the forward context. after my GRPO finishes its final epoch. It comes after a bunch of other traceback AssertionErrors.

I currently have vllm==0.7.3

This is my config:

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6 \
NPROC_PER_NODE=4 \
swift rlhf \
    --rlhf_type grpo \
    --model /vault/ultraz/open-r1/data/llama3-3b-lora-checkpoint_1023 \
    --model_type llama3_2 \
    --train_type lora \
    --dataset /vault/ultraz/unsloth_grpo/skythought_first.csv \
    --torch_dtype bfloat16 \
    --num_train_epochs 1 \
    --per_device_train_batch_size 4 \
    --per_device_eval_batch_size 4 \
    --gradient_accumulation_steps 4 \
    --eval_steps 2000 \
    --save_steps 2000 \
    --learning_rate 1e-6 \
    --save_total_limit 2 \
    --logging_steps 1 \
    --output_dir output \
    --warmup_ratio 0.05 \
    --dataloader_num_workers 8 \
    --reward_funcs accuracy format cosine repetition \
    --num_generations 2 \
    --use_vllm true \
    --vllm_gpu_memory_utilization 0.7 \
    --vllm_max_model_len 7000 \
    --max_completion_length 6000 \
    --max_length 7000 \
    --num_infer_workers 3 \
    --deepspeed zero3 \
    --temperature 1.0 \
    --system examples/train/grpo/prompt.txt \
    --top_p 1.0 \
    --top_k 80 \
    --log_completions true \
    --async_generate true \

Henchen99 avatar Apr 09 '25 10:04 Henchen99

So i solved it , i mean its do with eval steps for some reason evaluation is breaking it so i just set it super high for now

tejeshbhalla avatar Apr 09 '25 11:04 tejeshbhalla

should be fixed

hjh0119 avatar Apr 11 '25 06:04 hjh0119

Still got the same error message:

Forward context is not set. Please useset_forward_contextto set the forward context.

I am using vllm 0.8.4 and the swift source git cloned from github on 4/17/2025.

How to fix this problem?

tjoymeed avatar Apr 22 '25 20:04 tjoymeed