verl icon indicating copy to clipboard operation
verl copied to clipboard

[trainer] when train vlm using lora in VLLM_SLEEP_LEVEL=2 ( if vllm version >= 0.8.5 ) and without using layerd_summon, then the lora layers will not be updated to vllm

Open WncFht opened this issue 1 year ago • 4 comments

System Info

Package                            Version             Build    Editable project location
---------------------------------- ------------------- -------- -------------------------------
absl-py                            2.1.0
accelerate                         1.9.0
aiohappyeyeballs                   2.3.5
aiohttp                            3.10.1
aiohttp-cors                       0.8.1
aiosignal                          1.3.1
airportsdata                       20250909
altair                             5.5.0
annotated-types                    0.7.0
antlr4-python3-runtime             4.9.3
anyio                              4.4.0
apex                               0.1
argon2-cffi                        23.1.0
argon2-cffi-bindings               21.2.0
arrow                              1.3.0
asciitree                          0.3.3
astor                              0.8.1
asttokens                          2.4.1
astunparse                         1.6.3
async-lru                          2.0.4
async-timeout                      4.0.3
attrs                              24.2.0
audioread                          3.0.1
av                                 15.0.0
babel                              2.16.0
beautifulsoup4                     4.12.3
bitsandbytes                       0.47.0
black                              24.8.0
blake3                             1.0.5
bleach                             6.1.0
blinker                            1.9.0
blis                               0.7.11
blobfile                           3.0.0
build                              1.3.0
cachetools                         5.4.0
catalogue                          2.0.10
cbor2                              5.6.5
certifi                            2024.7.4
cffi                               1.17.0
cfgv                               3.4.0
charset-normalizer                 3.3.2
click                              8.1.7
cloudpathlib                       0.18.1
cloudpickle                        3.0.0
cmake                              3.30.2
codetiming                         1.4.0
colorful                           0.5.7
comm                               0.2.2
compressed-tensors                 0.10.2
confection                         0.1.5
contourpy                          1.2.1
cuda-bindings                      12.9.0
cuda-python                        12.5.0
cudf                               24.6.0
cugraph                            24.6.0
cugraph-dgl                        24.6.0
cugraph-equivariant                24.6.0
cugraph-pyg                        24.6.0
cugraph-service-client             24.6.0
cugraph-service-server             24.6.0
cuml                               24.6.0
cupy-cuda12x                       13.2.0
cycler                             0.12.1
cymem                              2.0.8
Cython                             3.0.11
dask                               2024.5.1
dask-cuda                          24.6.0
dask-cudf                          24.6.0
dask-expr                          1.1.1
datasets                           4.0.0
dbus-python                        1.2.18
debugpy                            1.8.5
decorator                          5.1.1
deep_ep                            1.0.0+a84a248
defusedxml                         0.7.1
depyf                              0.19.0
dill                               0.3.8
diskcache                          5.6.3
distlib                            0.3.9
distributed                        2024.5.1
distributed-ucxx                   0.38.0
distro                             1.9.0
dm-tree                            0.1.8
dnspython                          2.7.0
einops                             0.8.0
email_validator                    2.2.0
entrypoints                        0.4
exceptiongroup                     1.2.2
execnet                            2.1.1
executing                          2.0.1
expecttest                         0.1.3
fastapi                            0.116.1
fastapi-cli                        0.0.8
fastapi-cloud-cli                  0.1.4
fasteners                          0.19
fastjsonschema                     2.20.0
fastrlock                          0.8.2
filelock                           3.18.0
flash_attn                         2.7.4.post1
flashinfer-python                  0.2.9rc2
fonttools                          4.53.1
fqdn                               1.5.1
frozenlist                         1.4.1
fsspec                             2024.6.1
gast                               0.6.0
gguf                               0.17.1
gitdb                              4.0.12
GitPython                          3.1.44
google-api-core                    2.25.1
google-auth                        2.40.3
googleapis-common-protos           1.70.0
grpcio                             1.74.0
h11                                0.14.0
hf_transfer                        0.1.9
hf-xet                             1.1.5
httpcore                           1.0.5
httptools                          0.6.4
httpx                              0.27.0
huggingface-hub                    0.34.4
hydra-core                         1.3.2
hypothesis                         5.35.1
identify                           2.6.12
idna                               3.7
igraph                             0.11.6
importlib_metadata                 7.2.1
iniconfig                          2.0.0
intel-openmp                       2021.4.0
interegular                        0.3.3
ipykernel                          6.29.5
ipython                            8.26.0
ipywidgets                         8.1.7
isoduration                        20.11.0
isort                              5.13.2
jedi                               0.19.1
Jinja2                             3.1.6
jiter                              0.10.0
joblib                             1.4.2
json5                              0.9.25
jsonpointer                        3.0.0
jsonschema                         4.23.0
jsonschema-specifications          2023.12.1
jupyter_client                     8.6.2
jupyter_core                       5.7.2
jupyter-events                     0.10.0
jupyter-lsp                        2.2.5
jupyter_server                     2.14.2
jupyter_server_terminals           0.5.3
jupyterlab                         4.2.4
jupyterlab_code_formatter          3.0.2
jupyterlab_pygments                0.3.0
jupyterlab_server                  2.27.3
jupyterlab-tensorboard-pro         4.0.0
jupyterlab_widgets                 3.0.15
jupytext                           1.16.4
kiwisolver                         1.4.5
kvikio                             24.6.0
langcodes                          3.4.0
language_data                      1.2.0
lark                               1.2.2
lazy_loader                        0.4
librmm                             24.6.0
librosa                            0.10.1
liger_kernel                       0.6.0
lightning-thunder                  0.2.0.dev0
lightning-utilities                0.11.6
lintrunner                         0.12.5
llguidance                         0.7.30
llvmlite                           0.44.0
lm-format-enforcer                 0.10.12
locket                             1.0.0
looseversion                       1.3.0
lxml                               6.0.0
marisa-trie                        1.2.0
Markdown                           3.7
markdown-it-py                     3.0.0
MarkupSafe                         2.1.5
mathruler                          0.1.0
matplotlib                         3.9.2
matplotlib-inline                  0.1.7
mbridge                            0.13.0
mdit-py-plugins                    0.4.1
mdurl                              0.1.2
megatron-core                      0.13.0
mistral_common                     1.8.3
mistune                            3.0.2
mkl                                2021.1.1
mkl-devel                          2021.1.1
mkl-include                        2021.1.1
mock                               5.1.0
modelscope                         1.29.2
mpmath                             1.3.0
msgpack                            1.0.8
msgspec                            0.19.0
multidict                          6.0.5
multiprocess                       0.70.16
murmurhash                         1.0.10
mypy-extensions                    1.0.0
narwhals                           2.5.0
nbclient                           0.10.0
nbconvert                          7.16.4
nbformat                           5.10.4
nest-asyncio                       1.6.0
networkx                           3.3
ninja                              1.11.1.1
nodeenv                            1.9.1
notebook                           7.2.1
notebook_shim                      0.2.4
numba                              0.61.2
numcodecs                          0.11.0
numpy                              1.26.4
nvfuser                            0.2.6a0+1d02b13
nvidia-cublas-cu12                 12.6.4.1
nvidia-cuda-cupti-cu12             12.6.80
nvidia-cuda-nvrtc-cu12             12.6.77
nvidia-cuda-runtime-cu12           12.6.77
nvidia-cudnn-cu12                  9.5.1.17
nvidia-cudnn-frontend              1.5.2
nvidia-cufft-cu12                  11.3.0.4
nvidia-cufile-cu12                 1.11.1.6
nvidia-curand-cu12                 10.3.7.77
nvidia-cusolver-cu12               11.7.1.2
nvidia-cusparse-cu12               12.5.4.2
nvidia-cusparselt-cu12             0.6.3
nvidia-dali-cuda120                1.40.0              16741769
nvidia-ml-py                       13.580.65
nvidia-modelopt                    0.15.0
nvidia-nccl-cu12                   2.26.2
nvidia-nvimgcodec-cu12             0.3.0.5
nvidia-nvjitlink-cu12              12.6.85
nvidia-nvshmem-cu12                3.4.5
nvidia-nvtx-cu12                   12.6.77
nvidia-pyindex                     1.0.9
nvitop                             1.5.3
nvtx                               0.2.5
nx-cugraph                         24.6.0
omegaconf                          2.3.0
onnx                               1.16.0
openai                             1.90.0
opencensus                         0.11.4
opencensus-context                 0.1.3
opencv                             4.7.0
opencv-python-headless             4.12.0.88
opentelemetry-api                  1.35.0
opentelemetry-exporter-prometheus  0.56b0
opentelemetry-proto                1.35.0
opentelemetry-sdk                  1.35.0
opentelemetry-semantic-conventions 0.56b0
opt-einsum                         3.3.0
optree                             0.17.0
orjson                             3.11.0
outlines                           0.1.11
outlines_core                      0.2.10
overrides                          7.7.0
packaging                          25.0
pandas                             2.2.2
pandocfilters                      1.5.1
parso                              0.8.4
partd                              1.4.2
partial-json-parser                0.2.1.1.post6
pathspec                           0.12.1
peft                               0.16.0
pexpect                            4.9.0
pillow                             10.4.0
pip                                25.2
platformdirs                       4.2.2
plotly                             5.18.0
pluggy                             1.5.0
ply                                3.11
polygraphy                         0.49.12
pooch                              1.8.2
pre_commit                         4.2.0
preshed                            3.0.9
prometheus_client                  0.20.0
prometheus-fastapi-instrumentator  7.1.0
prompt_toolkit                     3.0.47
proto-plus                         1.26.1
protobuf                           5.29.5
psutil                             6.0.0
ptyprocess                         0.7.0
PuLP                               2.9.0
pure_eval                          0.2.3
py-cpuinfo                         9.0.0
py-spy                             0.4.0
pyarrow                            20.0.0
pyasn1                             0.6.1
pyasn1_modules                     0.4.2
pybase64                           1.4.2
pybind11                           2.13.4
pybind11_global                    2.13.4
pycocotools                        2.0+nv0.8.0
pycountry                          24.6.1
pycparser                          2.22
pycryptodomex                      3.23.0
pydantic                           2.11.7
pydantic_core                      2.33.2
pydantic-extra-types               2.10.5
pydeck                             0.9.1
pyext                              0.7
Pygments                           2.18.0
PyGObject                          3.42.1
pylatexenc                         2.10
pylibcugraph                       24.6.0
pylibcugraphops                    24.6.0
pylibraft                          24.6.0
pylibwholegraph                    24.6.0
pynvjitlink                        0.2.3
pynvml                             13.0.1
pyparsing                          3.1.2
pyproject_hooks                    1.2.0
pytest                             8.1.1
pytest-flakefinder                 1.1.0
pytest-rerunfailures               14.0
pytest-shard                       0.1.2
pytest-xdist                       3.6.1
python-dateutil                    2.9.0.post0
python-dotenv                      1.1.1
python-hostlist                    1.23.0
python-json-logger                 2.0.7
python-multipart                   0.0.20
pytz                               2023.4
pyvers                             0.1.0
PyYAML                             6.0.2
pyzmq                              26.1.0
qwen-vl-utils                      0.0.11
raft-dask                          24.6.0
rapids-dask-dependency             24.6.0a0
ray                                2.47.1
referencing                        0.35.1
regex                              2024.7.24
requests                           2.32.3
rfc3339-validator                  0.1.4
rfc3986-validator                  0.1.1
rich                               13.7.1
rich-toolkit                       0.14.8
rignore                            0.6.2
rmm                                24.6.0
rpds-py                            0.20.0
rsa                                4.9.1
ruff                               0.12.3
safetensors                        0.5.3
scikit-learn                       1.5.1
scipy                              1.14.0
Send2Trash                         1.8.3
sentencepiece                      0.2.0
sentry-sdk                         2.33.0
setproctitle                       1.3.7
setuptools                         70.3.0
sgl-kernel                         0.2.8
sglang                             0.4.10.post2
shellingham                        1.5.4
six                                1.16.0
smart-open                         7.0.4
smmap                              5.0.2
sniffio                            1.3.1
sortedcontainers                   2.4.0
soundfile                          0.13.1
soupsieve                          2.6
soxr                               0.5.0.post1
spacy                              3.7.5
spacy-legacy                       3.0.12
spacy-loggers                      1.0.5
srsly                              2.4.8
stack-data                         0.6.3
starlette                          0.47.1
streamlit                          1.40.0
sympy                              1.14.0
tabulate                           0.9.0
tbb                                2021.13.1
tblib                              3.0.0
tenacity                           9.1.2
tensorboard                        2.16.2
tensorboard-data-server            0.7.2
tensordict                         0.9.1
tensorrt                           10.3.0
terminado                          0.18.1
texttable                          1.7.0
thinc                              8.2.5
threadpoolctl                      3.5.0
thriftpy2                          0.5.0
tiktoken                           0.10.0
timm                               1.0.16
tinycss2                           1.3.0
tokenizers                         0.22.0
toml                               0.10.2
tomli                              2.0.1
toolz                              0.12.1
torch                              2.7.1
torchao                            0.14.0+git045c9597a          /home/fanghaotian/torchao
torchaudio                         2.7.1
torchdata                          0.11.0
torchvision                        0.22.1
tornado                            6.2
tqdm                               4.66.5
traitlets                          5.14.3
transformer_engine                 2.2.0+d0c452c
transformers                       4.56.1
treelite                           4.1.2
triton                             3.3.1
trl                                0.21.0
typer                              0.16.0
types-dataclasses                  0.6.6
types-python-dateutil              2.9.0.20240316
typing_extensions                  4.12.2
typing-inspection                  0.4.1
tzdata                             2024.1
ucx-py                             0.38.0
ucxx                               0.38.0
ujson                              5.10.0
uri-template                       1.3.0
urllib3                            2.0.7
uvicorn                            0.35.0
uvloop                             0.21.0
verl                               0.5.0.dev0                   /mnt/data2/fanghaotian/src/verl
virtualenv                         20.31.2
vllm                               0.10.0
wandb                              0.21.0
wasabi                             1.1.3
watchdog                           5.0.3
watchfiles                         1.1.0
wcwidth                            0.2.13
weasel                             0.4.1
webcolors                          24.8.0
webencodings                       0.5.1
websocket-client                   1.8.0
websockets                         15.0.1
Werkzeug                           3.0.3
wheel                              0.44.0
widgetsnbextension                 4.0.14
wrapt                              1.16.0
xdoctest                           1.0.2
xformers                           0.0.31
xgrammar                           0.1.21
xxhash                             3.5.0
yarl                               1.9.4
zarr                               2.18.2
zict                               3.0.0
zipp                               3.19.2

