-
Notifications
You must be signed in to change notification settings - Fork 196
[cfg, recipe, tests] feat: wire DAPO overlong reward buffer on V1 omni loop #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OnePunchMonk
wants to merge
12
commits into
verl-project:main
Choose a base branch
from
OnePunchMonk:dapo-p2-overlong-reward
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3f0b3f
[cfg, recipe, tests] feat: add Thinker DAPO phase one
WenzheWang bef712e
[doc] fix: expose DAPO example in docs
WenzheWang 8323ead
[cfg, recipe, tests] fix: address AVQA validation feedback
WenzheWang 6969a3c
[cfg, recipe, tests] fix: harden DAPO contracts
WenzheWang c467198
[tests] fix: match rollout correction mapping contract
WenzheWang 4a8eaf7
[doc, tests] fix: address DAPO review feedback
WenzheWang bc0bee6
[cfg, doc, tests] fix: simplify DAPO review scope
WenzheWang 7822a50
[cfg, recipe, tests] feat: wire DAPO overlong reward buffer on V1 omn…
OnePunchMonk 7dc3bd9
[cfg, tests] chore: trim redundant comments
OnePunchMonk d5ba609
Merge branch 'main' into dapo-p2-overlong-reward
OnePunchMonk 7fdf1dd
address review comments: local tokenizer in CPU test, trim README pha…
OnePunchMonk c929a51
fix: shared launcher contract still forbade overlong_buffer_cfg for b…
OnePunchMonk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
tests/special_e2e/run_dapo_qwen3_omni_thinker_lora_v1_smoke.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/usr/bin/env bash | ||
| # Qwen3-Omni Thinker DAPO + LoRA V1 smoke without dynamic sampling. | ||
|
|
||
| set -xeuo pipefail | ||
|
|
||
| if [[ "${SKIP_COMPAT_DEPS_INSTALL:-0}" != "1" ]]; then | ||
| uv pip install --system --break-system-packages transformers==5.12.1 accelerate==1.14.0 peft==0.19.1 | ||
| fi | ||
|
|
||
| export NCCL_IB_DISABLE=1 | ||
| export CPATH=/usr/include${CPATH:+:$CPATH} | ||
| export RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 | ||
| export VERL_USE_EXTERNAL_MODULES=verl_omni | ||
|
|
||
| NUM_GPUS=${NUM_GPUS:-2} | ||
| MODEL_PATH=${MODEL_PATH:-} | ||
| DATA_DIR=${DATA_DIR:-${HOME}/data/gsm8k} | ||
| TOTAL_TRAIN_STEPS=${TOTAL_TRAIN_STEPS:-2} | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
| EXCLUDE_MODULES=".*talker.*|.*code2wav.*|.*code_predictor.*|.*visual.*|.*audio_tower.*" | ||
|
|
||
| MODEL_PATH="${MODEL_PATH:-${HOME}/models/tiny-random/Qwen3-Omni}" | ||
| python3 "${REPO_ROOT}/tests/special_e2e/build_qwen3_omni_tiny_random.py" \ | ||
| --output-dir "${MODEL_PATH}" --force | ||
|
|
||
| if [ ! -f "${DATA_DIR}/train.parquet" ]; then | ||
| python3 "${REPO_ROOT}/tests/special_e2e/create_dummy_math_data.py" \ | ||
| --local_save_dir "${DATA_DIR}" | ||
| fi | ||
|
|
||
| python3 -m verl_omni.trainer.main_omni \ | ||
| data.train_files="${DATA_DIR}/train.parquet" \ | ||
| data.val_files="${DATA_DIR}/test.parquet" \ | ||
| data.train_batch_size=4 \ | ||
| data.max_prompt_length=256 \ | ||
| data.max_response_length=512 \ | ||
| data.val_max_samples=4 \ | ||
| data.truncation='error' \ | ||
| data.filter_overlong_prompts=true \ | ||
| actor_rollout_ref.model.path="${MODEL_PATH}" \ | ||
| +actor_rollout_ref.model.override_config.attn_implementation=sdpa \ | ||
| actor_rollout_ref.model.lora_rank=8 \ | ||
| actor_rollout_ref.model.lora_alpha=16 \ | ||
| actor_rollout_ref.model.lora_dtype=float32 \ | ||
| actor_rollout_ref.model.lora.merge=true \ | ||
| actor_rollout_ref.model.enable_gradient_checkpointing=true \ | ||
| actor_rollout_ref.model.use_remove_padding=true \ | ||
| actor_rollout_ref.model.exclude_modules="${EXCLUDE_MODULES}" \ | ||
| actor_rollout_ref.model.target_modules="['q_proj','k_proj','v_proj','o_proj']" \ | ||
| actor_rollout_ref.actor.freeze_vision_tower=true \ | ||
| actor_rollout_ref.actor.strategy=fsdp2 \ | ||
| actor_rollout_ref.actor.optim.lr=3e-6 \ | ||
| actor_rollout_ref.actor.optim.weight_decay=0.01 \ | ||
| actor_rollout_ref.actor.optim.clip_grad=1.0 \ | ||
| actor_rollout_ref.actor.ppo_mini_batch_size=4 \ | ||
| actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=1 \ | ||
| actor_rollout_ref.actor.use_dynamic_bsz=true \ | ||
| actor_rollout_ref.actor.ppo_max_token_len_per_gpu=20480 \ | ||
| actor_rollout_ref.actor.use_kl_loss=false \ | ||
| actor_rollout_ref.actor.entropy_coeff=0 \ | ||
| actor_rollout_ref.actor.policy_loss.loss_mode=vanilla \ | ||
| actor_rollout_ref.actor.clip_ratio_low=0.2 \ | ||
| actor_rollout_ref.actor.clip_ratio_high=0.28 \ | ||
| actor_rollout_ref.actor.clip_ratio_c=10.0 \ | ||
| actor_rollout_ref.actor.loss_agg_mode=token-mean \ | ||
| actor_rollout_ref.actor.fsdp_config.model_dtype=bfloat16 \ | ||
| actor_rollout_ref.actor.fsdp_config.param_offload=true \ | ||
| actor_rollout_ref.actor.fsdp_config.optimizer_offload=true \ | ||
| actor_rollout_ref.rollout.name=vllm_omni \ | ||
| actor_rollout_ref.rollout.n=2 \ | ||
| actor_rollout_ref.rollout.temperature=0.8 \ | ||
| actor_rollout_ref.rollout.tensor_model_parallel_size="${NUM_GPUS}" \ | ||
| actor_rollout_ref.rollout.gpu_memory_utilization=0.4 \ | ||
| actor_rollout_ref.rollout.max_num_seqs=16 \ | ||
| actor_rollout_ref.rollout.load_format=safetensors \ | ||
| actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=true \ | ||
| actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=20480 \ | ||
| actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=2 \ | ||
| actor_rollout_ref.rollout.enable_prefix_caching=false \ | ||
| +actor_rollout_ref.rollout.engine_kwargs.vllm_omni.output_mode="ar" \ | ||
| +actor_rollout_ref.rollout.engine_kwargs.vllm_omni.pipeline_name="qwen3_omni_moe" \ | ||
| actor_rollout_ref.rollout.val_kwargs.n=1 \ | ||
| actor_rollout_ref.rollout.val_kwargs.temperature=1.0 \ | ||
| actor_rollout_ref.rollout.val_kwargs.top_p=0.7 \ | ||
| actor_rollout_ref.ref.strategy=fsdp2 \ | ||
| actor_rollout_ref.ref.log_prob_use_dynamic_bsz=true \ | ||
| actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=20480 \ | ||
| actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=2 \ | ||
| actor_rollout_ref.ref.fsdp_config.param_offload=true \ | ||
| actor_rollout_ref.ref.fsdp_config.model_dtype=bfloat16 \ | ||
| algorithm.trainer_type=policy_gradient \ | ||
| algorithm.sample_source=online \ | ||
| algorithm.adv_estimator=grpo \ | ||
| algorithm.use_kl_in_reward=false \ | ||
| algorithm.filter_groups.enable=false \ | ||
| reward.reward_manager.source=register \ | ||
| reward.reward_manager.name=dapo \ | ||
| reward.reward_kwargs.max_resp_len=512 \ | ||
| reward.reward_kwargs.overlong_buffer_cfg.enable=true \ | ||
| reward.reward_kwargs.overlong_buffer_cfg.len=128 \ | ||
| reward.reward_kwargs.overlong_buffer_cfg.penalty_factor=1.0 \ | ||
| reward.reward_kwargs.overlong_buffer_cfg.log=true \ | ||
| trainer.val_before_train=false \ | ||
| trainer.balance_batch=true \ | ||
| trainer.critic_warmup=0 \ | ||
| trainer.logger=console \ | ||
| trainer.project_name=verl-test \ | ||
| trainer.experiment_name=dapo-qwen3-omni-thinker-lora-e2e-v1-wo-dynamic-sampling \ | ||
| trainer.n_gpus_per_node="${NUM_GPUS}" \ | ||
| trainer.nnodes=1 \ | ||
| trainer.test_freq=1 \ | ||
| trainer.save_freq=-1 \ | ||
| trainer.resume_mode=disable \ | ||
| trainer.total_training_steps="${TOTAL_TRAIN_STEPS}" \ | ||
| "$@" | ||
|
|
||
| echo "Qwen3-Omni Thinker DAPO+LoRA e2e V1 smoke without dynamic sampling passed." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright 2026 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Overlong penalty must change the reward on a truncated response (#446 Phase 2).""" | ||
|
|
||
| import numpy as np | ||
| import torch | ||
| from omegaconf import OmegaConf | ||
| from tokenizers import Tokenizer | ||
| from tokenizers.models import WordLevel | ||
| from tokenizers.pre_tokenizers import Whitespace | ||
| from transformers import AutoTokenizer, PreTrainedTokenizerFast | ||
| from verl import DataProto | ||
| from verl.experimental.reward_loop.reward_manager.dapo import DAPORewardManager | ||
|
|
||
| MAX_RESP_LEN = 16 | ||
| OVERLONG_BUFFER_LEN = 4 | ||
| OVERLONG_PENALTY_FACTOR = 1.0 | ||
|
|
||
|
|
||
| def _build_local_tokenizer(tmp_path) -> AutoTokenizer: | ||
| # A tiny in-memory tokenizer, so this test needs no network access or | ||
| # downloaded artifacts (the DAPO manager only calls tokenizer.decode()). | ||
| vocab = {"[UNK]": 0, **{str(i): i + 1 for i in range(100)}} | ||
| tokenizer = Tokenizer(WordLevel(vocab=vocab, unk_token="[UNK]")) | ||
| tokenizer.pre_tokenizer = Whitespace() | ||
| fast_tokenizer = PreTrainedTokenizerFast(tokenizer_object=tokenizer, unk_token="[UNK]") | ||
| fast_tokenizer.save_pretrained(tmp_path) | ||
| return AutoTokenizer.from_pretrained(tmp_path) | ||
|
|
||
|
|
||
| def _compute_score(data_source, solution_str, ground_truth, extra_info=None): | ||
| return 1.0 | ||
|
|
||
|
|
||
| def _build_manager(overlong_enable: bool, tokenizer) -> DAPORewardManager: | ||
| config = OmegaConf.create( | ||
| { | ||
| "reward": { | ||
| "reward_kwargs": { | ||
| "overlong_buffer_cfg": { | ||
| "enable": overlong_enable, | ||
| "len": OVERLONG_BUFFER_LEN, | ||
| "penalty_factor": OVERLONG_PENALTY_FACTOR, | ||
| "log": True, | ||
| }, | ||
| "max_resp_len": MAX_RESP_LEN, | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| return DAPORewardManager(config, tokenizer, _compute_score) | ||
|
|
||
|
|
||
| def _make_truncated_response() -> DataProto: | ||
| # valid_len == MAX_RESP_LEN, i.e. exceed_len == OVERLONG_BUFFER_LEN -> full penalty. | ||
| response_ids = torch.randint(0, 100, (1, MAX_RESP_LEN)) | ||
| attention_mask = torch.ones(1, MAX_RESP_LEN, dtype=torch.long) | ||
| non_tensors = { | ||
| "data_source": np.array(["dummy"], dtype=object), | ||
| "reward_model": np.array([{"ground_truth": "x"}], dtype=object), | ||
| "extra_info": np.array([{}], dtype=object), | ||
| } | ||
| return DataProto.from_dict( | ||
| tensors={"responses": response_ids, "attention_mask": attention_mask}, | ||
| non_tensors=non_tensors, | ||
| ) | ||
|
|
||
|
|
||
| def test_overlong_penalty_changes_reward_on_truncated_response(tmp_path): | ||
| batch = _make_truncated_response() | ||
| tokenizer = _build_local_tokenizer(tmp_path) | ||
|
|
||
| disabled = _build_manager(overlong_enable=False, tokenizer=tokenizer) | ||
| enabled = _build_manager(overlong_enable=True, tokenizer=tokenizer) | ||
|
|
||
| result_disabled = disabled.loop.run_until_complete(disabled.run_single(batch)) | ||
| result_enabled = enabled.loop.run_until_complete(enabled.run_single(batch)) | ||
|
|
||
| assert result_disabled["reward_score"] == 1.0 | ||
| assert "overlong" not in result_disabled["reward_extra_info"] | ||
|
|
||
| assert result_enabled["reward_score"] < result_disabled["reward_score"] | ||
| assert result_enabled["reward_extra_info"]["overlong"] | ||
| assert result_enabled["reward_extra_info"]["overlong_reward"] < 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you plan to support dynamic sampling in #540. Why don't you move the smoke test to #540, so that you can enable both overlong reward buffer and dynamic sampling in the same test script?
Besides, to make this test take effect, you also need to add it to
tests/gpu_smoke/run_gpu_smoke_omni_e2e.sh. If you have special pin version of third-party libraries, likeflashinfer-python==0.6.16.post3, you may need to update.github/actions/gpu-smoke-prepare/action.yml.