Ubuntu 22.04 cuda 12.6


Previously, I trained qwen2.5-vl-3B using lora and grpo. When I use the following scripts, it will not correctly work.

set -x

export CUDA_VISIBLE_DEVICES=1,2,3,4
# export HF_HONE=/mnt/data2/huggingface
export TORCH_CUDA_ARCH_LIST=9.0
export HF_DATASETS_CACHE=$HOME/data/.cache/huggingface/datasets
export WANDB_MODE=offline

MODEL=Qwen/Qwen2.5-VL-3B
TARGET_MODULES='["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]'
# If you are using vllm<=0.6.3, you might need to set the following environment variable to avoid bugs:
# export VLLM_ATTENTION_BACKEND=XFORMERS

python3 -m verl.trainer.main_ppo \
    algorithm.adv_estimator=grpo \
    data.train_files=$HOME/data/geo3k/train.parquet \
    data.val_files=$HOME/data/geo3k/test.parquet \
    data.train_batch_size=512 \
    data.max_prompt_length=1024 \
    data.max_response_length=2048 \
    data.filter_overlong_prompts=True \
    data.truncation='error' \
    data.image_key=images \
    actor_rollout_ref.model.path=$MODEL \
    actor_rollout_ref.model.use_remove_padding=True \
    actor_rollout_ref.model.lora_rank=64 \
    actor_rollout_ref.model.lora_alpha=32 \
    actor_rollout_ref.model.target_modules=$TARGET_MODULES \
    actor_rollout_ref.model.exclude_modules='.*visual.*' \
    actor_rollout_ref.model.enable_gradient_checkpointing=True \
    actor_rollout_ref.model.use_liger=True \
    actor_rollout_ref.actor.optim.lr=3e-5 \
    actor_rollout_ref.actor.ppo_mini_batch_size=128 \
    actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=8 \
    actor_rollout_ref.actor.use_kl_loss=True \
    actor_rollout_ref.actor.kl_loss_coef=0.01 \
    actor_rollout_ref.actor.kl_loss_type=low_var_kl \
    actor_rollout_ref.actor.entropy_coeff=0 \
    actor_rollout_ref.actor.strategy="fsdp" \
    actor_rollout_ref.actor.fsdp_config.model_dtype=bfloat16 \
    actor_rollout_ref.actor.fsdp_config.param_offload=False \
    actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \
    actor_rollout_ref.rollout.dtype=bfloat16 \
    actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=20 \
    actor_rollout_ref.rollout.tensor_model_parallel_size=4 \
    actor_rollout_ref.rollout.name=vllm \
    +actor_rollout_ref.rollout.engine_kwargs.vllm.disable_mm_preprocessor_cache=True \
    actor_rollout_ref.rollout.gpu_memory_utilization=0.5 \
    actor_rollout_ref.rollout.enable_chunked_prefill=False \
    actor_rollout_ref.rollout.enforce_eager=False \
    actor_rollout_ref.rollout.free_cache_engine=False \
    actor_rollout_ref.rollout.n=5 \
    actor_rollout_ref.rollout.load_format=safetensors \
    actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=20 \
    actor_rollout_ref.ref.fsdp_config.param_offload=True \
    algorithm.use_kl_in_reward=False \
    trainer.critic_warmup=0 \
    trainer.logger='["console","wandb"]' \
    trainer.project_name='verl_grpo_example_geo3k' \
    trainer.experiment_name='qwen2_5_vl_3b_lr3e-5_rank64' \
    trainer.n_gpus_per_node=4 \
    trainer.nnodes=1 \
    trainer.save_freq=20 \
    trainer.test_freq=5 \
    trainer.total_epochs=15 $@

Then I read code and found that in the workers/fsdp_workers.py:

        # used for LoRA
        self.base_sync_done: bool = "dummy" not in self.config.rollout.load_format
        self.layered_summon = self.config.rollout.get("layered_summon", False)
        if VLLM_SLEEP_LEVEL == 2 and not self.layered_summon:
            self.force_reload = True
            self.base_sync_done = False
        else:
            self.force_reload = False

if one's vllm version >= 0.8.5 and didn't activate the layered_summon, then the base_sync_done will be False. And they will only collect the base layers' param in fsdp_utils.py:

Image

This can lead to a result that every time when need to update the parms to vllm, there is no lora params to update. So the rollout model will always remain the base model.

Solution

I enable the layered_summon so it can work properly.

And here is a picture shows the experiments.

Image Image

The yellow turned on the layerd_summon and the purple is the fully params grpo. Other two color is the wrong case with different lora rank.

I'm wondering if I could make a PR to solve this problem.

Also, there is another problem: the type of target module is string, so we can't pass in a list. And if we use all-linear for vlm, the visual part will alse be added the lora layers.

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

set -x

export CUDA_VISIBLE_DEVICES=1,2,3,4
# export HF_HONE=/mnt/data2/huggingface
export TORCH_CUDA_ARCH_LIST=9.0
export HF_DATASETS_CACHE=$HOME/data/.cache/huggingface/datasets
export WANDB_MODE=offline

MODEL=Qwen/Qwen2.5-VL-3B
TARGET_MODULES='["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]'
# If you are using vllm<=0.6.3, you might need to set the following environment variable to avoid bugs:
# export VLLM_ATTENTION_BACKEND=XFORMERS

python3 -m verl.trainer.main_ppo \
    algorithm.adv_estimator=grpo \
    data.train_files=$HOME/data/geo3k/train.parquet \
    data.val_files=$HOME/data/geo3k/test.parquet \
    data.train_batch_size=512 \
    data.max_prompt_length=1024 \
    data.max_response_length=2048 \
    data.filter_overlong_prompts=True \
    data.truncation='error' \
    data.image_key=images \
    actor_rollout_ref.model.path=$MODEL \
    actor_rollout_ref.model.use_remove_padding=True \
    actor_rollout_ref.model.lora_rank=64 \
    actor_rollout_ref.model.lora_alpha=32 \
    actor_rollout_ref.model.target_modules=$TARGET_MODULES \
    actor_rollout_ref.model.exclude_modules='.*visual.*' \
    actor_rollout_ref.model.enable_gradient_checkpointing=True \
    actor_rollout_ref.model.use_liger=True \
    actor_rollout_ref.actor.optim.lr=3e-5 \
    actor_rollout_ref.actor.ppo_mini_batch_size=128 \
    actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=8 \
    actor_rollout_ref.actor.use_kl_loss=True \
    actor_rollout_ref.actor.kl_loss_coef=0.01 \
    actor_rollout_ref.actor.kl_loss_type=low_var_kl \
    actor_rollout_ref.actor.entropy_coeff=0 \
    actor_rollout_ref.actor.strategy="fsdp" \
    actor_rollout_ref.actor.fsdp_config.model_dtype=bfloat16 \
    actor_rollout_ref.actor.fsdp_config.param_offload=False \
    actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \
    actor_rollout_ref.rollout.dtype=bfloat16 \
    actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=20 \
    actor_rollout_ref.rollout.tensor_model_parallel_size=4 \
    actor_rollout_ref.rollout.name=vllm \
    +actor_rollout_ref.rollout.engine_kwargs.vllm.disable_mm_preprocessor_cache=True \
    actor_rollout_ref.rollout.gpu_memory_utilization=0.5 \
    actor_rollout_ref.rollout.enable_chunked_prefill=False \
    actor_rollout_ref.rollout.enforce_eager=False \
    actor_rollout_ref.rollout.free_cache_engine=False \
    actor_rollout_ref.rollout.n=5 \
    actor_rollout_ref.rollout.load_format=safetensors \
    actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=20 \
    actor_rollout_ref.ref.fsdp_config.param_offload=True \
    algorithm.use_kl_in_reward=False \
    trainer.critic_warmup=0 \
    trainer.logger='["console","wandb"]' \
    trainer.project_name='verl_grpo_example_geo3k' \
    trainer.experiment_name='qwen2_5_vl_3b_lr3e-5_rank64' \
    trainer.n_gpus_per_node=4 \
    trainer.nnodes=1 \
    trainer.save_freq=20 \
    trainer.test_freq=5 \
    trainer.total_epochs=15 $@

Expected behavior

Correctly train the vlm in grpo and lora mode.

WncFht avatar Sep 18 '25 08:09 WncFht

This bug has been fixed through: https://github.com/volcengine/verl/pull/3461. Can you try this patch?

techkang avatar Sep 18 '25 12:09 techkang

@techkang My verl include this patch, but it still has the problem above. In my opinion, #3461 fixed the situation when VLLM_SLEEP_LEVEL=2, the vllm will not load the weights. But it only load the base model weight without the lora layers.

I don't know if I got it wrong

WncFht avatar Sep 18 '25 14:09 WncFht

@WncFht Thanks for debugging this! You're right — only the base model's weights are loaded when VLLM_SLEEP_LEVEL=2. I did this to save as much memory as possible but it seem that there are still bugs in here. Feel free to propose a PR to fix it!

techkang avatar Sep 18 '25 14:09 techkang

I have fix it by this pr https://github.com/volcengine/verl/pull/3541, @techkang @WncFht cc.

piood avatar Sep 19 '25 10:09 piood