geminiDeveloper commited on
Commit
dfbcd52
·
verified ·
1 Parent(s): dc6be0e

Upload 1194 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. verl_0720_main/27b.sh +1115 -0
  2. verl_0720_main/27b.shZone.Identifier +4 -0
  3. verl_0720_main/27b_old_verl.sh +1044 -0
  4. verl_0720_main/27b_old_verl.shZone.Identifier +4 -0
  5. verl_0720_main/9b.sh +1118 -0
  6. verl_0720_main/9b.shZone.Identifier +4 -0
  7. verl_0720_main/9b_sp1_16k_fused_lmhead_smoke.sh +1111 -0
  8. verl_0720_main/mindspeed_config.yaml +132 -0
  9. verl_0720_main/mindspeed_config.yamlZone.Identifier +4 -0
  10. verl_0720_main/nanoclaw_qwen35_sp1_16k_stable_full.sh +1059 -0
  11. verl_0720_main/paper_docs/01_nanoclaw_harness_framework.md +280 -0
  12. verl_0720_main/paper_docs/02_nanoclaw_behavior_masking.md +29 -0
  13. verl_0720_main/paper_docs/03_nanoclaw_reward_design.md +58 -0
  14. verl_0720_main/verl/.agent/skills/issue/SKILL.md +47 -0
  15. verl_0720_main/verl/.agent/skills/pr/SKILL.md +33 -0
  16. verl_0720_main/verl/.gemini/config.yaml +10 -0
  17. verl_0720_main/verl/.git-blame-ignore-revs +13 -0
  18. verl_0720_main/verl/.github/CODEOWNERS +26 -0
  19. verl_0720_main/verl/.github/ISSUE_TEMPLATE/bug-report.yml +65 -0
  20. verl_0720_main/verl/.github/ISSUE_TEMPLATE/config.yml +2 -0
  21. verl_0720_main/verl/.github/ISSUE_TEMPLATE/feature-request.yml +32 -0
  22. verl_0720_main/verl/.github/PULL_REQUEST_TEMPLATE.md +41 -0
  23. verl_0720_main/verl/.github/dependabot.yml +9 -0
  24. verl_0720_main/verl/.github/workflows/.stash/e2e_ppo_trainer_torchtitan_vllm.yml +171 -0
  25. verl_0720_main/verl/.github/workflows/README.md +73 -0
  26. verl_0720_main/verl/.github/workflows/check-pr-title.yml +58 -0
  27. verl_0720_main/verl/.github/workflows/cpu_unit_tests.yml +121 -0
  28. verl_0720_main/verl/.github/workflows/doc.yml +103 -0
  29. verl_0720_main/verl/.github/workflows/docker-build-ascend-a2.yml +274 -0
  30. verl_0720_main/verl/.github/workflows/docker-build-ascend-a3.yml +274 -0
  31. verl_0720_main/verl/.github/workflows/docker-build-ascend-sglang-a2.yml +78 -0
  32. verl_0720_main/verl/.github/workflows/docker-build-ascend-sglang-a3.yml +78 -0
  33. verl_0720_main/verl/.github/workflows/e2e_ascend.yml +245 -0
  34. verl_0720_main/verl/.github/workflows/e2e_fully_async_policy.yml +180 -0
  35. verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_ascend.yml +192 -0
  36. verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_opd.yml +112 -0
  37. verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_trtllm.yml +180 -0
  38. verl_0720_main/verl/.github/workflows/e2e_one_step_off_policy.yml +181 -0
  39. verl_0720_main/verl/.github/workflows/e2e_one_step_off_policy_ascend.yml +193 -0
  40. verl_0720_main/verl/.github/workflows/e2e_ppo_grpo_trainer_trtllm.yml +310 -0
  41. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer.yml +81 -0
  42. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang.yml +215 -0
  43. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_2.yml +207 -0
  44. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_2_ascend.yml +145 -0
  45. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_ascend.yml +227 -0
  46. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm.yml +243 -0
  47. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_2.yml +328 -0
  48. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_2_ascend.yml +231 -0
  49. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_rocm.yml +265 -0
  50. verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_veomni_vllm.yml +160 -0
verl_0720_main/27b.sh ADDED
@@ -0,0 +1,1115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Qwen3.5-27B Nanoclaw 多轮 GRPO — VERL 0720 + NPU SP1/31K 长轨迹全优化版
3
+ #
4
+ # 关键修改:
5
+ # 1) 入口改为 python3 -m verl.trainer.main_ppo,不再使用 recipe.grpo_mindspeed_mm.main_ppo;
6
+ # 2) 不再使用 MM_CONFIG_FILE / MindSpeed-MM YAML;
7
+ # 3) 显式 text-only:data.return_multi_modal_inputs=False;
8
+ # 4) 数据输入改为 Nanoclaw base_tasks 目录,不再使用 Retool parquet/json;
9
+ # 5) 保留 27B 作业验证过的 HCCL buffer 与端口范围,降低 HcclAllreduce socket/资源压力;
10
+ # 6) 默认 val n=1、log_val_generations=10,降低验证额外资源压力;
11
+ # 7) 使用 FSDP2、reshard-after-forward、CPU offload policy、gradient checkpointing 和 activation offload;
12
+ # 8) 使用最新版 VERL V1/TransferQueue 和 nanoclaw_recipe,并按参考 YAML 的训练意图映射优化器与 KL;
13
+ # 9) 恢复正式训练所需的 22768 response / 16384 assistant 长轨迹预算;
14
+ # 10) actor/ref 的全词表 entropy 使用 256-token 分块;
15
+ # 11) 启用分块 Torch LM-head,避免完整 logits + NPU cross entropy 的多 GiB 峰值。
16
+
17
+ set -x
18
+
19
+ # ================= 正式长轨迹全优化版:Qwen3.5-27B NPU SP1 + 约 31K =================
20
+ export TRAIN_SP=1
21
+ export QWEN35_FLA_BACKEND=disabled
22
+ export MAX_PROMPT_LENGTH=8192
23
+ export MAX_RESPONSE_LENGTH=22768
24
+ export MAX_ASSISTANT_RESPONSE_LENGTH=16384
25
+ export MAX_TOOL_RESPONSE_LENGTH=8192
26
+ # 8192 + 22768 = 30960,向上对齐到 32768,确保单条最长轨迹能够组成独立 micro-batch。
27
+ export ACTOR_MAX_TOKEN_LEN_PER_GPU=32768
28
+ export LOG_PROB_MAX_TOKEN_LEN_PER_GPU=32768
29
+ export ROLLOUT_MAX_NUM_BATCHED_TOKENS=32768
30
+ export ACTOR_STRATEGY=fsdp2
31
+ export OFFLOAD=True
32
+ # 当前 VERL 的 checkpointing 分支不会传递自定义 chunk size;稳定版明确关闭它,确保实际使用 256。
33
+ export ENTROPY_FROM_LOGITS_WITH_CHUNKING=True
34
+ export ENTROPY_FROM_LOGITS_CHUNK_SIZE=256
35
+ export ENTROPY_CHECKPOINTING=False
36
+ # 27B 普通路径已实测在 actor update 的 npu_cross_entropy_loss 额外申请
37
+ # 7.23 GiB 时 OOM。fused Torch LM-head 按 token 分块直接计算 log-prob/entropy。
38
+ export USE_FUSED_KERNELS=True
39
+ export FUSED_KERNEL_BACKEND=torch
40
+ # 27B/31K 默认同时打开 activation offload 和 gradient checkpointing;保留故障隔离开关。
41
+ export ENABLE_ACTIVATION_OFFLOAD=${ENABLE_ACTIVATION_OFFLOAD:-True}
42
+
43
+
44
+ npu-smi info || true
45
+ pip install --upgrade pip
46
+ pip uninstall -y moxing-framework || true
47
+
48
+ # ================= 路径配置 =================
49
+ SCRIPT_DIR=/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/verl_0720_nanoclaw/verl_0720_main
50
+ if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
51
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
52
+ elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
53
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}
54
+ else
55
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
56
+ fi
57
+ WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
58
+ INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
59
+ BKGS=${BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs}
60
+ chmod 755 "${INSTALL_DIR}"
61
+
62
+ # Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
63
+
64
+ GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
65
+ COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-/opt/huawei/dataset/zyr_yuyin/bkgs/gcc-11.3.0-compiled-aarch64.tar.gz}
66
+
67
+ echo "--> 正在从缓存恢复 GCC 11.3.0..."
68
+ tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
69
+ export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
70
+ export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
71
+ export CC=${GCC_INSTALL_PREFIX}/bin/gcc
72
+ export CXX=${GCC_INSTALL_PREFIX}/bin/g++
73
+ echo "--> 验证 GCC 版本:"
74
+ gcc --version
75
+
76
+ cd "${BKGS}"
77
+ cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
78
+
79
+ VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-05-12/verl_new_26_05_09/pkgs}
80
+ rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
81
+ cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
82
+ cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
83
+
84
+ CANN_BKGS=${CANN_BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs/cann_0527}
85
+ cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
86
+ cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
87
+ cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
88
+
89
+ echo "################"
90
+ echo "## set verl env"
91
+ echo "################"
92
+
93
+ cd "${INSTALL_DIR}"
94
+
95
+ chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
96
+ bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
97
+ source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
98
+
99
+ chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
100
+ bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
101
+
102
+ chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
103
+ bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
104
+ source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
105
+
106
+ export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
107
+ export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
108
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
109
+
110
+ pip3 install torch==2.9.0
111
+ pip3 install pyyaml setuptools
112
+ pip3 install torch-npu==2.9.0
113
+ pip3 install torchvision==0.24.0 torchaudio==2.9.0
114
+
115
+ ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
116
+ export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
117
+ pip install pybind11==2.13.6
118
+
119
+ cd "${INSTALL_DIR}/vllm"
120
+ VLLM_TARGET_DEVICE=empty pip install .
121
+
122
+ cd "${INSTALL_DIR}/vllm-ascend"
123
+ pip install -e .
124
+ export VLLM_LOGGING_LEVEL=INFO
125
+
126
+ cd "${INSTALL_DIR}"
127
+ tar -xvf jemalloc-5.3.0.tar.bz2
128
+ cd jemalloc-5.3.0
129
+ ./configure --prefix="${INSTALL_DIR}"
130
+ make -j"$(nproc)"
131
+ make install
132
+ export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
133
+
134
+ # # ================= 可选:安装 MindSpeed 栈 =================
135
+ # # 纯 VERL engine 路线不依赖 MindSpeed-MM YAML。默认不安装,避免和新版 VERL engine 混淆。
136
+ # INSTALL_MINDSPEED_STACK=${INSTALL_MINDSPEED_STACK:-0}
137
+ # if [ "${INSTALL_MINDSPEED_STACK}" = "1" ]; then
138
+ # MindSpeed_PATH=${MindSpeed_PATH:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-slow-stable}
139
+ # cd "${MindSpeed_PATH}"
140
+ # cd Megatron-LM && pip install -e . --no-deps && cd ..
141
+ # cd MindSpeed && pip install -e . --no-deps && cd ..
142
+ # cd MindSpeed-MM && mkdir -p logs data ckpt && pip install -e . --no-deps && cd ..
143
+ # pip install beartype bs4 diffusers==0.30.3 ftfy imageio-ffmpeg pandarallel pytest-mock
144
+ # else
145
+ # echo "--> Skip MindSpeed/MindSpeed-MM installation for pure VERL engine route."
146
+ # fi
147
+
148
+
149
+
150
+ # ================= 安装 Triton-Ascend 3.2.1 =================
151
+ # 1. 卸载 triton(增加 -y 自动确认)
152
+ pip uninstall -y triton
153
+
154
+ # 2. 卸载 triton-ascend(增加 -y 自动确认)
155
+ pip uninstall -y triton-ascend
156
+ pip install --no-cache-dir --force-reinstall triton==3.5.0
157
+ pip install --no-deps /opt/huawei/dataset/zyr_yuyin/bkgs/triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
158
+
159
+
160
+ # ================= 安装新版 VERL =================
161
+ cd "${WORK_DIR}"
162
+ pip install -r requirements-npu.txt
163
+ # NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
164
+ python3 -m pip install -e . --no-deps
165
+ pip install --upgrade 'urllib3==1.26.11'
166
+ pip install loguru
167
+ pip install tree_sitter==0.21.3
168
+ pip install tree-sitter-java==0.21.0
169
+ pip install tree-sitter-javascript==0.21.4
170
+
171
+ ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
172
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
173
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
174
+
175
+ pip uninstall -y transformers || true
176
+ pip install transformers==5.3.0
177
+ pip install accelerate==1.13.0 mathruler
178
+ pip install jsonargparse
179
+ pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
180
+
181
+ # 稳定版只允许 SP=1:不安装普通 FLA,也不进入尚未完成 NPU 适配的 Ulysses CP。
182
+ if [ "${TRAIN_SP}" != "1" ]; then
183
+ echo "ERROR: the long-sequence all-optimization profile requires TRAIN_SP=1; got ${TRAIN_SP}." >&2
184
+ exit 2
185
+ fi
186
+ export NANOCLAW_REQUIRE_FLA=0
187
+ echo "--> Stable SP1: flash-linear-attention is disabled; Qwen3.5 will not build an Ulysses CP context."
188
+
189
+ # Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
190
+ # 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
191
+ NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
192
+ PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
193
+ SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
194
+ SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
195
+ python3 -m pip install --no-cache-dir --force-reinstall \
196
+ "numpy==${NUMPY_VERSION}" \
197
+ "pandas==${PANDAS_VERSION}" \
198
+ "scipy==${SCIPY_VERSION}" \
199
+ "scikit-learn==${SKLEARN_VERSION}"
200
+
201
+ python3 - <<'PY' || exit 2
202
+ import numpy
203
+ import pandas
204
+ import scipy
205
+ import sklearn
206
+ import sys
207
+ import transformers
208
+ import vllm
209
+
210
+ fla_version = "disabled-sp1"
211
+
212
+ print(
213
+ "[python_stack_preflight] "
214
+ f"python={sys.executable} "
215
+ f"numpy={numpy.__version__} "
216
+ f"pandas={pandas.__version__} "
217
+ f"scipy={scipy.__version__} "
218
+ f"sklearn={sklearn.__version__} "
219
+ f"transformers={transformers.__version__} "
220
+ f"vllm={vllm.__version__} "
221
+ f"fla={fla_version}"
222
+ )
223
+ print(
224
+ "[python_stack_paths] "
225
+ f"numpy={numpy.__file__} "
226
+ f"pandas={pandas.__file__}"
227
+ )
228
+ PY
229
+ pip list
230
+
231
+ # ================= 检查 Nanoclaw recipe =================
232
+ if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
233
+ echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
234
+ exit 2
235
+ fi
236
+ test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
237
+
238
+ # Qwen3.5 MRoPE position_ids 是 3/4 轴张量。未应用此补丁时,NPU
239
+ # FlashAttention 会把 seqLen 重复累计(例如 T=10131、sum(seqLen)=30393)。
240
+ QWEN35_MONKEY_PATCH_FILE=${WORK_DIR}/verl/models/transformers/monkey_patch.py
241
+ if [ ! -f "${QWEN35_MONKEY_PATCH_FILE}" ] || ! grep -q "def _normalize_fa_position_ids" "${QWEN35_MONKEY_PATCH_FILE}"; then
242
+ echo "ERROR: Qwen3.5 FlashAttention position_ids normalization patch is missing: ${QWEN35_MONKEY_PATCH_FILE}" >&2
243
+ echo "Upload the modified verl/ directory together with this standalone script." >&2
244
+ exit 2
245
+ fi
246
+
247
+ # Nanoclaw rollout model-version metadata 修复;否则完成 actor update 后会在
248
+ # _compute_metrics 中把 min_global_steps=None 强转 int 而崩溃。
249
+ TOOL_AGENT_LOOP_FILE=${WORK_DIR}/verl/experimental/agent_loop/tool_agent_loop.py
250
+ TRAINER_BASE_FILE=${WORK_DIR}/verl/trainer/ppo/v1/trainer_base.py
251
+ if [ ! -f "${TOOL_AGENT_LOOP_FILE}" ] || ! grep -q "output_min_global_steps" "${TOOL_AGENT_LOOP_FILE}"; then
252
+ echo "ERROR: Nanoclaw rollout version metadata merge fix is missing: ${TOOL_AGENT_LOOP_FILE}" >&2
253
+ exit 2
254
+ fi
255
+ if [ ! -f "${TRAINER_BASE_FILE}" ] || ! grep -q "def resolve_model_version" "${TRAINER_BASE_FILE}"; then
256
+ echo "ERROR: PPO metrics None-version fallback fix is missing: ${TRAINER_BASE_FILE}" >&2
257
+ exit 2
258
+ fi
259
+
260
+ # 27B 必须使用 Qwen3.5 分块 fused LM-head。若训练机没有同步更新后的 VERL,
261
+ # 在启动 Ray 前直接退出,避免再次运行四十分钟后才在 actor cross entropy OOM。
262
+ QWEN35_MODEL_PATCH_FILE=${WORK_DIR}/verl/models/transformers/qwen3_5.py
263
+ FUSED_LINEAR_FILE=${WORK_DIR}/verl/utils/experimental/torch_functional.py
264
+ if [ ! -f "${QWEN35_MODEL_PATCH_FILE}" ] || ! grep -q "def forward_with_torch_backend" "${QWEN35_MODEL_PATCH_FILE}"; then
265
+ echo "ERROR: Qwen3.5 fused Torch backend is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
266
+ exit 2
267
+ fi
268
+ if ! grep -q "vocab_weights.full_tensor().to(hidden_states.device)" "${QWEN35_MODEL_PATCH_FILE}"; then
269
+ echo "ERROR: Qwen3.5 FSDP2 CPU-offload fused LM-head device-staging fix is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
270
+ exit 2
271
+ fi
272
+ if [ ! -f "${FUSED_LINEAR_FILE}" ] || ! grep -q "class FusedLinearForPPO" "${FUSED_LINEAR_FILE}"; then
273
+ echo "ERROR: chunked FusedLinearForPPO is missing: ${FUSED_LINEAR_FILE}" >&2
274
+ exit 2
275
+ fi
276
+
277
+ ACTIVATION_OFFLOAD_FILE=${WORK_DIR}/verl/utils/activation_offload.py
278
+ if [ ! -f "${ACTIVATION_OFFLOAD_FILE}" ] || ! grep -q "Missing offload mapping for group" "${ACTIVATION_OFFLOAD_FILE}"; then
279
+ echo "ERROR: FSDP2 checkpoint activation-offload on-demand reload fix is missing: ${ACTIVATION_OFFLOAD_FILE}" >&2
280
+ exit 2
281
+ fi
282
+
283
+ # ================= PLOG =================
284
+ ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
285
+ task_name=worker-${VC_TASK_INDEX}
286
+ task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
287
+ mkdir -p "${task_plog_path}"
288
+ export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
289
+ echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
290
+
291
+ MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
292
+ MASTER_PORT=${PORT}
293
+ MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
294
+
295
+ cd "${WORK_DIR}"
296
+
297
+ mkdir -p /cache/ray_tmp
298
+
299
+ echo "Cleaning up old Ray processes..."
300
+ ray stop --force || true
301
+ sleep 5
302
+ rm -rf /cache/ray_tmp/*
303
+ pkill -9 -f raylet || true
304
+ pkill -9 -f plasma_store || true
305
+ pkill -9 -f gcs_server || true
306
+ echo "Waiting 20s for NPU/Ray resources to be released..."
307
+ npu-smi info || true
308
+ sleep 20
309
+
310
+ # ================= NPU / HCCL / Ray 环境 =================
311
+ export NON_MEGATRON=true
312
+ export MULTI_STREAM_MEMORY_REUSE=2
313
+ export OMP_NUM_THREADS=1
314
+ export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
315
+ export VLLM_LOGGING_LEVEL=INFO
316
+ export RAY_DEDUP_LOGS=0
317
+ export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
318
+ export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
319
+ export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
320
+ export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
321
+ export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
322
+ export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
323
+
324
+ # 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
325
+ export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
326
+ export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
327
+ export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
328
+ export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
329
+
330
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
331
+ export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
332
+ export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
333
+ export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
334
+ export WANDB_MODE=${WANDB_MODE:-disabled}
335
+ export PYTHONUNBUFFERED=1
336
+ export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
337
+ export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
338
+ export TOKENIZERS_PARALLELISM=false
339
+ export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
340
+ export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
341
+ export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
342
+ export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
343
+ export VLLM_USE_V1=${VLLM_USE_V1:-1}
344
+ export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
345
+ export HYDRA_FULL_ERROR=1
346
+ export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
347
+ export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
348
+ export RAY_timeout_ms=${RAY_timeout_ms:-600000}
349
+ export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
350
+ export RAY_USAGE_STATS_ENABLED=0
351
+ export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
352
+
353
+ ulimit -n 65536
354
+
355
+ # Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
356
+ export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
357
+
358
+ # ================= 路径与数据配置 =================
359
+ HDFS_ROOT=${HDFS_ROOT:-$PWD}
360
+ DATA_ROOT=${DATA_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_ckpt}
361
+
362
+ # Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
363
+ # base_tasks/data_*/env_builder.py
364
+ # base_tasks/data_*/prompts.md
365
+ # base_tasks/data_*/workplace_verifier.py
366
+ # base_tasks/data_*/manifest.json
367
+ # 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
368
+ DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/nanoclawRLdata/0710_add1000agent_qwen3_7_max_v1/exported_new_data}
369
+ train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
370
+ val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
371
+ train_files="['$train_base_tasks']"
372
+ test_files="['$val_base_tasks']"
373
+
374
+ if [ ! -d "${train_base_tasks}" ]; then
375
+ echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
376
+ exit 2
377
+ fi
378
+ if [ ! -d "${val_base_tasks}" ]; then
379
+ echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
380
+ exit 2
381
+ fi
382
+
383
+ model_path=${MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-27B}
384
+ verifier_model_path=${VERIFIER_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
385
+ # 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
386
+ unset MM_CONFIG_FILE || true
387
+
388
+ # Nanoclaw 工具配置
389
+ tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
390
+ nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
391
+ nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
392
+ # 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
393
+ nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_workplace_v14_qwen35_27b_sp1_fsdp2_31k_longseq_allopt}
394
+ # 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
395
+ nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
396
+ nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
397
+ nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
398
+ nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
399
+ nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
400
+ nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
401
+ nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
402
+ nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
403
+ nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
404
+ nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
405
+ nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
406
+ nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
407
+ nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
408
+ nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
409
+ nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-50}
410
+ nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
411
+ nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
412
+ nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
413
+ nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
414
+ nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
415
+ nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
416
+
417
+ # verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
418
+ # 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
419
+ verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
420
+ verifier_api_port=${VERIFIER_API_PORT:-8000}
421
+ verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
422
+ verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
423
+ verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
424
+ # 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM 内置 DP 统一服务。
425
+ # 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
426
+ verifier_api_tp=${VERIFIER_API_TP:-4}
427
+ verifier_api_dp=${VERIFIER_API_DP:-2}
428
+ verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
429
+ verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
430
+ verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
431
+ verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
432
+ verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
433
+ verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
434
+ verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
435
+ verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
436
+ verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
437
+ verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
438
+ verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
439
+ mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
440
+ mock_api_key=${MOCK_API_KEY:-dummy_key}
441
+ mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
442
+ # verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
443
+ mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
444
+ mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
445
+ # 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
446
+ nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
447
+ nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
448
+ # 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
449
+ nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
450
+ # verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
451
+ reward_num_workers=${REWARD_NUM_WORKERS:-52}
452
+
453
+ project_name=${PROJECT_NAME:-qwen3.5-27b_nanoclaw_grpo_verl_0720}
454
+ experiment_name=${EXPERIMENT_NAME:-qwen3.5-27b_nanoclaw_grpo_sp1_fsdp2_31k_longseq_allopt_lr1e6_fixedkl1e-3}
455
+ default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
456
+ start_time=$(date +%Y%m%d)_$(date +%H%M%S)
457
+ mkdir -p logs "${default_local_dir}"
458
+
459
+ # ================= 算法与并行参数 =================
460
+ adv_estimator=grpo
461
+ max_turns=${MAX_TURNS:-35}
462
+ max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
463
+ max_response_length=${MAX_RESPONSE_LENGTH:-22768}
464
+ max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
465
+ max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
466
+ max_model_len=$((max_prompt_length + max_response_length))
467
+
468
+ # MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
469
+ actor_lr=${ACTOR_LR:-1e-6}
470
+ actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
471
+ actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
472
+ actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
473
+ actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
474
+ actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
475
+ actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
476
+ actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
477
+ actor_shuffle=${ACTOR_SHUFFLE:-False}
478
+ actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
479
+ actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
480
+ actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
481
+ # MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
482
+ actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
483
+
484
+ # YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
485
+ algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
486
+ algorithm_lam=${ALGORITHM_LAM:-0.95}
487
+ use_kl_in_reward=${USE_KL_IN_REWARD:-True}
488
+ kl_penalty=${KL_PENALTY:-low_var_kl}
489
+ kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
490
+ kl_coef=${KL_COEF:-0.001}
491
+ # 关闭 actor-KL,避免与 reward-KL 重复惩罚。
492
+ actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
493
+ actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
494
+ actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
495
+
496
+ train_batch_size=${TRAIN_BATCH_SIZE:-64}
497
+ ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
498
+ n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
499
+ # 先压低验证,避免验证和训练稳定性混在一起。
500
+ n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
501
+ log_val_generations=${LOG_VAL_GENERATIONS:-10}
502
+
503
+ infer_tp=${INFER_TP:-4}
504
+ train_sp=${TRAIN_SP:-1}
505
+ offload=${OFFLOAD:-True}
506
+
507
+ # 长序列全优化版使用最新版 VERL 官方 Qwen3.5-27B 配方采用的 FSDP2。
508
+ actor_strategy=${ACTOR_STRATEGY:-fsdp2}
509
+ fsdp_size=${FSDP_SIZE:-}
510
+
511
+ actor_pack=${ACTOR_PACK:-1}
512
+ logprob_pack=${LOGPROB_PACK:-2}
513
+ actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
514
+ log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
515
+ entropy_from_logits_with_chunking=${ENTROPY_FROM_LOGITS_WITH_CHUNKING:-True}
516
+ entropy_from_logits_chunk_size=${ENTROPY_FROM_LOGITS_CHUNK_SIZE:-256}
517
+ entropy_checkpointing=${ENTROPY_CHECKPOINTING:-False}
518
+ use_fused_kernels=${USE_FUSED_KERNELS:-True}
519
+ fused_kernel_backend=${FUSED_KERNEL_BACKEND:-torch}
520
+ enable_activation_offload=${ENABLE_ACTIVATION_OFFLOAD:-True}
521
+ rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
522
+ rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
523
+ update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-2048}
524
+
525
+ # Qwen 官方推荐:Instruct/non-thinking reasoning tasks
526
+ rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
527
+ rollout_top_p=${ROLLOUT_TOP_P:-0.95}
528
+ rollout_top_k=${ROLLOUT_TOP_K:-20}
529
+ rollout_min_p=${ROLLOUT_MIN_P:-0.0}
530
+ rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
531
+ rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
532
+ rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
533
+
534
+ echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
535
+ echo "DEBUG: max_turns=${max_turns}"
536
+ echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
537
+ echo "DEBUG: entropy_chunking=${entropy_from_logits_with_chunking}, entropy_chunk_size=${entropy_from_logits_chunk_size}, entropy_checkpointing=${entropy_checkpointing}"
538
+ echo "DEBUG: fused_lmhead=${use_fused_kernels}, fused_backend=${fused_kernel_backend}, activation_offload=${enable_activation_offload}"
539
+ echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
540
+ echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
541
+ echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
542
+ echo "DEBUG: actor_max_token_len_per_gpu=${actor_max_token_len_per_gpu}, log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}"
543
+ echo "DEBUG: rollout sampling temperature=${rollout_temperature}, top_p=${rollout_top_p}, top_k=${rollout_top_k}, min_p=${rollout_min_p}, presence_penalty=${rollout_presence_penalty}, frequency_penalty=${rollout_frequency_penalty}, repetition_penalty=${rollout_repetition_penalty}"
544
+ echo "DEBUG: optimizer lr=${actor_lr}, scheduler=${actor_lr_scheduler_type}, warmup_ratio=${actor_lr_warmup_steps_ratio}, weight_decay=${actor_weight_decay}, betas=(${actor_adam_beta1},${actor_adam_beta2}), clip_grad=${actor_clip_grad}, ppo_epochs=${actor_ppo_epochs}, shuffle=${actor_shuffle}"
545
+ echo "DEBUG: KL use_in_reward=${use_kl_in_reward}, penalty=${kl_penalty}, ctrl=${kl_ctrl_type}, coef=${kl_coef}, actor_kl=${actor_use_kl_loss}"
546
+ echo "DEBUG: HCCL_BUFFSIZE=${HCCL_BUFFSIZE}, HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE}, HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE}"
547
+
548
+ val_before_train=${VAL_BEFORE_TRAIN:-False}
549
+ trainer_use_v1=${TRAINER_USE_V1:-True}
550
+ test_freq=${TEST_FREQ:-5000}
551
+ save_freq=${SAVE_FREQ:-2}
552
+
553
+ # ================= 分布式 =================
554
+ export TOTAL_NNODES=${TOTAL_NNODES:-5}
555
+ export TRAIN_NNODES=${TRAIN_NNODES:-4}
556
+ export NNODES=${NNODES:-${TRAIN_NNODES}}
557
+ export NODE_RANK=${VC_TASK_INDEX}
558
+ export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
559
+ export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
560
+
561
+ export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
562
+ export MASTER_PORT=${MASTER_PORT:-6167}
563
+ export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
564
+ export RAY_PORT=${RAY_PORT:-6167}
565
+
566
+ readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
567
+ export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
568
+ export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
569
+ export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
570
+ export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
571
+
572
+ export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
573
+
574
+ cat <<EOF
575
+ DEBUG: MASTER_ADDR=${MASTER_ADDR}
576
+ DEBUG: MASTER_PORT=${MASTER_PORT}
577
+ DEBUG: RAY_PORT=${RAY_PORT}
578
+ DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
579
+ DEBUG: CURRENT_IP=${CURRENT_IP}
580
+ DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
581
+ DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
582
+ DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
583
+ DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
584
+ DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
585
+ DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
586
+ DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
587
+ DEBUG: MOCK_API_BASE=${mock_api_base}
588
+ DEBUG: MOCK_MODEL_NAME=${mock_model_name}
589
+ DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
590
+ DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
591
+ DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
592
+ DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
593
+ DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
594
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
595
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
596
+ DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
597
+ DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
598
+ DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
599
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
600
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
601
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
602
+ DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
603
+ DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
604
+ DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
605
+ DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
606
+ DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
607
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
608
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
609
+ DEBUG: VERIFIER_API_TP=${verifier_api_tp}
610
+ DEBUG: VERIFIER_API_DP=${verifier_api_dp}
611
+ DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
612
+ DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
613
+ DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
614
+ DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
615
+ DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
616
+ DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
617
+ EOF
618
+
619
+ if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
620
+ echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
621
+ echo "--> [Verifier API Node] API base: ${mock_api_base}"
622
+ export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
623
+ mkdir -p "$(dirname "${verifier_api_log}")"
624
+ if [ -n "${verifier_api_start_cmd}" ]; then
625
+ echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
626
+ bash -lc "${verifier_api_start_cmd}" &
627
+ verifier_api_pid=$!
628
+ else
629
+ echo "--> [Verifier API Node] Starting default vLLM verifier API..."
630
+ verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
631
+ verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
632
+ if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
633
+ echo "ERROR: verifier TP*DP=${verifier_api_tp}*${verifier_api_dp}=${verifier_api_expected_device_count}, but VERIFIER_API_DEVICES=${verifier_api_devices} contains ${verifier_api_device_count} devices." >&2
634
+ exit 2
635
+ fi
636
+ export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
637
+ verifier_api_args=(
638
+ --model "${verifier_model_path}"
639
+ --tokenizer "${verifier_model_path}"
640
+ --host "${verifier_api_bind_host}"
641
+ --port "${verifier_api_port}"
642
+ --served-model-name "${mock_model_name}"
643
+ --tensor-parallel-size "${verifier_api_tp}"
644
+ --data-parallel-size "${verifier_api_dp}"
645
+ --distributed-executor-backend "${verifier_api_distributed_executor_backend}"
646
+ --dtype bfloat16
647
+ --max-model-len "${verifier_api_max_model_len}"
648
+ --max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
649
+ --max-num-seqs "${verifier_api_max_num_seqs}"
650
+ --gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
651
+ --trust-remote-code
652
+ )
653
+ if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
654
+ verifier_api_args+=(--enforce-eager)
655
+ fi
656
+ if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
657
+ verifier_api_args+=(--enable-prefix-caching)
658
+ fi
659
+ echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
660
+ python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
661
+ verifier_api_pid=$!
662
+ fi
663
+
664
+ echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
665
+ echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
666
+ python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
667
+ import os
668
+ import sys
669
+ import time
670
+ import urllib.request
671
+ from pathlib import Path
672
+
673
+ url = sys.argv[1]
674
+ timeout = float(sys.argv[2])
675
+ log_path = Path(sys.argv[3])
676
+ pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
677
+ started = time.time()
678
+ last_error = None
679
+ while time.time() - started < timeout:
680
+ if pid is not None:
681
+ try:
682
+ os.kill(pid, 0)
683
+ except OSError:
684
+ print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
685
+ if log_path.is_file():
686
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
687
+ sys.exit(1)
688
+ try:
689
+ with urllib.request.urlopen(url, timeout=5) as response:
690
+ if 200 <= response.status < 300:
691
+ print(f"READY: {url}", file=sys.stderr)
692
+ sys.exit(0)
693
+ except Exception as exc:
694
+ last_error = exc
695
+ time.sleep(5)
696
+ print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
697
+ if log_path.is_file():
698
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
699
+ sys.exit(1)
700
+ PY
701
+ verifier_readiness_rc=$?
702
+ if [ "${verifier_readiness_rc}" -ne 0 ]; then
703
+ echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
704
+ if kill -0 "${verifier_api_pid}" 2>/dev/null; then
705
+ kill "${verifier_api_pid}" 2>/dev/null || true
706
+ fi
707
+ wait "${verifier_api_pid}" 2>/dev/null || true
708
+ exit "${verifier_readiness_rc}"
709
+ fi
710
+
711
+ echo "--> [Verifier API Node] Ready. Keeping node alive."
712
+ wait "${verifier_api_pid}"
713
+ verifier_api_rc=$?
714
+ if [ "${verifier_api_rc}" -ne 0 ]; then
715
+ echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
716
+ fi
717
+ exit "${verifier_api_rc}"
718
+ fi
719
+
720
+ export TMPDIR=/cache/ray_tmp
721
+ export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
722
+
723
+ wait_for_ray_npu_resources() {
724
+ expected_npu=$1
725
+ timeout_seconds=${2:-900}
726
+ begin_ts=$(date +%s)
727
+
728
+ while true; do
729
+ total_npu=$(python3 - <<'PY' 2>/dev/null
730
+ import ray
731
+
732
+ try:
733
+ ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
734
+ print(int(ray.cluster_resources().get("NPU", 0)))
735
+ ray.shutdown()
736
+ except Exception:
737
+ print(0)
738
+ PY
739
+ )
740
+ total_npu=${total_npu:-0}
741
+ now_ts=$(date +%s)
742
+ elapsed=$((now_ts - begin_ts))
743
+
744
+ echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
745
+ ray status || true
746
+
747
+ if [ "${total_npu}" -ge "${expected_npu}" ]; then
748
+ echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
749
+ break
750
+ fi
751
+
752
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
753
+ echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
754
+ return 1
755
+ fi
756
+
757
+ sleep 5
758
+ done
759
+ }
760
+
761
+ wait_for_verifier_api() {
762
+ api_url="${mock_api_base}/models"
763
+ timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
764
+ begin_ts=$(date +%s)
765
+ last_diag_ts=0
766
+ while true; do
767
+ verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
768
+ import socket
769
+ import sys
770
+ import urllib.parse
771
+ import urllib.request
772
+
773
+ url = sys.argv[1]
774
+ parsed = urllib.parse.urlparse(url)
775
+ host = parsed.hostname
776
+ port = parsed.port or (443 if parsed.scheme == "https" else 80)
777
+ print(f"check url={url} host={host} port={port}")
778
+ try:
779
+ infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
780
+ print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
781
+ except Exception as exc:
782
+ print(f"dns_error={type(exc).__name__}: {exc}")
783
+ raise SystemExit(1)
784
+ try:
785
+ with socket.create_connection((host, port), timeout=5):
786
+ print("tcp=ok")
787
+ except Exception as exc:
788
+ print(f"tcp_error={type(exc).__name__}: {exc}")
789
+ raise SystemExit(1)
790
+ try:
791
+ with urllib.request.urlopen(url, timeout=10) as response:
792
+ print(f"http_status={response.status}")
793
+ raise SystemExit(0 if 200 <= response.status < 300 else 1)
794
+ except Exception as exc:
795
+ print(f"http_error={type(exc).__name__}: {exc}")
796
+ raise SystemExit(1)
797
+ PY
798
+ )
799
+ check_rc=$?
800
+ if [ "${check_rc}" = "0" ]; then
801
+ echo "Verifier API is ready: ${api_url}"
802
+ echo "${verifier_check_output}"
803
+ break
804
+ fi
805
+ now_ts=$(date +%s)
806
+ elapsed=$((now_ts - begin_ts))
807
+ echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
808
+ if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
809
+ last_diag_ts=${now_ts}
810
+ echo "--- verifier API check diagnostics ---"
811
+ echo "${verifier_check_output}"
812
+ echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
813
+ echo "--- check verifier node log: ${verifier_api_log} ---"
814
+ echo "--------------------------------------"
815
+ fi
816
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
817
+ echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
818
+ echo "Last verifier API diagnostics:" >&2
819
+ echo "${verifier_check_output}" >&2
820
+ return 1
821
+ fi
822
+ sleep 10
823
+ done
824
+ }
825
+
826
+ # ================= Nanoclaw workspace 根目录 =================
827
+ mkdir -p "${nanoclaw_temp_root}"
828
+ if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
829
+ echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
830
+ exit 2
831
+ fi
832
+ rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
833
+ if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
834
+ echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
835
+ echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
836
+ fi
837
+ echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
838
+ echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
839
+ echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
840
+ echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
841
+
842
+ # ================= 生成 Ray runtime env =================
843
+ RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
844
+ cat > "${RUNTIME_ENV_FILE}" <<YAML
845
+ working_dir: ./
846
+ excludes: ["/.git/", "/logs/", "/checkpoint/"]
847
+ env_vars:
848
+ TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
849
+ CUDA_DEVICE_MAX_CONNECTIONS: "1"
850
+ HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
851
+ HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
852
+ HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
853
+ HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
854
+ HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
855
+ HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
856
+ HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
857
+ P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
858
+ VLLM_USE_V1: "${VLLM_USE_V1}"
859
+ VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
860
+ VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
861
+ VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
862
+ VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
863
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
864
+ TOKENIZERS_PARALLELISM: "false"
865
+ HYDRA_FULL_ERROR: "1"
866
+ PYTHONUNBUFFERED: "1"
867
+ RAY_DEDUP_LOGS: "0"
868
+ WANDB_MODE: "${WANDB_MODE}"
869
+ MOCK_API_BASE: "${mock_api_base}"
870
+ MOCK_API_KEY: "${mock_api_key}"
871
+ MOCK_MODEL_NAME: "${mock_model_name}"
872
+ MOCK_API_TIMEOUT: "${mock_api_timeout}"
873
+ MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
874
+ NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
875
+ NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
876
+ NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
877
+ NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
878
+ NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
879
+ NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
880
+ NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
881
+ NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
882
+ NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
883
+ NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
884
+ NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
885
+ NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
886
+ NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
887
+ NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
888
+ NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
889
+ NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
890
+ NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
891
+ NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
892
+ NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
893
+ YAML
894
+
895
+ # ================= 启动 Ray 多机集群 =================
896
+ if [ "${NODE_RANK}" = "0" ]; then
897
+ echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
898
+ ray start --head \
899
+ --node-ip-address=${RAY_NODE_IP} \
900
+ --port=${RAY_PORT} \
901
+ --dashboard-host=0.0.0.0 \
902
+ --dashboard-port=${DASHBOARD_PORT} \
903
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
904
+ --disable-usage-stats \
905
+ --block &
906
+
907
+ sleep 10
908
+ wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
909
+ wait_for_verifier_api || exit 1
910
+ else
911
+ echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
912
+ sleep 20
913
+ ray start --address=${MASTER_ADDR}:${RAY_PORT} \
914
+ --node-ip-address=${RAY_NODE_IP} \
915
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
916
+ --disable-usage-stats \
917
+ --block &
918
+ sleep 10
919
+ fi
920
+
921
+ # ================= 训练参数数组 =================
922
+ training_args=(
923
+ python3 -m verl.trainer.main_ppo
924
+ +ray_kwargs.ray_init.address=auto
925
+ reward.num_workers=${reward_num_workers}
926
+ algorithm.adv_estimator=${adv_estimator}
927
+ algorithm.gamma=${algorithm_gamma}
928
+ algorithm.lam=${algorithm_lam}
929
+ algorithm.use_kl_in_reward=${use_kl_in_reward}
930
+ algorithm.kl_penalty=${kl_penalty}
931
+ algorithm.kl_ctrl.type=${kl_ctrl_type}
932
+ algorithm.kl_ctrl.kl_coef=${kl_coef}
933
+ data.train_files="${train_files}"
934
+ data.val_files="${test_files}"
935
+ data.return_raw_chat=True
936
+ data.return_multi_modal_inputs=False
937
+ data.image_key=images
938
+ data.shuffle=True
939
+ data.train_batch_size=${train_batch_size}
940
+ data.max_prompt_length=${max_prompt_length}
941
+ data.max_response_length=${max_response_length}
942
+ data.filter_overlong_prompts=True
943
+ data.truncation=error
944
+ data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
945
+ data.custom_cls.name=CustomRLHFDataset
946
+ "data.tool_config_path=${tool_config_path}"
947
+ "+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
948
+ "+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
949
+ "+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
950
+ "+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
951
+ "+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
952
+ "+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
953
+ "+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
954
+ "+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
955
+ +data.apply_chat_template_kwargs.enable_thinking=True
956
+ reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
957
+ reward.custom_reward_function.name=compute_score
958
+ "+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
959
+ "+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
960
+ "+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
961
+ "+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
962
+ "+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
963
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
964
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
965
+ "+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
966
+ "+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
967
+ "+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
968
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
969
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
970
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
971
+ "+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
972
+ "+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
973
+ "+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
974
+ "+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
975
+ "+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
976
+ actor_rollout_ref.model.path=${model_path}
977
+ actor_rollout_ref.model.use_remove_padding=True
978
+ actor_rollout_ref.model.enable_gradient_checkpointing=True
979
+ actor_rollout_ref.model.enable_activation_offload=${enable_activation_offload}
980
+ actor_rollout_ref.model.use_fused_kernels=${use_fused_kernels}
981
+ actor_rollout_ref.model.fused_kernel_options.impl_backend=${fused_kernel_backend}
982
+ actor_rollout_ref.actor.strategy=${actor_strategy}
983
+ actor_rollout_ref.ref.strategy=${actor_strategy}
984
+ actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
985
+ actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
986
+ actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
987
+ actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
988
+ actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
989
+ actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
990
+ actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
991
+ actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
992
+ actor_rollout_ref.actor.shuffle=${actor_shuffle}
993
+ actor_rollout_ref.actor.optim.lr=${actor_lr}
994
+ actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
995
+ actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
996
+ actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
997
+ "actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
998
+ actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
999
+ actor_rollout_ref.actor.use_dynamic_bsz=True
1000
+ actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
1001
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
1002
+ actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
1003
+ actor_rollout_ref.actor.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1004
+ actor_rollout_ref.actor.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1005
+ actor_rollout_ref.actor.entropy_checkpointing=${entropy_checkpointing}
1006
+ actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
1007
+ actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
1008
+ actor_rollout_ref.actor.fsdp_config.offload_policy=${offload}
1009
+ actor_rollout_ref.actor.fsdp_config.reshard_after_forward=True
1010
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1011
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1012
+ actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1013
+ actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
1014
+ actor_rollout_ref.ref.fsdp_config.offload_policy=${offload}
1015
+ actor_rollout_ref.ref.fsdp_config.reshard_after_forward=True
1016
+ actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
1017
+ actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1018
+ actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
1019
+ actor_rollout_ref.ref.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1020
+ actor_rollout_ref.ref.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1021
+ actor_rollout_ref.ref.entropy_checkpointing=${entropy_checkpointing}
1022
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1023
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1024
+ actor_rollout_ref.ref.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1025
+ actor_rollout_ref.rollout.name=vllm
1026
+ actor_rollout_ref.rollout.mode=async
1027
+ actor_rollout_ref.rollout.calculate_log_probs=True
1028
+ actor_rollout_ref.rollout.temperature=${rollout_temperature}
1029
+ actor_rollout_ref.rollout.top_p=${rollout_top_p}
1030
+ actor_rollout_ref.rollout.top_k=${rollout_top_k}
1031
+ actor_rollout_ref.rollout.min_p=${rollout_min_p}
1032
+ actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
1033
+ actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
1034
+ actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
1035
+ actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
1036
+ actor_rollout_ref.rollout.max_model_len=${max_model_len}
1037
+ actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
1038
+ actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
1039
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1040
+ actor_rollout_ref.rollout.enable_chunked_prefill=True
1041
+ actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
1042
+ actor_rollout_ref.rollout.free_cache_engine=True
1043
+ actor_rollout_ref.rollout.enforce_eager=False
1044
+ actor_rollout_ref.rollout.enable_prefix_caching=False
1045
+ actor_rollout_ref.rollout.multi_turn.enable=True
1046
+ actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
1047
+ actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
1048
+ actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
1049
+ "actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
1050
+ actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
1051
+ "actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
1052
+ actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
1053
+ actor_rollout_ref.rollout.n=${n_resp_per_prompt}
1054
+ actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
1055
+ actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
1056
+ actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
1057
+ actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
1058
+ actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
1059
+ actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
1060
+ actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
1061
+ actor_rollout_ref.rollout.val_kwargs.do_sample=True
1062
+ actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
1063
+ actor_rollout_ref.actor.use_torch_compile=False
1064
+ actor_rollout_ref.ref.use_torch_compile=False
1065
+ actor_rollout_ref.actor.use_torch_compile=False
1066
+ actor_rollout_ref.ref.use_torch_compile=False
1067
+ actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
1068
+ actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
1069
+ critic.fsdp.use_torch_compile=False
1070
+ trainer.use_v1=${trainer_use_v1}
1071
+ trainer.critic_warmup=0
1072
+ trainer.balance_batch=True
1073
+ trainer.logger=['console','tensorboard']
1074
+ trainer.project_name=${project_name}
1075
+ trainer.experiment_name=${experiment_name}
1076
+ trainer.nnodes=${NNODES}
1077
+ trainer.n_gpus_per_node=${NPUS_PER_NODE}
1078
+ trainer.val_before_train=${val_before_train}
1079
+ trainer.log_val_generations=${log_val_generations}
1080
+ trainer.save_freq=${save_freq}
1081
+ trainer.default_local_dir=${default_local_dir}
1082
+ trainer.test_freq=${test_freq}
1083
+ trainer.total_epochs=10
1084
+ )
1085
+
1086
+ if [ -n "${fsdp_size}" ]; then
1087
+ training_args+=(
1088
+ actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
1089
+ actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
1090
+ )
1091
+ fi
1092
+
1093
+ if [ -n "${nanoclaw_task_ids}" ]; then
1094
+ training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
1095
+ fi
1096
+
1097
+ if [ -n "${nanoclaw_max_steps}" ]; then
1098
+ training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
1099
+ fi
1100
+
1101
+ # ================= 启动训练主进程:仅主节点执行 =================
1102
+ if [ "${NODE_RANK}" = "0" ]; then
1103
+ echo "--> [Head Node] Starting VERL unified engine training..."
1104
+ echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
1105
+ echo "DEBUG: entrypoint=${training_args[*]}"
1106
+
1107
+ ray job submit \
1108
+ --address="http://127.0.0.1:${DASHBOARD_PORT}" \
1109
+ --runtime-env="${RUNTIME_ENV_FILE}" \
1110
+ -- \
1111
+ "${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
1112
+ else
1113
+ echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
1114
+ tail -f /dev/null
1115
+ fi
verl_0720_main/27b.shZone.Identifier ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=https://huggingface.co/datasets/geminiDeveloper/verl_0720_nanoclaw/tree/main
4
+ HostUrl=https://huggingface.co/api/resolve-cache/datasets/geminiDeveloper/verl_0720_nanoclaw/bacc33fa11aa841f3fa8343597382539716bbd0c/27b.sh?download=true&etag=%228ca3b6ac1b3d0febbb9671913ca036ea0ecc9bc3%22
verl_0720_main/27b_old_verl.sh ADDED
@@ -0,0 +1,1044 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Qwen3.5-27B Nanoclaw 多轮 GRPO 训练脚本 — VERL 0720 + Nanoclaw 兼容版
3
+ #
4
+ # 关键修改:
5
+ # 1) 入口改为 python3 -m verl.trainer.main_ppo,不再使用 recipe.grpo_mindspeed_mm.main_ppo;
6
+ # 2) 不再使用 MM_CONFIG_FILE / MindSpeed-MM YAML;
7
+ # 3) 显式 text-only:data.return_multi_modal_inputs=False;
8
+ # 4) 数据输入改为 Nanoclaw base_tasks 目录,不再使用 Retool parquet/json;
9
+ # 5) 保留 27B 作业验证过的 HCCL buffer 与端口范围,降低 HcclAllreduce socket/资源压力;
10
+ # 6) 默认 val n=1、log_val_generations=10,先验证训练稳定性;
11
+ # 7) 支持通过 ACTOR_STRATEGY=fsdp2 FSDP_SIZE=16 切到官方新版 NPU FSDP2/FSDP16 形状。
12
+ # 8) 使用最新版 VERL V1/TransferQueue 和 nanoclaw_recipe,并按参考 YAML 的训练意图映射优化器与 KL。
13
+
14
+ set -x
15
+
16
+ npu-smi info || true
17
+ pip install --upgrade pip
18
+ pip uninstall -y moxing-framework || true
19
+
20
+ # ================= 路径配置 =================
21
+ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
22
+ if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
23
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
24
+ elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
25
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}
26
+ else
27
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
28
+ fi
29
+ WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
30
+ INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
31
+ BKGS=${BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs}
32
+ chmod 755 "${INSTALL_DIR}"
33
+
34
+ # Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
35
+
36
+ GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
37
+ COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-/opt/huawei/dataset/zyr_yuyin/bkgs/gcc-11.3.0-compiled-aarch64.tar.gz}
38
+
39
+ echo "--> 正在从缓存恢复 GCC 11.3.0..."
40
+ tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
41
+ export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
42
+ export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
43
+ export CC=${GCC_INSTALL_PREFIX}/bin/gcc
44
+ export CXX=${GCC_INSTALL_PREFIX}/bin/g++
45
+ echo "--> 验证 GCC 版本:"
46
+ gcc --version
47
+
48
+ cd "${BKGS}"
49
+ cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
50
+
51
+ VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-05-12/verl_new_26_05_09/pkgs}
52
+ rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
53
+ cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
54
+ cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
55
+
56
+ CANN_BKGS=${CANN_BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs/cann_0527}
57
+ cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
58
+ cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
59
+ cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
60
+
61
+ echo "################"
62
+ echo "## set verl env"
63
+ echo "################"
64
+
65
+ cd "${INSTALL_DIR}"
66
+
67
+ chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
68
+ bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
69
+ source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
70
+
71
+ chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
72
+ bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
73
+
74
+ chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
75
+ bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
76
+ source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
77
+
78
+ export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
79
+ export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
80
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
81
+
82
+ pip3 install torch==2.9.0
83
+ pip3 install pyyaml setuptools
84
+ pip3 install torch-npu==2.9.0
85
+ pip3 install torchvision==0.24.0 torchaudio==2.9.0
86
+
87
+ ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
88
+ export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
89
+ pip install pybind11==2.13.6
90
+
91
+ cd "${INSTALL_DIR}/vllm"
92
+ VLLM_TARGET_DEVICE=empty pip install .
93
+
94
+ cd "${INSTALL_DIR}/vllm-ascend"
95
+ pip install -e .
96
+ export VLLM_LOGGING_LEVEL=INFO
97
+
98
+ cd "${INSTALL_DIR}"
99
+ tar -xvf jemalloc-5.3.0.tar.bz2
100
+ cd jemalloc-5.3.0
101
+ ./configure --prefix="${INSTALL_DIR}"
102
+ make -j"$(nproc)"
103
+ make install
104
+ export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
105
+
106
+ # # ================= 可选:安装 MindSpeed 栈 =================
107
+ # # 纯 VERL engine 路线不依赖 MindSpeed-MM YAML。默认不安装,避免和新版 VERL engine 混淆。
108
+ # INSTALL_MINDSPEED_STACK=${INSTALL_MINDSPEED_STACK:-0}
109
+ # if [ "${INSTALL_MINDSPEED_STACK}" = "1" ]; then
110
+ # MindSpeed_PATH=${MindSpeed_PATH:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-slow-stable}
111
+ # cd "${MindSpeed_PATH}"
112
+ # cd Megatron-LM && pip install -e . --no-deps && cd ..
113
+ # cd MindSpeed && pip install -e . --no-deps && cd ..
114
+ # cd MindSpeed-MM && mkdir -p logs data ckpt && pip install -e . --no-deps && cd ..
115
+ # pip install beartype bs4 diffusers==0.30.3 ftfy imageio-ffmpeg pandarallel pytest-mock
116
+ # else
117
+ # echo "--> Skip MindSpeed/MindSpeed-MM installation for pure VERL engine route."
118
+ # fi
119
+
120
+
121
+
122
+ # ================= 安装 Triton-Ascend 3.2.1 =================
123
+ # 1. 卸载 triton(增加 -y 自动确认)
124
+ pip uninstall -y triton
125
+
126
+ # 2. 卸载 triton-ascend(增加 -y 自动确认)
127
+ pip uninstall -y triton-ascend
128
+ pip install --no-cache-dir --force-reinstall triton==3.5.0
129
+ pip install --no-deps /opt/huawei/dataset/zyr_yuyin/bkgs/triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
130
+
131
+
132
+ # ================= 安装新版 VERL =================
133
+ cd "${WORK_DIR}"
134
+ pip install -r requirements-npu.txt
135
+ # NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
136
+ python3 -m pip install -e . --no-deps
137
+ pip install --upgrade 'urllib3==1.26.11'
138
+ pip install loguru
139
+ pip install tree_sitter==0.21.3
140
+ pip install tree-sitter-java==0.21.0
141
+ pip install tree-sitter-javascript==0.21.4
142
+
143
+ ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
144
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
145
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
146
+
147
+ pip uninstall -y transformers || true
148
+ pip install transformers==5.3.0
149
+ pip install accelerate==1.13.0 mathruler
150
+ pip install jsonargparse
151
+ pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
152
+
153
+ # 新版 VERL 的 Qwen3.5 Ulysses/SP patch 会使用 fla.ops.cp 来维护
154
+ # GatedDeltaNet 的跨序列分片状态。上游 FLA 的 NPU 训练兼容性未经当前 VERL 验证;
155
+ # WOE-Y/flash-linear-attention-npu 是 CANN 低层算子库,也不是可直接 import fla 的替代包。
156
+ FLASH_LINEAR_ATTENTION_VERSION=${FLASH_LINEAR_ATTENTION_VERSION:-0.5.0}
157
+ QWEN35_FLA_BACKEND=${QWEN35_FLA_BACKEND:-disabled}
158
+ requested_train_sp=${TRAIN_SP:-1}
159
+ if ! [[ "${requested_train_sp}" =~ ^[1-9][0-9]*$ ]]; then
160
+ echo "ERROR: TRAIN_SP must be a positive integer, got: ${requested_train_sp}" >&2
161
+ exit 2
162
+ fi
163
+ if [ "${requested_train_sp}" -gt 1 ]; then
164
+ export NANOCLAW_REQUIRE_FLA=1
165
+ case "${QWEN35_FLA_BACKEND}" in
166
+ upstream_experimental)
167
+ echo "WARNING: using upstream flash-linear-attention on NPU is experimental and not covered by VERL's NPU tests." >&2
168
+ python3 -m pip install --no-cache-dir "flash-linear-attention==${FLASH_LINEAR_ATTENTION_VERSION}"
169
+ ;;
170
+ npu_bridge)
171
+ echo "--> QWEN35_FLA_BACKEND=npu_bridge: expect a preinstalled NPU-compatible 'fla' Python compatibility layer."
172
+ ;;
173
+ *)
174
+ echo "ERROR: TRAIN_SP=${requested_train_sp} requires Qwen3.5 FLA context parallel, but no verified NPU FLA Python backend is configured." >&2
175
+ echo "Set TRAIN_SP=1 for the supported fallback. Use QWEN35_FLA_BACKEND=upstream_experimental only for an explicit NPU smoke test, or npu_bridge after installing a compatible bridge." >&2
176
+ exit 2
177
+ ;;
178
+ esac
179
+ else
180
+ export NANOCLAW_REQUIRE_FLA=0
181
+ echo "--> TRAIN_SP=1: skip flash-linear-attention; Qwen3.5 does not build an Ulysses CP context."
182
+ fi
183
+
184
+ # Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
185
+ # 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
186
+ NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
187
+ PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
188
+ SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
189
+ SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
190
+ python3 -m pip install --no-cache-dir --force-reinstall \
191
+ "numpy==${NUMPY_VERSION}" \
192
+ "pandas==${PANDAS_VERSION}" \
193
+ "scipy==${SCIPY_VERSION}" \
194
+ "scikit-learn==${SKLEARN_VERSION}"
195
+
196
+ python3 - <<'PY' || exit 2
197
+ import numpy
198
+ import os
199
+ import pandas
200
+ import scipy
201
+ import sklearn
202
+ import sys
203
+ import transformers
204
+ import vllm
205
+
206
+ if os.environ.get("NANOCLAW_REQUIRE_FLA") == "1":
207
+ import fla
208
+ from fla.ops.cp.comm import conv_cp_send_recv_bwd, conv_cp_send_recv_fwd
209
+ from fla.ops.cp.context import build_cp_context
210
+
211
+ fla_version = getattr(fla, "__version__", "unknown")
212
+ else:
213
+ fla_version = "not-required"
214
+
215
+ print(
216
+ "[python_stack_preflight] "
217
+ f"python={sys.executable} "
218
+ f"numpy={numpy.__version__} "
219
+ f"pandas={pandas.__version__} "
220
+ f"scipy={scipy.__version__} "
221
+ f"sklearn={sklearn.__version__} "
222
+ f"transformers={transformers.__version__} "
223
+ f"vllm={vllm.__version__} "
224
+ f"fla={fla_version}"
225
+ )
226
+ print(
227
+ "[python_stack_paths] "
228
+ f"numpy={numpy.__file__} "
229
+ f"pandas={pandas.__file__}"
230
+ )
231
+ PY
232
+ pip list
233
+
234
+ # ================= 检查 Nanoclaw recipe =================
235
+ if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
236
+ echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
237
+ exit 2
238
+ fi
239
+ test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
240
+
241
+ # ================= PLOG =================
242
+ ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
243
+ task_name=worker-${VC_TASK_INDEX}
244
+ task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
245
+ mkdir -p "${task_plog_path}"
246
+ export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
247
+ echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
248
+
249
+ MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
250
+ MASTER_PORT=${PORT}
251
+ MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
252
+
253
+ cd "${WORK_DIR}"
254
+
255
+ mkdir -p /cache/ray_tmp
256
+
257
+ echo "Cleaning up old Ray processes..."
258
+ ray stop --force || true
259
+ sleep 5
260
+ rm -rf /cache/ray_tmp/*
261
+ pkill -9 -f raylet || true
262
+ pkill -9 -f plasma_store || true
263
+ pkill -9 -f gcs_server || true
264
+ echo "Waiting 20s for NPU/Ray resources to be released..."
265
+ npu-smi info || true
266
+ sleep 20
267
+
268
+ # ================= NPU / HCCL / Ray 环境 =================
269
+ export NON_MEGATRON=true
270
+ export MULTI_STREAM_MEMORY_REUSE=2
271
+ export OMP_NUM_THREADS=1
272
+ export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
273
+ export VLLM_LOGGING_LEVEL=INFO
274
+ export RAY_DEDUP_LOGS=0
275
+ export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
276
+ export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
277
+ export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
278
+ export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
279
+ export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
280
+ export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
281
+
282
+ # 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
283
+ export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
284
+ export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
285
+ export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
286
+ export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
287
+
288
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
289
+ export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
290
+ export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
291
+ export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
292
+ export WANDB_MODE=${WANDB_MODE:-disabled}
293
+ export PYTHONUNBUFFERED=1
294
+ export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
295
+ export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
296
+ export TOKENIZERS_PARALLELISM=false
297
+ export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
298
+ export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
299
+ export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
300
+ export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
301
+ export VLLM_USE_V1=${VLLM_USE_V1:-1}
302
+ export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
303
+ export HYDRA_FULL_ERROR=1
304
+ export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
305
+ export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
306
+ export RAY_timeout_ms=${RAY_timeout_ms:-600000}
307
+ export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
308
+ export RAY_USAGE_STATS_ENABLED=0
309
+ export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
310
+
311
+ ulimit -n 65536
312
+
313
+ # Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
314
+ export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
315
+
316
+ # ================= 路径与数据配置 =================
317
+ HDFS_ROOT=${HDFS_ROOT:-$PWD}
318
+ DATA_ROOT=${DATA_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_ckpt}
319
+
320
+ # Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
321
+ # base_tasks/data_*/env_builder.py
322
+ # base_tasks/data_*/prompts.md
323
+ # base_tasks/data_*/workplace_verifier.py
324
+ # base_tasks/data_*/manifest.json
325
+ # 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
326
+ DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/nanoclawRLdata/0710_add1000agent_qwen3_7_max_v1/exported_new_data}
327
+ train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
328
+ val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
329
+ train_files="['$train_base_tasks']"
330
+ test_files="['$val_base_tasks']"
331
+
332
+ if [ ! -d "${train_base_tasks}" ]; then
333
+ echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
334
+ exit 2
335
+ fi
336
+ if [ ! -d "${val_base_tasks}" ]; then
337
+ echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
338
+ exit 2
339
+ fi
340
+
341
+ model_path=${MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-27B}
342
+ verifier_model_path=${VERIFIER_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
343
+ # 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
344
+ unset MM_CONFIG_FILE || true
345
+
346
+ # Nanoclaw 工具配置
347
+ tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
348
+ nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
349
+ nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
350
+ # 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
351
+ nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_workplace_v14_qwen35_27b_16k}
352
+ # 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
353
+ nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
354
+ nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
355
+ nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
356
+ nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
357
+ nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
358
+ nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
359
+ nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
360
+ nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
361
+ nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
362
+ nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
363
+ nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
364
+ nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
365
+ nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
366
+ nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
367
+ nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-35}
368
+ nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
369
+ nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
370
+ nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
371
+ nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
372
+ nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
373
+ nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
374
+
375
+ # verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
376
+ # 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
377
+ verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
378
+ verifier_api_port=${VERIFIER_API_PORT:-8000}
379
+ verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
380
+ verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
381
+ verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
382
+ # 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM 内置 DP 统一服务。
383
+ # 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
384
+ verifier_api_tp=${VERIFIER_API_TP:-4}
385
+ verifier_api_dp=${VERIFIER_API_DP:-2}
386
+ verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
387
+ verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
388
+ verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
389
+ verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
390
+ verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
391
+ verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
392
+ verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
393
+ verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
394
+ verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
395
+ verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
396
+ verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
397
+ mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
398
+ mock_api_key=${MOCK_API_KEY:-dummy_key}
399
+ mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
400
+ # verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
401
+ mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
402
+ mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
403
+ # 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
404
+ nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
405
+ nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
406
+ # 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
407
+ nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
408
+ # verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
409
+ reward_num_workers=${REWARD_NUM_WORKERS:-52}
410
+
411
+ project_name=${PROJECT_NAME:-qwen3.5-27b_nanoclaw_grpo_verl_0720}
412
+ experiment_name=${EXPERIMENT_NAME:-qwen3.5-27b_nanoclaw_grpo_16k_verl0720_lr1e6_fixedkl1e-3}
413
+ default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
414
+ start_time=$(date +%Y%m%d)_$(date +%H%M%S)
415
+ mkdir -p logs "${default_local_dir}"
416
+
417
+ # ================= 算法与并行参数 =================
418
+ adv_estimator=grpo
419
+ max_turns=${MAX_TURNS:-30}
420
+ max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
421
+ max_response_length=${MAX_RESPONSE_LENGTH:-22768}
422
+ max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
423
+ max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
424
+ max_model_len=$((max_prompt_length + max_response_length))
425
+
426
+ # MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
427
+ actor_lr=${ACTOR_LR:-1e-6}
428
+ actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
429
+ actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
430
+ actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
431
+ actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
432
+ actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
433
+ actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
434
+ actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
435
+ actor_shuffle=${ACTOR_SHUFFLE:-False}
436
+ actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
437
+ actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
438
+ actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
439
+ # MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
440
+ actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
441
+
442
+ # YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
443
+ algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
444
+ algorithm_lam=${ALGORITHM_LAM:-0.95}
445
+ use_kl_in_reward=${USE_KL_IN_REWARD:-True}
446
+ kl_penalty=${KL_PENALTY:-low_var_kl}
447
+ kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
448
+ kl_coef=${KL_COEF:-0.001}
449
+ # 关闭 actor-KL,避免与 reward-KL 重复惩罚。
450
+ actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
451
+ actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
452
+ actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
453
+
454
+ train_batch_size=${TRAIN_BATCH_SIZE:-64}
455
+ ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
456
+ n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
457
+ # 先压低验证,避免验证和训练稳定性混在一起。
458
+ n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
459
+ log_val_generations=${LOG_VAL_GENERATIONS:-10}
460
+
461
+ infer_tp=${INFER_TP:-4}
462
+ train_sp=${TRAIN_SP:-1}
463
+ offload=${OFFLOAD:-True}
464
+
465
+ # 默认沿用旧 new-engine 跑通 4k 前几步的形状;如 HCCL allreduce 仍失败,试 ACTOR_STRATEGY=fsdp2 FSDP_SIZE=16。
466
+ actor_strategy=${ACTOR_STRATEGY:-fsdp}
467
+ fsdp_size=${FSDP_SIZE:-}
468
+
469
+ actor_pack=${ACTOR_PACK:-1}
470
+ logprob_pack=${LOGPROB_PACK:-2}
471
+ actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
472
+ log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
473
+ rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
474
+ rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
475
+ update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-8192}
476
+
477
+ # Qwen 官方推荐:Instruct/non-thinking reasoning tasks
478
+ rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
479
+ rollout_top_p=${ROLLOUT_TOP_P:-0.95}
480
+ rollout_top_k=${ROLLOUT_TOP_K:-20}
481
+ rollout_min_p=${ROLLOUT_MIN_P:-0.0}
482
+ rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
483
+ rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
484
+ rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
485
+
486
+ echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
487
+ echo "DEBUG: max_turns=${max_turns}"
488
+ echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
489
+ echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
490
+ echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
491
+ echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
492
+ echo "DEBUG: actor_max_token_len_per_gpu=${actor_max_token_len_per_gpu}, log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}"
493
+ echo "DEBUG: rollout sampling temperature=${rollout_temperature}, top_p=${rollout_top_p}, top_k=${rollout_top_k}, min_p=${rollout_min_p}, presence_penalty=${rollout_presence_penalty}, frequency_penalty=${rollout_frequency_penalty}, repetition_penalty=${rollout_repetition_penalty}"
494
+ echo "DEBUG: optimizer lr=${actor_lr}, scheduler=${actor_lr_scheduler_type}, warmup_ratio=${actor_lr_warmup_steps_ratio}, weight_decay=${actor_weight_decay}, betas=(${actor_adam_beta1},${actor_adam_beta2}), clip_grad=${actor_clip_grad}, ppo_epochs=${actor_ppo_epochs}, shuffle=${actor_shuffle}"
495
+ echo "DEBUG: KL use_in_reward=${use_kl_in_reward}, penalty=${kl_penalty}, ctrl=${kl_ctrl_type}, coef=${kl_coef}, actor_kl=${actor_use_kl_loss}"
496
+ echo "DEBUG: HCCL_BUFFSIZE=${HCCL_BUFFSIZE}, HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE}, HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE}"
497
+
498
+ val_before_train=${VAL_BEFORE_TRAIN:-False}
499
+ trainer_use_v1=${TRAINER_USE_V1:-True}
500
+ test_freq=${TEST_FREQ:-5000}
501
+ save_freq=${SAVE_FREQ:-2}
502
+
503
+ # ================= 分布式 =================
504
+ export TOTAL_NNODES=${TOTAL_NNODES:-5}
505
+ export TRAIN_NNODES=${TRAIN_NNODES:-4}
506
+ export NNODES=${NNODES:-${TRAIN_NNODES}}
507
+ export NODE_RANK=${VC_TASK_INDEX}
508
+ export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
509
+ export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
510
+
511
+ export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
512
+ export MASTER_PORT=${MASTER_PORT:-6167}
513
+ export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
514
+ export RAY_PORT=${RAY_PORT:-6167}
515
+
516
+ readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
517
+ export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
518
+ export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
519
+ export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
520
+ export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
521
+
522
+ export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
523
+
524
+ cat <<EOF
525
+ DEBUG: MASTER_ADDR=${MASTER_ADDR}
526
+ DEBUG: MASTER_PORT=${MASTER_PORT}
527
+ DEBUG: RAY_PORT=${RAY_PORT}
528
+ DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
529
+ DEBUG: CURRENT_IP=${CURRENT_IP}
530
+ DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
531
+ DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
532
+ DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
533
+ DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
534
+ DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
535
+ DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
536
+ DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
537
+ DEBUG: MOCK_API_BASE=${mock_api_base}
538
+ DEBUG: MOCK_MODEL_NAME=${mock_model_name}
539
+ DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
540
+ DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
541
+ DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
542
+ DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
543
+ DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
544
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
545
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
546
+ DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
547
+ DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
548
+ DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
549
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
550
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
551
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
552
+ DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
553
+ DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
554
+ DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
555
+ DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
556
+ DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
557
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
558
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
559
+ DEBUG: VERIFIER_API_TP=${verifier_api_tp}
560
+ DEBUG: VERIFIER_API_DP=${verifier_api_dp}
561
+ DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
562
+ DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
563
+ DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
564
+ DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
565
+ DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
566
+ DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
567
+ EOF
568
+
569
+ if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
570
+ echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
571
+ echo "--> [Verifier API Node] API base: ${mock_api_base}"
572
+ export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
573
+ mkdir -p "$(dirname "${verifier_api_log}")"
574
+ if [ -n "${verifier_api_start_cmd}" ]; then
575
+ echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
576
+ bash -lc "${verifier_api_start_cmd}" &
577
+ verifier_api_pid=$!
578
+ else
579
+ echo "--> [Verifier API Node] Starting default vLLM verifier API..."
580
+ verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
581
+ verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
582
+ if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
583
+ echo "ERROR: verifier TP*DP=${verifier_api_tp}*${verifier_api_dp}=${verifier_api_expected_device_count}, but VERIFIER_API_DEVICES=${verifier_api_devices} contains ${verifier_api_device_count} devices." >&2
584
+ exit 2
585
+ fi
586
+ export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
587
+ verifier_api_args=(
588
+ --model "${verifier_model_path}"
589
+ --tokenizer "${verifier_model_path}"
590
+ --host "${verifier_api_bind_host}"
591
+ --port "${verifier_api_port}"
592
+ --served-model-name "${mock_model_name}"
593
+ --tensor-parallel-size "${verifier_api_tp}"
594
+ --data-parallel-size "${verifier_api_dp}"
595
+ --distributed-executor-backend "${verifier_api_distributed_executor_backend}"
596
+ --dtype bfloat16
597
+ --max-model-len "${verifier_api_max_model_len}"
598
+ --max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
599
+ --max-num-seqs "${verifier_api_max_num_seqs}"
600
+ --gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
601
+ --trust-remote-code
602
+ )
603
+ if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
604
+ verifier_api_args+=(--enforce-eager)
605
+ fi
606
+ if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
607
+ verifier_api_args+=(--enable-prefix-caching)
608
+ fi
609
+ echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
610
+ python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
611
+ verifier_api_pid=$!
612
+ fi
613
+
614
+ echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
615
+ echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
616
+ python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
617
+ import os
618
+ import sys
619
+ import time
620
+ import urllib.request
621
+ from pathlib import Path
622
+
623
+ url = sys.argv[1]
624
+ timeout = float(sys.argv[2])
625
+ log_path = Path(sys.argv[3])
626
+ pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
627
+ started = time.time()
628
+ last_error = None
629
+ while time.time() - started < timeout:
630
+ if pid is not None:
631
+ try:
632
+ os.kill(pid, 0)
633
+ except OSError:
634
+ print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
635
+ if log_path.is_file():
636
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
637
+ sys.exit(1)
638
+ try:
639
+ with urllib.request.urlopen(url, timeout=5) as response:
640
+ if 200 <= response.status < 300:
641
+ print(f"READY: {url}", file=sys.stderr)
642
+ sys.exit(0)
643
+ except Exception as exc:
644
+ last_error = exc
645
+ time.sleep(5)
646
+ print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
647
+ if log_path.is_file():
648
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
649
+ sys.exit(1)
650
+ PY
651
+ verifier_readiness_rc=$?
652
+ if [ "${verifier_readiness_rc}" -ne 0 ]; then
653
+ echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
654
+ if kill -0 "${verifier_api_pid}" 2>/dev/null; then
655
+ kill "${verifier_api_pid}" 2>/dev/null || true
656
+ fi
657
+ wait "${verifier_api_pid}" 2>/dev/null || true
658
+ exit "${verifier_readiness_rc}"
659
+ fi
660
+
661
+ echo "--> [Verifier API Node] Ready. Keeping node alive."
662
+ wait "${verifier_api_pid}"
663
+ verifier_api_rc=$?
664
+ if [ "${verifier_api_rc}" -ne 0 ]; then
665
+ echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
666
+ fi
667
+ exit "${verifier_api_rc}"
668
+ fi
669
+
670
+ export TMPDIR=/cache/ray_tmp
671
+ export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
672
+
673
+ wait_for_ray_npu_resources() {
674
+ expected_npu=$1
675
+ timeout_seconds=${2:-900}
676
+ begin_ts=$(date +%s)
677
+
678
+ while true; do
679
+ total_npu=$(python3 - <<'PY' 2>/dev/null
680
+ import ray
681
+
682
+ try:
683
+ ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
684
+ print(int(ray.cluster_resources().get("NPU", 0)))
685
+ ray.shutdown()
686
+ except Exception:
687
+ print(0)
688
+ PY
689
+ )
690
+ total_npu=${total_npu:-0}
691
+ now_ts=$(date +%s)
692
+ elapsed=$((now_ts - begin_ts))
693
+
694
+ echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
695
+ ray status || true
696
+
697
+ if [ "${total_npu}" -ge "${expected_npu}" ]; then
698
+ echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
699
+ break
700
+ fi
701
+
702
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
703
+ echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
704
+ return 1
705
+ fi
706
+
707
+ sleep 5
708
+ done
709
+ }
710
+
711
+ wait_for_verifier_api() {
712
+ api_url="${mock_api_base}/models"
713
+ timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
714
+ begin_ts=$(date +%s)
715
+ last_diag_ts=0
716
+ while true; do
717
+ verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
718
+ import socket
719
+ import sys
720
+ import urllib.parse
721
+ import urllib.request
722
+
723
+ url = sys.argv[1]
724
+ parsed = urllib.parse.urlparse(url)
725
+ host = parsed.hostname
726
+ port = parsed.port or (443 if parsed.scheme == "https" else 80)
727
+ print(f"check url={url} host={host} port={port}")
728
+ try:
729
+ infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
730
+ print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
731
+ except Exception as exc:
732
+ print(f"dns_error={type(exc).__name__}: {exc}")
733
+ raise SystemExit(1)
734
+ try:
735
+ with socket.create_connection((host, port), timeout=5):
736
+ print("tcp=ok")
737
+ except Exception as exc:
738
+ print(f"tcp_error={type(exc).__name__}: {exc}")
739
+ raise SystemExit(1)
740
+ try:
741
+ with urllib.request.urlopen(url, timeout=10) as response:
742
+ print(f"http_status={response.status}")
743
+ raise SystemExit(0 if 200 <= response.status < 300 else 1)
744
+ except Exception as exc:
745
+ print(f"http_error={type(exc).__name__}: {exc}")
746
+ raise SystemExit(1)
747
+ PY
748
+ )
749
+ check_rc=$?
750
+ if [ "${check_rc}" = "0" ]; then
751
+ echo "Verifier API is ready: ${api_url}"
752
+ echo "${verifier_check_output}"
753
+ break
754
+ fi
755
+ now_ts=$(date +%s)
756
+ elapsed=$((now_ts - begin_ts))
757
+ echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
758
+ if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
759
+ last_diag_ts=${now_ts}
760
+ echo "--- verifier API check diagnostics ---"
761
+ echo "${verifier_check_output}"
762
+ echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
763
+ echo "--- check verifier node log: ${verifier_api_log} ---"
764
+ echo "--------------------------------------"
765
+ fi
766
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
767
+ echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
768
+ echo "Last verifier API diagnostics:" >&2
769
+ echo "${verifier_check_output}" >&2
770
+ return 1
771
+ fi
772
+ sleep 10
773
+ done
774
+ }
775
+
776
+ # ================= Nanoclaw workspace 根目录 =================
777
+ mkdir -p "${nanoclaw_temp_root}"
778
+ if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
779
+ echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
780
+ exit 2
781
+ fi
782
+ rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
783
+ if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
784
+ echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
785
+ echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
786
+ fi
787
+ echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
788
+ echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
789
+ echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
790
+ echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
791
+
792
+ # ================= 生成 Ray runtime env =================
793
+ RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
794
+ cat > "${RUNTIME_ENV_FILE}" <<YAML
795
+ working_dir: ./
796
+ excludes: ["/.git/", "/logs/", "/checkpoint/"]
797
+ env_vars:
798
+ TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
799
+ CUDA_DEVICE_MAX_CONNECTIONS: "1"
800
+ HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
801
+ HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
802
+ HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
803
+ HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
804
+ HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
805
+ HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
806
+ HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
807
+ P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
808
+ VLLM_USE_V1: "${VLLM_USE_V1}"
809
+ VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
810
+ VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
811
+ VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
812
+ VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
813
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
814
+ TOKENIZERS_PARALLELISM: "false"
815
+ HYDRA_FULL_ERROR: "1"
816
+ PYTHONUNBUFFERED: "1"
817
+ RAY_DEDUP_LOGS: "0"
818
+ WANDB_MODE: "${WANDB_MODE}"
819
+ MOCK_API_BASE: "${mock_api_base}"
820
+ MOCK_API_KEY: "${mock_api_key}"
821
+ MOCK_MODEL_NAME: "${mock_model_name}"
822
+ MOCK_API_TIMEOUT: "${mock_api_timeout}"
823
+ MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
824
+ NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
825
+ NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
826
+ NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
827
+ NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
828
+ NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
829
+ NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
830
+ NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
831
+ NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
832
+ NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
833
+ NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
834
+ NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
835
+ NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
836
+ NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
837
+ NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
838
+ NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
839
+ NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
840
+ NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
841
+ NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
842
+ NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
843
+ YAML
844
+
845
+ # ================= 启动 Ray 多机集群 =================
846
+ if [ "${NODE_RANK}" = "0" ]; then
847
+ echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
848
+ ray start --head \
849
+ --node-ip-address=${RAY_NODE_IP} \
850
+ --port=${RAY_PORT} \
851
+ --dashboard-host=0.0.0.0 \
852
+ --dashboard-port=${DASHBOARD_PORT} \
853
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
854
+ --disable-usage-stats \
855
+ --block &
856
+
857
+ sleep 10
858
+ wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
859
+ wait_for_verifier_api || exit 1
860
+ else
861
+ echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
862
+ sleep 20
863
+ ray start --address=${MASTER_ADDR}:${RAY_PORT} \
864
+ --node-ip-address=${RAY_NODE_IP} \
865
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
866
+ --disable-usage-stats \
867
+ --block &
868
+ sleep 10
869
+ fi
870
+
871
+ # ================= 训练参数数组 =================
872
+ training_args=(
873
+ python3 -m verl.trainer.main_ppo
874
+ +ray_kwargs.ray_init.address=auto
875
+ reward.num_workers=${reward_num_workers}
876
+ algorithm.adv_estimator=${adv_estimator}
877
+ algorithm.gamma=${algorithm_gamma}
878
+ algorithm.lam=${algorithm_lam}
879
+ algorithm.use_kl_in_reward=${use_kl_in_reward}
880
+ algorithm.kl_penalty=${kl_penalty}
881
+ algorithm.kl_ctrl.type=${kl_ctrl_type}
882
+ algorithm.kl_ctrl.kl_coef=${kl_coef}
883
+ data.train_files="${train_files}"
884
+ data.val_files="${test_files}"
885
+ data.return_raw_chat=True
886
+ data.return_multi_modal_inputs=False
887
+ data.image_key=images
888
+ data.shuffle=True
889
+ data.train_batch_size=${train_batch_size}
890
+ data.max_prompt_length=${max_prompt_length}
891
+ data.max_response_length=${max_response_length}
892
+ data.filter_overlong_prompts=True
893
+ data.truncation=error
894
+ data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
895
+ data.custom_cls.name=CustomRLHFDataset
896
+ "data.tool_config_path=${tool_config_path}"
897
+ "+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
898
+ "+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
899
+ "+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
900
+ "+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
901
+ "+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
902
+ "+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
903
+ "+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
904
+ "+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
905
+ +data.apply_chat_template_kwargs.enable_thinking=True
906
+ reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
907
+ reward.custom_reward_function.name=compute_score
908
+ "+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
909
+ "+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
910
+ "+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
911
+ "+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
912
+ "+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
913
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
914
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
915
+ "+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
916
+ "+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
917
+ "+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
918
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
919
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
920
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
921
+ "+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
922
+ "+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
923
+ "+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
924
+ "+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
925
+ "+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
926
+ actor_rollout_ref.model.path=${model_path}
927
+ actor_rollout_ref.model.use_remove_padding=True
928
+ actor_rollout_ref.model.enable_gradient_checkpointing=True
929
+ actor_rollout_ref.actor.strategy=${actor_strategy}
930
+ actor_rollout_ref.ref.strategy=${actor_strategy}
931
+ actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
932
+ actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
933
+ actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
934
+ actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
935
+ actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
936
+ actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
937
+ actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
938
+ actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
939
+ actor_rollout_ref.actor.shuffle=${actor_shuffle}
940
+ actor_rollout_ref.actor.optim.lr=${actor_lr}
941
+ actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
942
+ actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
943
+ actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
944
+ "actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
945
+ actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
946
+ actor_rollout_ref.actor.use_dynamic_bsz=True
947
+ actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
948
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
949
+ actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
950
+ actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
951
+ actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
952
+ actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
953
+ actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
954
+ actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
955
+ actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
956
+ actor_rollout_ref.rollout.name=vllm
957
+ actor_rollout_ref.rollout.mode=async
958
+ actor_rollout_ref.rollout.temperature=${rollout_temperature}
959
+ actor_rollout_ref.rollout.top_p=${rollout_top_p}
960
+ actor_rollout_ref.rollout.top_k=${rollout_top_k}
961
+ actor_rollout_ref.rollout.min_p=${rollout_min_p}
962
+ actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
963
+ actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
964
+ actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
965
+ actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
966
+ actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
967
+ actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
968
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
969
+ actor_rollout_ref.rollout.enable_chunked_prefill=True
970
+ actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
971
+ actor_rollout_ref.rollout.free_cache_engine=True
972
+ actor_rollout_ref.rollout.enforce_eager=False
973
+ actor_rollout_ref.rollout.enable_prefix_caching=False
974
+ actor_rollout_ref.rollout.multi_turn.enable=True
975
+ actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
976
+ actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
977
+ actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
978
+ "actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
979
+ actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
980
+ "actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
981
+ actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
982
+ actor_rollout_ref.rollout.n=${n_resp_per_prompt}
983
+ actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
984
+ actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
985
+ actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
986
+ actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
987
+ actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
988
+ actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
989
+ actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
990
+ actor_rollout_ref.rollout.val_kwargs.do_sample=True
991
+ actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
992
+ actor_rollout_ref.actor.use_torch_compile=False
993
+ actor_rollout_ref.ref.use_torch_compile=False
994
+ actor_rollout_ref.actor.use_torch_compile=False
995
+ actor_rollout_ref.ref.use_torch_compile=False
996
+ actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
997
+ actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
998
+ critic.fsdp.use_torch_compile=False
999
+ trainer.use_v1=${trainer_use_v1}
1000
+ trainer.critic_warmup=0
1001
+ trainer.balance_batch=True
1002
+ trainer.logger=['console','tensorboard']
1003
+ trainer.project_name=${project_name}
1004
+ trainer.experiment_name=${experiment_name}
1005
+ trainer.nnodes=${NNODES}
1006
+ trainer.n_gpus_per_node=${NPUS_PER_NODE}
1007
+ trainer.val_before_train=${val_before_train}
1008
+ trainer.log_val_generations=${log_val_generations}
1009
+ trainer.save_freq=${save_freq}
1010
+ trainer.default_local_dir=${default_local_dir}
1011
+ trainer.test_freq=${test_freq}
1012
+ trainer.total_epochs=10
1013
+ )
1014
+
1015
+ if [ -n "${fsdp_size}" ]; then
1016
+ training_args+=(
1017
+ actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
1018
+ actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
1019
+ )
1020
+ fi
1021
+
1022
+ if [ -n "${nanoclaw_task_ids}" ]; then
1023
+ training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
1024
+ fi
1025
+
1026
+ if [ -n "${nanoclaw_max_steps}" ]; then
1027
+ training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
1028
+ fi
1029
+
1030
+ # ================= 启动训练主进程:仅主节点执行 =================
1031
+ if [ "${NODE_RANK}" = "0" ]; then
1032
+ echo "--> [Head Node] Starting VERL unified engine training..."
1033
+ echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
1034
+ echo "DEBUG: entrypoint=${training_args[*]}"
1035
+
1036
+ ray job submit \
1037
+ --address="http://127.0.0.1:${DASHBOARD_PORT}" \
1038
+ --runtime-env="${RUNTIME_ENV_FILE}" \
1039
+ -- \
1040
+ "${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
1041
+ else
1042
+ echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
1043
+ tail -f /dev/null
1044
+ fi
verl_0720_main/27b_old_verl.shZone.Identifier ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=https://huggingface.co/datasets/geminiDeveloper/contextBenchmark/tree/main/0720
4
+ HostUrl=https://huggingface.co/api/resolve-cache/datasets/geminiDeveloper/contextBenchmark/abe015ce7c2d5ba256eb08e79702363e02b7603e/0720%2F27b_old_verl.sh?download=true&etag=%22b92a32a229172e8f354b626b41c6254156d0476b%22
verl_0720_main/9b.sh ADDED
@@ -0,0 +1,1118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Qwen3.5-9B Nanoclaw 多轮 GRPO — VERL 0720 + NPU SP1/31K 长轨迹正式训练版
3
+ #
4
+ # 关键修改:
5
+ # 1) 入口改为 python3 -m verl.trainer.main_ppo,不再使用 recipe.grpo_mindspeed_mm.main_ppo;
6
+ # 2) 不再使用 MM_CONFIG_FILE / MindSpeed-MM YAML;
7
+ # 3) 显式 text-only:data.return_multi_modal_inputs=False;
8
+ # 4) 数据输入改为 Nanoclaw base_tasks 目录,不再使用 Retool parquet/json;
9
+ # 5) 保留 27B 作业验证过的 HCCL buffer 与端口范围,降低 HcclAllreduce socket/资源压力;
10
+ # 6) 默认 val n=1、log_val_generations=10,先验证训练稳定性;
11
+ # 7) 使用 FSDP2、reshard-after-forward、CPU offload policy 和 activation offload;
12
+ # 8) 使用最新版 VERL V1/TransferQueue 和 nanoclaw_recipe,并按参考 YAML 的训练意图映射优化器与 KL;
13
+ # 9) 恢复 Nanoclaw 正式训练需要的 22768 response / 16384 assistant 长轨迹预算;
14
+ # 10) 启用分块 Torch LM-head,直接计算 token log-prob/entropy,避免 31K×vocab 完整 logits 常驻显存;
15
+ # 11) 普通 entropy fallback 仍使用 256-token 分块,防止非 fused 路径产生十几 GiB 临时张量。
16
+
17
+ set -x
18
+
19
+ # ================= 正式长轨迹版:Qwen3.5 NPU SP1 + 约 31K =================
20
+ # Nanoclaw 的工具 observation 也占 response budget。8K response 会让有效轨迹过早
21
+ # 以 max_response_tokens 截断,因此正式训练恢复 22768 total response / 16384 assistant。
22
+ export TRAIN_SP=1
23
+ export QWEN35_FLA_BACKEND=disabled
24
+ export MAX_PROMPT_LENGTH=8192
25
+ export MAX_RESPONSE_LENGTH=22768
26
+ export MAX_ASSISTANT_RESPONSE_LENGTH=16384
27
+ export MAX_TOOL_RESPONSE_LENGTH=8192
28
+ # 8192 + 22768 = 30960;向上对齐到 32768,确保单条最长样本不会超过
29
+ # actor/ref/log-prob 动态 micro-batch 的 token 容量。
30
+ export ACTOR_MAX_TOKEN_LEN_PER_GPU=32768
31
+ export LOG_PROB_MAX_TOKEN_LEN_PER_GPU=32768
32
+ export ROLLOUT_MAX_NUM_BATCHED_TOKENS=32768
33
+ export ACTOR_STRATEGY=fsdp2
34
+ export OFFLOAD=True
35
+ # 当前 VERL 的 checkpointing 分支不会传递自定义 chunk size;稳定版明确关闭它,确保实际使用 256。
36
+ export ENTROPY_FROM_LOGITS_WITH_CHUNKING=True
37
+ export ENTROPY_FROM_LOGITS_CHUNK_SIZE=256
38
+ export ENTROPY_CHECKPOINTING=False
39
+ # Qwen3.5 fused Torch LM-head 按 token 分块计算全词表 log-prob/entropy,不保留
40
+ # 完整的 [T, vocab] logits;这是 SP1/31K 相比 16K 必须增加的显存保护。
41
+ export USE_FUSED_KERNELS=True
42
+ export FUSED_KERNEL_BACKEND=torch
43
+ # 正式长序列版默认打开 activation offload;保留环境变量开关用于 NPU 故障隔离。
44
+ export ENABLE_ACTIVATION_OFFLOAD=${ENABLE_ACTIVATION_OFFLOAD:-True}
45
+
46
+
47
+ npu-smi info || true
48
+ pip install --upgrade pip
49
+ pip uninstall -y moxing-framework || true
50
+
51
+ # ================= 路径配置 =================
52
+ SCRIPT_DIR=/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/verl_0720_nanoclaw/verl_0720_main
53
+ if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
54
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
55
+ elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
56
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}
57
+ else
58
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
59
+ fi
60
+ WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
61
+ INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
62
+ BKGS=${BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs}
63
+ chmod 755 "${INSTALL_DIR}"
64
+
65
+ # Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
66
+
67
+ GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
68
+ COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-/opt/huawei/dataset/zyr_yuyin/bkgs/gcc-11.3.0-compiled-aarch64.tar.gz}
69
+
70
+ echo "--> 正在从缓存恢复 GCC 11.3.0..."
71
+ tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
72
+ export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
73
+ export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
74
+ export CC=${GCC_INSTALL_PREFIX}/bin/gcc
75
+ export CXX=${GCC_INSTALL_PREFIX}/bin/g++
76
+ echo "--> 验证 GCC 版本:"
77
+ gcc --version
78
+
79
+ cd "${BKGS}"
80
+ cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
81
+
82
+ VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-05-12/verl_new_26_05_09/pkgs}
83
+ rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
84
+ cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
85
+ cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
86
+
87
+ CANN_BKGS=${CANN_BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs/cann_0527}
88
+ cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
89
+ cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
90
+ cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
91
+
92
+ echo "################"
93
+ echo "## set verl env"
94
+ echo "################"
95
+
96
+ cd "${INSTALL_DIR}"
97
+
98
+ chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
99
+ bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
100
+ source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
101
+
102
+ chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
103
+ bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
104
+
105
+ chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
106
+ bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
107
+ source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
108
+
109
+ export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
110
+ export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
111
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
112
+
113
+ pip3 install torch==2.9.0
114
+ pip3 install pyyaml setuptools
115
+ pip3 install torch-npu==2.9.0
116
+ pip3 install torchvision==0.24.0 torchaudio==2.9.0
117
+
118
+ ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
119
+ export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
120
+ pip install pybind11==2.13.6
121
+
122
+ cd "${INSTALL_DIR}/vllm"
123
+ VLLM_TARGET_DEVICE=empty pip install .
124
+
125
+ cd "${INSTALL_DIR}/vllm-ascend"
126
+ pip install -e .
127
+ export VLLM_LOGGING_LEVEL=INFO
128
+
129
+ cd "${INSTALL_DIR}"
130
+ tar -xvf jemalloc-5.3.0.tar.bz2
131
+ cd jemalloc-5.3.0
132
+ ./configure --prefix="${INSTALL_DIR}"
133
+ make -j"$(nproc)"
134
+ make install
135
+ export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
136
+
137
+ # # ================= 可选:安装 MindSpeed 栈 =================
138
+ # # 纯 VERL engine 路线不依赖 MindSpeed-MM YAML。默认不安装,避免和新版 VERL engine 混淆。
139
+ # INSTALL_MINDSPEED_STACK=${INSTALL_MINDSPEED_STACK:-0}
140
+ # if [ "${INSTALL_MINDSPEED_STACK}" = "1" ]; then
141
+ # MindSpeed_PATH=${MindSpeed_PATH:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-slow-stable}
142
+ # cd "${MindSpeed_PATH}"
143
+ # cd Megatron-LM && pip install -e . --no-deps && cd ..
144
+ # cd MindSpeed && pip install -e . --no-deps && cd ..
145
+ # cd MindSpeed-MM && mkdir -p logs data ckpt && pip install -e . --no-deps && cd ..
146
+ # pip install beartype bs4 diffusers==0.30.3 ftfy imageio-ffmpeg pandarallel pytest-mock
147
+ # else
148
+ # echo "--> Skip MindSpeed/MindSpeed-MM installation for pure VERL engine route."
149
+ # fi
150
+
151
+
152
+
153
+ # ================= 安装 Triton-Ascend 3.2.1 =================
154
+ # 1. 卸载 triton(增加 -y 自动确认)
155
+ pip uninstall -y triton
156
+
157
+ # 2. 卸载 triton-ascend(增加 -y 自动确认)
158
+ pip uninstall -y triton-ascend
159
+ pip install --no-cache-dir --force-reinstall triton==3.5.0
160
+ pip install --no-deps /opt/huawei/dataset/zyr_yuyin/bkgs/triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
161
+
162
+
163
+ # ================= 安装新版 VERL =================
164
+ cd "${WORK_DIR}"
165
+ pip install -r requirements-npu.txt
166
+ # NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
167
+ python3 -m pip install -e . --no-deps
168
+ pip install --upgrade 'urllib3==1.26.11'
169
+ pip install loguru
170
+ pip install tree_sitter==0.21.3
171
+ pip install tree-sitter-java==0.21.0
172
+ pip install tree-sitter-javascript==0.21.4
173
+
174
+ ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
175
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
176
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
177
+
178
+ pip uninstall -y transformers || true
179
+ pip install transformers==5.3.0
180
+ pip install accelerate==1.13.0 mathruler
181
+ pip install jsonargparse
182
+ pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
183
+
184
+ # 稳定版只允许 SP=1:不安装普通 FLA,也不进入尚未完成 NPU 适配的 Ulysses CP。
185
+ if [ "${TRAIN_SP}" != "1" ]; then
186
+ echo "ERROR: the long-sequence all-optimization profile requires TRAIN_SP=1; got ${TRAIN_SP}." >&2
187
+ exit 2
188
+ fi
189
+ export NANOCLAW_REQUIRE_FLA=0
190
+ echo "--> Stable SP1: flash-linear-attention is disabled; Qwen3.5 will not build an Ulysses CP context."
191
+
192
+ # Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
193
+ # 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
194
+ NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
195
+ PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
196
+ SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
197
+ SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
198
+ python3 -m pip install --no-cache-dir --force-reinstall \
199
+ "numpy==${NUMPY_VERSION}" \
200
+ "pandas==${PANDAS_VERSION}" \
201
+ "scipy==${SCIPY_VERSION}" \
202
+ "scikit-learn==${SKLEARN_VERSION}"
203
+
204
+ python3 - <<'PY' || exit 2
205
+ import numpy
206
+ import pandas
207
+ import scipy
208
+ import sklearn
209
+ import sys
210
+ import transformers
211
+ import vllm
212
+
213
+ fla_version = "disabled-sp1"
214
+
215
+ print(
216
+ "[python_stack_preflight] "
217
+ f"python={sys.executable} "
218
+ f"numpy={numpy.__version__} "
219
+ f"pandas={pandas.__version__} "
220
+ f"scipy={scipy.__version__} "
221
+ f"sklearn={sklearn.__version__} "
222
+ f"transformers={transformers.__version__} "
223
+ f"vllm={vllm.__version__} "
224
+ f"fla={fla_version}"
225
+ )
226
+ print(
227
+ "[python_stack_paths] "
228
+ f"numpy={numpy.__file__} "
229
+ f"pandas={pandas.__file__}"
230
+ )
231
+ PY
232
+ pip list
233
+
234
+ # ================= 检查 Nanoclaw recipe =================
235
+ if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
236
+ echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
237
+ exit 2
238
+ fi
239
+ test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
240
+
241
+ # Qwen3.5 MRoPE position_ids 是 3/4 轴张量。未应用此补丁时,NPU
242
+ # FlashAttention 会把 seqLen 重复累计(例如 T=10131、sum(seqLen)=30393)。
243
+ QWEN35_MONKEY_PATCH_FILE=${WORK_DIR}/verl/models/transformers/monkey_patch.py
244
+ if [ ! -f "${QWEN35_MONKEY_PATCH_FILE}" ] || ! grep -q "def _normalize_fa_position_ids" "${QWEN35_MONKEY_PATCH_FILE}"; then
245
+ echo "ERROR: Qwen3.5 FlashAttention position_ids normalization patch is missing: ${QWEN35_MONKEY_PATCH_FILE}" >&2
246
+ echo "Upload the modified verl/ directory together with this standalone script." >&2
247
+ exit 2
248
+ fi
249
+
250
+ # Nanoclaw 会在首次模型调用前写入 rollout metadata。旧 ToolAgentLoop 因此
251
+ # 未复制 min/max_global_steps,导致完整训练 step 后在 metrics 阶段把 None 转 int 崩溃。
252
+ TOOL_AGENT_LOOP_FILE=${WORK_DIR}/verl/experimental/agent_loop/tool_agent_loop.py
253
+ TRAINER_BASE_FILE=${WORK_DIR}/verl/trainer/ppo/v1/trainer_base.py
254
+ if [ ! -f "${TOOL_AGENT_LOOP_FILE}" ] || ! grep -q "output_min_global_steps" "${TOOL_AGENT_LOOP_FILE}"; then
255
+ echo "ERROR: Nanoclaw rollout version metadata merge fix is missing: ${TOOL_AGENT_LOOP_FILE}" >&2
256
+ exit 2
257
+ fi
258
+ if [ ! -f "${TRAINER_BASE_FILE}" ] || ! grep -q "def resolve_model_version" "${TRAINER_BASE_FILE}"; then
259
+ echo "ERROR: PPO metrics None-version fallback fix is missing: ${TRAINER_BASE_FILE}" >&2
260
+ exit 2
261
+ fi
262
+
263
+ # 31K 长序列必须使用分块 LM-head;如果训练机只上传了 shell 而没有对应的
264
+ # VERL Qwen3.5 fused backend,则在启动 Ray 前直接失败,避免数十分钟后才 OOM。
265
+ QWEN35_MODEL_PATCH_FILE=${WORK_DIR}/verl/models/transformers/qwen3_5.py
266
+ FUSED_LINEAR_FILE=${WORK_DIR}/verl/utils/experimental/torch_functional.py
267
+ if [ ! -f "${QWEN35_MODEL_PATCH_FILE}" ] || ! grep -q "def forward_with_torch_backend" "${QWEN35_MODEL_PATCH_FILE}"; then
268
+ echo "ERROR: Qwen3.5 fused Torch backend is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
269
+ exit 2
270
+ fi
271
+ if ! grep -q "vocab_weights.full_tensor().to(hidden_states.device)" "${QWEN35_MODEL_PATCH_FILE}"; then
272
+ echo "ERROR: Qwen3.5 FSDP2 CPU-offload fused LM-head device-staging fix is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
273
+ exit 2
274
+ fi
275
+ if [ ! -f "${FUSED_LINEAR_FILE}" ] || ! grep -q "class FusedLinearForPPO" "${FUSED_LINEAR_FILE}"; then
276
+ echo "ERROR: chunked FusedLinearForPPO is missing: ${FUSED_LINEAR_FILE}" >&2
277
+ exit 2
278
+ fi
279
+
280
+ ACTIVATION_OFFLOAD_FILE=${WORK_DIR}/verl/utils/activation_offload.py
281
+ if [ ! -f "${ACTIVATION_OFFLOAD_FILE}" ] || ! grep -q "Missing offload mapping for group" "${ACTIVATION_OFFLOAD_FILE}"; then
282
+ echo "ERROR: FSDP2 checkpoint activation-offload on-demand reload fix is missing: ${ACTIVATION_OFFLOAD_FILE}" >&2
283
+ exit 2
284
+ fi
285
+
286
+ # ================= PLOG =================
287
+ ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
288
+ task_name=worker-${VC_TASK_INDEX}
289
+ task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
290
+ mkdir -p "${task_plog_path}"
291
+ export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
292
+ echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
293
+
294
+ MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
295
+ MASTER_PORT=${PORT}
296
+ MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
297
+
298
+ cd "${WORK_DIR}"
299
+
300
+ mkdir -p /cache/ray_tmp
301
+
302
+ echo "Cleaning up old Ray processes..."
303
+ ray stop --force || true
304
+ sleep 5
305
+ rm -rf /cache/ray_tmp/*
306
+ pkill -9 -f raylet || true
307
+ pkill -9 -f plasma_store || true
308
+ pkill -9 -f gcs_server || true
309
+ echo "Waiting 20s for NPU/Ray resources to be released..."
310
+ npu-smi info || true
311
+ sleep 20
312
+
313
+ # ================= NPU / HCCL / Ray 环境 =================
314
+ export NON_MEGATRON=true
315
+ export MULTI_STREAM_MEMORY_REUSE=2
316
+ export OMP_NUM_THREADS=1
317
+ export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
318
+ export VLLM_LOGGING_LEVEL=INFO
319
+ export RAY_DEDUP_LOGS=0
320
+ export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
321
+ export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
322
+ export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
323
+ export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
324
+ export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
325
+ export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
326
+
327
+ # 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
328
+ export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
329
+ export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
330
+ export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
331
+ export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
332
+
333
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
334
+ export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
335
+ export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
336
+ export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
337
+ export WANDB_MODE=${WANDB_MODE:-disabled}
338
+ export PYTHONUNBUFFERED=1
339
+ export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
340
+ export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
341
+ export TOKENIZERS_PARALLELISM=false
342
+ export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
343
+ export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
344
+ export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
345
+ export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
346
+ export VLLM_USE_V1=${VLLM_USE_V1:-1}
347
+ export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
348
+ export HYDRA_FULL_ERROR=1
349
+ export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
350
+ export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
351
+ export RAY_timeout_ms=${RAY_timeout_ms:-600000}
352
+ export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
353
+ export RAY_USAGE_STATS_ENABLED=0
354
+ export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
355
+
356
+ ulimit -n 65536
357
+
358
+ # Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
359
+ export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
360
+
361
+ # ================= 路径与数据配置 =================
362
+ HDFS_ROOT=${HDFS_ROOT:-$PWD}
363
+ DATA_ROOT=${DATA_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_ckpt}
364
+
365
+ # Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
366
+ # base_tasks/data_*/env_builder.py
367
+ # base_tasks/data_*/prompts.md
368
+ # base_tasks/data_*/workplace_verifier.py
369
+ # base_tasks/data_*/manifest.json
370
+ # 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
371
+ DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/nanoclawRLdata/0710_add1000agent_qwen3_7_max_v1/exported_new_data}
372
+ train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
373
+ val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
374
+ train_files="['$train_base_tasks']"
375
+ test_files="['$val_base_tasks']"
376
+
377
+ if [ ! -d "${train_base_tasks}" ]; then
378
+ echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
379
+ exit 2
380
+ fi
381
+ if [ ! -d "${val_base_tasks}" ]; then
382
+ echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
383
+ exit 2
384
+ fi
385
+
386
+ model_path=${MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
387
+ verifier_model_path=${VERIFIER_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
388
+ # 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
389
+ unset MM_CONFIG_FILE || true
390
+
391
+ # Nanoclaw 工具配置
392
+ tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
393
+ nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
394
+ nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
395
+ # 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
396
+ nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_workplace_v14_qwen35_9b_sp1_fsdp2_31k_longseq_allopt}
397
+ # 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
398
+ nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
399
+ nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
400
+ nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
401
+ nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
402
+ nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
403
+ nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
404
+ nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
405
+ nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
406
+ nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
407
+ nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
408
+ nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
409
+ nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
410
+ nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
411
+ nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
412
+ nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-50}
413
+ nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
414
+ nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
415
+ nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
416
+ nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
417
+ nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
418
+ nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
419
+
420
+ # verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
421
+ # 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
422
+ verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
423
+ verifier_api_port=${VERIFIER_API_PORT:-8000}
424
+ verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
425
+ verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
426
+ verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
427
+ # 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM ���置 DP 统一服务。
428
+ # 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
429
+ verifier_api_tp=${VERIFIER_API_TP:-4}
430
+ verifier_api_dp=${VERIFIER_API_DP:-2}
431
+ verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
432
+ verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
433
+ verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
434
+ verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
435
+ verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
436
+ verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
437
+ verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
438
+ verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
439
+ verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
440
+ verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
441
+ verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
442
+ mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
443
+ mock_api_key=${MOCK_API_KEY:-dummy_key}
444
+ mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
445
+ # verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
446
+ mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
447
+ mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
448
+ # 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
449
+ nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
450
+ nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
451
+ # 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
452
+ nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
453
+ # verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
454
+ reward_num_workers=${REWARD_NUM_WORKERS:-52}
455
+
456
+ project_name=${PROJECT_NAME:-qwen3.5-9b_nanoclaw_grpo_verl_0720}
457
+ experiment_name=${EXPERIMENT_NAME:-qwen3.5-9b_nanoclaw_grpo_sp1_fsdp2_31k_longseq_allopt_lr1e6_fixedkl1e-3}
458
+ default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
459
+ start_time=$(date +%Y%m%d)_$(date +%H%M%S)
460
+ mkdir -p logs "${default_local_dir}"
461
+
462
+ # ================= 算法与并行参数 =================
463
+ adv_estimator=grpo
464
+ max_turns=${MAX_TURNS:-35}
465
+ max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
466
+ max_response_length=${MAX_RESPONSE_LENGTH:-22768}
467
+ max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
468
+ max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
469
+ max_model_len=$((max_prompt_length + max_response_length))
470
+
471
+ # MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
472
+ actor_lr=${ACTOR_LR:-1e-6}
473
+ actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
474
+ actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
475
+ actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
476
+ actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
477
+ actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
478
+ actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
479
+ actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
480
+ actor_shuffle=${ACTOR_SHUFFLE:-False}
481
+ actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
482
+ actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
483
+ actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
484
+ # MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
485
+ actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
486
+
487
+ # YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
488
+ algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
489
+ algorithm_lam=${ALGORITHM_LAM:-0.95}
490
+ use_kl_in_reward=${USE_KL_IN_REWARD:-True}
491
+ kl_penalty=${KL_PENALTY:-low_var_kl}
492
+ kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
493
+ kl_coef=${KL_COEF:-0.001}
494
+ # 关闭 actor-KL,避免与 reward-KL 重复惩罚。
495
+ actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
496
+ actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
497
+ actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
498
+
499
+ train_batch_size=${TRAIN_BATCH_SIZE:-64}
500
+ ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
501
+ n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
502
+ # 先压低验证,避免验证和训练稳定性混在一起。
503
+ n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
504
+ log_val_generations=${LOG_VAL_GENERATIONS:-10}
505
+
506
+ infer_tp=${INFER_TP:-4}
507
+ train_sp=${TRAIN_SP:-1}
508
+ offload=${OFFLOAD:-True}
509
+
510
+ # 长序列全优化版使用最新版 VERL 官方 Qwen3.5 路径采用的 FSDP2。
511
+ actor_strategy=${ACTOR_STRATEGY:-fsdp2}
512
+ fsdp_size=${FSDP_SIZE:-}
513
+
514
+ actor_pack=${ACTOR_PACK:-1}
515
+ logprob_pack=${LOGPROB_PACK:-2}
516
+ actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
517
+ log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
518
+ entropy_from_logits_with_chunking=${ENTROPY_FROM_LOGITS_WITH_CHUNKING:-True}
519
+ entropy_from_logits_chunk_size=${ENTROPY_FROM_LOGITS_CHUNK_SIZE:-256}
520
+ entropy_checkpointing=${ENTROPY_CHECKPOINTING:-False}
521
+ use_fused_kernels=${USE_FUSED_KERNELS:-True}
522
+ fused_kernel_backend=${FUSED_KERNEL_BACKEND:-torch}
523
+ enable_activation_offload=${ENABLE_ACTIVATION_OFFLOAD:-True}
524
+ rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
525
+ rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
526
+ update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-2048}
527
+
528
+ # Qwen 官方推荐:Instruct/non-thinking reasoning tasks
529
+ rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
530
+ rollout_top_p=${ROLLOUT_TOP_P:-0.95}
531
+ rollout_top_k=${ROLLOUT_TOP_K:-20}
532
+ rollout_min_p=${ROLLOUT_MIN_P:-0.0}
533
+ rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
534
+ rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
535
+ rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
536
+
537
+ echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
538
+ echo "DEBUG: max_turns=${max_turns}"
539
+ echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
540
+ echo "DEBUG: entropy_chunking=${entropy_from_logits_with_chunking}, entropy_chunk_size=${entropy_from_logits_chunk_size}, entropy_checkpointing=${entropy_checkpointing}"
541
+ echo "DEBUG: fused_lmhead=${use_fused_kernels}, fused_backend=${fused_kernel_backend}, activation_offload=${enable_activation_offload}"
542
+ echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
543
+ echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
544
+ echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
545
+ echo "DEBUG: actor_max_token_len_per_gpu=${actor_max_token_len_per_gpu}, log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}"
546
+ echo "DEBUG: rollout sampling temperature=${rollout_temperature}, top_p=${rollout_top_p}, top_k=${rollout_top_k}, min_p=${rollout_min_p}, presence_penalty=${rollout_presence_penalty}, frequency_penalty=${rollout_frequency_penalty}, repetition_penalty=${rollout_repetition_penalty}"
547
+ echo "DEBUG: optimizer lr=${actor_lr}, scheduler=${actor_lr_scheduler_type}, warmup_ratio=${actor_lr_warmup_steps_ratio}, weight_decay=${actor_weight_decay}, betas=(${actor_adam_beta1},${actor_adam_beta2}), clip_grad=${actor_clip_grad}, ppo_epochs=${actor_ppo_epochs}, shuffle=${actor_shuffle}"
548
+ echo "DEBUG: KL use_in_reward=${use_kl_in_reward}, penalty=${kl_penalty}, ctrl=${kl_ctrl_type}, coef=${kl_coef}, actor_kl=${actor_use_kl_loss}"
549
+ echo "DEBUG: HCCL_BUFFSIZE=${HCCL_BUFFSIZE}, HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE}, HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE}"
550
+
551
+ val_before_train=${VAL_BEFORE_TRAIN:-False}
552
+ trainer_use_v1=${TRAINER_USE_V1:-True}
553
+ test_freq=${TEST_FREQ:-5000}
554
+ save_freq=${SAVE_FREQ:-2}
555
+
556
+ # ================= 分布式 =================
557
+ export TOTAL_NNODES=${TOTAL_NNODES:-5}
558
+ export TRAIN_NNODES=${TRAIN_NNODES:-4}
559
+ export NNODES=${NNODES:-${TRAIN_NNODES}}
560
+ export NODE_RANK=${VC_TASK_INDEX}
561
+ export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
562
+ export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
563
+
564
+ export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
565
+ export MASTER_PORT=${MASTER_PORT:-6167}
566
+ export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
567
+ export RAY_PORT=${RAY_PORT:-6167}
568
+
569
+ readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
570
+ export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
571
+ export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
572
+ export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
573
+ export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
574
+
575
+ export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
576
+
577
+ cat <<EOF
578
+ DEBUG: MASTER_ADDR=${MASTER_ADDR}
579
+ DEBUG: MASTER_PORT=${MASTER_PORT}
580
+ DEBUG: RAY_PORT=${RAY_PORT}
581
+ DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
582
+ DEBUG: CURRENT_IP=${CURRENT_IP}
583
+ DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
584
+ DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
585
+ DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
586
+ DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
587
+ DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
588
+ DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
589
+ DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
590
+ DEBUG: MOCK_API_BASE=${mock_api_base}
591
+ DEBUG: MOCK_MODEL_NAME=${mock_model_name}
592
+ DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
593
+ DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
594
+ DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
595
+ DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
596
+ DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
597
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
598
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
599
+ DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
600
+ DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
601
+ DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
602
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
603
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
604
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
605
+ DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
606
+ DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
607
+ DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
608
+ DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
609
+ DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
610
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
611
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
612
+ DEBUG: VERIFIER_API_TP=${verifier_api_tp}
613
+ DEBUG: VERIFIER_API_DP=${verifier_api_dp}
614
+ DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
615
+ DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
616
+ DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
617
+ DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
618
+ DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
619
+ DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
620
+ EOF
621
+
622
+ if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
623
+ echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
624
+ echo "--> [Verifier API Node] API base: ${mock_api_base}"
625
+ export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
626
+ mkdir -p "$(dirname "${verifier_api_log}")"
627
+ if [ -n "${verifier_api_start_cmd}" ]; then
628
+ echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
629
+ bash -lc "${verifier_api_start_cmd}" &
630
+ verifier_api_pid=$!
631
+ else
632
+ echo "--> [Verifier API Node] Starting default vLLM verifier API..."
633
+ verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
634
+ verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
635
+ if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
636
+ echo "ERROR: verifier TP*DP=${verifier_api_tp}*${verifier_api_dp}=${verifier_api_expected_device_count}, but VERIFIER_API_DEVICES=${verifier_api_devices} contains ${verifier_api_device_count} devices." >&2
637
+ exit 2
638
+ fi
639
+ export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
640
+ verifier_api_args=(
641
+ --model "${verifier_model_path}"
642
+ --tokenizer "${verifier_model_path}"
643
+ --host "${verifier_api_bind_host}"
644
+ --port "${verifier_api_port}"
645
+ --served-model-name "${mock_model_name}"
646
+ --tensor-parallel-size "${verifier_api_tp}"
647
+ --data-parallel-size "${verifier_api_dp}"
648
+ --distributed-executor-backend "${verifier_api_distributed_executor_backend}"
649
+ --dtype bfloat16
650
+ --max-model-len "${verifier_api_max_model_len}"
651
+ --max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
652
+ --max-num-seqs "${verifier_api_max_num_seqs}"
653
+ --gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
654
+ --trust-remote-code
655
+ )
656
+ if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
657
+ verifier_api_args+=(--enforce-eager)
658
+ fi
659
+ if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
660
+ verifier_api_args+=(--enable-prefix-caching)
661
+ fi
662
+ echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
663
+ python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
664
+ verifier_api_pid=$!
665
+ fi
666
+
667
+ echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
668
+ echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
669
+ python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
670
+ import os
671
+ import sys
672
+ import time
673
+ import urllib.request
674
+ from pathlib import Path
675
+
676
+ url = sys.argv[1]
677
+ timeout = float(sys.argv[2])
678
+ log_path = Path(sys.argv[3])
679
+ pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
680
+ started = time.time()
681
+ last_error = None
682
+ while time.time() - started < timeout:
683
+ if pid is not None:
684
+ try:
685
+ os.kill(pid, 0)
686
+ except OSError:
687
+ print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
688
+ if log_path.is_file():
689
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
690
+ sys.exit(1)
691
+ try:
692
+ with urllib.request.urlopen(url, timeout=5) as response:
693
+ if 200 <= response.status < 300:
694
+ print(f"READY: {url}", file=sys.stderr)
695
+ sys.exit(0)
696
+ except Exception as exc:
697
+ last_error = exc
698
+ time.sleep(5)
699
+ print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
700
+ if log_path.is_file():
701
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
702
+ sys.exit(1)
703
+ PY
704
+ verifier_readiness_rc=$?
705
+ if [ "${verifier_readiness_rc}" -ne 0 ]; then
706
+ echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
707
+ if kill -0 "${verifier_api_pid}" 2>/dev/null; then
708
+ kill "${verifier_api_pid}" 2>/dev/null || true
709
+ fi
710
+ wait "${verifier_api_pid}" 2>/dev/null || true
711
+ exit "${verifier_readiness_rc}"
712
+ fi
713
+
714
+ echo "--> [Verifier API Node] Ready. Keeping node alive."
715
+ wait "${verifier_api_pid}"
716
+ verifier_api_rc=$?
717
+ if [ "${verifier_api_rc}" -ne 0 ]; then
718
+ echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
719
+ fi
720
+ exit "${verifier_api_rc}"
721
+ fi
722
+
723
+ export TMPDIR=/cache/ray_tmp
724
+ export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
725
+
726
+ wait_for_ray_npu_resources() {
727
+ expected_npu=$1
728
+ timeout_seconds=${2:-900}
729
+ begin_ts=$(date +%s)
730
+
731
+ while true; do
732
+ total_npu=$(python3 - <<'PY' 2>/dev/null
733
+ import ray
734
+
735
+ try:
736
+ ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
737
+ print(int(ray.cluster_resources().get("NPU", 0)))
738
+ ray.shutdown()
739
+ except Exception:
740
+ print(0)
741
+ PY
742
+ )
743
+ total_npu=${total_npu:-0}
744
+ now_ts=$(date +%s)
745
+ elapsed=$((now_ts - begin_ts))
746
+
747
+ echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
748
+ ray status || true
749
+
750
+ if [ "${total_npu}" -ge "${expected_npu}" ]; then
751
+ echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
752
+ break
753
+ fi
754
+
755
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
756
+ echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
757
+ return 1
758
+ fi
759
+
760
+ sleep 5
761
+ done
762
+ }
763
+
764
+ wait_for_verifier_api() {
765
+ api_url="${mock_api_base}/models"
766
+ timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
767
+ begin_ts=$(date +%s)
768
+ last_diag_ts=0
769
+ while true; do
770
+ verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
771
+ import socket
772
+ import sys
773
+ import urllib.parse
774
+ import urllib.request
775
+
776
+ url = sys.argv[1]
777
+ parsed = urllib.parse.urlparse(url)
778
+ host = parsed.hostname
779
+ port = parsed.port or (443 if parsed.scheme == "https" else 80)
780
+ print(f"check url={url} host={host} port={port}")
781
+ try:
782
+ infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
783
+ print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
784
+ except Exception as exc:
785
+ print(f"dns_error={type(exc).__name__}: {exc}")
786
+ raise SystemExit(1)
787
+ try:
788
+ with socket.create_connection((host, port), timeout=5):
789
+ print("tcp=ok")
790
+ except Exception as exc:
791
+ print(f"tcp_error={type(exc).__name__}: {exc}")
792
+ raise SystemExit(1)
793
+ try:
794
+ with urllib.request.urlopen(url, timeout=10) as response:
795
+ print(f"http_status={response.status}")
796
+ raise SystemExit(0 if 200 <= response.status < 300 else 1)
797
+ except Exception as exc:
798
+ print(f"http_error={type(exc).__name__}: {exc}")
799
+ raise SystemExit(1)
800
+ PY
801
+ )
802
+ check_rc=$?
803
+ if [ "${check_rc}" = "0" ]; then
804
+ echo "Verifier API is ready: ${api_url}"
805
+ echo "${verifier_check_output}"
806
+ break
807
+ fi
808
+ now_ts=$(date +%s)
809
+ elapsed=$((now_ts - begin_ts))
810
+ echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
811
+ if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
812
+ last_diag_ts=${now_ts}
813
+ echo "--- verifier API check diagnostics ---"
814
+ echo "${verifier_check_output}"
815
+ echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
816
+ echo "--- check verifier node log: ${verifier_api_log} ---"
817
+ echo "--------------------------------------"
818
+ fi
819
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
820
+ echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
821
+ echo "Last verifier API diagnostics:" >&2
822
+ echo "${verifier_check_output}" >&2
823
+ return 1
824
+ fi
825
+ sleep 10
826
+ done
827
+ }
828
+
829
+ # ================= Nanoclaw workspace 根目录 =================
830
+ mkdir -p "${nanoclaw_temp_root}"
831
+ if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
832
+ echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
833
+ exit 2
834
+ fi
835
+ rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
836
+ if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
837
+ echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
838
+ echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
839
+ fi
840
+ echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
841
+ echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
842
+ echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
843
+ echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
844
+
845
+ # ================= 生成 Ray runtime env =================
846
+ RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
847
+ cat > "${RUNTIME_ENV_FILE}" <<YAML
848
+ working_dir: ./
849
+ excludes: ["/.git/", "/logs/", "/checkpoint/"]
850
+ env_vars:
851
+ TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
852
+ CUDA_DEVICE_MAX_CONNECTIONS: "1"
853
+ HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
854
+ HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
855
+ HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
856
+ HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
857
+ HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
858
+ HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
859
+ HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
860
+ P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
861
+ VLLM_USE_V1: "${VLLM_USE_V1}"
862
+ VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
863
+ VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
864
+ VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
865
+ VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
866
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
867
+ TOKENIZERS_PARALLELISM: "false"
868
+ HYDRA_FULL_ERROR: "1"
869
+ PYTHONUNBUFFERED: "1"
870
+ RAY_DEDUP_LOGS: "0"
871
+ WANDB_MODE: "${WANDB_MODE}"
872
+ MOCK_API_BASE: "${mock_api_base}"
873
+ MOCK_API_KEY: "${mock_api_key}"
874
+ MOCK_MODEL_NAME: "${mock_model_name}"
875
+ MOCK_API_TIMEOUT: "${mock_api_timeout}"
876
+ MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
877
+ NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
878
+ NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
879
+ NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
880
+ NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
881
+ NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
882
+ NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
883
+ NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
884
+ NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
885
+ NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
886
+ NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
887
+ NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
888
+ NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
889
+ NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
890
+ NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
891
+ NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
892
+ NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
893
+ NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
894
+ NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
895
+ NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
896
+ YAML
897
+
898
+ # ================= 启动 Ray 多机集群 =================
899
+ if [ "${NODE_RANK}" = "0" ]; then
900
+ echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
901
+ ray start --head \
902
+ --node-ip-address=${RAY_NODE_IP} \
903
+ --port=${RAY_PORT} \
904
+ --dashboard-host=0.0.0.0 \
905
+ --dashboard-port=${DASHBOARD_PORT} \
906
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
907
+ --disable-usage-stats \
908
+ --block &
909
+
910
+ sleep 10
911
+ wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
912
+ wait_for_verifier_api || exit 1
913
+ else
914
+ echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
915
+ sleep 20
916
+ ray start --address=${MASTER_ADDR}:${RAY_PORT} \
917
+ --node-ip-address=${RAY_NODE_IP} \
918
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
919
+ --disable-usage-stats \
920
+ --block &
921
+ sleep 10
922
+ fi
923
+
924
+ # ================= 训练参数数组 =================
925
+ training_args=(
926
+ python3 -m verl.trainer.main_ppo
927
+ +ray_kwargs.ray_init.address=auto
928
+ reward.num_workers=${reward_num_workers}
929
+ algorithm.adv_estimator=${adv_estimator}
930
+ algorithm.gamma=${algorithm_gamma}
931
+ algorithm.lam=${algorithm_lam}
932
+ algorithm.use_kl_in_reward=${use_kl_in_reward}
933
+ algorithm.kl_penalty=${kl_penalty}
934
+ algorithm.kl_ctrl.type=${kl_ctrl_type}
935
+ algorithm.kl_ctrl.kl_coef=${kl_coef}
936
+ data.train_files="${train_files}"
937
+ data.val_files="${test_files}"
938
+ data.return_raw_chat=True
939
+ data.return_multi_modal_inputs=False
940
+ data.image_key=images
941
+ data.shuffle=True
942
+ data.train_batch_size=${train_batch_size}
943
+ data.max_prompt_length=${max_prompt_length}
944
+ data.max_response_length=${max_response_length}
945
+ data.filter_overlong_prompts=True
946
+ data.truncation=error
947
+ data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
948
+ data.custom_cls.name=CustomRLHFDataset
949
+ "data.tool_config_path=${tool_config_path}"
950
+ "+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
951
+ "+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
952
+ "+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
953
+ "+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
954
+ "+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
955
+ "+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
956
+ "+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
957
+ "+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
958
+ +data.apply_chat_template_kwargs.enable_thinking=True
959
+ reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
960
+ reward.custom_reward_function.name=compute_score
961
+ "+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
962
+ "+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
963
+ "+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
964
+ "+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
965
+ "+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
966
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
967
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
968
+ "+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
969
+ "+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
970
+ "+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
971
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
972
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
973
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
974
+ "+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
975
+ "+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
976
+ "+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
977
+ "+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
978
+ "+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
979
+ actor_rollout_ref.model.path=${model_path}
980
+ actor_rollout_ref.model.use_remove_padding=True
981
+ actor_rollout_ref.model.enable_gradient_checkpointing=True
982
+ actor_rollout_ref.model.enable_activation_offload=${enable_activation_offload}
983
+ actor_rollout_ref.model.use_fused_kernels=${use_fused_kernels}
984
+ actor_rollout_ref.model.fused_kernel_options.impl_backend=${fused_kernel_backend}
985
+ actor_rollout_ref.actor.strategy=${actor_strategy}
986
+ actor_rollout_ref.ref.strategy=${actor_strategy}
987
+ actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
988
+ actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
989
+ actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
990
+ actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
991
+ actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
992
+ actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
993
+ actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
994
+ actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
995
+ actor_rollout_ref.actor.shuffle=${actor_shuffle}
996
+ actor_rollout_ref.actor.optim.lr=${actor_lr}
997
+ actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
998
+ actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
999
+ actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
1000
+ "actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
1001
+ actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
1002
+ actor_rollout_ref.actor.use_dynamic_bsz=True
1003
+ actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
1004
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
1005
+ actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
1006
+ actor_rollout_ref.actor.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1007
+ actor_rollout_ref.actor.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1008
+ actor_rollout_ref.actor.entropy_checkpointing=${entropy_checkpointing}
1009
+ actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
1010
+ actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
1011
+ actor_rollout_ref.actor.fsdp_config.offload_policy=${offload}
1012
+ actor_rollout_ref.actor.fsdp_config.reshard_after_forward=True
1013
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1014
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1015
+ actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1016
+ actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
1017
+ actor_rollout_ref.ref.fsdp_config.offload_policy=${offload}
1018
+ actor_rollout_ref.ref.fsdp_config.reshard_after_forward=True
1019
+ actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
1020
+ actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1021
+ actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
1022
+ actor_rollout_ref.ref.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1023
+ actor_rollout_ref.ref.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1024
+ actor_rollout_ref.ref.entropy_checkpointing=${entropy_checkpointing}
1025
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1026
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1027
+ actor_rollout_ref.ref.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1028
+ actor_rollout_ref.rollout.name=vllm
1029
+ actor_rollout_ref.rollout.mode=async
1030
+ actor_rollout_ref.rollout.calculate_log_probs=True
1031
+ actor_rollout_ref.rollout.temperature=${rollout_temperature}
1032
+ actor_rollout_ref.rollout.top_p=${rollout_top_p}
1033
+ actor_rollout_ref.rollout.top_k=${rollout_top_k}
1034
+ actor_rollout_ref.rollout.min_p=${rollout_min_p}
1035
+ actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
1036
+ actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
1037
+ actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
1038
+ actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
1039
+ actor_rollout_ref.rollout.max_model_len=${max_model_len}
1040
+ actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
1041
+ actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
1042
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1043
+ actor_rollout_ref.rollout.enable_chunked_prefill=True
1044
+ actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
1045
+ actor_rollout_ref.rollout.free_cache_engine=True
1046
+ actor_rollout_ref.rollout.enforce_eager=False
1047
+ actor_rollout_ref.rollout.enable_prefix_caching=False
1048
+ actor_rollout_ref.rollout.multi_turn.enable=True
1049
+ actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
1050
+ actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
1051
+ actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
1052
+ "actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
1053
+ actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
1054
+ "actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
1055
+ actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
1056
+ actor_rollout_ref.rollout.n=${n_resp_per_prompt}
1057
+ actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
1058
+ actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
1059
+ actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
1060
+ actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
1061
+ actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
1062
+ actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
1063
+ actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
1064
+ actor_rollout_ref.rollout.val_kwargs.do_sample=True
1065
+ actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
1066
+ actor_rollout_ref.actor.use_torch_compile=False
1067
+ actor_rollout_ref.ref.use_torch_compile=False
1068
+ actor_rollout_ref.actor.use_torch_compile=False
1069
+ actor_rollout_ref.ref.use_torch_compile=False
1070
+ actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
1071
+ actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
1072
+ critic.fsdp.use_torch_compile=False
1073
+ trainer.use_v1=${trainer_use_v1}
1074
+ trainer.critic_warmup=0
1075
+ trainer.balance_batch=True
1076
+ trainer.logger=['console','tensorboard']
1077
+ trainer.project_name=${project_name}
1078
+ trainer.experiment_name=${experiment_name}
1079
+ trainer.nnodes=${NNODES}
1080
+ trainer.n_gpus_per_node=${NPUS_PER_NODE}
1081
+ trainer.val_before_train=${val_before_train}
1082
+ trainer.log_val_generations=${log_val_generations}
1083
+ trainer.save_freq=${save_freq}
1084
+ trainer.default_local_dir=${default_local_dir}
1085
+ trainer.test_freq=${test_freq}
1086
+ trainer.total_epochs=10
1087
+ )
1088
+
1089
+ if [ -n "${fsdp_size}" ]; then
1090
+ training_args+=(
1091
+ actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
1092
+ actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
1093
+ )
1094
+ fi
1095
+
1096
+ if [ -n "${nanoclaw_task_ids}" ]; then
1097
+ training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
1098
+ fi
1099
+
1100
+ if [ -n "${nanoclaw_max_steps}" ]; then
1101
+ training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
1102
+ fi
1103
+
1104
+ # ================= 启动训练主进程:仅主节点执行 =================
1105
+ if [ "${NODE_RANK}" = "0" ]; then
1106
+ echo "--> [Head Node] Starting VERL unified engine training..."
1107
+ echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
1108
+ echo "DEBUG: entrypoint=${training_args[*]}"
1109
+
1110
+ ray job submit \
1111
+ --address="http://127.0.0.1:${DASHBOARD_PORT}" \
1112
+ --runtime-env="${RUNTIME_ENV_FILE}" \
1113
+ -- \
1114
+ "${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
1115
+ else
1116
+ echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
1117
+ tail -f /dev/null
1118
+ fi
verl_0720_main/9b.shZone.Identifier ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=https://huggingface.co/datasets/geminiDeveloper/verl_0720_nanoclaw/tree/main
4
+ HostUrl=https://huggingface.co/api/resolve-cache/datasets/geminiDeveloper/verl_0720_nanoclaw/bacc33fa11aa841f3fa8343597382539716bbd0c/9b.sh?download=true&etag=%222e9618c5440b127aac84d097bad37e196c42df41%22
verl_0720_main/9b_sp1_16k_fused_lmhead_smoke.sh ADDED
@@ -0,0 +1,1111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Qwen3.5-9B Nanoclaw 多轮 GRPO — NPU SP1/16K fused LM-head 两步真实训练实验
3
+ #
4
+ # 关键修改:
5
+ # 1) 入口改为 python3 -m verl.trainer.main_ppo,不再使用 recipe.grpo_mindspeed_mm.main_ppo;
6
+ # 2) 不再使用 MM_CONFIG_FILE / MindSpeed-MM YAML;
7
+ # 3) 显式 text-only:data.return_multi_modal_inputs=False;
8
+ # 4) 数据输入改为 Nanoclaw base_tasks 目录,不再使用 Retool parquet/json;
9
+ # 5) 保留 27B 作业验证过的 HCCL buffer 与端口范围,降低 HcclAllreduce socket/资源压力;
10
+ # 6) smoke 默认关闭训练前/训练后验证和 checkpoint,只验证两次完整训练 step;
11
+ # 7) 稳定版固定使用已经完成初始化与 rollout 验证的 FSDP1/offload 形状。
12
+ # 8) 使用最新版 VERL V1/TransferQueue 和 nanoclaw_recipe,并按参考 YAML 的训练意图映射优化器与 KL;
13
+ # 9) actor/ref 的全词表 entropy 使用 256-token 分块,避免 16K SP1 old-log-prob 阶段产生十几 GiB 临时张量。
14
+ # 10) 启用 Qwen3.5 fused Torch LM-head,按 token 分块直接产生 log-prob/entropy,不保留完整 T×vocab logits;
15
+ # 11) 默认仅跑 2 个完整训练 step,覆盖真实 rollout/reward/old-ref-log-prob/actor backward/optimizer/权重同步。
16
+
17
+ set -x
18
+
19
+ # ================= 独立稳定版:强制 Qwen3.5 NPU SP1 + 16K =================
20
+ # 不允许外部作业环境把这些核心安全参数覆盖回 SP8/31K。
21
+ export TRAIN_SP=1
22
+ export QWEN35_FLA_BACKEND=disabled
23
+ export MAX_PROMPT_LENGTH=8192
24
+ export MAX_RESPONSE_LENGTH=8192
25
+ export MAX_ASSISTANT_RESPONSE_LENGTH=8192
26
+ export MAX_TOOL_RESPONSE_LENGTH=8192
27
+ export ACTOR_MAX_TOKEN_LEN_PER_GPU=16384
28
+ export LOG_PROB_MAX_TOKEN_LEN_PER_GPU=16384
29
+ export ROLLOUT_MAX_NUM_BATCHED_TOKENS=16384
30
+ export ACTOR_STRATEGY=fsdp
31
+ export OFFLOAD=True
32
+ # 当前 VERL 的 checkpointing 分支不会传递自定义 chunk size;稳定版明确关闭它,确保实际使用 256。
33
+ export ENTROPY_FROM_LOGITS_WITH_CHUNKING=True
34
+ export ENTROPY_FROM_LOGITS_CHUNK_SIZE=256
35
+ export ENTROPY_CHECKPOINTING=False
36
+ # 本实验只改变 LM-head 路径;保留已经走到 old-log-prob 的 FSDP1/SP1/offload 拓扑。
37
+ export USE_FUSED_KERNELS=True
38
+ export FUSED_KERNEL_BACKEND=torch
39
+ export ENABLE_ACTIVATION_OFFLOAD=False
40
+ # 缩小全局实验规模,但每条样本仍允许真实 16K,显存压力不会被短上下文掩盖。
41
+ export TRAIN_BATCH_SIZE=8
42
+ export PPO_MINI_BATCH_SIZE=8
43
+ export N_RESP_PER_PROMPT=8
44
+ export TOTAL_TRAINING_STEPS=2
45
+ export VAL_BEFORE_TRAIN=False
46
+ export TEST_FREQ=-1
47
+ export SAVE_FREQ=-1
48
+ export LOG_VAL_GENERATIONS=0
49
+
50
+
51
+ npu-smi info || true
52
+ pip install --upgrade pip
53
+ pip uninstall -y moxing-framework || true
54
+
55
+ # ================= 路径配置 =================
56
+ SCRIPT_DIR=/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/verl_0720_nanoclaw/verl_0720_main
57
+ if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
58
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
59
+ elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
60
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}
61
+ else
62
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
63
+ fi
64
+ WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
65
+ INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
66
+ BKGS=${BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs}
67
+ chmod 755 "${INSTALL_DIR}"
68
+
69
+ # Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
70
+
71
+ GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
72
+ COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-/opt/huawei/dataset/zyr_yuyin/bkgs/gcc-11.3.0-compiled-aarch64.tar.gz}
73
+
74
+ echo "--> 正在从缓存恢复 GCC 11.3.0..."
75
+ tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
76
+ export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
77
+ export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
78
+ export CC=${GCC_INSTALL_PREFIX}/bin/gcc
79
+ export CXX=${GCC_INSTALL_PREFIX}/bin/g++
80
+ echo "--> 验证 GCC 版本:"
81
+ gcc --version
82
+
83
+ cd "${BKGS}"
84
+ cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
85
+
86
+ VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-05-12/verl_new_26_05_09/pkgs}
87
+ rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
88
+ cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
89
+ cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
90
+
91
+ CANN_BKGS=${CANN_BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs/cann_0527}
92
+ cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
93
+ cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
94
+ cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
95
+
96
+ echo "################"
97
+ echo "## set verl env"
98
+ echo "################"
99
+
100
+ cd "${INSTALL_DIR}"
101
+
102
+ chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
103
+ bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
104
+ source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
105
+
106
+ chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
107
+ bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
108
+
109
+ chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
110
+ bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
111
+ source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
112
+
113
+ export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
114
+ export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
115
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
116
+
117
+ pip3 install torch==2.9.0
118
+ pip3 install pyyaml setuptools
119
+ pip3 install torch-npu==2.9.0
120
+ pip3 install torchvision==0.24.0 torchaudio==2.9.0
121
+
122
+ ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
123
+ export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
124
+ pip install pybind11==2.13.6
125
+
126
+ cd "${INSTALL_DIR}/vllm"
127
+ VLLM_TARGET_DEVICE=empty pip install .
128
+
129
+ cd "${INSTALL_DIR}/vllm-ascend"
130
+ pip install -e .
131
+ export VLLM_LOGGING_LEVEL=INFO
132
+
133
+ cd "${INSTALL_DIR}"
134
+ tar -xvf jemalloc-5.3.0.tar.bz2
135
+ cd jemalloc-5.3.0
136
+ ./configure --prefix="${INSTALL_DIR}"
137
+ make -j"$(nproc)"
138
+ make install
139
+ export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
140
+
141
+ # # ================= 可选:安装 MindSpeed 栈 =================
142
+ # # 纯 VERL engine 路线不依赖 MindSpeed-MM YAML。默认不安装,避免和新版 VERL engine 混淆。
143
+ # INSTALL_MINDSPEED_STACK=${INSTALL_MINDSPEED_STACK:-0}
144
+ # if [ "${INSTALL_MINDSPEED_STACK}" = "1" ]; then
145
+ # MindSpeed_PATH=${MindSpeed_PATH:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-slow-stable}
146
+ # cd "${MindSpeed_PATH}"
147
+ # cd Megatron-LM && pip install -e . --no-deps && cd ..
148
+ # cd MindSpeed && pip install -e . --no-deps && cd ..
149
+ # cd MindSpeed-MM && mkdir -p logs data ckpt && pip install -e . --no-deps && cd ..
150
+ # pip install beartype bs4 diffusers==0.30.3 ftfy imageio-ffmpeg pandarallel pytest-mock
151
+ # else
152
+ # echo "--> Skip MindSpeed/MindSpeed-MM installation for pure VERL engine route."
153
+ # fi
154
+
155
+
156
+
157
+ # ================= 安装 Triton-Ascend 3.2.1 =================
158
+ # 1. 卸载 triton(增加 -y 自动确认)
159
+ pip uninstall -y triton
160
+
161
+ # 2. 卸载 triton-ascend(增加 -y 自动确认)
162
+ pip uninstall -y triton-ascend
163
+ pip install --no-cache-dir --force-reinstall triton==3.5.0
164
+ pip install --no-deps /opt/huawei/dataset/zyr_yuyin/bkgs/triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
165
+
166
+
167
+ # ================= 安装新版 VERL =================
168
+ cd "${WORK_DIR}"
169
+ pip install -r requirements-npu.txt
170
+ # NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
171
+ python3 -m pip install -e . --no-deps
172
+ pip install --upgrade 'urllib3==1.26.11'
173
+ pip install loguru
174
+ pip install tree_sitter==0.21.3
175
+ pip install tree-sitter-java==0.21.0
176
+ pip install tree-sitter-javascript==0.21.4
177
+
178
+ ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
179
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
180
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
181
+
182
+ pip uninstall -y transformers || true
183
+ pip install transformers==5.3.0
184
+ pip install accelerate==1.13.0 mathruler
185
+ pip install jsonargparse
186
+ pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
187
+
188
+ # 稳定版只允许 SP=1:不安装普通 FLA,也不进入尚未完成 NPU 适配的 Ulysses CP。
189
+ if [ "${TRAIN_SP}" != "1" ]; then
190
+ echo "ERROR: the standalone stable profile requires TRAIN_SP=1; got ${TRAIN_SP}." >&2
191
+ exit 2
192
+ fi
193
+ export NANOCLAW_REQUIRE_FLA=0
194
+ echo "--> Stable SP1: flash-linear-attention is disabled; Qwen3.5 will not build an Ulysses CP context."
195
+
196
+ # Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
197
+ # 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
198
+ NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
199
+ PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
200
+ SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
201
+ SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
202
+ python3 -m pip install --no-cache-dir --force-reinstall \
203
+ "numpy==${NUMPY_VERSION}" \
204
+ "pandas==${PANDAS_VERSION}" \
205
+ "scipy==${SCIPY_VERSION}" \
206
+ "scikit-learn==${SKLEARN_VERSION}"
207
+
208
+ python3 - <<'PY' || exit 2
209
+ import numpy
210
+ import pandas
211
+ import scipy
212
+ import sklearn
213
+ import sys
214
+ import transformers
215
+ import vllm
216
+
217
+ fla_version = "disabled-sp1"
218
+
219
+ print(
220
+ "[python_stack_preflight] "
221
+ f"python={sys.executable} "
222
+ f"numpy={numpy.__version__} "
223
+ f"pandas={pandas.__version__} "
224
+ f"scipy={scipy.__version__} "
225
+ f"sklearn={sklearn.__version__} "
226
+ f"transformers={transformers.__version__} "
227
+ f"vllm={vllm.__version__} "
228
+ f"fla={fla_version}"
229
+ )
230
+ print(
231
+ "[python_stack_paths] "
232
+ f"numpy={numpy.__file__} "
233
+ f"pandas={pandas.__file__}"
234
+ )
235
+ PY
236
+ pip list
237
+
238
+ # ================= 检查 Nanoclaw recipe =================
239
+ if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
240
+ echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
241
+ exit 2
242
+ fi
243
+ test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
244
+
245
+ # Qwen3.5 MRoPE position_ids 是 3/4 轴张量。未应用此补丁时,NPU
246
+ # FlashAttention 会把 seqLen 重复累计(例如 T=10131、sum(seqLen)=30393)。
247
+ QWEN35_MONKEY_PATCH_FILE=${WORK_DIR}/verl/models/transformers/monkey_patch.py
248
+ if [ ! -f "${QWEN35_MONKEY_PATCH_FILE}" ] || ! grep -q "def _normalize_fa_position_ids" "${QWEN35_MONKEY_PATCH_FILE}"; then
249
+ echo "ERROR: Qwen3.5 FlashAttention position_ids normalization patch is missing: ${QWEN35_MONKEY_PATCH_FILE}" >&2
250
+ echo "Upload the modified verl/ directory together with this standalone script." >&2
251
+ exit 2
252
+ fi
253
+
254
+ # Nanoclaw 会在首次模型调用前写入 rollout metadata。旧 ToolAgentLoop 因此
255
+ # 未复制 min/max_global_steps,导致完整训练 step 后在 metrics 阶段把 None 转 int 崩溃。
256
+ TOOL_AGENT_LOOP_FILE=${WORK_DIR}/verl/experimental/agent_loop/tool_agent_loop.py
257
+ TRAINER_BASE_FILE=${WORK_DIR}/verl/trainer/ppo/v1/trainer_base.py
258
+ if [ ! -f "${TOOL_AGENT_LOOP_FILE}" ] || ! grep -q "output_min_global_steps" "${TOOL_AGENT_LOOP_FILE}"; then
259
+ echo "ERROR: Nanoclaw rollout version metadata merge fix is missing: ${TOOL_AGENT_LOOP_FILE}" >&2
260
+ exit 2
261
+ fi
262
+ if [ ! -f "${TRAINER_BASE_FILE}" ] || ! grep -q "def resolve_model_version" "${TRAINER_BASE_FILE}"; then
263
+ echo "ERROR: PPO metrics None-version fallback fix is missing: ${TRAINER_BASE_FILE}" >&2
264
+ exit 2
265
+ fi
266
+
267
+ # fused Torch LM-head 必须同时具备 Qwen3.5 backend 和分块 autograd 实现。
268
+ QWEN35_MODEL_PATCH_FILE=${WORK_DIR}/verl/models/transformers/qwen3_5.py
269
+ FUSED_LINEAR_FILE=${WORK_DIR}/verl/utils/experimental/torch_functional.py
270
+ if [ ! -f "${QWEN35_MODEL_PATCH_FILE}" ] || ! grep -q "def forward_with_torch_backend" "${QWEN35_MODEL_PATCH_FILE}"; then
271
+ echo "ERROR: Qwen3.5 fused Torch backend is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
272
+ exit 2
273
+ fi
274
+ if [ ! -f "${FUSED_LINEAR_FILE}" ] || ! grep -q "class FusedLinearForPPO" "${FUSED_LINEAR_FILE}"; then
275
+ echo "ERROR: chunked FusedLinearForPPO is missing: ${FUSED_LINEAR_FILE}" >&2
276
+ exit 2
277
+ fi
278
+
279
+ # ================= PLOG =================
280
+ ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
281
+ task_name=worker-${VC_TASK_INDEX}
282
+ task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
283
+ mkdir -p "${task_plog_path}"
284
+ export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
285
+ echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
286
+
287
+ MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
288
+ MASTER_PORT=${PORT}
289
+ MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
290
+
291
+ cd "${WORK_DIR}"
292
+
293
+ mkdir -p /cache/ray_tmp
294
+
295
+ echo "Cleaning up old Ray processes..."
296
+ ray stop --force || true
297
+ sleep 5
298
+ rm -rf /cache/ray_tmp/*
299
+ pkill -9 -f raylet || true
300
+ pkill -9 -f plasma_store || true
301
+ pkill -9 -f gcs_server || true
302
+ echo "Waiting 20s for NPU/Ray resources to be released..."
303
+ npu-smi info || true
304
+ sleep 20
305
+
306
+ # ================= NPU / HCCL / Ray 环境 =================
307
+ export NON_MEGATRON=true
308
+ export MULTI_STREAM_MEMORY_REUSE=2
309
+ export OMP_NUM_THREADS=1
310
+ export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
311
+ export VLLM_LOGGING_LEVEL=INFO
312
+ export RAY_DEDUP_LOGS=0
313
+ export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
314
+ export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
315
+ export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
316
+ export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
317
+ export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
318
+ export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
319
+
320
+ # 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
321
+ export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
322
+ export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
323
+ export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
324
+ export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
325
+
326
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
327
+ export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
328
+ export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
329
+ export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
330
+ export WANDB_MODE=${WANDB_MODE:-disabled}
331
+ export PYTHONUNBUFFERED=1
332
+ export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
333
+ export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
334
+ export TOKENIZERS_PARALLELISM=false
335
+ export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
336
+ export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
337
+ export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
338
+ export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
339
+ export VLLM_USE_V1=${VLLM_USE_V1:-1}
340
+ export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
341
+ export HYDRA_FULL_ERROR=1
342
+ export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
343
+ export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
344
+ export RAY_timeout_ms=${RAY_timeout_ms:-600000}
345
+ export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
346
+ export RAY_USAGE_STATS_ENABLED=0
347
+ export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
348
+
349
+ ulimit -n 65536
350
+
351
+ # Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
352
+ export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
353
+
354
+ # ================= 路径与数据配置 =================
355
+ HDFS_ROOT=${HDFS_ROOT:-$PWD}
356
+ DATA_ROOT=${DATA_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_ckpt}
357
+
358
+ # Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
359
+ # base_tasks/data_*/env_builder.py
360
+ # base_tasks/data_*/prompts.md
361
+ # base_tasks/data_*/workplace_verifier.py
362
+ # base_tasks/data_*/manifest.json
363
+ # 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
364
+ DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/nanoclawRLdata/0710_add1000agent_qwen3_7_max_v1/exported_new_data}
365
+ train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
366
+ val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
367
+ train_files="['$train_base_tasks']"
368
+ test_files="['$val_base_tasks']"
369
+
370
+ if [ ! -d "${train_base_tasks}" ]; then
371
+ echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
372
+ exit 2
373
+ fi
374
+ if [ ! -d "${val_base_tasks}" ]; then
375
+ echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
376
+ exit 2
377
+ fi
378
+
379
+ model_path=${MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
380
+ verifier_model_path=${VERIFIER_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
381
+ # 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
382
+ unset MM_CONFIG_FILE || true
383
+
384
+ # Nanoclaw 工具配置
385
+ tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
386
+ nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
387
+ nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
388
+ # 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
389
+ nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_workplace_qwen35_9b_sp1_16k_fused_lmhead_smoke}
390
+ # 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
391
+ nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
392
+ nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
393
+ nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
394
+ nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
395
+ nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
396
+ nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
397
+ nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
398
+ nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
399
+ nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
400
+ nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
401
+ nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
402
+ nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
403
+ nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
404
+ nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
405
+ nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-50}
406
+ nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
407
+ nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
408
+ nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
409
+ nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
410
+ nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
411
+ nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
412
+
413
+ # verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
414
+ # 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
415
+ verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
416
+ verifier_api_port=${VERIFIER_API_PORT:-8000}
417
+ verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
418
+ verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
419
+ verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
420
+ # 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM 内置 DP 统一服务。
421
+ # 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
422
+ verifier_api_tp=${VERIFIER_API_TP:-4}
423
+ verifier_api_dp=${VERIFIER_API_DP:-2}
424
+ verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
425
+ verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
426
+ verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
427
+ verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
428
+ verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
429
+ verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
430
+ verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
431
+ verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
432
+ verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
433
+ verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
434
+ verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
435
+ mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
436
+ mock_api_key=${MOCK_API_KEY:-dummy_key}
437
+ mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
438
+ # verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
439
+ mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
440
+ mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
441
+ # 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
442
+ nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
443
+ nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
444
+ # 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
445
+ nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
446
+ # verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
447
+ reward_num_workers=${REWARD_NUM_WORKERS:-52}
448
+
449
+ project_name=${PROJECT_NAME:-qwen3.5-9b_nanoclaw_grpo_verl_0720}
450
+ experiment_name=${EXPERIMENT_NAME:-qwen3.5-9b_nanoclaw_grpo_sp1_16k_fused_lmhead_smoke}
451
+ default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
452
+ start_time=$(date +%Y%m%d)_$(date +%H%M%S)
453
+ mkdir -p logs "${default_local_dir}"
454
+
455
+ # ================= 算法与并行参数 =================
456
+ adv_estimator=grpo
457
+ max_turns=${MAX_TURNS:-35}
458
+ max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
459
+ max_response_length=${MAX_RESPONSE_LENGTH:-22768}
460
+ max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
461
+ max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
462
+ max_model_len=$((max_prompt_length + max_response_length))
463
+
464
+ # MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
465
+ actor_lr=${ACTOR_LR:-1e-6}
466
+ actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
467
+ actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
468
+ actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
469
+ actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
470
+ actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
471
+ actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
472
+ actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
473
+ actor_shuffle=${ACTOR_SHUFFLE:-False}
474
+ actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
475
+ actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
476
+ actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
477
+ # MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
478
+ actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
479
+
480
+ # YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
481
+ algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
482
+ algorithm_lam=${ALGORITHM_LAM:-0.95}
483
+ use_kl_in_reward=${USE_KL_IN_REWARD:-True}
484
+ kl_penalty=${KL_PENALTY:-low_var_kl}
485
+ kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
486
+ kl_coef=${KL_COEF:-0.001}
487
+ # 关闭 actor-KL,避免与 reward-KL 重复惩罚。
488
+ actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
489
+ actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
490
+ actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
491
+
492
+ train_batch_size=${TRAIN_BATCH_SIZE:-64}
493
+ ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
494
+ n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
495
+ # 先压低验证,避免验证和训练稳定性混在一起。
496
+ n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
497
+ log_val_generations=${LOG_VAL_GENERATIONS:-10}
498
+
499
+ infer_tp=${INFER_TP:-4}
500
+ train_sp=${TRAIN_SP:-1}
501
+ offload=${OFFLOAD:-True}
502
+
503
+ # 稳定版固定沿用已经完成初始化与 rollout 验证的 FSDP1/offload 形状。
504
+ actor_strategy=${ACTOR_STRATEGY:-fsdp}
505
+ fsdp_size=${FSDP_SIZE:-}
506
+
507
+ actor_pack=${ACTOR_PACK:-1}
508
+ logprob_pack=${LOGPROB_PACK:-2}
509
+ actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
510
+ log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
511
+ entropy_from_logits_with_chunking=${ENTROPY_FROM_LOGITS_WITH_CHUNKING:-True}
512
+ entropy_from_logits_chunk_size=${ENTROPY_FROM_LOGITS_CHUNK_SIZE:-256}
513
+ entropy_checkpointing=${ENTROPY_CHECKPOINTING:-False}
514
+ use_fused_kernels=${USE_FUSED_KERNELS:-True}
515
+ fused_kernel_backend=${FUSED_KERNEL_BACKEND:-torch}
516
+ enable_activation_offload=${ENABLE_ACTIVATION_OFFLOAD:-False}
517
+ rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
518
+ rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
519
+ update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-8192}
520
+
521
+ # Qwen 官方推荐:Instruct/non-thinking reasoning tasks
522
+ rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
523
+ rollout_top_p=${ROLLOUT_TOP_P:-0.95}
524
+ rollout_top_k=${ROLLOUT_TOP_K:-20}
525
+ rollout_min_p=${ROLLOUT_MIN_P:-0.0}
526
+ rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
527
+ rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
528
+ rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
529
+
530
+ echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
531
+ echo "DEBUG: max_turns=${max_turns}"
532
+ echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
533
+ echo "DEBUG: entropy_chunking=${entropy_from_logits_with_chunking}, entropy_chunk_size=${entropy_from_logits_chunk_size}, entropy_checkpointing=${entropy_checkpointing}"
534
+ echo "DEBUG: fused_lmhead=${use_fused_kernels}, fused_backend=${fused_kernel_backend}, activation_offload=${enable_activation_offload}"
535
+ echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
536
+ echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
537
+ echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
538
+ echo "DEBUG: actor_max_token_len_per_gpu=${actor_max_token_len_per_gpu}, log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}"
539
+ echo "DEBUG: rollout sampling temperature=${rollout_temperature}, top_p=${rollout_top_p}, top_k=${rollout_top_k}, min_p=${rollout_min_p}, presence_penalty=${rollout_presence_penalty}, frequency_penalty=${rollout_frequency_penalty}, repetition_penalty=${rollout_repetition_penalty}"
540
+ echo "DEBUG: optimizer lr=${actor_lr}, scheduler=${actor_lr_scheduler_type}, warmup_ratio=${actor_lr_warmup_steps_ratio}, weight_decay=${actor_weight_decay}, betas=(${actor_adam_beta1},${actor_adam_beta2}), clip_grad=${actor_clip_grad}, ppo_epochs=${actor_ppo_epochs}, shuffle=${actor_shuffle}"
541
+ echo "DEBUG: KL use_in_reward=${use_kl_in_reward}, penalty=${kl_penalty}, ctrl=${kl_ctrl_type}, coef=${kl_coef}, actor_kl=${actor_use_kl_loss}"
542
+ echo "DEBUG: HCCL_BUFFSIZE=${HCCL_BUFFSIZE}, HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE}, HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE}"
543
+
544
+ val_before_train=${VAL_BEFORE_TRAIN:-False}
545
+ trainer_use_v1=${TRAINER_USE_V1:-True}
546
+ test_freq=${TEST_FREQ:-5000}
547
+ save_freq=${SAVE_FREQ:-2}
548
+ total_training_steps=${TOTAL_TRAINING_STEPS:-2}
549
+
550
+ # ================= 分布式 =================
551
+ export TOTAL_NNODES=${TOTAL_NNODES:-5}
552
+ export TRAIN_NNODES=${TRAIN_NNODES:-4}
553
+ export NNODES=${NNODES:-${TRAIN_NNODES}}
554
+ export NODE_RANK=${VC_TASK_INDEX}
555
+ export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
556
+ export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
557
+
558
+ export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
559
+ export MASTER_PORT=${MASTER_PORT:-6167}
560
+ export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
561
+ export RAY_PORT=${RAY_PORT:-6167}
562
+
563
+ readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
564
+ export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
565
+ export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
566
+ export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
567
+ export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
568
+
569
+ export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
570
+
571
+ cat <<EOF
572
+ DEBUG: MASTER_ADDR=${MASTER_ADDR}
573
+ DEBUG: MASTER_PORT=${MASTER_PORT}
574
+ DEBUG: RAY_PORT=${RAY_PORT}
575
+ DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
576
+ DEBUG: CURRENT_IP=${CURRENT_IP}
577
+ DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
578
+ DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
579
+ DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
580
+ DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
581
+ DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
582
+ DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
583
+ DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
584
+ DEBUG: MOCK_API_BASE=${mock_api_base}
585
+ DEBUG: MOCK_MODEL_NAME=${mock_model_name}
586
+ DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
587
+ DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
588
+ DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
589
+ DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
590
+ DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
591
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
592
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
593
+ DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
594
+ DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
595
+ DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
596
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
597
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
598
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
599
+ DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
600
+ DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
601
+ DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
602
+ DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
603
+ DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
604
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
605
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
606
+ DEBUG: VERIFIER_API_TP=${verifier_api_tp}
607
+ DEBUG: VERIFIER_API_DP=${verifier_api_dp}
608
+ DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
609
+ DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
610
+ DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
611
+ DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
612
+ DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
613
+ DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
614
+ EOF
615
+
616
+ if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
617
+ echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
618
+ echo "--> [Verifier API Node] API base: ${mock_api_base}"
619
+ export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
620
+ mkdir -p "$(dirname "${verifier_api_log}")"
621
+ if [ -n "${verifier_api_start_cmd}" ]; then
622
+ echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
623
+ bash -lc "${verifier_api_start_cmd}" &
624
+ verifier_api_pid=$!
625
+ else
626
+ echo "--> [Verifier API Node] Starting default vLLM verifier API..."
627
+ verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
628
+ verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
629
+ if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
630
+ echo "ERROR: verifier TP*DP=${verifier_api_tp}*${verifier_api_dp}=${verifier_api_expected_device_count}, but VERIFIER_API_DEVICES=${verifier_api_devices} contains ${verifier_api_device_count} devices." >&2
631
+ exit 2
632
+ fi
633
+ export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
634
+ verifier_api_args=(
635
+ --model "${verifier_model_path}"
636
+ --tokenizer "${verifier_model_path}"
637
+ --host "${verifier_api_bind_host}"
638
+ --port "${verifier_api_port}"
639
+ --served-model-name "${mock_model_name}"
640
+ --tensor-parallel-size "${verifier_api_tp}"
641
+ --data-parallel-size "${verifier_api_dp}"
642
+ --distributed-executor-backend "${verifier_api_distributed_executor_backend}"
643
+ --dtype bfloat16
644
+ --max-model-len "${verifier_api_max_model_len}"
645
+ --max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
646
+ --max-num-seqs "${verifier_api_max_num_seqs}"
647
+ --gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
648
+ --trust-remote-code
649
+ )
650
+ if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
651
+ verifier_api_args+=(--enforce-eager)
652
+ fi
653
+ if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
654
+ verifier_api_args+=(--enable-prefix-caching)
655
+ fi
656
+ echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
657
+ python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
658
+ verifier_api_pid=$!
659
+ fi
660
+
661
+ echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
662
+ echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
663
+ python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
664
+ import os
665
+ import sys
666
+ import time
667
+ import urllib.request
668
+ from pathlib import Path
669
+
670
+ url = sys.argv[1]
671
+ timeout = float(sys.argv[2])
672
+ log_path = Path(sys.argv[3])
673
+ pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
674
+ started = time.time()
675
+ last_error = None
676
+ while time.time() - started < timeout:
677
+ if pid is not None:
678
+ try:
679
+ os.kill(pid, 0)
680
+ except OSError:
681
+ print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
682
+ if log_path.is_file():
683
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
684
+ sys.exit(1)
685
+ try:
686
+ with urllib.request.urlopen(url, timeout=5) as response:
687
+ if 200 <= response.status < 300:
688
+ print(f"READY: {url}", file=sys.stderr)
689
+ sys.exit(0)
690
+ except Exception as exc:
691
+ last_error = exc
692
+ time.sleep(5)
693
+ print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
694
+ if log_path.is_file():
695
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
696
+ sys.exit(1)
697
+ PY
698
+ verifier_readiness_rc=$?
699
+ if [ "${verifier_readiness_rc}" -ne 0 ]; then
700
+ echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
701
+ if kill -0 "${verifier_api_pid}" 2>/dev/null; then
702
+ kill "${verifier_api_pid}" 2>/dev/null || true
703
+ fi
704
+ wait "${verifier_api_pid}" 2>/dev/null || true
705
+ exit "${verifier_readiness_rc}"
706
+ fi
707
+
708
+ echo "--> [Verifier API Node] Ready. Keeping node alive."
709
+ wait "${verifier_api_pid}"
710
+ verifier_api_rc=$?
711
+ if [ "${verifier_api_rc}" -ne 0 ]; then
712
+ echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
713
+ fi
714
+ exit "${verifier_api_rc}"
715
+ fi
716
+
717
+ export TMPDIR=/cache/ray_tmp
718
+ export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
719
+
720
+ wait_for_ray_npu_resources() {
721
+ expected_npu=$1
722
+ timeout_seconds=${2:-900}
723
+ begin_ts=$(date +%s)
724
+
725
+ while true; do
726
+ total_npu=$(python3 - <<'PY' 2>/dev/null
727
+ import ray
728
+
729
+ try:
730
+ ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
731
+ print(int(ray.cluster_resources().get("NPU", 0)))
732
+ ray.shutdown()
733
+ except Exception:
734
+ print(0)
735
+ PY
736
+ )
737
+ total_npu=${total_npu:-0}
738
+ now_ts=$(date +%s)
739
+ elapsed=$((now_ts - begin_ts))
740
+
741
+ echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
742
+ ray status || true
743
+
744
+ if [ "${total_npu}" -ge "${expected_npu}" ]; then
745
+ echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
746
+ break
747
+ fi
748
+
749
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
750
+ echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
751
+ return 1
752
+ fi
753
+
754
+ sleep 5
755
+ done
756
+ }
757
+
758
+ wait_for_verifier_api() {
759
+ api_url="${mock_api_base}/models"
760
+ timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
761
+ begin_ts=$(date +%s)
762
+ last_diag_ts=0
763
+ while true; do
764
+ verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
765
+ import socket
766
+ import sys
767
+ import urllib.parse
768
+ import urllib.request
769
+
770
+ url = sys.argv[1]
771
+ parsed = urllib.parse.urlparse(url)
772
+ host = parsed.hostname
773
+ port = parsed.port or (443 if parsed.scheme == "https" else 80)
774
+ print(f"check url={url} host={host} port={port}")
775
+ try:
776
+ infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
777
+ print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
778
+ except Exception as exc:
779
+ print(f"dns_error={type(exc).__name__}: {exc}")
780
+ raise SystemExit(1)
781
+ try:
782
+ with socket.create_connection((host, port), timeout=5):
783
+ print("tcp=ok")
784
+ except Exception as exc:
785
+ print(f"tcp_error={type(exc).__name__}: {exc}")
786
+ raise SystemExit(1)
787
+ try:
788
+ with urllib.request.urlopen(url, timeout=10) as response:
789
+ print(f"http_status={response.status}")
790
+ raise SystemExit(0 if 200 <= response.status < 300 else 1)
791
+ except Exception as exc:
792
+ print(f"http_error={type(exc).__name__}: {exc}")
793
+ raise SystemExit(1)
794
+ PY
795
+ )
796
+ check_rc=$?
797
+ if [ "${check_rc}" = "0" ]; then
798
+ echo "Verifier API is ready: ${api_url}"
799
+ echo "${verifier_check_output}"
800
+ break
801
+ fi
802
+ now_ts=$(date +%s)
803
+ elapsed=$((now_ts - begin_ts))
804
+ echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
805
+ if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
806
+ last_diag_ts=${now_ts}
807
+ echo "--- verifier API check diagnostics ---"
808
+ echo "${verifier_check_output}"
809
+ echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
810
+ echo "--- check verifier node log: ${verifier_api_log} ---"
811
+ echo "--------------------------------------"
812
+ fi
813
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
814
+ echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
815
+ echo "Last verifier API diagnostics:" >&2
816
+ echo "${verifier_check_output}" >&2
817
+ return 1
818
+ fi
819
+ sleep 10
820
+ done
821
+ }
822
+
823
+ # ================= Nanoclaw workspace 根目录 =================
824
+ mkdir -p "${nanoclaw_temp_root}"
825
+ if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
826
+ echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
827
+ exit 2
828
+ fi
829
+ rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
830
+ if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
831
+ echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
832
+ echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
833
+ fi
834
+ echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
835
+ echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
836
+ echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
837
+ echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
838
+
839
+ # ================= 生成 Ray runtime env =================
840
+ RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
841
+ cat > "${RUNTIME_ENV_FILE}" <<YAML
842
+ working_dir: ./
843
+ excludes: ["/.git/", "/logs/", "/checkpoint/"]
844
+ env_vars:
845
+ TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
846
+ CUDA_DEVICE_MAX_CONNECTIONS: "1"
847
+ HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
848
+ HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
849
+ HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
850
+ HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
851
+ HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
852
+ HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
853
+ HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
854
+ P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
855
+ VLLM_USE_V1: "${VLLM_USE_V1}"
856
+ VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
857
+ VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
858
+ VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
859
+ VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
860
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
861
+ TOKENIZERS_PARALLELISM: "false"
862
+ HYDRA_FULL_ERROR: "1"
863
+ PYTHONUNBUFFERED: "1"
864
+ RAY_DEDUP_LOGS: "0"
865
+ WANDB_MODE: "${WANDB_MODE}"
866
+ MOCK_API_BASE: "${mock_api_base}"
867
+ MOCK_API_KEY: "${mock_api_key}"
868
+ MOCK_MODEL_NAME: "${mock_model_name}"
869
+ MOCK_API_TIMEOUT: "${mock_api_timeout}"
870
+ MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
871
+ NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
872
+ NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
873
+ NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
874
+ NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
875
+ NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
876
+ NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
877
+ NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
878
+ NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
879
+ NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
880
+ NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
881
+ NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
882
+ NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
883
+ NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
884
+ NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
885
+ NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
886
+ NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
887
+ NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
888
+ NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
889
+ NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
890
+ YAML
891
+
892
+ # ================= 启动 Ray 多机集群 =================
893
+ if [ "${NODE_RANK}" = "0" ]; then
894
+ echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
895
+ ray start --head \
896
+ --node-ip-address=${RAY_NODE_IP} \
897
+ --port=${RAY_PORT} \
898
+ --dashboard-host=0.0.0.0 \
899
+ --dashboard-port=${DASHBOARD_PORT} \
900
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
901
+ --disable-usage-stats \
902
+ --block &
903
+
904
+ sleep 10
905
+ wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
906
+ wait_for_verifier_api || exit 1
907
+ else
908
+ echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
909
+ sleep 20
910
+ ray start --address=${MASTER_ADDR}:${RAY_PORT} \
911
+ --node-ip-address=${RAY_NODE_IP} \
912
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
913
+ --disable-usage-stats \
914
+ --block &
915
+ sleep 10
916
+ fi
917
+
918
+ # ================= 训练参数数组 =================
919
+ training_args=(
920
+ python3 -m verl.trainer.main_ppo
921
+ +ray_kwargs.ray_init.address=auto
922
+ reward.num_workers=${reward_num_workers}
923
+ algorithm.adv_estimator=${adv_estimator}
924
+ algorithm.gamma=${algorithm_gamma}
925
+ algorithm.lam=${algorithm_lam}
926
+ algorithm.use_kl_in_reward=${use_kl_in_reward}
927
+ algorithm.kl_penalty=${kl_penalty}
928
+ algorithm.kl_ctrl.type=${kl_ctrl_type}
929
+ algorithm.kl_ctrl.kl_coef=${kl_coef}
930
+ algorithm.rollout_correction.bypass_mode=False
931
+ data.train_files="${train_files}"
932
+ data.val_files="${test_files}"
933
+ data.return_raw_chat=True
934
+ data.return_multi_modal_inputs=False
935
+ data.image_key=images
936
+ data.shuffle=True
937
+ data.train_batch_size=${train_batch_size}
938
+ data.max_prompt_length=${max_prompt_length}
939
+ data.max_response_length=${max_response_length}
940
+ data.filter_overlong_prompts=True
941
+ data.truncation=error
942
+ data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
943
+ data.custom_cls.name=CustomRLHFDataset
944
+ "data.tool_config_path=${tool_config_path}"
945
+ "+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
946
+ "+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
947
+ "+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
948
+ "+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
949
+ "+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
950
+ "+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
951
+ "+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
952
+ "+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
953
+ +data.apply_chat_template_kwargs.enable_thinking=True
954
+ reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
955
+ reward.custom_reward_function.name=compute_score
956
+ "+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
957
+ "+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
958
+ "+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
959
+ "+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
960
+ "+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
961
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
962
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
963
+ "+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
964
+ "+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
965
+ "+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
966
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
967
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
968
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
969
+ "+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
970
+ "+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
971
+ "+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
972
+ "+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
973
+ "+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
974
+ actor_rollout_ref.model.path=${model_path}
975
+ actor_rollout_ref.model.use_remove_padding=True
976
+ actor_rollout_ref.model.enable_gradient_checkpointing=True
977
+ actor_rollout_ref.model.enable_activation_offload=${enable_activation_offload}
978
+ actor_rollout_ref.model.use_fused_kernels=${use_fused_kernels}
979
+ actor_rollout_ref.model.fused_kernel_options.impl_backend=${fused_kernel_backend}
980
+ actor_rollout_ref.actor.strategy=${actor_strategy}
981
+ actor_rollout_ref.ref.strategy=${actor_strategy}
982
+ actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
983
+ actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
984
+ actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
985
+ actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
986
+ actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
987
+ actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
988
+ actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
989
+ actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
990
+ actor_rollout_ref.actor.shuffle=${actor_shuffle}
991
+ actor_rollout_ref.actor.optim.lr=${actor_lr}
992
+ actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
993
+ actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
994
+ actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
995
+ "actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
996
+ actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
997
+ actor_rollout_ref.actor.use_dynamic_bsz=True
998
+ actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
999
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
1000
+ actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
1001
+ actor_rollout_ref.actor.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1002
+ actor_rollout_ref.actor.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1003
+ actor_rollout_ref.actor.entropy_checkpointing=${entropy_checkpointing}
1004
+ actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
1005
+ actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
1006
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1007
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1008
+ actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1009
+ actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
1010
+ actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
1011
+ actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1012
+ actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
1013
+ actor_rollout_ref.ref.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1014
+ actor_rollout_ref.ref.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1015
+ actor_rollout_ref.ref.entropy_checkpointing=${entropy_checkpointing}
1016
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
1017
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
1018
+ actor_rollout_ref.ref.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
1019
+ actor_rollout_ref.rollout.name=vllm
1020
+ actor_rollout_ref.rollout.mode=async
1021
+ actor_rollout_ref.rollout.calculate_log_probs=True
1022
+ actor_rollout_ref.rollout.temperature=${rollout_temperature}
1023
+ actor_rollout_ref.rollout.top_p=${rollout_top_p}
1024
+ actor_rollout_ref.rollout.top_k=${rollout_top_k}
1025
+ actor_rollout_ref.rollout.min_p=${rollout_min_p}
1026
+ actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
1027
+ actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
1028
+ actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
1029
+ actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
1030
+ actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
1031
+ actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
1032
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
1033
+ actor_rollout_ref.rollout.enable_chunked_prefill=True
1034
+ actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
1035
+ actor_rollout_ref.rollout.free_cache_engine=True
1036
+ actor_rollout_ref.rollout.enforce_eager=False
1037
+ actor_rollout_ref.rollout.enable_prefix_caching=False
1038
+ actor_rollout_ref.rollout.multi_turn.enable=True
1039
+ actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
1040
+ actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
1041
+ actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
1042
+ "actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
1043
+ actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
1044
+ "actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
1045
+ actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
1046
+ actor_rollout_ref.rollout.n=${n_resp_per_prompt}
1047
+ actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
1048
+ actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
1049
+ actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
1050
+ actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
1051
+ actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
1052
+ actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
1053
+ actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
1054
+ actor_rollout_ref.rollout.val_kwargs.do_sample=True
1055
+ actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
1056
+ actor_rollout_ref.actor.use_torch_compile=False
1057
+ actor_rollout_ref.ref.use_torch_compile=False
1058
+ actor_rollout_ref.actor.use_torch_compile=False
1059
+ actor_rollout_ref.ref.use_torch_compile=False
1060
+ actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
1061
+ actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
1062
+ critic.fsdp.use_torch_compile=False
1063
+ trainer.use_v1=${trainer_use_v1}
1064
+ trainer.v1.trainer_mode=sync
1065
+ trainer.critic_warmup=0
1066
+ trainer.balance_batch=True
1067
+ trainer.logger=['console','tensorboard']
1068
+ trainer.project_name=${project_name}
1069
+ trainer.experiment_name=${experiment_name}
1070
+ trainer.nnodes=${NNODES}
1071
+ trainer.n_gpus_per_node=${NPUS_PER_NODE}
1072
+ trainer.val_before_train=${val_before_train}
1073
+ trainer.log_val_generations=${log_val_generations}
1074
+ trainer.save_freq=${save_freq}
1075
+ trainer.default_local_dir=${default_local_dir}
1076
+ trainer.resume_mode=disable
1077
+ trainer.test_freq=${test_freq}
1078
+ trainer.total_epochs=10
1079
+ trainer.total_training_steps=${total_training_steps}
1080
+ )
1081
+
1082
+ if [ -n "${fsdp_size}" ]; then
1083
+ training_args+=(
1084
+ actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
1085
+ actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
1086
+ )
1087
+ fi
1088
+
1089
+ if [ -n "${nanoclaw_task_ids}" ]; then
1090
+ training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
1091
+ fi
1092
+
1093
+ if [ -n "${nanoclaw_max_steps}" ]; then
1094
+ training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
1095
+ fi
1096
+
1097
+ # ================= 启动训练主进程:仅主节点执行 =================
1098
+ if [ "${NODE_RANK}" = "0" ]; then
1099
+ echo "--> [Head Node] Starting VERL unified engine training..."
1100
+ echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
1101
+ echo "DEBUG: entrypoint=${training_args[*]}"
1102
+
1103
+ ray job submit \
1104
+ --address="http://127.0.0.1:${DASHBOARD_PORT}" \
1105
+ --runtime-env="${RUNTIME_ENV_FILE}" \
1106
+ -- \
1107
+ "${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
1108
+ else
1109
+ echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
1110
+ tail -f /dev/null
1111
+ fi
verl_0720_main/mindspeed_config.yaml ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defaults:
2
+ - model:
3
+ - qwen25_32b
4
+
5
+ megatron_training:
6
+ use_ascend_coc: True
7
+ coc_fused_kernel: True
8
+ coc_parallel_num: 2
9
+ model: qwen25_32b
10
+ tokenizer_type: PretrainedFromHF
11
+ tokenizer_name_or_path: /opt/huawei/dataset/zyr_ulan/models/Qwen2.5-32B-Instruct
12
+ data_path: /opt/huawei/dataset/zyr_ulan/lyf/datasets/code_only_gemini3_and_gsm8k_train/gemini3_only/data_english_train_gemini3_to_train_clean_1/data_english_train_gemini3_to_train_clean_1
13
+ variable_seq_lengths: true
14
+ global_batch_size: 128
15
+ use_fused_rmsnorm: true
16
+ use_mcore_models: true
17
+ sequence_parallel: true
18
+ use_flash_attn: true
19
+ no_masked_softmax_fusion: true
20
+ attention_softmax_in_fp32: true
21
+ no_gradient_accumulation_fusion: true
22
+ use_fused_swiglu: true
23
+ use_fused_rotary_pos_emb: true
24
+ bf16: true
25
+ save_interval: 100
26
+ train_iters: 200
27
+ seq_length: 8192
28
+ stage: ray_grpo
29
+ attention_dropout: 0.0
30
+ init_method_std: 0.01
31
+ hidden_dropout: 0.0
32
+ distributed_backend: nccl
33
+ no_shared_storage: true
34
+ dataset_additional_keys: ['labels', 'id', 'llm_checker', 'code_checker']
35
+ split: 100,0,0
36
+ no_shuffle: false
37
+ full_shuffle_instruction_dataset: false
38
+ seed: 1
39
+ reuse_fp32_param: false
40
+ recompute_granularity: 'full'
41
+ recompute_method: 'uniform'
42
+ recompute_num_layers: 1
43
+ use_distributed_optimizer: true
44
+ swap_attention: true
45
+ reset_position_ids: true
46
+
47
+ actor_config:
48
+ model: qwen25_32b
49
+ tensor_model_parallel_size: 4
50
+ pipeline_model_parallel_size: 4
51
+ micro_batch_size: 4
52
+ lr: 1e-6
53
+ lr_decay_style: constant
54
+ min_lr: 0
55
+ weight_decay: 0.01
56
+ lr_warmup_fraction: 0.0
57
+ clip_grad: 1.0
58
+ adam_beta1: 0.9
59
+ adam_beta2: 0.95
60
+ finetune: true
61
+ load: /opt/huawei/dataset/zyr_ulan/models/qwen2.5-32b/Qwen2.5-32B-Instruct-pp4tp4/
62
+ save: /opt/huawei/dataset/zyr_ulan/lyf/models/save/stage_sft_0831/stage_RL/qwen_32b_instruct_RL_lyf_if_code_only_gemini3data_only/
63
+ no_load_optim: true
64
+ no_load_rng: true
65
+
66
+ rl_config:
67
+ is_qwen3: false
68
+ full_satisfaction_bonus: 0.0
69
+ code_checker_failure_prob: 0.0
70
+ reward_scaling_strategy: "linear"
71
+ tag_style: 'angle'
72
+ prompt_style: 'v2'
73
+ granular_acc_factor: 0.0
74
+ thinking_bonus: 0.0
75
+ thinking_penalty: 0.0
76
+ use_integrated_worker: true
77
+ guarantee_order: false
78
+ blocking: true
79
+ actor_forward_micro_batch_size: 4
80
+ ref_forward_micro_batch_size: 4
81
+ kl_penalty: low_var_kl
82
+ shuffle_mini_batch: false
83
+ log_max_throughput: false
84
+ num_cpus_for_local_task: 1.0
85
+ use_tensorboard: true
86
+ gamma: 1.0
87
+ lam: 0.95
88
+ adv_estimator: group_norm
89
+ kl_ctrl_type: fixed
90
+ init_kl_coef: 0.001
91
+ mini_batch_size: 128
92
+ max_prompt_length: 2048
93
+ rollout_max_tokens: 6144
94
+ epochs: 1
95
+ clip_ratio: 0.2
96
+ entropy_coeff: 0.0
97
+ n_samples_per_prompt: 8
98
+ rule_reward: true
99
+ use_remove_padding: true
100
+ verifier_function: ["llm_checker", "code_checker"]
101
+ verifier_weight: [0.7, 0.3]
102
+ overlong_buffer_enable: true
103
+ overlong_buffer: 1536
104
+ overlong_buffer_penalty_factor: 0.0
105
+ use_wandb: false
106
+ actor_resource:
107
+ num_npus: 32
108
+
109
+ generate_config:
110
+ trust_remote_code: true
111
+ offload_train_optimizer: true
112
+ offload_train_grad: true
113
+ offload_train_param: true
114
+ infer_tensor_parallel_size: 4
115
+ infer_pipeline_parallel_size: 1
116
+ infer_expert_parallel_size: 1
117
+ max_num_seqs: 256
118
+ max_model_len: 8192
119
+ max_num_batched_tokens: 8192
120
+ dtype: "bfloat16"
121
+ gpu_memory_utilization: 0.6
122
+ sampling_config:
123
+ logprobs: 1
124
+ max_tokens: 6144
125
+ top_p: 1.0
126
+ top_k: -1
127
+ min_p: 0.0
128
+ temperature: 1.0
129
+ detokenize: false
130
+
131
+ profiler_config:
132
+ use_profiler: false
verl_0720_main/mindspeed_config.yamlZone.Identifier ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=https://huggingface.co/datasets/geminiDeveloper/contextBenchmark/tree/main/0720
4
+ HostUrl=https://huggingface.co/api/resolve-cache/datasets/geminiDeveloper/contextBenchmark/94e9154f5f65b80efb1223a4cdb0bf6cc533351d/0720%2Fmindspeed_config.yaml?download=true&etag=%2254e2c117c570ccdcb2383ba81e3d205f23046776%22
verl_0720_main/nanoclaw_qwen35_sp1_16k_stable_full.sh ADDED
@@ -0,0 +1,1059 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Qwen3.5 Nanoclaw 多轮 GRPO 训练脚本 — VERL 0720 + NPU SP1/16K 独立稳定版
3
+ #
4
+ # 关键修改:
5
+ # 1) 入口改为 python3 -m verl.trainer.main_ppo,不再使用 recipe.grpo_mindspeed_mm.main_ppo;
6
+ # 2) 不再使用 MM_CONFIG_FILE / MindSpeed-MM YAML;
7
+ # 3) 显式 text-only:data.return_multi_modal_inputs=False;
8
+ # 4) 数据输入改为 Nanoclaw base_tasks 目录,不再使用 Retool parquet/json;
9
+ # 5) 保留 27B 作业验证过的 HCCL buffer 与端口范围,降低 HcclAllreduce socket/资源压力;
10
+ # 6) 默认 val n=1、log_val_generations=10,先验证训练稳定性;
11
+ # 7) 稳定版固定使用已经完成初始化与 rollout 验证的 FSDP1/offload 形状。
12
+ # 8) 使用最新版 VERL V1/TransferQueue 和 nanoclaw_recipe,并按参考 YAML 的训练意图映射优化器与 KL;
13
+ # 9) actor/ref 的全词表 entropy 使用 256-token 分块,避免 16K SP1 old-log-prob 阶段产生十几 GiB 临时张量。
14
+
15
+ set -x
16
+
17
+ # ================= 独立稳定版:强制 Qwen3.5 NPU SP1 + 16K =================
18
+ # 不允许外部作业环境把这些核心安全参数覆盖回 SP8/31K。
19
+ export TRAIN_SP=1
20
+ export QWEN35_FLA_BACKEND=disabled
21
+ export MAX_PROMPT_LENGTH=8192
22
+ export MAX_RESPONSE_LENGTH=8192
23
+ export MAX_ASSISTANT_RESPONSE_LENGTH=8192
24
+ export MAX_TOOL_RESPONSE_LENGTH=8192
25
+ export ACTOR_MAX_TOKEN_LEN_PER_GPU=16384
26
+ export LOG_PROB_MAX_TOKEN_LEN_PER_GPU=16384
27
+ export ROLLOUT_MAX_NUM_BATCHED_TOKENS=16384
28
+ export ACTOR_STRATEGY=fsdp
29
+ export OFFLOAD=True
30
+ # 当前 VERL 的 checkpointing 分支不会传递自定义 chunk size;稳定版明确关闭它,确保实际使用 256。
31
+ export ENTROPY_FROM_LOGITS_WITH_CHUNKING=True
32
+ export ENTROPY_FROM_LOGITS_CHUNK_SIZE=256
33
+ export ENTROPY_CHECKPOINTING=False
34
+
35
+
36
+ npu-smi info || true
37
+ pip install --upgrade pip
38
+ pip uninstall -y moxing-framework || true
39
+
40
+ # ================= 路径配置 =================
41
+ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
42
+ if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
43
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
44
+ elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
45
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}
46
+ else
47
+ DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
48
+ fi
49
+ WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
50
+ INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
51
+ BKGS=${BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs}
52
+ chmod 755 "${INSTALL_DIR}"
53
+
54
+ # Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
55
+
56
+ GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
57
+ COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-/opt/huawei/dataset/zyr_yuyin/bkgs/gcc-11.3.0-compiled-aarch64.tar.gz}
58
+
59
+ echo "--> 正在从缓存恢复 GCC 11.3.0..."
60
+ tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
61
+ export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
62
+ export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
63
+ export CC=${GCC_INSTALL_PREFIX}/bin/gcc
64
+ export CXX=${GCC_INSTALL_PREFIX}/bin/g++
65
+ echo "--> 验证 GCC 版本:"
66
+ gcc --version
67
+
68
+ cd "${BKGS}"
69
+ cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
70
+
71
+ VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-05-12/verl_new_26_05_09/pkgs}
72
+ rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
73
+ cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
74
+ cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
75
+
76
+ CANN_BKGS=${CANN_BKGS:-/opt/huawei/dataset/zyr_yuyin/bkgs/cann_0527}
77
+ cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
78
+ cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
79
+ cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
80
+
81
+ echo "################"
82
+ echo "## set verl env"
83
+ echo "################"
84
+
85
+ cd "${INSTALL_DIR}"
86
+
87
+ chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
88
+ bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
89
+ source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
90
+
91
+ chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
92
+ bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
93
+
94
+ chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
95
+ bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
96
+ source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
97
+
98
+ export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
99
+ export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
100
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
101
+
102
+ pip3 install torch==2.9.0
103
+ pip3 install pyyaml setuptools
104
+ pip3 install torch-npu==2.9.0
105
+ pip3 install torchvision==0.24.0 torchaudio==2.9.0
106
+
107
+ ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
108
+ export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
109
+ pip install pybind11==2.13.6
110
+
111
+ cd "${INSTALL_DIR}/vllm"
112
+ VLLM_TARGET_DEVICE=empty pip install .
113
+
114
+ cd "${INSTALL_DIR}/vllm-ascend"
115
+ pip install -e .
116
+ export VLLM_LOGGING_LEVEL=INFO
117
+
118
+ cd "${INSTALL_DIR}"
119
+ tar -xvf jemalloc-5.3.0.tar.bz2
120
+ cd jemalloc-5.3.0
121
+ ./configure --prefix="${INSTALL_DIR}"
122
+ make -j"$(nproc)"
123
+ make install
124
+ export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
125
+
126
+ # # ================= 可选:安装 MindSpeed 栈 =================
127
+ # # 纯 VERL engine 路线不依赖 MindSpeed-MM YAML。默认不安装,避免和新版 VERL engine 混淆。
128
+ # INSTALL_MINDSPEED_STACK=${INSTALL_MINDSPEED_STACK:-0}
129
+ # if [ "${INSTALL_MINDSPEED_STACK}" = "1" ]; then
130
+ # MindSpeed_PATH=${MindSpeed_PATH:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-slow-stable}
131
+ # cd "${MindSpeed_PATH}"
132
+ # cd Megatron-LM && pip install -e . --no-deps && cd ..
133
+ # cd MindSpeed && pip install -e . --no-deps && cd ..
134
+ # cd MindSpeed-MM && mkdir -p logs data ckpt && pip install -e . --no-deps && cd ..
135
+ # pip install beartype bs4 diffusers==0.30.3 ftfy imageio-ffmpeg pandarallel pytest-mock
136
+ # else
137
+ # echo "--> Skip MindSpeed/MindSpeed-MM installation for pure VERL engine route."
138
+ # fi
139
+
140
+
141
+
142
+ # ================= 安装 Triton-Ascend 3.2.1 =================
143
+ # 1. 卸载 triton(增加 -y 自动确认)
144
+ pip uninstall -y triton
145
+
146
+ # 2. 卸载 triton-ascend(增加 -y 自动确认)
147
+ pip uninstall -y triton-ascend
148
+ pip install --no-cache-dir --force-reinstall triton==3.5.0
149
+ pip install --no-deps /opt/huawei/dataset/zyr_yuyin/bkgs/triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
150
+
151
+
152
+ # ================= 安装新版 VERL =================
153
+ cd "${WORK_DIR}"
154
+ pip install -r requirements-npu.txt
155
+ # NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
156
+ python3 -m pip install -e . --no-deps
157
+ pip install --upgrade 'urllib3==1.26.11'
158
+ pip install loguru
159
+ pip install tree_sitter==0.21.3
160
+ pip install tree-sitter-java==0.21.0
161
+ pip install tree-sitter-javascript==0.21.4
162
+
163
+ ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
164
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
165
+ echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
166
+
167
+ pip uninstall -y transformers || true
168
+ pip install transformers==5.3.0
169
+ pip install accelerate==1.13.0 mathruler
170
+ pip install jsonargparse
171
+ pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
172
+
173
+ # 稳定版只允许 SP=1:不安装普通 FLA,也不进入尚未完成 NPU 适配的 Ulysses CP。
174
+ if [ "${TRAIN_SP}" != "1" ]; then
175
+ echo "ERROR: the standalone stable profile requires TRAIN_SP=1; got ${TRAIN_SP}." >&2
176
+ exit 2
177
+ fi
178
+ export NANOCLAW_REQUIRE_FLA=0
179
+ echo "--> Stable SP1: flash-linear-attention is disabled; Qwen3.5 will not build an Ulysses CP context."
180
+
181
+ # Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
182
+ # 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
183
+ NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
184
+ PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
185
+ SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
186
+ SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
187
+ python3 -m pip install --no-cache-dir --force-reinstall \
188
+ "numpy==${NUMPY_VERSION}" \
189
+ "pandas==${PANDAS_VERSION}" \
190
+ "scipy==${SCIPY_VERSION}" \
191
+ "scikit-learn==${SKLEARN_VERSION}"
192
+
193
+ python3 - <<'PY' || exit 2
194
+ import numpy
195
+ import pandas
196
+ import scipy
197
+ import sklearn
198
+ import sys
199
+ import transformers
200
+ import vllm
201
+
202
+ fla_version = "disabled-sp1"
203
+
204
+ print(
205
+ "[python_stack_preflight] "
206
+ f"python={sys.executable} "
207
+ f"numpy={numpy.__version__} "
208
+ f"pandas={pandas.__version__} "
209
+ f"scipy={scipy.__version__} "
210
+ f"sklearn={sklearn.__version__} "
211
+ f"transformers={transformers.__version__} "
212
+ f"vllm={vllm.__version__} "
213
+ f"fla={fla_version}"
214
+ )
215
+ print(
216
+ "[python_stack_paths] "
217
+ f"numpy={numpy.__file__} "
218
+ f"pandas={pandas.__file__}"
219
+ )
220
+ PY
221
+ pip list
222
+
223
+ # ================= 检查 Nanoclaw recipe =================
224
+ if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
225
+ echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
226
+ exit 2
227
+ fi
228
+ test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
229
+
230
+ # Qwen3.5 MRoPE position_ids 是 3/4 轴张量。未应用此补丁时,NPU
231
+ # FlashAttention 会把 seqLen 重复累计(例如 T=10131、sum(seqLen)=30393)。
232
+ QWEN35_MONKEY_PATCH_FILE=${WORK_DIR}/verl/models/transformers/monkey_patch.py
233
+ if [ ! -f "${QWEN35_MONKEY_PATCH_FILE}" ] || ! grep -q "def _normalize_fa_position_ids" "${QWEN35_MONKEY_PATCH_FILE}"; then
234
+ echo "ERROR: Qwen3.5 FlashAttention position_ids normalization patch is missing: ${QWEN35_MONKEY_PATCH_FILE}" >&2
235
+ echo "Upload the modified verl/ directory together with this standalone script." >&2
236
+ exit 2
237
+ fi
238
+
239
+ # ================= PLOG =================
240
+ ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
241
+ task_name=worker-${VC_TASK_INDEX}
242
+ task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
243
+ mkdir -p "${task_plog_path}"
244
+ export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
245
+ echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
246
+
247
+ MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
248
+ MASTER_PORT=${PORT}
249
+ MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
250
+
251
+ cd "${WORK_DIR}"
252
+
253
+ mkdir -p /cache/ray_tmp
254
+
255
+ echo "Cleaning up old Ray processes..."
256
+ ray stop --force || true
257
+ sleep 5
258
+ rm -rf /cache/ray_tmp/*
259
+ pkill -9 -f raylet || true
260
+ pkill -9 -f plasma_store || true
261
+ pkill -9 -f gcs_server || true
262
+ echo "Waiting 20s for NPU/Ray resources to be released..."
263
+ npu-smi info || true
264
+ sleep 20
265
+
266
+ # ================= NPU / HCCL / Ray 环境 =================
267
+ export NON_MEGATRON=true
268
+ export MULTI_STREAM_MEMORY_REUSE=2
269
+ export OMP_NUM_THREADS=1
270
+ export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
271
+ export VLLM_LOGGING_LEVEL=INFO
272
+ export RAY_DEDUP_LOGS=0
273
+ export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
274
+ export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
275
+ export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
276
+ export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
277
+ export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
278
+ export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
279
+
280
+ # 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
281
+ export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
282
+ export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
283
+ export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
284
+ export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
285
+
286
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
287
+ export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
288
+ export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
289
+ export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
290
+ export WANDB_MODE=${WANDB_MODE:-disabled}
291
+ export PYTHONUNBUFFERED=1
292
+ export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
293
+ export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
294
+ export TOKENIZERS_PARALLELISM=false
295
+ export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
296
+ export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
297
+ export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
298
+ export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
299
+ export VLLM_USE_V1=${VLLM_USE_V1:-1}
300
+ export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
301
+ export HYDRA_FULL_ERROR=1
302
+ export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
303
+ export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
304
+ export RAY_timeout_ms=${RAY_timeout_ms:-600000}
305
+ export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
306
+ export RAY_USAGE_STATS_ENABLED=0
307
+ export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
308
+
309
+ ulimit -n 65536
310
+
311
+ # Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
312
+ export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
313
+
314
+ # ================= 路径与数据配置 =================
315
+ HDFS_ROOT=${HDFS_ROOT:-$PWD}
316
+ DATA_ROOT=${DATA_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_ckpt}
317
+
318
+ # Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
319
+ # base_tasks/data_*/env_builder.py
320
+ # base_tasks/data_*/prompts.md
321
+ # base_tasks/data_*/workplace_verifier.py
322
+ # base_tasks/data_*/manifest.json
323
+ # 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
324
+ DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/nanoclawRLdata/0710_add1000agent_qwen3_7_max_v1/exported_new_data}
325
+ train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
326
+ val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
327
+ train_files="['$train_base_tasks']"
328
+ test_files="['$val_base_tasks']"
329
+
330
+ if [ ! -d "${train_base_tasks}" ]; then
331
+ echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
332
+ exit 2
333
+ fi
334
+ if [ ! -d "${val_base_tasks}" ]; then
335
+ echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
336
+ exit 2
337
+ fi
338
+
339
+ model_path=${MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-27B}
340
+ verifier_model_path=${VERIFIER_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
341
+ # 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
342
+ unset MM_CONFIG_FILE || true
343
+
344
+ # Nanoclaw 工具配置
345
+ tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
346
+ nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
347
+ nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
348
+ # 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
349
+ nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/verl-nanoclaw-rl/nanoclawRL_temp_workplace_v14_qwen35_27b_16k}
350
+ # 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
351
+ nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
352
+ nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
353
+ nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
354
+ nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
355
+ nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
356
+ nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
357
+ nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
358
+ nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
359
+ nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
360
+ nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
361
+ nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
362
+ nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
363
+ nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
364
+ nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
365
+ nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-35}
366
+ nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
367
+ nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
368
+ nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
369
+ nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
370
+ nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
371
+ nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
372
+
373
+ # verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
374
+ # 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
375
+ verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
376
+ verifier_api_port=${VERIFIER_API_PORT:-8000}
377
+ verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
378
+ verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
379
+ verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
380
+ # 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM 内置 DP 统一服务。
381
+ # 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
382
+ verifier_api_tp=${VERIFIER_API_TP:-4}
383
+ verifier_api_dp=${VERIFIER_API_DP:-2}
384
+ verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
385
+ verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
386
+ verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
387
+ verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
388
+ verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
389
+ verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
390
+ verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
391
+ verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
392
+ verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
393
+ verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
394
+ verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
395
+ mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
396
+ mock_api_key=${MOCK_API_KEY:-dummy_key}
397
+ mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
398
+ # verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
399
+ mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
400
+ mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
401
+ # 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
402
+ nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
403
+ nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
404
+ # 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
405
+ nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
406
+ # verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
407
+ reward_num_workers=${REWARD_NUM_WORKERS:-52}
408
+
409
+ project_name=${PROJECT_NAME:-qwen3.5-27b_nanoclaw_grpo_verl_0720}
410
+ experiment_name=${EXPERIMENT_NAME:-qwen3.5-27b_nanoclaw_grpo_16k_verl0720_lr1e6_fixedkl1e-3}
411
+ default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
412
+ start_time=$(date +%Y%m%d)_$(date +%H%M%S)
413
+ mkdir -p logs "${default_local_dir}"
414
+
415
+ # ================= 算法与并行参数 =================
416
+ adv_estimator=grpo
417
+ max_turns=${MAX_TURNS:-30}
418
+ max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
419
+ max_response_length=${MAX_RESPONSE_LENGTH:-22768}
420
+ max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
421
+ max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
422
+ max_model_len=$((max_prompt_length + max_response_length))
423
+
424
+ # MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
425
+ actor_lr=${ACTOR_LR:-1e-6}
426
+ actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
427
+ actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
428
+ actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
429
+ actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
430
+ actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
431
+ actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
432
+ actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
433
+ actor_shuffle=${ACTOR_SHUFFLE:-False}
434
+ actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
435
+ actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
436
+ actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
437
+ # MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
438
+ actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
439
+
440
+ # YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
441
+ algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
442
+ algorithm_lam=${ALGORITHM_LAM:-0.95}
443
+ use_kl_in_reward=${USE_KL_IN_REWARD:-True}
444
+ kl_penalty=${KL_PENALTY:-low_var_kl}
445
+ kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
446
+ kl_coef=${KL_COEF:-0.001}
447
+ # 关闭 actor-KL,避免与 reward-KL 重复惩罚。
448
+ actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
449
+ actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
450
+ actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
451
+
452
+ train_batch_size=${TRAIN_BATCH_SIZE:-64}
453
+ ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
454
+ n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
455
+ # 先压低验证,避免验证和训练稳定性混在一起。
456
+ n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
457
+ log_val_generations=${LOG_VAL_GENERATIONS:-10}
458
+
459
+ infer_tp=${INFER_TP:-4}
460
+ train_sp=${TRAIN_SP:-1}
461
+ offload=${OFFLOAD:-True}
462
+
463
+ # 稳定版固定沿用已经完成初始化与 rollout 验证的 FSDP1/offload 形状。
464
+ actor_strategy=${ACTOR_STRATEGY:-fsdp}
465
+ fsdp_size=${FSDP_SIZE:-}
466
+
467
+ actor_pack=${ACTOR_PACK:-1}
468
+ logprob_pack=${LOGPROB_PACK:-2}
469
+ actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
470
+ log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
471
+ entropy_from_logits_with_chunking=${ENTROPY_FROM_LOGITS_WITH_CHUNKING:-True}
472
+ entropy_from_logits_chunk_size=${ENTROPY_FROM_LOGITS_CHUNK_SIZE:-256}
473
+ entropy_checkpointing=${ENTROPY_CHECKPOINTING:-False}
474
+ rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
475
+ rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
476
+ update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-8192}
477
+
478
+ # Qwen 官方推荐:Instruct/non-thinking reasoning tasks
479
+ rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
480
+ rollout_top_p=${ROLLOUT_TOP_P:-0.95}
481
+ rollout_top_k=${ROLLOUT_TOP_K:-20}
482
+ rollout_min_p=${ROLLOUT_MIN_P:-0.0}
483
+ rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
484
+ rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
485
+ rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
486
+
487
+ echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
488
+ echo "DEBUG: max_turns=${max_turns}"
489
+ echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
490
+ echo "DEBUG: entropy_chunking=${entropy_from_logits_with_chunking}, entropy_chunk_size=${entropy_from_logits_chunk_size}, entropy_checkpointing=${entropy_checkpointing}"
491
+ echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
492
+ echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
493
+ echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
494
+ echo "DEBUG: actor_max_token_len_per_gpu=${actor_max_token_len_per_gpu}, log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}"
495
+ echo "DEBUG: rollout sampling temperature=${rollout_temperature}, top_p=${rollout_top_p}, top_k=${rollout_top_k}, min_p=${rollout_min_p}, presence_penalty=${rollout_presence_penalty}, frequency_penalty=${rollout_frequency_penalty}, repetition_penalty=${rollout_repetition_penalty}"
496
+ echo "DEBUG: optimizer lr=${actor_lr}, scheduler=${actor_lr_scheduler_type}, warmup_ratio=${actor_lr_warmup_steps_ratio}, weight_decay=${actor_weight_decay}, betas=(${actor_adam_beta1},${actor_adam_beta2}), clip_grad=${actor_clip_grad}, ppo_epochs=${actor_ppo_epochs}, shuffle=${actor_shuffle}"
497
+ echo "DEBUG: KL use_in_reward=${use_kl_in_reward}, penalty=${kl_penalty}, ctrl=${kl_ctrl_type}, coef=${kl_coef}, actor_kl=${actor_use_kl_loss}"
498
+ echo "DEBUG: HCCL_BUFFSIZE=${HCCL_BUFFSIZE}, HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE}, HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE}"
499
+
500
+ val_before_train=${VAL_BEFORE_TRAIN:-False}
501
+ trainer_use_v1=${TRAINER_USE_V1:-True}
502
+ test_freq=${TEST_FREQ:-5000}
503
+ save_freq=${SAVE_FREQ:-2}
504
+
505
+ # ================= 分布式 =================
506
+ export TOTAL_NNODES=${TOTAL_NNODES:-5}
507
+ export TRAIN_NNODES=${TRAIN_NNODES:-4}
508
+ export NNODES=${NNODES:-${TRAIN_NNODES}}
509
+ export NODE_RANK=${VC_TASK_INDEX}
510
+ export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
511
+ export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
512
+
513
+ export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
514
+ export MASTER_PORT=${MASTER_PORT:-6167}
515
+ export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
516
+ export RAY_PORT=${RAY_PORT:-6167}
517
+
518
+ readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
519
+ export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
520
+ export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
521
+ export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
522
+ export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
523
+
524
+ export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
525
+
526
+ cat <<EOF
527
+ DEBUG: MASTER_ADDR=${MASTER_ADDR}
528
+ DEBUG: MASTER_PORT=${MASTER_PORT}
529
+ DEBUG: RAY_PORT=${RAY_PORT}
530
+ DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
531
+ DEBUG: CURRENT_IP=${CURRENT_IP}
532
+ DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
533
+ DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
534
+ DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
535
+ DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
536
+ DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
537
+ DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
538
+ DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
539
+ DEBUG: MOCK_API_BASE=${mock_api_base}
540
+ DEBUG: MOCK_MODEL_NAME=${mock_model_name}
541
+ DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
542
+ DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
543
+ DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
544
+ DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
545
+ DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
546
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
547
+ DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
548
+ DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
549
+ DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
550
+ DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
551
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
552
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
553
+ DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
554
+ DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
555
+ DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
556
+ DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
557
+ DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
558
+ DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
559
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
560
+ DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
561
+ DEBUG: VERIFIER_API_TP=${verifier_api_tp}
562
+ DEBUG: VERIFIER_API_DP=${verifier_api_dp}
563
+ DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
564
+ DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
565
+ DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
566
+ DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
567
+ DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
568
+ DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
569
+ EOF
570
+
571
+ if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
572
+ echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
573
+ echo "--> [Verifier API Node] API base: ${mock_api_base}"
574
+ export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
575
+ mkdir -p "$(dirname "${verifier_api_log}")"
576
+ if [ -n "${verifier_api_start_cmd}" ]; then
577
+ echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
578
+ bash -lc "${verifier_api_start_cmd}" &
579
+ verifier_api_pid=$!
580
+ else
581
+ echo "--> [Verifier API Node] Starting default vLLM verifier API..."
582
+ verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
583
+ verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
584
+ if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
585
+ echo "ERROR: verifier TP*DP=${verifier_api_tp}*${verifier_api_dp}=${verifier_api_expected_device_count}, but VERIFIER_API_DEVICES=${verifier_api_devices} contains ${verifier_api_device_count} devices." >&2
586
+ exit 2
587
+ fi
588
+ export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
589
+ verifier_api_args=(
590
+ --model "${verifier_model_path}"
591
+ --tokenizer "${verifier_model_path}"
592
+ --host "${verifier_api_bind_host}"
593
+ --port "${verifier_api_port}"
594
+ --served-model-name "${mock_model_name}"
595
+ --tensor-parallel-size "${verifier_api_tp}"
596
+ --data-parallel-size "${verifier_api_dp}"
597
+ --distributed-executor-backend "${verifier_api_distributed_executor_backend}"
598
+ --dtype bfloat16
599
+ --max-model-len "${verifier_api_max_model_len}"
600
+ --max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
601
+ --max-num-seqs "${verifier_api_max_num_seqs}"
602
+ --gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
603
+ --trust-remote-code
604
+ )
605
+ if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
606
+ verifier_api_args+=(--enforce-eager)
607
+ fi
608
+ if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
609
+ verifier_api_args+=(--enable-prefix-caching)
610
+ fi
611
+ echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
612
+ python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
613
+ verifier_api_pid=$!
614
+ fi
615
+
616
+ echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
617
+ echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
618
+ python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
619
+ import os
620
+ import sys
621
+ import time
622
+ import urllib.request
623
+ from pathlib import Path
624
+
625
+ url = sys.argv[1]
626
+ timeout = float(sys.argv[2])
627
+ log_path = Path(sys.argv[3])
628
+ pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
629
+ started = time.time()
630
+ last_error = None
631
+ while time.time() - started < timeout:
632
+ if pid is not None:
633
+ try:
634
+ os.kill(pid, 0)
635
+ except OSError:
636
+ print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
637
+ if log_path.is_file():
638
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
639
+ sys.exit(1)
640
+ try:
641
+ with urllib.request.urlopen(url, timeout=5) as response:
642
+ if 200 <= response.status < 300:
643
+ print(f"READY: {url}", file=sys.stderr)
644
+ sys.exit(0)
645
+ except Exception as exc:
646
+ last_error = exc
647
+ time.sleep(5)
648
+ print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
649
+ if log_path.is_file():
650
+ print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
651
+ sys.exit(1)
652
+ PY
653
+ verifier_readiness_rc=$?
654
+ if [ "${verifier_readiness_rc}" -ne 0 ]; then
655
+ echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
656
+ if kill -0 "${verifier_api_pid}" 2>/dev/null; then
657
+ kill "${verifier_api_pid}" 2>/dev/null || true
658
+ fi
659
+ wait "${verifier_api_pid}" 2>/dev/null || true
660
+ exit "${verifier_readiness_rc}"
661
+ fi
662
+
663
+ echo "--> [Verifier API Node] Ready. Keeping node alive."
664
+ wait "${verifier_api_pid}"
665
+ verifier_api_rc=$?
666
+ if [ "${verifier_api_rc}" -ne 0 ]; then
667
+ echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
668
+ fi
669
+ exit "${verifier_api_rc}"
670
+ fi
671
+
672
+ export TMPDIR=/cache/ray_tmp
673
+ export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
674
+
675
+ wait_for_ray_npu_resources() {
676
+ expected_npu=$1
677
+ timeout_seconds=${2:-900}
678
+ begin_ts=$(date +%s)
679
+
680
+ while true; do
681
+ total_npu=$(python3 - <<'PY' 2>/dev/null
682
+ import ray
683
+
684
+ try:
685
+ ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
686
+ print(int(ray.cluster_resources().get("NPU", 0)))
687
+ ray.shutdown()
688
+ except Exception:
689
+ print(0)
690
+ PY
691
+ )
692
+ total_npu=${total_npu:-0}
693
+ now_ts=$(date +%s)
694
+ elapsed=$((now_ts - begin_ts))
695
+
696
+ echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
697
+ ray status || true
698
+
699
+ if [ "${total_npu}" -ge "${expected_npu}" ]; then
700
+ echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
701
+ break
702
+ fi
703
+
704
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
705
+ echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
706
+ return 1
707
+ fi
708
+
709
+ sleep 5
710
+ done
711
+ }
712
+
713
+ wait_for_verifier_api() {
714
+ api_url="${mock_api_base}/models"
715
+ timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
716
+ begin_ts=$(date +%s)
717
+ last_diag_ts=0
718
+ while true; do
719
+ verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
720
+ import socket
721
+ import sys
722
+ import urllib.parse
723
+ import urllib.request
724
+
725
+ url = sys.argv[1]
726
+ parsed = urllib.parse.urlparse(url)
727
+ host = parsed.hostname
728
+ port = parsed.port or (443 if parsed.scheme == "https" else 80)
729
+ print(f"check url={url} host={host} port={port}")
730
+ try:
731
+ infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
732
+ print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
733
+ except Exception as exc:
734
+ print(f"dns_error={type(exc).__name__}: {exc}")
735
+ raise SystemExit(1)
736
+ try:
737
+ with socket.create_connection((host, port), timeout=5):
738
+ print("tcp=ok")
739
+ except Exception as exc:
740
+ print(f"tcp_error={type(exc).__name__}: {exc}")
741
+ raise SystemExit(1)
742
+ try:
743
+ with urllib.request.urlopen(url, timeout=10) as response:
744
+ print(f"http_status={response.status}")
745
+ raise SystemExit(0 if 200 <= response.status < 300 else 1)
746
+ except Exception as exc:
747
+ print(f"http_error={type(exc).__name__}: {exc}")
748
+ raise SystemExit(1)
749
+ PY
750
+ )
751
+ check_rc=$?
752
+ if [ "${check_rc}" = "0" ]; then
753
+ echo "Verifier API is ready: ${api_url}"
754
+ echo "${verifier_check_output}"
755
+ break
756
+ fi
757
+ now_ts=$(date +%s)
758
+ elapsed=$((now_ts - begin_ts))
759
+ echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
760
+ if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
761
+ last_diag_ts=${now_ts}
762
+ echo "--- verifier API check diagnostics ---"
763
+ echo "${verifier_check_output}"
764
+ echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
765
+ echo "--- check verifier node log: ${verifier_api_log} ---"
766
+ echo "--------------------------------------"
767
+ fi
768
+ if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
769
+ echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
770
+ echo "Last verifier API diagnostics:" >&2
771
+ echo "${verifier_check_output}" >&2
772
+ return 1
773
+ fi
774
+ sleep 10
775
+ done
776
+ }
777
+
778
+ # ================= Nanoclaw workspace 根目录 =================
779
+ mkdir -p "${nanoclaw_temp_root}"
780
+ if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
781
+ echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
782
+ exit 2
783
+ fi
784
+ rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
785
+ if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
786
+ echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
787
+ echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
788
+ fi
789
+ echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
790
+ echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
791
+ echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
792
+ echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
793
+
794
+ # ================= 生成 Ray runtime env =================
795
+ RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
796
+ cat > "${RUNTIME_ENV_FILE}" <<YAML
797
+ working_dir: ./
798
+ excludes: ["/.git/", "/logs/", "/checkpoint/"]
799
+ env_vars:
800
+ TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
801
+ CUDA_DEVICE_MAX_CONNECTIONS: "1"
802
+ HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
803
+ HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
804
+ HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
805
+ HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
806
+ HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
807
+ HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
808
+ HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
809
+ P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
810
+ VLLM_USE_V1: "${VLLM_USE_V1}"
811
+ VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
812
+ VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
813
+ VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
814
+ VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
815
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
816
+ TOKENIZERS_PARALLELISM: "false"
817
+ HYDRA_FULL_ERROR: "1"
818
+ PYTHONUNBUFFERED: "1"
819
+ RAY_DEDUP_LOGS: "0"
820
+ WANDB_MODE: "${WANDB_MODE}"
821
+ MOCK_API_BASE: "${mock_api_base}"
822
+ MOCK_API_KEY: "${mock_api_key}"
823
+ MOCK_MODEL_NAME: "${mock_model_name}"
824
+ MOCK_API_TIMEOUT: "${mock_api_timeout}"
825
+ MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
826
+ NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
827
+ NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
828
+ NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
829
+ NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
830
+ NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
831
+ NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
832
+ NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
833
+ NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
834
+ NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
835
+ NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
836
+ NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
837
+ NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
838
+ NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
839
+ NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
840
+ NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
841
+ NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
842
+ NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
843
+ NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
844
+ NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
845
+ YAML
846
+
847
+ # ================= 启动 Ray 多机集群 =================
848
+ if [ "${NODE_RANK}" = "0" ]; then
849
+ echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
850
+ ray start --head \
851
+ --node-ip-address=${RAY_NODE_IP} \
852
+ --port=${RAY_PORT} \
853
+ --dashboard-host=0.0.0.0 \
854
+ --dashboard-port=${DASHBOARD_PORT} \
855
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
856
+ --disable-usage-stats \
857
+ --block &
858
+
859
+ sleep 10
860
+ wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
861
+ wait_for_verifier_api || exit 1
862
+ else
863
+ echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
864
+ sleep 20
865
+ ray start --address=${MASTER_ADDR}:${RAY_PORT} \
866
+ --node-ip-address=${RAY_NODE_IP} \
867
+ --resources="{\"NPU\":${NPUS_PER_NODE}}" \
868
+ --disable-usage-stats \
869
+ --block &
870
+ sleep 10
871
+ fi
872
+
873
+ # ================= 训练参数数组 =================
874
+ training_args=(
875
+ python3 -m verl.trainer.main_ppo
876
+ +ray_kwargs.ray_init.address=auto
877
+ reward.num_workers=${reward_num_workers}
878
+ algorithm.adv_estimator=${adv_estimator}
879
+ algorithm.gamma=${algorithm_gamma}
880
+ algorithm.lam=${algorithm_lam}
881
+ algorithm.use_kl_in_reward=${use_kl_in_reward}
882
+ algorithm.kl_penalty=${kl_penalty}
883
+ algorithm.kl_ctrl.type=${kl_ctrl_type}
884
+ algorithm.kl_ctrl.kl_coef=${kl_coef}
885
+ data.train_files="${train_files}"
886
+ data.val_files="${test_files}"
887
+ data.return_raw_chat=True
888
+ data.return_multi_modal_inputs=False
889
+ data.image_key=images
890
+ data.shuffle=True
891
+ data.train_batch_size=${train_batch_size}
892
+ data.max_prompt_length=${max_prompt_length}
893
+ data.max_response_length=${max_response_length}
894
+ data.filter_overlong_prompts=True
895
+ data.truncation=error
896
+ data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
897
+ data.custom_cls.name=CustomRLHFDataset
898
+ "data.tool_config_path=${tool_config_path}"
899
+ "+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
900
+ "+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
901
+ "+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
902
+ "+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
903
+ "+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
904
+ "+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
905
+ "+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
906
+ "+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
907
+ +data.apply_chat_template_kwargs.enable_thinking=True
908
+ reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
909
+ reward.custom_reward_function.name=compute_score
910
+ "+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
911
+ "+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
912
+ "+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
913
+ "+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
914
+ "+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
915
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
916
+ "+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
917
+ "+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
918
+ "+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
919
+ "+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
920
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
921
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
922
+ "+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
923
+ "+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
924
+ "+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
925
+ "+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
926
+ "+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
927
+ "+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
928
+ actor_rollout_ref.model.path=${model_path}
929
+ actor_rollout_ref.model.use_remove_padding=True
930
+ actor_rollout_ref.model.enable_gradient_checkpointing=True
931
+ actor_rollout_ref.actor.strategy=${actor_strategy}
932
+ actor_rollout_ref.ref.strategy=${actor_strategy}
933
+ actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
934
+ actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
935
+ actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
936
+ actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
937
+ actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
938
+ actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
939
+ actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
940
+ actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
941
+ actor_rollout_ref.actor.shuffle=${actor_shuffle}
942
+ actor_rollout_ref.actor.optim.lr=${actor_lr}
943
+ actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
944
+ actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
945
+ actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
946
+ "actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
947
+ actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
948
+ actor_rollout_ref.actor.use_dynamic_bsz=True
949
+ actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
950
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
951
+ actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
952
+ actor_rollout_ref.actor.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
953
+ actor_rollout_ref.actor.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
954
+ actor_rollout_ref.actor.entropy_checkpointing=${entropy_checkpointing}
955
+ actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
956
+ actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
957
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
958
+ actor_rollout_ref.actor.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
959
+ actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
960
+ actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
961
+ actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
962
+ actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
963
+ actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
964
+ actor_rollout_ref.ref.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
965
+ actor_rollout_ref.ref.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
966
+ actor_rollout_ref.ref.entropy_checkpointing=${entropy_checkpointing}
967
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
968
+ actor_rollout_ref.ref.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
969
+ actor_rollout_ref.ref.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
970
+ actor_rollout_ref.rollout.name=vllm
971
+ actor_rollout_ref.rollout.mode=async
972
+ actor_rollout_ref.rollout.calculate_log_probs=True
973
+ actor_rollout_ref.rollout.temperature=${rollout_temperature}
974
+ actor_rollout_ref.rollout.top_p=${rollout_top_p}
975
+ actor_rollout_ref.rollout.top_k=${rollout_top_k}
976
+ actor_rollout_ref.rollout.min_p=${rollout_min_p}
977
+ actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
978
+ actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
979
+ actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
980
+ actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
981
+ actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
982
+ actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
983
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
984
+ actor_rollout_ref.rollout.enable_chunked_prefill=True
985
+ actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
986
+ actor_rollout_ref.rollout.free_cache_engine=True
987
+ actor_rollout_ref.rollout.enforce_eager=False
988
+ actor_rollout_ref.rollout.enable_prefix_caching=False
989
+ actor_rollout_ref.rollout.multi_turn.enable=True
990
+ actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
991
+ actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
992
+ actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
993
+ "actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
994
+ actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
995
+ "actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
996
+ actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
997
+ actor_rollout_ref.rollout.n=${n_resp_per_prompt}
998
+ actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
999
+ actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
1000
+ actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
1001
+ actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
1002
+ actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
1003
+ actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
1004
+ actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
1005
+ actor_rollout_ref.rollout.val_kwargs.do_sample=True
1006
+ actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
1007
+ actor_rollout_ref.actor.use_torch_compile=False
1008
+ actor_rollout_ref.ref.use_torch_compile=False
1009
+ actor_rollout_ref.actor.use_torch_compile=False
1010
+ actor_rollout_ref.ref.use_torch_compile=False
1011
+ actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
1012
+ actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
1013
+ critic.fsdp.use_torch_compile=False
1014
+ trainer.use_v1=${trainer_use_v1}
1015
+ trainer.critic_warmup=0
1016
+ trainer.balance_batch=True
1017
+ trainer.logger=['console','tensorboard']
1018
+ trainer.project_name=${project_name}
1019
+ trainer.experiment_name=${experiment_name}
1020
+ trainer.nnodes=${NNODES}
1021
+ trainer.n_gpus_per_node=${NPUS_PER_NODE}
1022
+ trainer.val_before_train=${val_before_train}
1023
+ trainer.log_val_generations=${log_val_generations}
1024
+ trainer.save_freq=${save_freq}
1025
+ trainer.default_local_dir=${default_local_dir}
1026
+ trainer.test_freq=${test_freq}
1027
+ trainer.total_epochs=10
1028
+ )
1029
+
1030
+ if [ -n "${fsdp_size}" ]; then
1031
+ training_args+=(
1032
+ actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
1033
+ actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
1034
+ )
1035
+ fi
1036
+
1037
+ if [ -n "${nanoclaw_task_ids}" ]; then
1038
+ training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
1039
+ fi
1040
+
1041
+ if [ -n "${nanoclaw_max_steps}" ]; then
1042
+ training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
1043
+ fi
1044
+
1045
+ # ================= 启动训练主进程:仅主节点执行 =================
1046
+ if [ "${NODE_RANK}" = "0" ]; then
1047
+ echo "--> [Head Node] Starting VERL unified engine training..."
1048
+ echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
1049
+ echo "DEBUG: entrypoint=${training_args[*]}"
1050
+
1051
+ ray job submit \
1052
+ --address="http://127.0.0.1:${DASHBOARD_PORT}" \
1053
+ --runtime-env="${RUNTIME_ENV_FILE}" \
1054
+ -- \
1055
+ "${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
1056
+ else
1057
+ echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
1058
+ tail -f /dev/null
1059
+ fi
verl_0720_main/paper_docs/01_nanoclaw_harness_framework.md ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NanoClaw:面向通用 Agent 强化学习的轻量级交互框架
2
+
3
+ 现有通用 Agent 框架通常以完整的产品运行体验为目标,需要同时处理用户身份、会话管理、长期记忆、插件生态、外部服务、消息渠道、权限审批和多 Agent 编排等问题。这些能力对于真实应用十分重要,但当框架被直接用于强化学习时,也会引入大量与策略学习无关的状态和开销:同一任务可能受到历史记忆、网络服务、插件版本或后台进程的影响;每条 rollout 都需要维护复杂运行时;系统故障也难以区分究竟来自模型策略还是外部基础设施。NanoClaw 的设计目标并不是复刻一个完整的产品级 Agent,而是提取其中真正决定 Agent 学习能力的最小交互闭环,并将其转化为稳定、可验证且能够大规模并行的 RL 训练环境。
4
+
5
+ ## 1. 相比 OpenClaw,NanoClaw 精简了什么,又保留了什么
6
+
7
+ OpenClaw 等通用 Agent 框架面向长期运行的真实用户场景,其能力边界通常覆盖持久化会话、用户画像、长期记忆、消息渠道、插件或技能市场、外部服务连接、后台任务、复杂权限控制以及多 Agent 协作。这些模块共同构成了完整的 Agent 产品,但并非训练模型形成工具使用和环境操作能力所必需。NanoClaw 因此主动移除了上述产品层功能,不维护跨任务的长期状态,不依赖动态插件生态,不将网络服务、消息平台或复杂编排系统纳入训练闭环,也不要求每条轨迹启动一套完整的 Agent 服务。
8
+
9
+ 下表从训练环境的角度概括了两类框架的边界。这里比较的不是产品功能是否“有用”,而是这些功能是否应当进入每一条 RL rollout。
10
+
11
+ | 比较维度 | OpenClaw 等完整 Agent 框架 | NanoClaw | 对 RL 训练的直接影响 |
12
+ |---|---|---|---|
13
+ | 会话生命周期 | 面向长期用户会话,任务前后状态可以持续存在 | 每条任务是独立 episode,结束后不继承会话状态 | 避免前一条轨迹的信息进入后一条轨迹 |
14
+ | 长期记忆 | 可读取用户记忆、历史偏好和跨会话知识 | 默认不共享跨任务记忆,只使用当前任务和工作区 | 同一输入对应更稳定、可复现的初始状态 |
15
+ | 工具与技能 | 可动态安装插件、发现技能并连接第三方服务 | 使用固定且领域无关的基础工具集合 | 不同任务共享同一行动空间,减少插件版本带来的变量 |
16
+ | 外部连接 | 可访问邮件、日历、浏览器、消息平台和在线 API | 主要操作隔离工作区内的文件和受限命令环境 | 降低网络波动、认证失败和服务变化造成的奖励噪声 |
17
+ | 后台运行 | 可能包含定时任务、事件监听、子 Agent 和异步服务 | 不保留跨 episode 的后台任务或全局 Agent 状态 | rollout 之间无需协调长期进程,可以独立并行 |
18
+ | 权限与用户交互 | 需要处理用户身份、审批、渠道权限和安全策略 | 权限边界在任务工作区和受限工具中预先确定 | 减少与任务求解无关的交互分支和系统失败点 |
19
+ | 环境状态 | 状态分布在会话、数据库、插件和外部服务中 | 主要状态显式存在于独立工作区中 | 最终状态可以复制、比较、回放和验证 |
20
+ | 任务评价 | 更关注完整应用体验和用户侧结果 | verifier 直接评价最终工作区是否满足任务目标 | 可将开放式 Agent 任务转化为明确奖励 |
21
+
22
+ 上表主要说明 NanoClaw 从完整 Agent 系统中移除了哪些外围复杂性;与之对应,下表总结了框架仍然保留的 Agent 核心能力。这些能力构成了不可继续删减的最小闭环:如果去掉其中任何一项,任务就会退化为普通问答、静态函数调用或不可验证的文本生成,而不再是完整的 Agent 学习过程。
23
+
24
+ | 保留的核心能力 | 在 NanoClaw 中的具体表现 | 为什么必须保留 | 简单例子 |
25
+ |---|---|---|---|
26
+ | 任务理解与行动规划 | 模型根据开放式指令分析目标、约束和当前证据,再选择下一步行动 | Agent 需要把抽象目标转化为可执行步骤,而不是复现固定动作标签 | 从“只修改重试次数”推断不能改变其他配置,并决定先检查再编辑 |
27
+ | 多轮交互与错误恢复 | 工具 observation 持续返回上下文,成功结果和错误结果都会影响后续决策 | 真实任务通常无法一次完成,也无法保证第一次行动总是正确 | 精确替换失败后重新搜索位置,修改完成后再次读取确认 |
28
+ | 独立且可修改的真实环境 | 每条轨迹拥有可读取、可改变、可保存的独立工作区 | 只有真实状态变化才能区分“声称完成”和“实际完成” | `config.yaml` 中的字段真实地从 3 变为 5,而非只在回答中声称已修改 |
29
+ | 通用且可组合的原子工具 | 使用统一的发现、读取、搜索、写入、精确编辑、补丁、目录操作和受限执行工具 | 工具集必须覆盖完整任务闭环,同时避免把某类 benchmark 的解法编码为专用 API | 同一套工具可以完成代码重构、配置修复、CSV 统计、日志分析和文档生成 |
30
+ | 主动终止、状态验证与轨迹归因 | 模型主动 final,verifier 检查最终工作区,完整交互轨迹与奖励对应 | Agent 既要判断何时完成,也要允许多种正确路径获得统一、可归因的奖励 | 将“读取—编辑—复查—结束”的全部决策与最终正向奖励关联 |
31
+
32
+ 其中,通用原子工具是 NanoClaw 保留 Agent 泛化能力的关键。工具集的设计目标不是覆盖尽可能多的产品功能,而是覆盖工作区任务中不可再分的基础操作,使模型能够通过组合基础动作构造复杂行为。NanoClaw 当前工具的能力边界如下:
33
+
34
+ | 工具 | 原子能力 | 为什么具有通用性 | 可覆盖的典型任务 |
35
+ |---|---|---|---|
36
+ | `list_dir` | 查看指定目录的直接内容或递归结构 | 几乎所有未知环境任务都需要先建立对文件布局的认识,不依赖任何特定文件格式 | 了解代码仓库结构、发现数据目录、检查交付物是否生成 |
37
+ | `find` | 按通用路径模式定位文件 | 将“寻找操作对象”从具体任务中抽象出来,同一模式可作用于代码、配置、数据和文档 | 查找所有 Python 文件、定位 YAML 配置、发现 CSV、日志或测试文件 |
38
+ | `read_file` | 读取一个文本文件的内容或受限片段 | 为任意文本型环境状态提供统一观察接口,不预设文件语义 | 阅读源代码、配置、Markdown、CSV、JSON、日志和脚本 |
39
+ | `grep` | 以正则表达式跨文件搜索内容 | 支持从大规模环境中进行稀疏证据检索,避免为代码搜索、日志搜索或字段搜索分别设计工具 | 查找函数引用、配置键、错误码、用户名、时间戳和异常模式 |
40
+ | `write_file` | 创建文件或完整写入新内容 | 统一表示“产生新交付物”,交付物类型由任务决定而非工具决定 | 生成代码、测试、报告、JSON 结果、脚本和说明文档 |
41
+ | `edit_file` | 对已知位置进行精确局部替换 | 适合最小修改并保留未涉及内容,可用于任何可文本化文件 | 修改函数名、修复一个配置值、纠正文档段落或更新数据记录 |
42
+ | `apply_patch` | 在一个或多个文件中执行成组精确修改 | 将多个局部编辑组合为一致的结构变换,同时仍不绑定具体语言或任务 | 跨文件重构、同步修改实现与测试、批量修复多处配置 |
43
+ | `mkdir` | 创建工作区目录结构 | 文件组织本身是环境状态的一部分,适用于任何需要结构化交付的任务 | 创建源码包、报告目录、数据输出目录或测试目录 |
44
+ | `bash` | 在受限工作区中运行经过校验的命令、脚本、计算和测试 | 为静态文件操作补充通用计算与执行能力,使工具集不需要为每种数据格式或编程语言新增专用 API;其能力与安全边界在下文单独讨论 | 统计 CSV、聚合日志、运行工作区脚本、执行测试和检查生成结果 |
45
+
46
+ ### 受限 Bash:通用执行能力及其安全边界
47
+
48
+ `bash` 是 NanoClaw 工具集中不可由普通文件工具替代的一环。`read_file` 和 `grep` 可以观察文本,`edit_file` 和 `apply_patch` 可以改变文本,但许多 Agent 任务还要求模型对环境执行真实计算,例如统计大型 CSV、聚合日志、运行已有分析脚本、检查代码语法或执行测试。如果为每一种计算分别设计 `csv_sum`、`log_counter`、`run_python_test` 等专用接口,工具数量会随着 benchmark 增长,并将任务解法直接编码进 harness。NanoClaw 因此保留了 Bash 的组合能力,但提供的不是具有宿主机权限的任意终端,而是一个以当前 rollout 工作区为根目录、经过命令和路径校验、具有时间与输出预算的受限执行工具。
49
+
50
+ 以下命令展示了受限 Bash 在不同任务中的实际用途。它们均由同一个 `bash` 工具执行,不需要为代码、数据和日志任务分别定义 API;示例中的文件存在时,命令可以直接在 NanoClaw 工作区根目录运行。
51
+
52
+ | 任务目的 | 可执行示例 | Bash 提供的不可替代能力 |
53
+ |---|---|---|
54
+ | 发现待分析代码 | `find . -name '*.py'` | 在未知目录结构中进行递归发现,而不必逐层调用目录工具 |
55
+ | 定位并汇总错误日志 | `grep -R -n 'ERROR' logs | cut -d: -f1 | sort | uniq -c` | 将检索、字段提取、排序和计数组合为一次可观察的计算 |
56
+ | 统计结构化数据 | `awk -F, 'NR > 1 {sum += $4; n += 1} END {print "rows=" n, "total=" sum}' data/orders.csv` | 对较大文件进行流式计算,避免将全部数据放入模型上下文 |
57
+ | 运行通用分析程序 | `python3 scripts/analyze.py` | 让模型先生成或修改工作区脚本,再对真实输入执行复杂逻辑 |
58
+ | 验证修改是否正确 | `python3 tests/test_config.py` | 将测试结果作为新的 observation 返回,支持��修改—验证—纠错”闭环 |
59
+ | 检查输出规模 | `wc -l results/report.csv` | 用低成本环境计算验证交付物,而不是依赖模型目测或估计 |
60
+
61
+ 例如,在订单分析任务中,模型不需要逐行读取包含数万条记录的 `orders.csv`。它可以先观察文件头部,随后调用:
62
+
63
+ ```text
64
+ <tool_call>
65
+ <function=bash>
66
+ <parameter=command>
67
+ awk -F, 'NR > 1 {sum += $4; n += 1} END {print "rows=" n, "total=" sum}' data/orders.csv
68
+ </parameter>
69
+ </function>
70
+ </tool_call>
71
+
72
+ Tool:
73
+ rows=18432 total=967521.40
74
+ ```
75
+
76
+ 该设计把确定性的扫描和算术计算交给环境,把任务理解、计算方法选择以及结果解释留给模型。一方面,它显著减少长文件进入上下文产生的 token 开销;另一方面,模型必须根据任务主动决定使用哪个命令、处理哪个文件以及如何验证结果,因此并未获得任何与特定 benchmark 绑定的捷径。
77
+
78
+ Bash 的通用性同时带来了必须正面处理的风险:若直接向模型开放宿主机 Shell,模型可能误删文件、启动长期后台进程、读取其他 rollout,甚至搜索 `env_builder`、`verifier` 或标准答案形成奖励作弊。NanoClaw 将这些风险分为“运行安全”和“评测防作弊”两类,并在工具入口、工作区组织和评测流程三个层面设置边界。
79
+
80
+ | 防护维度 | NanoClaw 的限制 | 防止的风险 |
81
+ |---|---|---|
82
+ | 命令白名单 | 仅允许文件查看与操作、文本检索、排序聚合以及工作区脚本执行等基础命令,如 `cat`、`head`、`tail`、`wc`、`ls`、`find`、`grep`、`sort`、`uniq`、`cut`、`awk`、`sed`、`tr`、`python3` 等;`curl`、`wget`、`ssh` 等不在行动空间中 | 防止模型任意启动系统程序、主动连接外部服务或扩大执行权限 |
83
+ | 工作区相对路径 | 命令中的路径操作数必须解析到当前 rollout 工作区内部;绝对路径、`..` 父目录跳转和 `~` 展开均被拒绝,路径解析还会检查符号链接解析后的实际位置 | 防止读取宿主机文件、任务定义目录、其他样本或工作区外的评测代码 |
84
+ | Shell 语法限制 | 禁止后台执行符 `&`、反引号、进程替换、命令级环境变量赋值以及 Shell 变量/命令展开;嵌套的 `bash -c` 或 `sh -c` 也不允许 | 防止通过二次解释或环境注入绕过命令与路径校验,或在 episode 结束后留下驻留进程 |
85
+ | 脚本递归校验 | 模型可以运行工作区内的 `.sh` 或 `.py` 文件,但脚本路径必须位于工作区;Shell 脚本中的每条命令仍经过白名单和路径检查,Python 脚本则拒绝绝对路径、父目录路径以及 `subprocess`、`os.system`、`requests`、`urllib`、`socket`、动态 `eval/exec`、递归删除等高风险模式 | 防止模型通过“先写脚本、再执行脚本”绕过 Bash 入口限制 |
86
+ | 进程生命周期 | 子进程以当前独立工作区为工作目录,`HOME` 与临时目录也重定向到该工作区;不允许后台任务,每次执行均具有超时控制,临时执行脚本在调用后删除 | 限制任务对宿主环境的持续影响,并避免进程跨 episode 存活 |
87
+ | Observation 预算 | 标准输出和标准错误由工具捕获,返回内容最多保留 8,000 个字符 | 防止命令一次性向模型上下文灌入无限内容,控制 rollout 成本 |
88
+ | 按任务关闭 | `allow_bash` 可以在任务级关闭;不需要通用执行的任务可以只暴露文件原子工具 | 使高风险能力遵循最小权限原则,而不是对所有任务强制开放 |
89
+ | Rollout 隔离 | 每条轨迹拥有单独的结果目录和 `workspace_after`;即使两个样本对应同一任务,它们也不会共享可写工作区 | 防止一个模型样本覆盖、读取或利用另一个样本的中间结果 |
90
+ | 构建与验证分离 | `env_builder` 在模型开始行动前由训练框架调用,`verifier` 在轨迹结束后由框架调用;二者属于环境控制面,不作为文件复制到模型的可操作工作区中,也不是模型可调用的工具 | 防止模型直接读取环境构造逻辑、验证规则或隐藏答案,再针对 verifier 制造伪结果 |
91
+
92
+ 其中,最后两项直接针对多 rollout 训练中的相互干扰与奖励作弊。NanoClaw 的数据流可以简化为:
93
+
94
+ ```text
95
+ 隐藏的任务控制面
96
+ env_builder ──生成──> rollout_i/workspace_after
97
+
98
+ 模型 ↔ 受限工具
99
+
100
+ 最终工作区状态
101
+
102
+ verifier <────轨迹结束后检查────┘
103
+ ```
104
+
105
+ 模型处于图中间的数据面,只能观察任务指令、自己的工具调用历史以及自己工作区内的文件。`env_builder` 的源文件、`verifier` 的判分程序、同一批次其他 rollout 的目录均位于这一边界之外。即使 `rm`、`mv` 或 `chmod` 等文件操作被允许,其作用路径也只能落在当前工作区:模型最坏只能破坏自己的环境��因此失去奖励,而不能修改其他样本或训练基础设施。verifier 只接收轨迹完成后的工作区进行检查,模型也不能把“调用 verifier 并观察判分规则”作为探索动作。
106
+
107
+ 下表给出若干边界示例。其目的不是依靠提示词劝告模型保持安全,而是在工具执行前直接拒绝越界动作。
108
+
109
+ | 请求示例 | 执行结果 | 原因 |
110
+ |---|---|---|
111
+ | `grep -R -n 'timeout' .` | 允许 | 白名单命令,搜索范围位于当前工作区 |
112
+ | `python3 scripts/analyze.py` | 允许 | 脚本位于工作区并通过安全检查 |
113
+ | `cat /etc/passwd` | 拒绝 | 使用宿主机绝对路径 |
114
+ | `find .. -name 'verifier.py'` | 拒绝 | 试图跳转到工作区父目录 |
115
+ | `cat ../task/env_builder.py` | 拒绝 | 试图读取环境构造代码 |
116
+ | `cat $OLDPWD/verifier.py` | 拒绝 | 试图通过 Shell 变量展开隐藏越界路径 |
117
+ | `bash -c 'cat hidden_file'` | 拒绝 | 禁止嵌套 Shell 再解释命令 |
118
+ | `curl https://example.com/answer` | 拒绝 | 网络命令不在白名单中 |
119
+ | `X=1 curl https://example.com/answer` | 拒绝 | 禁止用命令前变量赋值绕过首个命令名检查 |
120
+ | `python3 -c 'import requests; ...'` | 拒绝 | Python 网络访问模式被安全检查拦截 |
121
+ | `python3 -m some_module` | 拒绝 | 禁止通过模块入口间接启动未审计程序 |
122
+ | `python3 long_job.py &` | 拒绝 | 禁止后台进程跨工具调用持续运行 |
123
+
124
+ 需要指出的是,这些机制定义的是 **Agent RL harness 的受限行动边界**,其目标是阻止模型的常规误操作、直接路径逃逸、跨样本干扰和显式 verifier hacking;它不应被表述为能够对任意恶意本地代码提供形式化安全证明。若将未知模型作为主动攻击者部署到生产环境,还应在 harness 外叠加容器、文件系统 namespace、禁网策略、系统调用过滤和独立低权限用户。论文实验所需的结论更为具体:在统一的受限工具协议下,策略不能通过正常可用动作访问 `env_builder`、`verifier` 或其他 rollout,只能依靠当前任务证据改变自己的最终工作区,并由隐藏 verifier 进行事后评分。因而,Bash 提升的是领域无关的计算与验证能力,而不是开放宿主机权限或提供奖励捷径。
125
+
126
+ 这组工具的“较完备性”体现在对一般工作区任务闭环的覆盖,而不在于工具数量。它能够表达以下连续过程:
127
+
128
+ ```text
129
+ 发现环境(list_dir / find)
130
+ → 获取证据(read_file / grep)
131
+ → 改变状态(write_file / edit_file / apply_patch / mkdir)
132
+ → 执行计算或测试(bash)
133
+ → 再次读取、搜索或执行以验证结果
134
+ → 主动结束任务
135
+ ```
136
+
137
+ 不同领域的任务可以复用同一套组合逻辑,而不需要增加任务专用工具:
138
+
139
+ | 任务类型 | 一种可能的工具组合 | 工具组合所完成的闭环 |
140
+ |---|---|---|
141
+ | 代码重构 | `find → grep → read_file → apply_patch → bash` | 找到相关源文件和引用,完成跨文件修改,再运行测试或语法检查 |
142
+ | 配置修复 | `find → read_file → edit_file → read_file` | 定位并理解配置,只修改目标字段,再确认其他字段保持不变 |
143
+ | CSV 数据分析 | `list_dir → read_file → write_file → bash → read_file` | 确认输入数据,编写通用分析脚本,运行统计并检查输出报告 |
144
+ | 大型日志排查 | `find → grep → bash → write_file` | 定位日志,用模式搜索和命令聚合异常,生成结构化分析结果 |
145
+ | 文档生成 | `find → grep → read_file → write_file` | 从多个来源检索和汇总证据,生成新的报告或说明文档 |
146
+ | 代码测试与修复 | `bash → grep → read_file → edit_file → bash` | 运行测试获得失败 observation,定位错误,修改实现并重新验证 |
147
+
148
+ 这些例子说明,任务泛化不是通过不断扩充插件实现的,而是来自原子工具的可组合性。代码重构和日志分析在语义上差异很大,但都可以分解为环境发现、证据获取、状态变换和结果验证。模型需要学习的是如何依据任务和 observation 选择、排序并组合这些操作,而不是记忆某个任务对应的专用函数。因此,当任务文件结构、领域或自然语言表述发生变化时,行动空间仍然保持稳定,已经学习到的工具使用策略可以继续复用。
149
+
150
+ NanoClaw 对“完备”的主张也具有明确边界:它并不试图覆盖浏览器交互、实时通信、外部 SaaS 或长期个人助理等全部产品场景;在这些场景中,OpenClaw 的扩展工具和服务连接仍然必要。NanoClaw 所追求的是对**可在隔离工作区中表示、执行并验证的 Agent 任务**形成较完备的基础操作集合。在这一边界内,文件发现、内容观察、证据搜索、状态修改、结构创建、通用计算和结果验证均有对应能力,因而无需针对代码、数据、日志或文档任务分别改变 harness。
151
+
152
+ 因此,NanoClaw 与 OpenClaw 的区���不在于是否具备 Agent 能力,而在于系统边界不同:OpenClaw 希望承载完整、长期且开放的 Agent 应用,NanoClaw 则将其中与策略学习直接相关的部分压缩为任务、环境、工具、交互和验证五个基本要素。被移除的是面向产品运行的外围复杂性,被保留的是能够产生一般性 Agent 行为的核心机制。由此,模型学习的对象不再是某个具体 Agent 产品的内部规则,而是如何理解任务、获取证据、操作环境、利用反馈并完成目标。
153
+
154
+ 例如,对于“将 `config.yaml` 中的 `max_retries` 修改为 5”这一任务,完整 Agent 框架可能首先恢复用户会话、加载长期记忆、检查已安装技能和权限状态,再决定是否调用文件或终端工具;如果历史记忆中恰好存在同名项目,甚至可能改变本次任务的行为。NanoClaw 则始终从一个为当前 rollout 新建的工作区开始,模型只能依据当前任务、工作区文件和统一工具完成修改,最后由 verifier 检查目标字段是否为 5、其他字段是否保持不变。两者都能完成文件编辑,但前者优化的是长期 Agent 产品体验,后者刻意构造了一个边界清楚、初始状态确定、结果可验证的学习样本。
155
+
156
+ ## 2. 为什么这种轻量化适合高效且具有泛化性的 RL 训练
157
+
158
+ 强化学习要求对同一策略进行大量并行采样,并根据环境反馈稳定地比较不同轨迹。重型 Agent 框架中的长期记忆、外部服务和后台状态会破坏这一前提:即使输入任务相同,不同 rollout 也可能因为隐藏状态不同而得到不同结果;网络、插件或服务异常还可能被错误地归因于模型行为。NanoClaw 为每条轨迹建立独立且可复现的工作区,不共享历史记忆和中间文件,使环境差异主要来自模型自身的行动。这种明确的 episode 边界降低了奖励噪声,也使失败轨迹能够被复现、检查和重新验证。
159
+
160
+ NanoClaw 的主要设计选择可以与 Agent RL 中的具体困难一一对应:
161
+
162
+ | Agent RL 中的困难 | 直接使用重型框架时的表现 | NanoClaw 的对应设计 | 训练收益 |
163
+ |---|---|---|---|
164
+ | 初始状态不一致 | 不同 rollout 可能读取不同历史记忆、会话或插件状态 | 每条轨迹从独立工作区和相同任务定义开始 | 提高样本之间的可比较性,降低奖励方差 |
165
+ | rollout 启动成本高 | 每条样本需要初始化完整服务、连接和后台组件 | 只准备任务文件、基础工具和工作区 | 更多资源可用于模型生成和参数更新 |
166
+ | 故障来源难区分 | 网络超时、认证失败或插件异常可能被计为模型失败 | 核心交互限制在本地、可控环境中 | 更容易判断失败来自策略还是环境 |
167
+ | 动作空间随任务变化 | 不同插件提供不同 API,模型容易记忆 benchmark 接口 | 所有任务共享读取、搜索、编辑和执行等通用动作 | 促进跨文件类型和跨任务迁移 |
168
+ | 正确轨迹不唯一 | 过程监督往往只接受参考步骤 | verifier 评价最终状态,不规定固定操作顺序 | 允许探索、试错和自我修正 |
169
+ | 并行轨迹相互污染 | 共享目录、记忆或后台服务会传播中间状态 | 每个 rollout 拥有独立工作区 | 轨迹可以安全分发到大量 worker |
170
+ | 失败难以复现 | 关键状态存在于外部系统或临时服务中 | 输入文件、工具事件和最终工作区均可保存 | 支持回放、误差分析和 verifier 复查 |
171
+
172
+ 轻量化还直接降低了 rollout 成本。每条样本只需要准备任务工作区和有限的工具执行环境,不需要为其维护持久化服务、数据库、消息渠道或插件进程。不同轨迹之间没有复杂依赖,可以被自然地分配到大量并行 worker 上;一条轨迹发生工具错误或任务失败时,也不会污染其他样本。训练系统的大部分资源因此可以集中于模型生成和参数更新,而不是消耗在 Agent 产品运行时上。这使得长序列、多轮工具交互和多样本探索能够在可控成本下扩展。
173
+
174
+ NanoClaw 的泛化性同样来自这种最小化设计。框架向模型提供的是读取、搜索、修改和执行等领域无关的原子能力,而不是针对某个 benchmark 定制的任务 API。代码修改、配置处理、文档生成、结构化数据分析和系统排查等任务虽然语义不同,却可以共享同一套行动空间和交互协议。任务差异主要由自然语言指令、初始环境和最终验证标准表达,因此扩展任务不需要为模型重新设计一套专用工具。
175
+
176
+ 与此同时,NanoClaw 采用面向最终状态的奖励视角。Agent 任务通常不存在唯一正确轨迹:模型可以使用不同的文件检查顺序、搜索策略或编辑方法得到同样正确的结果。如果奖励依赖预先规定的操作路径,模型只能模仿有限的轨迹,难以形成真正的探索和纠错能力。NanoClaw 关注最终环境是否满足任务目标,从��允许多种有效策略获得相同正向反馈。模型能够在训练中学习更一般的“观察—规划—执行—检查—修正”能力,而不是记忆某一类任务的固定调用模板。
177
+
178
+ 因此,效率与泛化在 NanoClaw 中并不是两个独立目标。减少隐藏状态和外围服务,一方面降低了并行采样成本并提高了奖励稳定性,另一方面也避免模型过度适应某个重型框架的产品特性;保留通用工具和开放行动路径,则使有限的运行时能够覆盖更广泛的任务分布。框架越少注入任务专用结构,策略学习就越集中于可迁移的问题求解能力。
179
+
180
+ 以同一任务采样多个候选轨迹为例,模型可能分别采用“先完整读取再编辑”“先搜索字段再编辑”或“生成补丁后重新检查”等策略。在共享长期状态的系统中,这些轨迹可能相互看到中间结果,难以判断差异究竟来自策略还是状态污染;在 NanoClaw 中,每个候选都从相同的初始文件副本开始,并在自己的工作区中独立执行。最终,多个不同轨迹可以因为得到同样正确的文件状态而获得正向奖励,失败轨迹也可以根据其独立工作区被准确定位。这一过程同时体现了采样效率、奖励可靠性和策略多样性。
181
+
182
+ ## 3. NanoClaw 如何嵌入 RL 训练闭环
183
+
184
+ 在 RL 训练中,NanoClaw 被视为连接策略模型与任务环境的轻量交互层。每个训练 episode 从一条任务开始:系统根据任务定义准备一个独立工作区,并向模型提供任务指令和统一的工具能力。模型随后在多轮交互中观察环境、产生思考、选择行动并接收真实工具结果。随着交互推进,模型的每次决定及其环境反馈共同构成一条完整轨迹,直到模型主动给出最终回答,或者达到预设的交互预算。
185
+
186
+ 从标准 RL 表述来看,NanoClaw 中各要素具有清晰对应关系:
187
+
188
+ | RL 要素 | NanoClaw 中的具体载体 | 在轨迹中的例子 |
189
+ |---|---|---|
190
+ | 初始状态 | 用户任务、初始工作区和可用工具 | `config.yaml` 初始包含 `max_retries: 3` |
191
+ | 策略 | 当前待训练的语言模型 | 根据任务和历史 observation 决定下一步 |
192
+ | 动作 | 模型生成的工具调用或最终回答 | 调用 `read_file`、`edit_file`,或主动结束 |
193
+ | 环境 | 隔离工作区与工具执行器 | 读取文件、写入修改并返回执行结果 |
194
+ | Observation | 工具返回的真实结果 | 文件内容、搜索结果、命令输出或错误信息 |
195
+ | 轨迹 | 多轮模型输出、工具调用和 observation | “读取—编辑—复查—结束”的完整交互序列 |
196
+ | 终止条件 | 模型主动给出 final answer,或达到交互预算 | 完成修改后停止调用工具 |
197
+ | 奖励 | verifier 对最终工作区的检查结果 | 字段修改正确且其他内容未变,得到正向奖励 |
198
+ | 策略更新依据 | 奖励与该轨迹中模型输出的对应关系 | 正确轨迹被强化,低质量决策概率被抑制 |
199
+
200
+ 轨迹结束后,训练系统不要求模型复现参考操作序列,而是检查最终工作区是否达到任务要求。验证结果被转换为该 episode 的奖励,并与轨迹中的模型输出对应起来,用于后续的优势估计和策略更新。由此,NanoClaw 将开放式的 Agent 行为转化为标准 RL 可以处理的结构:策略负责产生行动,工具和工作区构成环境,环境状态变化形成 observation,最终验证器提供 reward。模型可以自由探索行动路径,但必须通过真实环境结果证明任务已经完成。
201
+
202
+ 下面给出一个基于 NanoClaw 真实训练协议的简化 episode。示例保留了实际 system prompt 中的关键约束、实际 user prompt 包装方式、真实工具名称,以及训练时使用的 `qwen3_coder` XML 工具调用格式;为了便于阅读,仅省略完整工具 schema、运行元数据和 token 记录。假设初始工作区包含一个 `config.yaml`,任务要求只修改其中的重试次数。
203
+
204
+ ```text
205
+ System:
206
+ You are solving a Nanoclaw workspace task inside VERL multi-turn RL.
207
+ A fresh per-rollout workspace is prepared automatically before the first
208
+ workspace tool call.
209
+ All tool paths must be relative to that workspace. Do not use absolute paths
210
+ or '..'.
211
+ Inspect files before editing them, make the smallest correct changes, then
212
+ stop with a final answer.
213
+ The verifier scores the final workspace, not your final prose answer.
214
+
215
+ User:
216
+ Solve this task by using the workspace tools to inspect and modify files.
217
+ Only provide a final answer after the requested workspace changes are complete.
218
+
219
+ Task:
220
+ 将 config.yaml 中的 max_retries 从 3 修改为 5,其他配置保持不变。
221
+
222
+ Assistant:
223
+ 我需要先检查文件内容,确认目标字段及其上下文,再进行局部修改。
224
+ <tool_call>
225
+ <function=read_file>
226
+ <parameter=path>
227
+ config.yaml
228
+ </parameter>
229
+ </function>
230
+ </tool_call>
231
+
232
+ Tool observation:
233
+ max_retries: 3
234
+ timeout: 30
235
+
236
+ Assistant:
237
+ 目标字段存在,且只需要替换这一处内容。我将使用精确编辑,避免改动其他配置。
238
+ <tool_call>
239
+ <function=edit_file>
240
+ <parameter=path>
241
+ config.yaml
242
+ </parameter>
243
+ <parameter=old_text>
244
+ max_retries: 3
245
+ </parameter>
246
+ <parameter=new_text>
247
+ max_retries: 5
248
+ </parameter>
249
+ </function>
250
+ </tool_call>
251
+
252
+ Tool observation:
253
+ Success: applied 1 edit(s).
254
+
255
+ Assistant:
256
+ 修改已经完成。为了确认最终状态,我需要重新读取文件。
257
+ <tool_call>
258
+ <function=read_file>
259
+ <parameter=path>
260
+ config.yaml
261
+ </parameter>
262
+ </function>
263
+ </tool_call>
264
+
265
+ Tool observation:
266
+ max_retries: 5
267
+ timeout: 30
268
+
269
+ Assistant final answer:
270
+ 已完成配置修改。
271
+
272
+ Verifier:
273
+ 最终工作区中 max_retries == 5,且 timeout 等其他字段保持不变,reward = 1。
274
+ ```
275
+
276
+ 这个例子展示了 NanoClaw 嵌入 RL 后的最小闭环。模型看到的不是预先标注好的正确工具序列,而是任务、当前工作区和通用工具;每次工具返回都会成为后续决策的新 observation。模型可以选择其他有效路径,例如使用搜索工具定位字段或使用补丁工具完成修改,只要最终工作区满足验证条件,就可以获得相同奖励。训练所约束的是任务结果,而不是某条固定轨迹,因此同一套交互协议既能支持探索,也能将开放式 Agent 行为转换为稳定的 RL 信号。
277
+
278
+ 这一嵌入方式进一步体现了轻量化带来的训练效率。NanoClaw 不替代底层分布式 RL 系统,而是作为一层薄的环境接口接入既有的采样、调度和参数更新流程。模型推理仍可由高吞吐推理引擎批量执行,轨迹仍可由分布式 worker 并行采集,NanoClaw 只负责为每条样本提供独立环境、执行工具并保存最终状态。由于 episode 之间没有长期记忆、后台服务或跨样本依赖,增加并行度时不需要同步复杂的 Agent 全局状态,扩展成本主要由模型推理本身决定。
279
+
280
+ 最终,NanoClaw 在 RL 中形成了一个闭合且清晰的学习回路:任务定义模型需要解决的问题,通用工具限定模型可以采取的行动,隔离工作区承载可观察和可修改的环境状态,最终验证将任务完成程度转换为奖励,RL 算法再利用这些奖励更新策略。第一部分所描述的产品功能精简,使这一闭环能够稳定复制到大量独立样本;第二部分所描述的通用工具、状态隔离和最终状态奖励,则使并行采样不仅更高效,也能够支持多样化策略探索和跨任务能力迁移。NanoClaw 的作用由此不是增加一套新的重型 Agent 基础设施,而是以最小的运行时成本,为通用 Agent RL 提供真实、可验证且可扩展的环境交互基础。
verl_0720_main/paper_docs/02_nanoclaw_behavior_masking.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Nanoclaw:面向长程 Agent 强化学习的行为感知掩码机制
2
+
3
+ 在长程 Agent 强化学习中,最终任务奖励与局部行为质量之间往往并不完全一致。一个 rollout 可能最终完成任务并获得正优势,但其中仍包含无效循环、重复调用工具或因长度预算耗尽而被截断的回复。标准 GRPO 会依据整条轨迹的结果更新响应 token,这意味着成功轨迹中的低质量局部行为也可能得到正向强化。例如,模型虽然在前几轮已经完成关键修改,却在后续不断重复读取相同文件;只要最终 verifier 判定任务成功,这些冗余行为就可能随整条轨迹一起被提高概率。随着训练推进,这类错误信用分配会进一步增加响应长度和无效交互,消耗有限的 token 预算,并最终表现为收敛速度下降和截断率升高。
4
+
5
+ 为解决这一问题,Nanoclaw 引入了**行为感知的非对称优势掩码机制**。该机制首先在 rollout 阶段定位具有明确退化特征的 assistant turn,并记录其 token 区间;在 GRPO 完成优势计算后,再根据 token 的优势方向决定是否将其排除在策略损失之外。设基础响应掩码为 \(m_t^{base}\),检测到的低质量行为区间集合为 \(\mathcal{B}\),token 优势为 \(\hat{A}_t\),则实际训练掩码可以写为:
6
+
7
+ \[
8
+ m_t = m_t^{base}\left[1-\mathbb{I}\left(t\in\mathcal{B}\ \land\ \hat{A}_t>0\right)\right].
9
+ \]
10
+
11
+ 因此,当低质量行为位于正优势轨迹中时,对应 token 的掩码被置为 0,避免模型因为最终任务成功而强化该行为;当这些 token 的优势小于或等于 0 时,掩码仍保持有效,使负向梯度继续降低其生成概率。该机制不会删除 rollout、改变 verifier 奖励或移除模型后续决策所需的上下文,而只在 actor 更新前调整哪些 token 参与策略损失。它因而可以被理解为一种细粒度的信用分配修正:**阻断错误的正强化,同时保留正确的负向学习信号**。
12
+
13
+ 当前 Nanoclaw 的完整掩码配置包含以下机制:
14
+
15
+ | 掩码机制 | 识别对象 | 在训练中的作用 |
16
+ |---|---|---|
17
+ | 循环回复掩码 | assistant 回复中连续重复的文本片段或 token 序列 | 防止语言循环因轨迹得分较高而被正向强化 |
18
+ | 重复工具结果轮次掩码 | 再次产生相同工具、参数和执行结果的 assistant turn | 抑制没有带来新信息或新状态的冗余工具交互 |
19
+ | 预算耗尽末轮掩码 | 因达到 response token 上限而终止时的最后一个 assistant turn | 避免不完整、被截断的末轮输出被当作有效正样本学习 |
20
+ | 仅掩盖正优势 | 上述异常轮次中满足 \(\hat{A}_t>0\) 的有效 token | 保留异常行为的负优势信号,避免全量掩码导致模型失去纠错机会 |
21
+
22
+ 一个简单例子可以说明这种非对称设计。假设某条轨迹最终完成任务并获得正优势,但中间包含一次没有新增信息的重复 `read_file`。在未使用掩码时,这一轮与有效编辑步骤都会受到正向更新;启用掩码后,重复读取对应的正优势 token 不参与 loss,而真正推动任务完成的其他步骤仍正常学习。相反,如果一条失败轨迹中的循环回复具有负优势,相关 token 不会被掩盖,模型仍可从失败中学习降低该行为的概率。相比直接丢弃整个异常轮次,这一设计保留了更完整、更有方向性的训练信号。
23
+
24
+ 我们在 4B 模型上进行了严格受控的消融实验。实验设置包含 `Mask-ON` 与 `Mask-OFF` 两组:前者开启上述全部行为掩码,后者关闭全部行为掩码;两组使用相同的初始模型、训练数据、优化器与学习率、batch size、rollout 数量、长度预算、奖励函数及其他训练参数。尤其地,两组实验采用相同的 data seed,使每个训练 step 接收到的数据及其 batch 组成保持一致。因此,两条曲线之间的差异不能用样本顺序不同或某一组恰好遇到更简单的 batch 来解释,主要实验变量被限制为是否启用行为掩码。
25
+
26
+ 实验结果显示,`Mask-ON` 的任务准确率在训练早期增长更快,并在相同训练步数下持续高于 `Mask-OFF`;与此同时,`Mask-ON` 的响应截断率更低。两项指标呈现一致的机制性证据:更高且增长更快的准确率说明掩码减少了错误正强化,提高了有效策略信号的利用效率;更低的截断率说明模型减少了循环回复和无效工具交互,能够将有限上下文预算用于真正推进任务的步骤。由于两组实验逐 batch 使用相同训练数据,这一对照直接支持性能提升来自掩码机制,而不是数据采样差异。
27
+
28
+ 从论文证据链来看,这一结论由三个层次共同支撑。首先,**变量控制**保证除 mask 开关外的训练条件完全一致;其次,**优化结果**表现为准确率曲线更快上升且整体更高;最后,**行为结果**表现为截断率同步下降,与“减少无效 token 和退化轮次”的方法动机相吻合。准确率与截断率的共同变化比单一最终分数更有解释力:如果 mask 只是偶然改变了奖励波动,并不必然同时降低截断;当前结果则表明它确实改善了策略的交互效率。正式论文中可以同时报告逐步训练曲线、达到固定准确率所需的训练步数、最终准确率及平均截断率,并进一步使用多个随机种子报告均值和方差,以补充当前同数据序列受控消融的统计稳健性。
29
+
verl_0720_main/paper_docs/03_nanoclaw_reward_design.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Nanoclaw:面向开放式 Agent 任务的分层可验证奖励设计
2
+
3
+ 奖励函数是 Agent 强化学习中最关键、也最容易引入偏差的组成部分。与数学问答不同,Agent 任务的答案通常不是一个可以直接精确匹配的字符串,而是由模型经过多轮推理和工具调用后形成的环境状态。同一个任务可能存在多条正确轨迹,工作区中的结果也可能具有不同但等价的表达形式。如果直接评价完整轨迹,不仅需要处理数万 token 的推理、工具调用和环境反馈,带来很高的判分成本,还会将 verifier 对操作顺序和表达风格的偏好引入奖励,压缩模型的策略探索空间。更严重的是,模型可能学习迎合轨迹评分器所偏好的表面模式,而不是真正完成任务,从而形成 reward hacking。为此,Nanoclaw 将奖励设计分为两个层次:宏观层面判断模型是否主动完成任务,并只对最终工作区评分;微观层面使用结构化的混合 verifier 判断工作区中的每项结果是否正确。
4
+
5
+ ## 主动终止门控与最终状态奖励
6
+
7
+ Nanoclaw 在宏观层面采用 `require_final_answer` 机制。只有当模型主动停止工具调用,并输出一个非空的最终回答时,当前 rollout 才被视为完整结束,随后才会运行 workplace verifier;如果模型因为总 response token 数耗尽、单轮长度耗尽、最大轮数或其他非主动原因终止,则不执行正常的结果评分,奖励直接记为 0。设轨迹为 \(\tau\),最终工作区为 \(W_T\),主动完成指示变量为 \(I_{\mathrm{final}}(\tau)\),工作区验证分数为 \(V(W_T)\),则核心奖励可以表示为:
8
+
9
+ \[
10
+ R(\tau)=I_{\mathrm{final}}(\tau)\cdot V(W_T).
11
+ \]
12
+
13
+ 这一门控使“知道何时结束”成为 Agent 策略的一部分。仅仅在工作区中留下部分正确结果还不够,模型还需要判断任务是否已经完成,并主动从 ReAct 循环切换到最终回答。否则,如果截断轨迹也能稳定获得部分奖励,模型就缺少及时结束的动力,甚至可能通过持续输出、反复检查或堆积局部结果获得非零分数。主动终止门控因此同时提供了完成性约束和效率约束,但无需额外设计长度惩罚。
14
+
15
+ 在通过终止门控后,奖励只取决于最终 workplace,而不评价中间轨迹。模型可以采用不同的搜索顺序、工具组合和修改方法,只要最终环境满足任务要求,就能够获得相同奖励。这种 outcome-based verification 一方面避免了对长轨迹反复调用大模型判分的资源开销,另一方面不会把某条人工轨迹误当成唯一正确解,从而保留强化学习所需的探索空间。由于 reward 绑定到可检查的环境结果,而不是模型在推理文本中声称“已经完成”,模型也更难仅通过语言表述骗取奖励。
16
+
17
+ ## 确定性检查与 LLM 语义检查
18
+
19
+ 在具体任务层面,每条数据包含一个 `workplace_verifier`,但 Nanoclaw 不试图用手写代码精确描述所有语义条件。复杂 Agent 任务的输出格式具有较大的合理变化空间,纯代码 verifier 很容易把数据构造者的隐含假设错误地当成任务要求。例如,prompt 可能只要求将结果保存为 `result_email.json`,验证代码却默认该 JSON 必须具有名为 `content` 的顶级字段;此时模型即使生成了语义正确、结构合理的结果,也会因为 prompt 从未声明的 schema 约束被误判。随着任务复杂度增加,枚举所有合法表达形式不仅构造成本很高,也很容易产生大量假阴性。
20
+
21
+ 因此,我们采用“**确定性边界检查 + LLM 语义检查**”的混合式 verifier。代码只负责判断具有唯一、客观答案的结构条件,例如目标文件的路径和名称是否正确、要求的结果文件是否存在;除这些能够绝对确定的检查项外,文件内容是否满足指令、答案是否正确、字段语义是否一致等条件均交由 LLM checker 判断。该分工让程序检查承担最可靠的边界约束,让语言模型处理难以通过固定规则覆盖的语义等价性,避免用脆弱的代码 schema 替代用户真正提出的要求。
22
+
23
+ 为了使 LLM 判分任务足够简单且稳定,每个 checker 都被改写为包含参考答案的二元判定问题。checker prompt 同时给出待检查内容、明确的判断标准和正确参考,例如:
24
+
25
+ ```text
26
+ 请检查答案文本是否包含正确答案“671 元人民币”。
27
+ 已知该问题的计算结果应为 671 元人民币,因此正确答案就是 671 元。
28
+ 如果满足要求,只回答 YES;否则只回答 NO。
29
+ ```
30
+
31
+ 这种设计不是让 verifier 重新独立求解完整 Agent 任务,而是将复杂验证分解成若干局部的文本蕴含或一致性判断。参考答案直接出现在 checker prompt 中,模型只需对照候选内容判断条件是否成立,因此即使使用速度较快、参数规模较小的模型,也能保持较高的判断精度,同��显著降低大规模 rollout 的奖励计算成本。
32
+
33
+ ## 正向与负向双向检查
34
+
35
+ 仅使用“正确内容是否出现”的正向检查仍可能产生 reward hacking:策略可以将大量候选答案、姓名或数值全部写入结果文件,从而碰巧覆盖正确答案。为此,Nanoclaw 将语义检查分为互补的两类。**正向检查**确认必要答案、文本或操作结果确实存在并符合要求;**负向检查**确认输出中没有出现明确禁止、与事实冲突或不应包含的内容。例如,若任务要求列表中不得包含已经付费的客人 James,可以构造如下检查:
36
+
37
+ ```text
38
+ 请检查列表中是否包含已经付费的客人 James。
39
+ 如果没有出现 James,回答 YES;如果出现了 James,回答 NO。
40
+ ```
41
+
42
+ 只有同时通过正向和负向检查,输出才既满足召回要求,又满足精确性要求。这使模型无法通过堆砌大量内容获得高分,也减少了“正确答案存在,但同时包含明显错误答案”的假阳性。最终 workplace 分数由多个独立检查项聚合而成,因而能够提供比单一通过/失败信号更细致的任务完成度,同时保持每个子判定足够简单。
43
+
44
+ ## 实验一:主动终止门控消融
45
+
46
+ 我们在 2B 模型上对 `require_final_answer` 进行了受控消融。`True` 与 `False` 两组实验除该开关外使用完全相同的模型、数据和训练参数。直观上,`False` 组即使在 rollout 被截断时也可以根据已完成的 workplace 获得部分分数,因此在固定轨迹分布下,其平均奖励理论上不低于带门控的 `True` 组。然而实验呈现出相反或至少不支持这一预期的结果:训练最初十余步中,`True` 组的平均奖励更高;随后两组逐渐接近,部分阶段 `True` 组仍略高。同时,`True` 组的平均输出长度明显更短。
47
+
48
+ 这一现象说明,允许截断样本获得部分分并没有转化为更好的长期策略。所谓 `False` 组“应当得分更高”的推断隐含了两组产生相同轨迹的假设,但在强化学习中,奖励规则会反过来改变策略分布。关闭门控后,部分分削弱了模型主动结束任务的学习信号,使其更容易继续调用工具或输出直至预算耗尽;这些更长、更不完整的轨迹又降低了有效 rollout 的比例和后续训练信号质量。开启门控则建立了清晰的完成边界:只有“完成环境修改并主动结束”的轨迹才能获得奖励,从而使模型更快学会在适当时机终止。`True` 组能够以更短输出达到相当或更高的平均奖励,表明其单位生成 token 的奖励效率更高,而不是简单依靠截断惩罚压低长度。
49
+
50
+ 这一结果还具有直接的系统意义。更短的平均输出减少了 rollout 阶段的生成 token 数和 KV cache 占用,可以提升训练吞吐;推理时也能减少无效工具调用和等待时间。对于没有主动结束的样本,门控还可以跳过昂贵的 workplace verifier 调用。因此,`require_final_answer` 同时改善了策略完成性、训练效率与部署阶段的交互效率。正式论文中可以联合报告平均奖励、任务成功率、主动结束率、截断率和平均输出长度,从而区分“分数变化”与“行为效率变化”。
51
+
52
+ ## 实验二:小模型 Verifier 的可靠性
53
+
54
+ 为验证训练阶段使用的小型 checker 是否足以承担语义判分,我们对模型采样产生的 workplace 进行了独立复评:训练时使用 Qwen3.5-9B verifier,实验后再使用更大规模的 GLM-5.1 对相同结果重新打分。两者判断的一致率达到 **95%**。这一结果说明,通过将复杂任务拆解为包含参考答案的 YES/NO 检查项,原本开放的结果验证已经被转化为低复杂度判别任务;因此无需在每个 rollout 中部署超大模型,也能够获得与强 verifier 高度一致的判断,并显著降低奖励计算的算力与延迟成本。
55
+
56
+ 严格来说,95% 衡量的是 Qwen3.5-9B 与 GLM-5.1 的判分一致性,而不是在人工金标准上的绝对准确率,但它为 checker 设计的可行性提供了直接证据:如果判分问题仍需要复杂推理,小模型与更强模型通常会出现更大分歧。
57
+
58
+ 总体而言,Nanoclaw 的奖励函数不是单一模型打分器,而是一套分层验证机制:`require_final_answer` 在轨迹层面建立主动完成门槛,最终状态奖励在策略层面保留多路径探索空间,确定性代码检查保证文件边界正确,带参考答案的 LLM checker 判断复杂语义,正负双向检测共同抑制内容堆砌式 reward hacking。2B 模型的终止门控消融和 Qwen3.5-9B/GLM-5.1 的 95% 判分一致率分别从策略学习与 verifier 可靠性两个角度支持了这一设计。
verl_0720_main/verl/.agent/skills/issue/SKILL.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: issue
3
+ description: Create or update a GitHub issue following verl project conventions.
4
+ user_invocable: true
5
+ ---
6
+
7
+ When the user asks to create or update an issue, follow these steps:
8
+
9
+ ### 1. Gather Context
10
+
11
+ Read the following to understand available issue types and their required fields:
12
+
13
+ - [`bug-report.yml`](.github/ISSUE_TEMPLATE/bug-report.yml)
14
+ - [`feature-request.yml`](.github/ISSUE_TEMPLATE/feature-request.yml)
15
+
16
+ If updating an existing issue, read its current title, body, labels, and comments first.
17
+
18
+ ### 2. Determine Issue Type
19
+
20
+ Based on the user's description, select the appropriate template:
21
+
22
+ - **Bug report** ([`bug-report.yml`](.github/ISSUE_TEMPLATE/bug-report.yml)) — something is broken or behaves unexpectedly
23
+ - **Feature request** ([`feature-request.yml`](.github/ISSUE_TEMPLATE/feature-request.yml)) — a new capability or enhancement
24
+ - **Blank issue** — if neither template fits
25
+
26
+ ### 3. Compose the Issue
27
+
28
+ Fill in the template fields based on information from the user and the codebase. For bug reports, run `python scripts/diagnose.py` to gather system info if possible.
29
+
30
+ When updating, ensure the title and body still accurately reflect the current state of the issue.
31
+
32
+ ### 4. Check for Duplicates
33
+
34
+ Search for existing issues before creating:
35
+
36
+ ```
37
+ gh issue list --repo verl-project/verl --state open --search "<keywords>"
38
+ ```
39
+
40
+ If a duplicate exists, inform the user instead of creating a new one.
41
+
42
+ ### 5. Create or Update the Issue
43
+
44
+ - **Create**: add `good first issue` and/or `call for contribution` labels if the issue is straightforward and suitable for new contributors.
45
+ - **Update**: update title, body, and labels as needed.
46
+
47
+ Return the issue URL when done.
verl_0720_main/verl/.agent/skills/pr/SKILL.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: pr
3
+ description: Create or update a pull request following verl project conventions.
4
+ user_invocable: true
5
+ ---
6
+
7
+ When the user asks to create or update a PR, follow these steps:
8
+
9
+ ### 1. Gather Context
10
+
11
+ Read the following and understand the current branch's changes compared to main:
12
+
13
+ - [`CONTRIBUTING.md`](CONTRIBUTING.md)
14
+ - [`PULL_REQUEST_TEMPLATE.md`](.github/PULL_REQUEST_TEMPLATE.md)
15
+
16
+ If a PR already exists for this branch, also read its current title, body, and review comments.
17
+
18
+ ### 2. Compose PR Title and Body
19
+
20
+ Follow the PR template strictly for both title format and body sections. Only check checklist boxes for steps that have actually been completed.
21
+
22
+ When updating, ensure the title and body still accurately reflect **all** changes on the branch, not just the latest commit.
23
+
24
+ ### 3. Pre-submit Checks
25
+
26
+ Run pre-commit and fix any issues before creating or pushing.
27
+
28
+ ### 4. Create or Update the PR
29
+
30
+ - **Create**: target `main` by default unless the user specifies otherwise.
31
+ - **Update**: push new commits and update the title and body if the scope has changed. **Read the current PR title and body first** and incorporate any edits the user may have made directly on GitHub — never overwrite with a version generated from scratch.
32
+
33
+ Return the PR URL when done.
verl_0720_main/verl/.gemini/config.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ have_fun: false
2
+ code_review:
3
+ disable: false
4
+ comment_severity_threshold: HIGH
5
+ max_review_comments: -1
6
+ pull_request_opened:
7
+ help: false
8
+ summary: false
9
+ code_review: true
10
+ ignore_patterns: []
verl_0720_main/verl/.git-blame-ignore-revs ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Local uasge: git config blame.ignoreRevsFile .git-blame-ignore-revs
2
+
3
+ # [dev] feat: immigrate from yapf & pylint to ruff based on pre-commit
4
+ # Changed 268 files, +10k/-9k lines. This is the biggest formatter change.
5
+ b00f77d8559b48d57a33c0132a5ba1c81891a536
6
+
7
+ # [ci] refactor: reduce ruff line-length from 300 to 120
8
+ # Changed 238 files, +6k/-1k lines. Global formatting change.
9
+ 00a10a8ef389556f957a2f36132b2358fd6a109f
10
+
11
+ # [Lint] fix: linting errors in all files
12
+ # Changed 179 files, +1k/-3k lines. Global lint fix.
13
+ 8e5ad4688a13de81727c014a3c2e2fb26324bc20
verl_0720_main/verl/.github/CODEOWNERS ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /docs @eric-haibin-lin @zhaochenyang20 @hongpeng-guo
2
+ /docs/amd_tutorial @yushengsu-thu
3
+ /docs/slang_multiturn @zhaochenyang20 @SwordFaith
4
+ /docs/ascend_tutorial @wucong25
5
+
6
+ /third_party/sglang @zhaochenyang20 @SwordFaith
7
+ /third_party/vllm @PeterSH6 @wuxibin89
8
+
9
+ /examples/grpo_trainer @vermouth1992 @PeterSH6 @tardis-key @wucong25 @ji-huazhong
10
+
11
+ /verl/single_controller @zw0610 @wuxibin89 @hongpeng-guo
12
+ /verl/trainer @eric-haibin-lin @vermouth1992 @tongyx361 @PeterSH6
13
+ /verl/models/mcore @ISEEKYAN @vermouth1992
14
+ /verl/models/transformers @vermouth1992 @PeterSH6 @tardis-key @wucong25 @ji-huazhong
15
+ /verl/workers/engine @eric-haibin-lin @vermouth1992 @ZihengJiang @ArronHZG
16
+ /verl/workers/roles @eric-haibin-lin @vermouth1992 @ZihengJiang
17
+ /verl/workers/engine/fsdp @eric-haibin-lin @vermouth1992 @ZihengJiang
18
+ /verl/workers/engine/veomni @wuxibin89 @Luosuu @FoolPlayer
19
+ /verl/workers/rollout/vllm_rollout @wuxibin89 @PeterSH6 @chenhaiq @ArronHZG
20
+ /verl/workers/rollout/sglang_rollout @zhaochenyang20 @SwordFaith @chenhaiq @ArronHZG
21
+ /verl/workers/engine/megatron @ISEEKYAN @vermouth1992
22
+ /verl/experimental @wuxibin89 @ArronHZG
23
+
24
+ /tests/single_controller @zw0610 @wuxibin89
25
+ /tests/trainer @eric-haibin-lin @vermouth1992 @tongyx361 @PeterSH6
26
+ /tests/workers/rollout/vllm_rollout @wuxibin89 @PeterSH6 @chenhaiq
verl_0720_main/verl/.github/ISSUE_TEMPLATE/bug-report.yml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modified from https://github.com/huggingface/transformers/blob/main/.github/ISSUE_TEMPLATE/bug-report.yml?plain=1
2
+ name: "\U0001F41B Bug Report"
3
+ description: Submit a bug report to help us improve verl
4
+ labels: [ "bug" ]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for taking the time to fill out this bug report! 🤗
10
+
11
+ - type: textarea
12
+ id: system-info
13
+ attributes:
14
+ label: System Info
15
+ description: Please share your system info with us. You can run the command `python scripts/diagnose.py` and copy-paste its output below.
16
+ placeholder: verl version, platform, python version, ...
17
+ validations:
18
+ required: true
19
+
20
+ - type: checkboxes
21
+ id: information-scripts-examples
22
+ attributes:
23
+ label: Information
24
+ description: 'The problem arises when using:'
25
+ options:
26
+ - label: "The official example scripts"
27
+ - label: "My own modified scripts"
28
+
29
+ - type: checkboxes
30
+ id: information-tasks
31
+ attributes:
32
+ label: Tasks
33
+ description: "The tasks I am working on are:"
34
+ options:
35
+ - label: "An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)"
36
+ - label: "My own task or dataset (give details below)"
37
+
38
+ - type: textarea
39
+ id: reproduction
40
+ validations:
41
+ required: true
42
+ attributes:
43
+ label: Reproduction
44
+ description: |
45
+ Please provide a code sample that reproduces the problem you ran into. It can be a Colab link or just a code snippet.
46
+ Please include relevant config information with your code.
47
+ If you have code snippets, error messages, stack traces please provide them here as well.
48
+ Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
49
+ Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.
50
+
51
+ placeholder: |
52
+ Steps to reproduce the behavior:
53
+
54
+ 1.
55
+ 2.
56
+ 3.
57
+
58
+
59
+ - type: textarea
60
+ id: expected-behavior
61
+ validations:
62
+ required: true
63
+ attributes:
64
+ label: Expected behavior
65
+ description: "A clear and concise description of what you would expect to happen."
verl_0720_main/verl/.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ blank_issues_enabled: true
2
+ version: 0.1
verl_0720_main/verl/.github/ISSUE_TEMPLATE/feature-request.yml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modified from https://github.com/huggingface/transformers/blob/main/.github/ISSUE_TEMPLATE/feature-request.yml?plain=1
2
+ name: "\U0001F680 Feature request"
3
+ description: Submit a proposal/request for a new verl feature
4
+ labels: [ "Feature request" ]
5
+ body:
6
+ - type: textarea
7
+ id: feature-request
8
+ validations:
9
+ required: true
10
+ attributes:
11
+ label: Feature request
12
+ description: |
13
+ A clear and concise description of the feature proposal. Please provide a link to the paper and code in case they exist.
14
+
15
+ - type: textarea
16
+ id: motivation
17
+ validations:
18
+ required: true
19
+ attributes:
20
+ label: Motivation
21
+ description: |
22
+ Please outline the motivation for the proposal. Is your feature request related to a problem? e.g., I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too.
23
+
24
+
25
+ - type: textarea
26
+ id: contribution
27
+ validations:
28
+ required: true
29
+ attributes:
30
+ label: Your contribution
31
+ description: |
32
+ Is there any way that you could help, e.g. by submitting a PR? Make sure to read the CONTRIBUTING.MD [readme](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md)
verl_0720_main/verl/.github/PULL_REQUEST_TEMPLATE.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### What does this PR do?
2
+
3
+ > Add **concise** overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.
4
+
5
+ ### Checklist Before Starting
6
+
7
+ - [ ] Search for similar PRs. Paste at least one query link here: ...
8
+ - [ ] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI)
9
+ - `{modules}` include `fsdp`, `megatron`, `veomni`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward`, `fully_async`, `one_step_off`
10
+ - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]`
11
+ - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test`
12
+ - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title.
13
+ - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching`
14
+
15
+ ### Test
16
+
17
+ > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.
18
+
19
+ ### API and Usage Example
20
+
21
+ > Demonstrate how the API changes if any, and provide usage example(s) if possible.
22
+
23
+ ```python
24
+ # Add code snippet or script demonstrating how to use this
25
+ ```
26
+
27
+ ### Design & Code Changes
28
+
29
+ > Demonstrate the high-level design if this PR is complex, and list the specific changes.
30
+
31
+ ### Checklist Before Submitting
32
+
33
+ > [!IMPORTANT]
34
+ > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
35
+
36
+ - [ ] Read the [Contribute Guide](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md).
37
+ - [ ] Apply [pre-commit checks](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always`
38
+ - [ ] Add / Update [the documentation](https://github.com/verl-project/verl/tree/main/docs).
39
+ - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/verl-project/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ...
40
+ - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
41
+ - [ ] If your PR is related to the `recipe` submodule, please also update the reference to the submodule commit via `git submodule update --remote` or `cd recipe && git pull origin main`.
verl_0720_main/verl/.github/dependabot.yml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ## Enabled the dependabot to check the dependencies of the project
2
+ ## Dependabot will open pull requests to update dependencies automatically
3
+
4
+ version: 2
5
+ updates:
6
+ - package-ecosystem: pip
7
+ directory: "/"
8
+ schedule:
9
+ interval: weekly
verl_0720_main/verl/.github/workflows/.stash/e2e_ppo_trainer_torchtitan_vllm.yml ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ # NOTE: The TorchTitan engine requires a *nightly* PyTorch + torchtitan (the ``spmd_types`` APIs
33
+ # are nightly-only). To avoid maintaining a dedicated Docker image, this workflow installs those
34
+ # nightlies in-job on top of the standard CI image (see the install step). Because the image's
35
+ # vLLM is built against a *stable* torch, the run step preloads the nightly cuBLAS to resolve the
36
+ # resulting ``undefined symbol: cublasGemmEx`` mismatch. The pinned nightly versions need periodic
37
+ # bumping (old nightly wheels are garbage-collected from the index). Consider running this on a
38
+ # schedule / as non-blocking if the nightly toolchain proves flaky.
39
+
40
+ name: e2e_ppo_trainer_torchtitan_vllm
41
+
42
+ on:
43
+ # Trigger the workflow on push or pull request,
44
+ # but only for the main branch.
45
+ push:
46
+ branches:
47
+ - main
48
+ - v0.*
49
+ paths:
50
+ - "verl/workers/engine/torchtitan/**"
51
+ - "verl/workers/config/engine.py"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "!docker/**"
58
+ # Docs
59
+ - "!**/*.md"
60
+ - "!docs/**"
61
+ # Entrypoints
62
+ - ".github/workflows/e2e_ppo_trainer_torchtitan_vllm.yml"
63
+ - "tests/special_e2e/run_ppo_trainer_torchtitan.sh"
64
+ - "verl/workers/engine/torchtitan/**"
65
+ - "verl/workers/config/engine.py"
66
+ - "examples/data_preprocess/gsm8k.py"
67
+ - "verl/trainer/main_ppo.py"
68
+ - "verl/trainer/config/ppo_trainer.yaml"
69
+
70
+ # Cancel jobs on the same ref if a new one is triggered
71
+ concurrency:
72
+ group: ${{ github.workflow }}-${{ github.ref }}
73
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
74
+
75
+ # Declare permissions just read content.
76
+ permissions:
77
+ contents: read
78
+
79
+ env:
80
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
81
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
82
+
83
+ jobs:
84
+ setup:
85
+ if: github.repository_owner == 'verl-project'
86
+ runs-on: ubuntu-latest
87
+ outputs:
88
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
89
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
90
+ steps:
91
+ - uses: actions/checkout@v4
92
+ - id: create-runner
93
+ uses: volcengine/vemlp-github-runner@v1
94
+ with:
95
+ mode: "create"
96
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
97
+ mlp-image: "${{ env.IMAGE }}"
98
+
99
+ e2e_ppo_trainer_torchtitan_vllm:
100
+ needs: setup
101
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
102
+ timeout-minutes: 60 # Increase this timeout value as needed
103
+ env:
104
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
105
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
106
+ HF_ENDPOINT: "https://hf-mirror.com"
107
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
108
+ steps:
109
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110
+ with:
111
+ fetch-depth: 0
112
+ - name: Install the current repository + TorchTitan nightly stack
113
+ run: |
114
+ pip3 install -r requirements-test.txt
115
+ pip3 install -r requirements.txt
116
+ pip3 install --no-deps -e .
117
+ # TorchTitan's spmd_types APIs require a nightly PyTorch; the image's vLLM is built against
118
+ # a stable torch (ABI-incompatible -> undefined symbol: torch::Library::_def). Install a
119
+ # nightly-torch stack from the PyTorch index. Why these versions:
120
+ # vllm 1.0.0.dev20260620 : newest nightly-torch vLLM whose API verl's rollout code
121
+ # supports (0704+ refactored vllm.utils and dropped the
122
+ # `FlexibleArgumentParser` import path verl relies on).
123
+ # torch 2.14.0.dev20260625 : >= the spmd_types DTensor/fully_shard fix floor, and
124
+ # ~5 days from vLLM's dev0620 build -> ABI-compatible.
125
+ # torchvision 0.29.0.dev20260626 : pins torch dev0625 exactly (0-day ABI gap).
126
+ # torchtitan 0.1.0.dev20260701 : provides spmd_backend; declares no torch dep.
127
+ # vLLM pins torch==dev0620, so install it (with deps) first, then bump torch/torchvision to
128
+ # the versions above with --no-deps (keeps the ABI-safe gap, preserves vLLM's dep set).
129
+ INDEX="https://download.pytorch.org/whl/nightly/cu130"
130
+ pip3 install --pre vllm==1.0.0.dev20260620+cu130 --extra-index-url "${INDEX}"
131
+ pip3 install --pre torchtitan==0.1.0.dev20260701+cu130 --extra-index-url "${INDEX}"
132
+ pip3 install --pre --no-deps \
133
+ torch==2.14.0.dev20260625+cu130 \
134
+ torchvision==0.29.0.dev20260626+cu130 \
135
+ --extra-index-url "${INDEX}"
136
+ # The image ships classic flash-attn 2 (flash_attn_2_cuda.so) built against stable torch;
137
+ # under nightly torch it fails to load (undefined symbol: c10::...materialize_cow_storage).
138
+ # vLLM's rotary-embedding path imports flash_attn unconditionally and crashes on the broken
139
+ # .so. Remove it so vLLM falls back to its native rotary kernel.
140
+ pip3 uninstall -y flash-attn
141
+ - name: Check final pip list
142
+ run: |
143
+ pip3 list
144
+ - name: Prepare GSM8K dataset21
145
+ run: |
146
+ ray stop --force
147
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
148
+ - name: Running GSM8K E2E training test on 8 L20 GPUs with TorchTitan engine (FSDP_SIZE=8, spmd_types, flex, selective AC)
149
+ run: |
150
+ ray stop --force
151
+ # vLLM in the base image is built against stable torch; preload the nightly cuBLAS so
152
+ # its C extensions resolve against the nightly torch (fixes undefined symbol cublasGemmEx).
153
+ export LD_PRELOAD="$(python3 -c 'import glob, os, sysconfig; c = glob.glob(os.path.join(sysconfig.get_paths()["purelib"], "nvidia", "cu13", "lib", "libcublas.so.13")); print(c[0] if c else "")')"
154
+ NUM_GPUS=8 FSDP_SIZE=8 TOTAL_TRAIN_STEPS=2 \
155
+ bash tests/special_e2e/run_ppo_trainer_torchtitan.sh
156
+
157
+ cleanup:
158
+ runs-on: ubuntu-latest
159
+ needs:
160
+ [
161
+ setup,
162
+ e2e_ppo_trainer_torchtitan_vllm,
163
+ ]
164
+ if: always()
165
+ steps:
166
+ - id: destroy-runner
167
+ uses: volcengine/vemlp-github-runner@v1
168
+ with:
169
+ mode: "destroy"
170
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
171
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Adding a New Workflow
2
+
3
+ When adding a new workflow for continuous integration (CI), you have two runner options: a fixed runner or a machine from the vemlp.
4
+
5
+ - **Fixed Runner**: To use a fixed runner, specify it in your workflow using the `runs-on` keyword, like `runs-on: [L20x8]`.
6
+ - **Vemlp Runner**: Opting for a Vemlp machine allows you to launch tasks elastically.
7
+
8
+ Here is a template to assist you. This template is designed for using Vemlp machines. Currently, for each workflow, you need to create a `setup` and a `cleanup` job. When using this template, the main parts you need to modify are the `IMAGE` environment variable and the specific `job steps`.
9
+
10
+ ```yaml
11
+ name: Your Default Workflow
12
+
13
+ on:
14
+ push:
15
+ branches:
16
+ - main
17
+ - v0.*
18
+ pull_request:
19
+ branches:
20
+ - main
21
+ - v0.*
22
+ paths:
23
+ - "**/*.py"
24
+ - ".github/workflows/template.yml"
25
+
26
+ concurrency:
27
+ group: ${{ github.workflow }}-${{ github.ref }}
28
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
29
+
30
+ permissions:
31
+ contents: read
32
+
33
+ env:
34
+ IMAGE: "your vemlp image" # e.g. "verl-ci-cn-beijing.cr.volces.com/verlai/verl:sgl0512.dev2"
35
+ DYNAMIC_RUNNER_URL: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner" # public veFaas api
36
+
37
+ jobs:
38
+ setup:
39
+ if: github.repository_owner == 'verl-project'
40
+ runs-on: ubuntu-latest
41
+ outputs:
42
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
43
+ task-id: ${{ steps.create-runner.outputs.task-id }}
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - id: create-runner
47
+ uses: volcengine/vemlp-github-runner@v1
48
+ with:
49
+ mode: "create"
50
+ faas-url: "${{ env.DYNAMIC_RUNNER_URL }}"
51
+ image: "${{ env.DEFAULT_IMAGE }}"
52
+
53
+ your_job:
54
+ needs: setup
55
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'default-runner' }}"]
56
+ steps:
57
+ xxxx # your jobs
58
+
59
+ cleanup:
60
+ runs-on: ubuntu-latest
61
+ needs: [setup, your_job]
62
+ if: always()
63
+ steps:
64
+ - id: destroy-runner
65
+ uses: volcengine/vemlp-github-runner@v1
66
+ with:
67
+ mode: "destroy"
68
+ faas-url: "${{ env.DYNAMIC_RUNNER_URL }}"
69
+ task-id: "${{ needs.setup.outputs.task-id }}"
70
+ ```
71
+
72
+ ### Model and Dataset
73
+ To avoid CI relies on network, we pre-download dataset on a NFS on the CI machine. The path for models are \${HOME}/models and the path for dataset is \${HOME}/models/hf_data.
verl_0720_main/verl/.github/workflows/check-pr-title.yml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+
33
+ on:
34
+ pull_request:
35
+ types: [opened, edited, synchronize]
36
+
37
+ jobs:
38
+ check-title:
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - name: Checkout code
42
+ uses: actions/checkout@v4
43
+
44
+ - name: Set up Python
45
+ uses: actions/setup-python@v5
46
+ with:
47
+ python-version: '3.11'
48
+
49
+ - name: Run PR title checker
50
+ run: python3 tests/special_sanity/check_pr_title.py
51
+ env:
52
+ PR_TITLE: ${{ github.event.pull_request.title }}
53
+
54
+ - name: Run PR description checker
55
+ run: python3 tests/special_sanity/check_pr_description.py
56
+ env:
57
+ PR_TITLE: ${{ github.event.pull_request.title }}
58
+ GITHUB_EVENT_PATH: ${{ github.event_path }}
verl_0720_main/verl/.github/workflows/cpu_unit_tests.yml ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: cpu_unit_tests
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ push:
38
+ branches:
39
+ - main
40
+ - v0.*
41
+ pull_request:
42
+ branches:
43
+ - main
44
+ - v0.*
45
+ paths:
46
+ - "**/*.py"
47
+ - "!tests/special_sanity/**"
48
+ - .github/workflows/cpu_unit_tests.yml
49
+
50
+ # Cancel jobs on the same ref if a new one is triggered
51
+ concurrency:
52
+ group: ${{ github.workflow }}-${{ github.ref }}
53
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
54
+
55
+ # Declare permissions just read content.
56
+ permissions:
57
+ contents: read
58
+
59
+ env:
60
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
61
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
62
+
63
+ jobs:
64
+ setup:
65
+ if: github.repository_owner == 'verl-project'
66
+ runs-on: ubuntu-latest
67
+ outputs:
68
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
69
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
70
+ steps:
71
+ - uses: actions/checkout@v4
72
+ - id: create-runner
73
+ uses: volcengine/vemlp-github-runner@v1
74
+ with:
75
+ mode: "create"
76
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
77
+ mlp-image: "${{ env.IMAGE }}"
78
+
79
+ cpu_unit_tests:
80
+ needs: setup
81
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
82
+ timeout-minutes: 20 # Increase this timeout value as needed
83
+ env:
84
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
85
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
86
+ HF_ENDPOINT: "https://hf-mirror.com"
87
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
88
+ TORCH_COMPILE_DISABLE: 1
89
+ TORCHINDUCTOR_DISABLE: 1
90
+ steps:
91
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
92
+ with:
93
+ fetch-depth: 0
94
+ - name: Install the current repository
95
+ run: |
96
+ pip3 install -r requirements-test.txt
97
+ pip3 install --no-deps -e .
98
+ pip3 install --no-deps TransferQueue==0.1.8
99
+ - name: Check final pip list
100
+ run: |
101
+ pip3 list
102
+ - name: Download datasets
103
+ run: |
104
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
105
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k
106
+ - name: Running CPU unit tests
107
+ run: |
108
+ echo '[pytest]' > pytest.ini
109
+ echo 'python_files = *_on_cpu.py' >> pytest.ini
110
+ pytest -s -x --asyncio-mode=auto tests/
111
+ cleanup:
112
+ runs-on: ubuntu-latest
113
+ needs: [setup, cpu_unit_tests]
114
+ if: always()
115
+ steps:
116
+ - id: destroy-runner
117
+ uses: volcengine/vemlp-github-runner@v1
118
+ with:
119
+ mode: "destroy"
120
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
121
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/doc.yml ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+
33
+ name: doc_test
34
+
35
+ on:
36
+ # Trigger the workflow on push or pull request,
37
+ # but only for the main branch
38
+ push:
39
+ branches:
40
+ - main
41
+ - v0.*
42
+ pull_request:
43
+ branches:
44
+ - main
45
+ - v0.*
46
+ paths:
47
+ - "**/*.py"
48
+ - "docs/**"
49
+ - .github/workflows/doc.yml
50
+
51
+ # Cancel jobs on the same ref if a new one is triggered
52
+ concurrency:
53
+ group: ${{ github.workflow }}-${{ github.ref }}
54
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
55
+
56
+ # Declare permissions just read content.
57
+ permissions:
58
+ contents: read # for checkout
59
+ pages: write # for deploy-pages
60
+ id-token: write # for deploy-pages
61
+
62
+ jobs:
63
+ doc_test:
64
+ runs-on: ubuntu-latest
65
+ timeout-minutes: 5 # Increase this timeout value as needed
66
+ strategy:
67
+ matrix:
68
+ python-version: ["3.10"]
69
+ steps:
70
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
71
+ - name: Set up Python ${{ matrix.python-version }}
72
+ uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
73
+ with:
74
+ python-version: ${{ matrix.python-version }}
75
+ - name: Install the current repository
76
+ run: |
77
+ pip3 install -r requirements-test.txt
78
+ pip3 install --no-deps -e .
79
+ pip install -r docs/requirements-docs.txt
80
+ - name: Check final pip list
81
+ run: |
82
+ pip3 list
83
+ - name: Run doc make html
84
+ run: |
85
+ cd docs
86
+ make clean
87
+ make html SPHINXOPTS="--keep-going -w _build/sphinx.log"
88
+ if grep -q ": ERROR:" _build/sphinx.log; then
89
+ echo "🚨 Sphinx doc build contained ERRORs - see _build/sphinx.log"
90
+ exit 1
91
+ fi
92
+ if grep -q "WARNING: document isn't included in any toctree" _build/sphinx.log; then
93
+ echo "🚨 Sphinx doc build contained WARNING. Please include newly added docs in index.rst. See _build/sphinx.log for details"
94
+ exit 1
95
+ fi
96
+ if grep -q "WARNING: Inline emphasis" _build/sphinx.log; then
97
+ echo "🚨 Sphinx doc build contained WARNING. Please check inline emphasis is correct. See _build/sphinx.log for details"
98
+ exit 1
99
+ fi
100
+ if grep -q "WARNING: Definition list ends without a blank line" _build/sphinx.log; then
101
+ echo "🚨 Sphinx doc build contained WARNING. Please check if the indentation is correct. See _build/sphinx.log for details"
102
+ exit 1
103
+ fi
verl_0720_main/verl/.github/workflows/docker-build-ascend-a2.yml ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: docker-build-ascend-a2
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: ["main"]
7
+ paths:
8
+ - "docker/ascend/Dockerfile.ascend_9.0.0_a2"
9
+ - "docker/ascend/Dockerfile.ascend_9.0.0_a2_v0.8.0"
10
+ - ".github/workflows/docker-build-ascend-a2.yml"
11
+
12
+ schedule:
13
+ - cron: "0 16 * * *"
14
+
15
+ env:
16
+ QUAY_REPO: quay.io/ascend/verl
17
+
18
+ jobs:
19
+ # ============================================================
20
+ # 第一阶段:分架构构建并推送 digest(main 镜像)
21
+ # ============================================================
22
+ build-push-digest:
23
+ name: build-${{ matrix.tag }}
24
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
25
+ concurrency:
26
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.tag }}
27
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
28
+ runs-on: ${{ matrix.runner }}
29
+ permissions:
30
+ packages: write
31
+ contents: read
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ include:
36
+ - arch: linux/amd64
37
+ runner: ubuntu-latest
38
+ tag: amd64
39
+ - arch: linux/arm64
40
+ runner: ubuntu-22.04-arm
41
+ tag: arm64
42
+ outputs:
43
+ tag: ${{ steps.version.outputs.tag }}
44
+ steps:
45
+ - name: Remove unnecessary parts in github actions runners to free up disk space
46
+ uses: jlumbroso/free-disk-space@v1.3.1
47
+ with:
48
+ tool-cache: true
49
+
50
+ - name: Checkout code
51
+ uses: actions/checkout@v4
52
+
53
+ - name: Set up Python
54
+ uses: actions/setup-python@v5
55
+ with:
56
+ python-version: "3.11"
57
+
58
+ - name: Get base image name and tag
59
+ id: base_image
60
+ run: |
61
+ BASE_IMAGE_FULL=$(grep '^FROM' ./docker/ascend/Dockerfile.ascend_9.0.0_a2 | head -1 | cut -d' ' -f2)
62
+ echo "Base image full: $BASE_IMAGE_FULL"
63
+ BASE_IMAGE_TAG=$(echo "$BASE_IMAGE_FULL" | cut -d':' -f2)
64
+ echo "Base image tag: $BASE_IMAGE_TAG"
65
+ NEW_IMAGE_NAME="verl-$BASE_IMAGE_TAG"
66
+ echo "New image name: $NEW_IMAGE_NAME"
67
+ echo "base_image_tag=$BASE_IMAGE_TAG" >> "$GITHUB_OUTPUT"
68
+ echo "new_image_name=$NEW_IMAGE_NAME" >> "$GITHUB_OUTPUT"
69
+
70
+ - name: Get image tag
71
+ id: version
72
+ run: |
73
+ echo "tag=latest-cann9.0.0-torch_npu2.9.0post2-910b-ubuntu22.04-py3.11-vllm" >> "$GITHUB_OUTPUT"
74
+
75
+ - name: Set up Docker Buildx
76
+ uses: docker/setup-buildx-action@v3
77
+ with:
78
+ install: true
79
+ driver: docker-container
80
+ use: true
81
+
82
+ - name: Login to Quay.io
83
+ uses: docker/login-action@v3
84
+ with:
85
+ registry: quay.io
86
+ username: ${{ secrets.QUAY_USERNAME }}
87
+ password: ${{ secrets.QUAY_PASSWORD }}
88
+
89
+ - name: Clean Docker cache before build
90
+ run: |
91
+ docker system prune -a -f --volumes || true
92
+
93
+ - name: Build and push by digest (main image)
94
+ uses: docker/build-push-action@v6
95
+ id: build_main
96
+ with:
97
+ context: .
98
+ platforms: ${{ matrix.arch }}
99
+ file: ./docker/ascend/Dockerfile.ascend_9.0.0_a2
100
+ push: true
101
+ outputs: type=image,name=${{ env.QUAY_REPO }},push-by-digest=true,name-canonical=true,push=true
102
+ provenance: false
103
+ cache-from: type=gha
104
+ cache-to: type=gha,mode=max
105
+ build-args: |
106
+ BUILDKIT_INLINE_CACHE=1
107
+
108
+ - name: Export digest (main image)
109
+ run: |
110
+ mkdir -p ${{ runner.temp }}/digests
111
+ digest="${{ steps.build_main.outputs.digest }}"
112
+ touch "${{ runner.temp }}/digests/main-${digest#sha256:}"
113
+
114
+ - name: Upload digest (main image)
115
+ uses: actions/upload-artifact@v4
116
+ with:
117
+ name: digests-main-${{ matrix.tag }}
118
+ path: ${{ runner.temp }}/digests/*
119
+ if-no-files-found: error
120
+ retention-days: 1
121
+
122
+ # ============================================================
123
+ # 第一阶段(v0.8.0):分架构构建并推送 digest
124
+ # ============================================================
125
+ build-push-digest-v080:
126
+ name: build-v0.8.0-${{ matrix.tag }}
127
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
128
+ concurrency:
129
+ group: ${{ github.workflow }}-${{ github.ref }}-v0.8.0-${{ matrix.tag }}
130
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
131
+ runs-on: ${{ matrix.runner }}
132
+ permissions:
133
+ packages: write
134
+ contents: read
135
+ strategy:
136
+ fail-fast: false
137
+ matrix:
138
+ include:
139
+ - arch: linux/amd64
140
+ runner: ubuntu-latest
141
+ tag: amd64
142
+ - arch: linux/arm64
143
+ runner: ubuntu-22.04-arm
144
+ tag: arm64
145
+ steps:
146
+ - name: Remove unnecessary parts in github actions runners to free up disk space
147
+ uses: jlumbroso/free-disk-space@v1.3.1
148
+ with:
149
+ tool-cache: true
150
+
151
+ - name: Checkout code
152
+ uses: actions/checkout@v4
153
+
154
+ - name: Set up Python
155
+ uses: actions/setup-python@v5
156
+ with:
157
+ python-version: "3.11"
158
+
159
+ - name: Set up Docker Buildx
160
+ uses: docker/setup-buildx-action@v3
161
+ with:
162
+ install: true
163
+ driver: docker-container
164
+ use: true
165
+
166
+ - name: Login to Quay.io
167
+ uses: docker/login-action@v3
168
+ with:
169
+ registry: quay.io
170
+ username: ${{ secrets.QUAY_USERNAME }}
171
+ password: ${{ secrets.QUAY_PASSWORD }}
172
+
173
+ - name: Clean Docker cache before build
174
+ run: |
175
+ docker system prune -a -f --volumes || true
176
+
177
+ - name: Build and push by digest (v0.8.0 image)
178
+ uses: docker/build-push-action@v6
179
+ id: build_v080
180
+ with:
181
+ context: .
182
+ platforms: ${{ matrix.arch }}
183
+ file: ./docker/ascend/Dockerfile.ascend_9.0.0_a2_v0.8.0
184
+ push: true
185
+ outputs: type=image,name=${{ env.QUAY_REPO }},push-by-digest=true,name-canonical=true,push=true
186
+ provenance: false
187
+ cache-from: type=gha
188
+ cache-to: type=gha,mode=max
189
+ build-args: |
190
+ BUILDKIT_INLINE_CACHE=1
191
+
192
+ - name: Export digest (v0.8.0 image)
193
+ run: |
194
+ mkdir -p ${{ runner.temp }}/digests-v080
195
+ digest="${{ steps.build_v080.outputs.digest }}"
196
+ touch "${{ runner.temp }}/digests-v080/v080-${digest#sha256:}"
197
+
198
+ - name: Upload digest (v0.8.0 image)
199
+ uses: actions/upload-artifact@v4
200
+ with:
201
+ name: digests-v080-${{ matrix.tag }}
202
+ path: ${{ runner.temp }}/digests-v080/*
203
+ if-no-files-found: error
204
+ retention-days: 1
205
+
206
+ # ============================================================
207
+ # 第二阶段:合并多架构 manifest(main 镜像)
208
+ # ============================================================
209
+ merge-image:
210
+ name: merge
211
+ runs-on: ubuntu-latest
212
+ needs: build-push-digest
213
+ steps:
214
+ - name: Download digests (main image)
215
+ uses: actions/download-artifact@v4
216
+ with:
217
+ path: ${{ runner.temp }}/digests-main
218
+ pattern: digests-main-*
219
+ merge-multiple: true
220
+
221
+ - name: Login to Quay.io
222
+ uses: docker/login-action@v3
223
+ with:
224
+ registry: quay.io
225
+ username: ${{ secrets.QUAY_USERNAME }}
226
+ password: ${{ secrets.QUAY_PASSWORD }}
227
+
228
+ - name: Set up Docker Buildx
229
+ uses: docker/setup-buildx-action@v3
230
+
231
+ - name: Merge and push multi-arch image (main)
232
+ env:
233
+ IMAGE: ${{ env.QUAY_REPO }}
234
+ run: |
235
+ DIGESTS=$(printf "$IMAGE@sha256:%s " $(ls ${{ runner.temp }}/digests-main | sed 's/^main-//'))
236
+ echo "Main image digests: $DIGESTS"
237
+ docker buildx imagetools create \
238
+ -t "$IMAGE:${{ needs.build-push-digest.outputs.tag }}" \
239
+ $DIGESTS
240
+
241
+ # ============================================================
242
+ # 第二阶段(v0.8.0):合并多架构 manifest
243
+ # ============================================================
244
+ merge-image-v080:
245
+ name: merge-v0.8.0
246
+ runs-on: ubuntu-latest
247
+ needs: build-push-digest-v080
248
+ steps:
249
+ - name: Download digests (v0.8.0 image)
250
+ uses: actions/download-artifact@v4
251
+ with:
252
+ path: ${{ runner.temp }}/digests-v080
253
+ pattern: digests-v080-*
254
+ merge-multiple: true
255
+
256
+ - name: Login to Quay.io
257
+ uses: docker/login-action@v3
258
+ with:
259
+ registry: quay.io
260
+ username: ${{ secrets.QUAY_USERNAME }}
261
+ password: ${{ secrets.QUAY_PASSWORD }}
262
+
263
+ - name: Set up Docker Buildx
264
+ uses: docker/setup-buildx-action@v3
265
+
266
+ - name: Merge and push multi-arch image (v0.8.0)
267
+ env:
268
+ IMAGE: ${{ env.QUAY_REPO }}
269
+ run: |
270
+ DIGESTS=$(printf "$IMAGE@sha256:%s " $(ls ${{ runner.temp }}/digests-v080 | sed 's/^v080-//'))
271
+ echo "v0.8.0 image digests: $DIGESTS"
272
+ docker buildx imagetools create \
273
+ -t "$IMAGE:v0.8.0-cann9.0.0-torch2.9.0post2-910b-ubuntu22.04-py3.11-vllm" \
274
+ $DIGESTS
verl_0720_main/verl/.github/workflows/docker-build-ascend-a3.yml ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: docker-build-ascend-a3
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: ["main"]
7
+ paths:
8
+ - "docker/ascend/Dockerfile.ascend_9.0.0_a3"
9
+ - "docker/ascend/Dockerfile.ascend_9.0.0_a3_v0.8.0"
10
+ - ".github/workflows/docker-build-ascend-a3.yml"
11
+
12
+ schedule:
13
+ - cron: "0 19 * * *"
14
+
15
+ env:
16
+ QUAY_REPO: quay.io/ascend/verl
17
+
18
+ jobs:
19
+ # ============================================================
20
+ # 第一阶段:分架构构建并推送 digest(main 镜像)
21
+ # ============================================================
22
+ build-push-digest:
23
+ name: build-${{ matrix.tag }}
24
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
25
+ concurrency:
26
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.tag }}
27
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
28
+ runs-on: ${{ matrix.runner }}
29
+ permissions:
30
+ packages: write
31
+ contents: read
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ include:
36
+ - arch: linux/amd64
37
+ runner: ubuntu-latest
38
+ tag: amd64
39
+ - arch: linux/arm64
40
+ runner: ubuntu-22.04-arm
41
+ tag: arm64
42
+ outputs:
43
+ tag: ${{ steps.version.outputs.tag }}
44
+ steps:
45
+ - name: Remove unnecessary parts in github actions runners to free up disk space
46
+ uses: jlumbroso/free-disk-space@v1.3.1
47
+ with:
48
+ tool-cache: true
49
+
50
+ - name: Checkout code
51
+ uses: actions/checkout@v4
52
+
53
+ - name: Set up Python
54
+ uses: actions/setup-python@v5
55
+ with:
56
+ python-version: "3.11"
57
+
58
+ - name: Get base image name and tag
59
+ id: base_image
60
+ run: |
61
+ BASE_IMAGE_FULL=$(grep '^FROM' ./docker/ascend/Dockerfile.ascend_9.0.0_a3 | head -1 | cut -d' ' -f2)
62
+ echo "Base image full: $BASE_IMAGE_FULL"
63
+ BASE_IMAGE_TAG=$(echo "$BASE_IMAGE_FULL" | cut -d':' -f2)
64
+ echo "Base image tag: $BASE_IMAGE_TAG"
65
+ NEW_IMAGE_NAME="verl-$BASE_IMAGE_TAG"
66
+ echo "New image name: $NEW_IMAGE_NAME"
67
+ echo "base_image_tag=$BASE_IMAGE_TAG" >> "$GITHUB_OUTPUT"
68
+ echo "new_image_name=$NEW_IMAGE_NAME" >> "$GITHUB_OUTPUT"
69
+
70
+ - name: Get image tag
71
+ id: version
72
+ run: |
73
+ echo "tag=latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm" >> "$GITHUB_OUTPUT"
74
+
75
+ - name: Set up Docker Buildx
76
+ uses: docker/setup-buildx-action@v3
77
+ with:
78
+ install: true
79
+ driver: docker-container
80
+ use: true
81
+
82
+ - name: Login to Quay.io
83
+ uses: docker/login-action@v3
84
+ with:
85
+ registry: quay.io
86
+ username: ${{ secrets.QUAY_USERNAME }}
87
+ password: ${{ secrets.QUAY_PASSWORD }}
88
+
89
+ - name: Clean Docker cache before build
90
+ run: |
91
+ docker system prune -a -f --volumes || true
92
+
93
+ - name: Build and push by digest (main image)
94
+ uses: docker/build-push-action@v6
95
+ id: build_main
96
+ with:
97
+ context: .
98
+ platforms: ${{ matrix.arch }}
99
+ file: ./docker/ascend/Dockerfile.ascend_9.0.0_a3
100
+ push: true
101
+ outputs: type=image,name=${{ env.QUAY_REPO }},push-by-digest=true,name-canonical=true,push=true
102
+ provenance: false
103
+ cache-from: type=gha
104
+ cache-to: type=gha,mode=max
105
+ build-args: |
106
+ BUILDKIT_INLINE_CACHE=1
107
+
108
+ - name: Export digest (main image)
109
+ run: |
110
+ mkdir -p ${{ runner.temp }}/digests
111
+ digest="${{ steps.build_main.outputs.digest }}"
112
+ touch "${{ runner.temp }}/digests/main-${digest#sha256:}"
113
+
114
+ - name: Upload digest (main image)
115
+ uses: actions/upload-artifact@v4
116
+ with:
117
+ name: digests-main-${{ matrix.tag }}
118
+ path: ${{ runner.temp }}/digests/*
119
+ if-no-files-found: error
120
+ retention-days: 1
121
+
122
+ # ============================================================
123
+ # 第一阶段(v0.8.0):分架构构建并推送 digest
124
+ # ============================================================
125
+ build-push-digest-v080:
126
+ name: build-v0.8.0-${{ matrix.tag }}
127
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
128
+ concurrency:
129
+ group: ${{ github.workflow }}-${{ github.ref }}-v0.8.0-${{ matrix.tag }}
130
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
131
+ runs-on: ${{ matrix.runner }}
132
+ permissions:
133
+ packages: write
134
+ contents: read
135
+ strategy:
136
+ fail-fast: false
137
+ matrix:
138
+ include:
139
+ - arch: linux/amd64
140
+ runner: ubuntu-latest
141
+ tag: amd64
142
+ - arch: linux/arm64
143
+ runner: ubuntu-22.04-arm
144
+ tag: arm64
145
+ steps:
146
+ - name: Remove unnecessary parts in github actions runners to free up disk space
147
+ uses: jlumbroso/free-disk-space@v1.3.1
148
+ with:
149
+ tool-cache: true
150
+
151
+ - name: Checkout code
152
+ uses: actions/checkout@v4
153
+
154
+ - name: Set up Python
155
+ uses: actions/setup-python@v5
156
+ with:
157
+ python-version: "3.11"
158
+
159
+ - name: Set up Docker Buildx
160
+ uses: docker/setup-buildx-action@v3
161
+ with:
162
+ install: true
163
+ driver: docker-container
164
+ use: true
165
+
166
+ - name: Login to Quay.io
167
+ uses: docker/login-action@v3
168
+ with:
169
+ registry: quay.io
170
+ username: ${{ secrets.QUAY_USERNAME }}
171
+ password: ${{ secrets.QUAY_PASSWORD }}
172
+
173
+ - name: Clean Docker cache before build
174
+ run: |
175
+ docker system prune -a -f --volumes || true
176
+
177
+ - name: Build and push by digest (v0.8.0 image)
178
+ uses: docker/build-push-action@v6
179
+ id: build_v080
180
+ with:
181
+ context: .
182
+ platforms: ${{ matrix.arch }}
183
+ file: ./docker/ascend/Dockerfile.ascend_9.0.0_a3_v0.8.0
184
+ push: true
185
+ outputs: type=image,name=${{ env.QUAY_REPO }},push-by-digest=true,name-canonical=true,push=true
186
+ provenance: false
187
+ cache-from: type=gha
188
+ cache-to: type=gha,mode=max
189
+ build-args: |
190
+ BUILDKIT_INLINE_CACHE=1
191
+
192
+ - name: Export digest (v0.8.0 image)
193
+ run: |
194
+ mkdir -p ${{ runner.temp }}/digests-v080
195
+ digest="${{ steps.build_v080.outputs.digest }}"
196
+ touch "${{ runner.temp }}/digests-v080/v080-${digest#sha256:}"
197
+
198
+ - name: Upload digest (v0.8.0 image)
199
+ uses: actions/upload-artifact@v4
200
+ with:
201
+ name: digests-v080-${{ matrix.tag }}
202
+ path: ${{ runner.temp }}/digests-v080/*
203
+ if-no-files-found: error
204
+ retention-days: 1
205
+
206
+ # ============================================================
207
+ # 第二阶段:合并多架构 manifest(main 镜像)
208
+ # ============================================================
209
+ merge-image:
210
+ name: merge
211
+ runs-on: ubuntu-latest
212
+ needs: build-push-digest
213
+ steps:
214
+ - name: Download digests (main image)
215
+ uses: actions/download-artifact@v4
216
+ with:
217
+ path: ${{ runner.temp }}/digests-main
218
+ pattern: digests-main-*
219
+ merge-multiple: true
220
+
221
+ - name: Login to Quay.io
222
+ uses: docker/login-action@v3
223
+ with:
224
+ registry: quay.io
225
+ username: ${{ secrets.QUAY_USERNAME }}
226
+ password: ${{ secrets.QUAY_PASSWORD }}
227
+
228
+ - name: Set up Docker Buildx
229
+ uses: docker/setup-buildx-action@v3
230
+
231
+ - name: Merge and push multi-arch image (main)
232
+ env:
233
+ IMAGE: ${{ env.QUAY_REPO }}
234
+ run: |
235
+ DIGESTS=$(printf "$IMAGE@sha256:%s " $(ls ${{ runner.temp }}/digests-main | sed 's/^main-//'))
236
+ echo "Main image digests: $DIGESTS"
237
+ docker buildx imagetools create \
238
+ -t "$IMAGE:${{ needs.build-push-digest.outputs.tag }}" \
239
+ $DIGESTS
240
+
241
+ # ============================================================
242
+ # 第二阶段(v0.8.0):合并多架构 manifest
243
+ # ============================================================
244
+ merge-image-v080:
245
+ name: merge-v0.8.0
246
+ runs-on: ubuntu-latest
247
+ needs: build-push-digest-v080
248
+ steps:
249
+ - name: Download digests (v0.8.0 image)
250
+ uses: actions/download-artifact@v4
251
+ with:
252
+ path: ${{ runner.temp }}/digests-v080
253
+ pattern: digests-v080-*
254
+ merge-multiple: true
255
+
256
+ - name: Login to Quay.io
257
+ uses: docker/login-action@v3
258
+ with:
259
+ registry: quay.io
260
+ username: ${{ secrets.QUAY_USERNAME }}
261
+ password: ${{ secrets.QUAY_PASSWORD }}
262
+
263
+ - name: Set up Docker Buildx
264
+ uses: docker/setup-buildx-action@v3
265
+
266
+ - name: Merge and push multi-arch image (v0.8.0)
267
+ env:
268
+ IMAGE: ${{ env.QUAY_REPO }}
269
+ run: |
270
+ DIGESTS=$(printf "$IMAGE@sha256:%s " $(ls ${{ runner.temp }}/digests-v080 | sed 's/^v080-//'))
271
+ echo "v0.8.0 image digests: $DIGESTS"
272
+ docker buildx imagetools create \
273
+ -t "$IMAGE:v0.8.0-cann9.0.0-torch2.9.0post2-a3-ubuntu22.04-py3.11-vllm" \
274
+ $DIGESTS
verl_0720_main/verl/.github/workflows/docker-build-ascend-sglang-a2.yml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: docker-build-ascend-sglang-a2
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: ["main"]
7
+ paths:
8
+ - "docker/ascend/Dockerfile.ascend.sglang_8.5.0_a2"
9
+ - ".github/workflows/docker-build-ascend-sglang-a2.yml"
10
+
11
+ schedule:
12
+ - cron: "0 16 * * *"
13
+
14
+ jobs:
15
+ build-ascend-sglang-image-a2:
16
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
17
+ runs-on: ubuntu-latest
18
+ concurrency:
19
+ group: ${{ github.workflow }}-${{ github.ref }}-build-ascend-sglang-image-a2
20
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
21
+ steps:
22
+ - name: Remove unnecessary parts in github actions runners to free up disk space
23
+ uses: jlumbroso/free-disk-space@v1.3.1
24
+ with:
25
+ tool-cache: true
26
+
27
+ - name: Checkout code
28
+ uses: actions/checkout@v4
29
+
30
+ - name: Set up Python
31
+ uses: actions/setup-python@v5
32
+ with:
33
+ python-version: "3.11"
34
+
35
+ - name: Get base image name and tag
36
+ id: base_image
37
+ run: |
38
+ BASE_IMAGE_FULL=$(grep '^FROM' ./docker/ascend/Dockerfile.ascend.sglang_8.5.0_a2 | head -1 | cut -d' ' -f2)
39
+ echo "Base image full: $BASE_IMAGE_FULL"
40
+ BASE_IMAGE_TAG=$(echo "$BASE_IMAGE_FULL" | cut -d':' -f2)
41
+ echo "Base image tag: $BASE_IMAGE_TAG"
42
+ NEW_IMAGE_NAME="verl-sglang-$BASE_IMAGE_TAG"
43
+ echo "New image name: $NEW_IMAGE_NAME"
44
+ echo "base_image_tag=$BASE_IMAGE_TAG" >> "$GITHUB_OUTPUT"
45
+ echo "new_image_name=$NEW_IMAGE_NAME" >> "$GITHUB_OUTPUT"
46
+
47
+ - name: Get image tag
48
+ id: version
49
+ run: |
50
+ echo "tag=latest-cann8.5.0-torch_npu2.8.0post2-910b-ubuntu22.04-py3.11-sglang" >> "$GITHUB_OUTPUT"
51
+
52
+ - name: Set up Docker Buildx
53
+ uses: docker/setup-buildx-action@v3
54
+
55
+ - name: Login to Quay.io
56
+ uses: docker/login-action@v3
57
+ with:
58
+ registry: quay.io
59
+ username: ${{ secrets.QUAY_USERNAME }}
60
+ password: ${{ secrets.QUAY_PASSWORD }}
61
+
62
+ - name: Clean Docker cache before build
63
+ run: |
64
+ docker system prune -a -f --volumes || true
65
+
66
+ - name: Build and push images Quay
67
+ uses: docker/build-push-action@v6
68
+ with:
69
+ context: .
70
+ platforms: linux/amd64,linux/arm64
71
+ file: ./docker/ascend/Dockerfile.ascend.sglang_8.5.0_a2
72
+ push: true
73
+ tags: |
74
+ quay.io/ascend/verl:${{ steps.version.outputs.tag }}
75
+ cache-from: type=gha
76
+ cache-to: type=gha,mode=max
77
+ build-args: |
78
+ BUILDKIT_INLINE_CACHE=1
verl_0720_main/verl/.github/workflows/docker-build-ascend-sglang-a3.yml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: docker-build-ascend-sglang-a3
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: ["main"]
7
+ paths:
8
+ - "docker/ascend/Dockerfile.ascend.sglang_8.5.0_a3"
9
+ - ".github/workflows/docker-build-ascend-sglang-a3.yml"
10
+
11
+ schedule:
12
+ - cron: "0 16 * * *"
13
+
14
+ jobs:
15
+ build-ascend-sglang-image-a3:
16
+ if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'verl-project' }}
17
+ runs-on: ubuntu-latest
18
+ concurrency:
19
+ group: ${{ github.workflow }}-${{ github.ref }}-build-ascend-sglang-image-a3
20
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
21
+ steps:
22
+ - name: Remove unnecessary parts in github actions runners to free up disk space
23
+ uses: jlumbroso/free-disk-space@v1.3.1
24
+ with:
25
+ tool-cache: true
26
+
27
+ - name: Checkout code
28
+ uses: actions/checkout@v4
29
+
30
+ - name: Set up Python
31
+ uses: actions/setup-python@v5
32
+ with:
33
+ python-version: "3.11"
34
+
35
+ - name: Get base image name and tag
36
+ id: base_image
37
+ run: |
38
+ BASE_IMAGE_FULL=$(grep '^FROM' ./docker/ascend/Dockerfile.ascend.sglang_8.5.0_a3 | head -1 | cut -d' ' -f2)
39
+ echo "Base image full: $BASE_IMAGE_FULL"
40
+ BASE_IMAGE_TAG=$(echo "$BASE_IMAGE_FULL" | cut -d':' -f2)
41
+ echo "Base image tag: $BASE_IMAGE_TAG"
42
+ NEW_IMAGE_NAME="verl-sglang-$BASE_IMAGE_TAG"
43
+ echo "New image name: $NEW_IMAGE_NAME"
44
+ echo "base_image_tag=$BASE_IMAGE_TAG" >> "$GITHUB_OUTPUT"
45
+ echo "new_image_name=$NEW_IMAGE_NAME" >> "$GITHUB_OUTPUT"
46
+
47
+ - name: Get image tag
48
+ id: version
49
+ run: |
50
+ echo "tag=latest-cann8.5.0-torch_npu2.8.0post2-a3-ubuntu22.04-py3.11-sglang" >> "$GITHUB_OUTPUT"
51
+
52
+ - name: Set up Docker Buildx
53
+ uses: docker/setup-buildx-action@v3
54
+
55
+ - name: Login to Quay.io
56
+ uses: docker/login-action@v3
57
+ with:
58
+ registry: quay.io
59
+ username: ${{ secrets.QUAY_USERNAME }}
60
+ password: ${{ secrets.QUAY_PASSWORD }}
61
+
62
+ - name: Clean Docker cache before build
63
+ run: |
64
+ docker system prune -a -f --volumes || true
65
+
66
+ - name: Build and push images Quay
67
+ uses: docker/build-push-action@v6
68
+ with:
69
+ context: .
70
+ platforms: linux/amd64,linux/arm64
71
+ file: ./docker/ascend/Dockerfile.ascend.sglang_8.5.0_a3
72
+ push: true
73
+ tags: |
74
+ quay.io/ascend/verl:${{ steps.version.outputs.tag }}
75
+ cache-from: type=gha
76
+ cache-to: type=gha,mode=max
77
+ build-args: |
78
+ BUILDKIT_INLINE_CACHE=1
verl_0720_main/verl/.github/workflows/e2e_ascend.yml ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ push:
38
+ branches:
39
+ - main
40
+ - v0.*
41
+ pull_request:
42
+ branches:
43
+ - main
44
+ paths:
45
+ - ".github/workflows/e2e_ascend.yml"
46
+ - "examples/data_preprocess/**"
47
+ - "examples/grpo_trainer/**"
48
+ - "examples/ppo_trainer/**"
49
+ - "examples/sft/**"
50
+ - "verl/experimental/one_step_off_policy/**"
51
+ - "tests/special_npu/**"
52
+ - "tests/special_sanity/check_device_api_usage.py"
53
+ - "verl/**"
54
+ - "pyproject.toml"
55
+ - "requirements-npu.txt"
56
+ - "setup.py"
57
+
58
+ # Cancel jobs on the same ref if a new one is triggered
59
+ concurrency:
60
+ group: ${{ github.workflow }}-${{ github.ref }}
61
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
62
+
63
+ permissions:
64
+ contents: read
65
+
66
+ jobs:
67
+ llm_rl_job:
68
+ if: github.repository_owner == 'verl-project'
69
+ name: E2E Ascend testing for RL training scenarios of LLM models
70
+ runs-on: linux-aarch64-a3-8
71
+ timeout-minutes: 120
72
+ container:
73
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm
74
+ options: >-
75
+ --shm-size 16g
76
+ env:
77
+ HF_ENDPOINT: "https://hf-mirror.com"
78
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
79
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
80
+ UV_INDEX_STRATEGY: unsafe-best-match
81
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
82
+ UV_HTTP_TIMEOUT: 120
83
+ UV_NO_CACHE: "1"
84
+ UV_SYSTEM_PYTHON: "1"
85
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
86
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
87
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
88
+ steps:
89
+ - name: Check npu and CANN info
90
+ run: |
91
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
92
+ npu-smi info
93
+ - name: Install uv
94
+ run: pip install uv
95
+ - name: Check initial pip list from image
96
+ run: |
97
+ uv pip list
98
+ - name: Checkout verl-project/verl repo
99
+ uses: actions/checkout@v4
100
+ with:
101
+ fetch-depth: 0
102
+ clean: true
103
+ - name: Install the current repository
104
+ run: |
105
+ uv pip install --no-deps -e .
106
+ uv pip install --no-deps TransferQueue==0.1.8
107
+ - name: Check final pip list
108
+ run: |
109
+ uv pip list
110
+ - name: Preprocess gsm8k dataset
111
+ run: |
112
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
113
+ - name: Running gsm8k e2e training tests with PPO on ASCEND NPU (FSDP backend)
114
+ run: |
115
+ ray stop --force
116
+ bash tests/special_npu/run_qwen3_06b_ppo.sh
117
+ rm -rf $HOME/ckpts
118
+ - name: Running gsm8k e2e training tests with GRPO on ASCEND NPU (FSDP backend)
119
+ run: |
120
+ ray stop --force
121
+ bash tests/special_npu/run_qwen3_8b_grpo_profiling.sh
122
+ python3 "tests/utils/test_check_profiler_output.py" --profiler_dir="./profiler_data-dis" --device="npu"
123
+ rm -rf ./profiler_data-dis
124
+ rm -rf $HOME/ckpts
125
+ - name: Running gsm8k e2e training tests with GRPO on ASCEND NPU (MindSpeed backend)
126
+ run: |
127
+ ray stop --force
128
+ USE_DIST_CKPT=True bash tests/special_npu/run_qwen3_06b_grpo_mindspeed.sh
129
+ rm -rf $HOME/dist_ckpt/qwen3_06b_grpo_mindspeed
130
+ rm -rf $HOME/ckpts
131
+ - name: Running gsm8k e2e training tests with GRPO on ASCEND NPU (MindSpeed backend, MoE Model)
132
+ run: |
133
+ ray stop --force
134
+ USE_DIST_CKPT=True USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen3moe_minimal.json DUMMY_MODEL_PATH=$HOME/dist_ckpt/qwen3_30b_grpo_mindspeed bash tests/special_npu/run_qwen3_30b_grpo_mindspeed.sh
135
+
136
+ engine_mindspeed_llm_rl_job:
137
+ if: github.repository_owner == 'verl-project'
138
+ name: E2E Ascend testing for RL training scenarios of LLM models using MindSpeed_LLM engine
139
+ runs-on: linux-aarch64-a3-8
140
+ timeout-minutes: 120
141
+ container:
142
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann8.5.0-torch_npu2.8.0post2-a3-ubuntu22.04-py3.11-sglang
143
+ options: >-
144
+ --shm-size 16g
145
+ env:
146
+ HF_ENDPOINT: "https://hf-mirror.com"
147
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
148
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
149
+ UV_INDEX_STRATEGY: unsafe-best-match
150
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
151
+ UV_HTTP_TIMEOUT: 120
152
+ UV_NO_CACHE: "1"
153
+ UV_SYSTEM_PYTHON: "1"
154
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
155
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
156
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
157
+ steps:
158
+ - name: Check npu and CANN info
159
+ run: |
160
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
161
+ npu-smi info
162
+ - name: Install uv
163
+ run: pip install uv
164
+ - name: Check initial pip list from image
165
+ run: |
166
+ uv pip list
167
+ - name: Checkout verl-project/verl repo
168
+ uses: actions/checkout@v4
169
+ with:
170
+ fetch-depth: 0
171
+ clean: true
172
+ - name: Install the current repository
173
+ run: |
174
+ uv pip install --no-deps --no-build-isolation -e .
175
+ uv pip install --no-deps TransferQueue==0.1.8
176
+ - name: Check final pip list
177
+ run: |
178
+ uv pip list
179
+ - name: Configure related dependencies
180
+ run: |
181
+ git clone --depth 1 --branch core_v0.12.1 https://github.com/NVIDIA/Megatron-LM.git /Megatron-LM
182
+ rm -rf /MindSpeed
183
+ git clone https://gitcode.com/ascend/MindSpeed.git /MindSpeed
184
+ git clone https://gitcode.com/ascend/MindSpeed-LLM.git /MindSpeed-LLM
185
+ - name: Preprocess gsm8k dataset
186
+ run: |
187
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
188
+ - name: Running gsm8k e2e training tests with GRPO on ASCEND NPU (MindSpeedLLM backend)
189
+ run: |
190
+ ray stop --force
191
+ export PYTHONPATH=$PYTHONPATH:/Megatron-LM
192
+ export PYTHONPATH=$PYTHONPATH:/MindSpeed
193
+ export PYTHONPATH=$PYTHONPATH:/MindSpeed-LLM
194
+ rm -rf /root/.cache/torch_extensions/py311_cpu/npu_rotary_position_embedding
195
+ bash tests/special_npu/run_qwen3_8b_grpo_mindspeedllm.sh
196
+ - name: Running gsm8k e2e training tests with GRPO on ASCEND NPU (MindSpeedLLM backend, MoE Model)
197
+ run: |
198
+ ray stop --force
199
+ export PYTHONPATH=$PYTHONPATH:/Megatron-LM
200
+ export PYTHONPATH=$PYTHONPATH:/MindSpeed
201
+ export PYTHONPATH=$PYTHONPATH:/MindSpeed-LLM
202
+ rm -rf /root/.cache/torch_extensions/py311_cpu/npu_rotary_position_embedding
203
+ USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen3moe_minimal.json DUMMY_MODEL_PATH=$HOME/dist_ckpt/qwen3_30b_grpo_mindspeedllm bash tests/special_npu/run_qwen3_30b_grpo_mindspeedllm.sh
204
+ rm -rf $HOME/dist_ckpt/qwen3_30b_grpo_mindspeedllm
205
+
206
+ vlm_rl_job:
207
+ if: github.repository_owner == 'verl-project'
208
+ name: E2E Ascend testing for RL training scenarios of VLM models
209
+ runs-on: linux-aarch64-a2b3-8
210
+ timeout-minutes: 120
211
+ container:
212
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-910b-ubuntu22.04-py3.11-vllm
213
+ options: >-
214
+ --shm-size 80g
215
+ env:
216
+ HF_ENDPOINT: "https://hf-mirror.com"
217
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
218
+ steps:
219
+ - name: Check npu and CANN info
220
+ run: |
221
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
222
+ npu-smi info
223
+ - name: Check initial pip list from image
224
+ run: |
225
+ pip list
226
+ - name: Checkout verl-project/verl repo
227
+ uses: actions/checkout@v4
228
+ with:
229
+ fetch-depth: 0
230
+ clean: true
231
+ - name: Install the current repository
232
+ run: |
233
+ pip install --no-deps -e .
234
+ pip install --no-deps TransferQueue==0.1.8
235
+ - name: Check final pip list
236
+ run: |
237
+ pip list
238
+ - name: Preprocess geo3k dataset
239
+ run: |
240
+ python examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/.cache/datasets/hiyouga/geometry3k
241
+ - name: Running geo3k e2e training tests with GRPO on ASCEND NPU
242
+ run: |
243
+ ray stop --force
244
+ SAVE_FREQ=-1 TOTAL_TRAINING_STEPS=1 bash tests/special_npu/run_qwen3_vl_8b_Instruct_fsdp2_npu.sh
245
+ rm -rf $HOME/ckpts
verl_0720_main/verl/.github/workflows/e2e_fully_async_policy.yml ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_fully_async_policy
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ - "!**/*.md"
46
+ - "!**/*.sh"
47
+ # Other entrypoints
48
+ - "!examples/*trainer*"
49
+ - "!tests/**"
50
+ - "!verl/trainer/main_*.py"
51
+ - "!verl/trainer/fsdp_sft_trainer.py"
52
+ - "verl/experimental/fully_async_policy"
53
+ pull_request:
54
+ branches:
55
+ - main
56
+ - v0.*
57
+ paths:
58
+ - "**/*.py"
59
+ - "!**/*.md"
60
+ - "!**/*.sh"
61
+ # Other entrypoints
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py"
66
+ # Home
67
+ - "verl/experimental/fully_async_policy"
68
+ # Entrypoints
69
+ - ".github/workflows/e2e_fully_async_policy.yml"
70
+ - "examples/data_preprocess/gsm8k.py"
71
+ - "tests/special_e2e/run_fully_async_policy.sh"
72
+
73
+ # Cancel jobs on the same ref if a new one is triggered
74
+ concurrency:
75
+ group: ${{ github.workflow }}-${{ github.ref }}
76
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
77
+
78
+ # Declare permissions just read content.
79
+ permissions:
80
+ contents: read
81
+
82
+ env:
83
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
84
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
85
+
86
+ jobs:
87
+ setup:
88
+ if: github.repository_owner == 'verl-project'
89
+ runs-on: ubuntu-latest
90
+ outputs:
91
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
92
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
93
+ steps:
94
+ - uses: actions/checkout@v4
95
+ - id: create-runner
96
+ uses: volcengine/vemlp-github-runner@v1
97
+ with:
98
+ mode: "create"
99
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
100
+ mlp-image: "${{ env.IMAGE }}"
101
+
102
+ # Test FSDP2 strategy
103
+ e2e_fully_async_policy_fsdp2:
104
+ needs: setup
105
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
106
+ timeout-minutes: 10 # Increase timeout for async training
107
+ env:
108
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
109
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
110
+ HF_ENDPOINT: "https://hf-mirror.com"
111
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
112
+ ACTOR_STRATEGY: "fsdp2"
113
+ steps:
114
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
115
+ with:
116
+ fetch-depth: 0
117
+ - name: Install the current repository
118
+ run: |
119
+ pip3 install -r requirements-test.txt
120
+ pip3 install --no-deps -e .
121
+ pip3 install --no-deps TransferQueue==0.1.8
122
+ pip3 install cupy-cuda13x==13.6.0
123
+ - name: Check final pip list
124
+ run: |
125
+ pip3 list
126
+ - name: Prepare GSM8K dataset
127
+ run: |
128
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
129
+ - name: Running the E2E test with fully_async_policy algorithm (FSDP2)
130
+ run: |
131
+ ray stop --force
132
+ bash tests/special_e2e/run_fully_async_policy.sh
133
+
134
+ # Test Megatron strategy
135
+ e2e_fully_async_policy_megatron:
136
+ needs: [setup, e2e_fully_async_policy_fsdp2]
137
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
138
+ timeout-minutes: 10 # Increase timeout for async training
139
+ env:
140
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
141
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
142
+ HF_ENDPOINT: "https://hf-mirror.com"
143
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
144
+ ACTOR_STRATEGY: "megatron"
145
+ steps:
146
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
147
+ with:
148
+ fetch-depth: 0
149
+ - name: Install the current repository
150
+ run: |
151
+ pip3 install -r requirements-test.txt
152
+ pip3 install -r requirements.txt
153
+ pip3 install --no-deps -e .
154
+ pip3 install cupy-cuda13x==13.6.0
155
+ pip3 uninstall -y mbridge
156
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
157
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
158
+ pip3 install "nvidia-modelopt>=0.37.0"
159
+ - name: Check final pip list
160
+ run: |
161
+ pip3 list
162
+ - name: Prepare GSM8K dataset
163
+ run: |
164
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
165
+ - name: Running the E2E test with fully_async_policy algorithm (Megatron)
166
+ run: |
167
+ ray stop --force
168
+ bash tests/special_e2e/run_fully_async_policy.sh
169
+
170
+ cleanup:
171
+ runs-on: ubuntu-latest
172
+ needs: [setup, e2e_fully_async_policy_fsdp2]
173
+ if: always()
174
+ steps:
175
+ - id: destroy-runner
176
+ uses: volcengine/vemlp-github-runner@v1
177
+ with:
178
+ mode: "destroy"
179
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
180
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_ascend.yml ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_fully_async_policy_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ - "!**/*.md"
46
+ - "!**/*.sh"
47
+ # Other entrypoints
48
+ - "!examples/*trainer*"
49
+ - "!tests/**"
50
+ - "!verl/trainer/main_*.py"
51
+ - "!verl/trainer/fsdp_sft_trainer.py"
52
+ - "verl/experimental/fully_async_policy"
53
+ pull_request:
54
+ branches:
55
+ - main
56
+ - v0.*
57
+ paths:
58
+ - "**/*.py"
59
+ - "!**/*.md"
60
+ - "!**/*.sh"
61
+ # Other entrypoints
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py"
66
+ # Home
67
+ - "verl/experimental/fully_async_policy"
68
+ # Entrypoints
69
+ - ".github/workflows/e2e_fully_async_policy_ascend.yml"
70
+ - "examples/data_preprocess/gsm8k.py"
71
+ - "tests/special_e2e/run_fully_async_policy.sh"
72
+
73
+ # Cancel jobs on the same ref if a new one is triggered
74
+ concurrency:
75
+ group: ${{ github.workflow }}-${{ github.ref }}
76
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
77
+
78
+ # Declare permissions just read content.
79
+ permissions:
80
+ contents: read
81
+
82
+ jobs:
83
+ # Test FSDP2 strategy
84
+ e2e_fully_async_policy_fsdp2_ascend:
85
+ if: github.repository_owner == 'verl-project'
86
+ runs-on: linux-aarch64-a3-8
87
+ timeout-minutes: 60 # Increase this timeout value as needed
88
+ container:
89
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm
90
+ options: >-
91
+ --shm-size 16g
92
+ env:
93
+ HF_ENDPOINT: "https://hf-mirror.com"
94
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
95
+ ACTOR_STRATEGY: "fsdp2"
96
+ device_name: "npu"
97
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
98
+ UV_INDEX_STRATEGY: unsafe-best-match
99
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
100
+ UV_HTTP_TIMEOUT: 120
101
+ UV_NO_CACHE: "1"
102
+ UV_SYSTEM_PYTHON: "1"
103
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
104
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
105
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
106
+ steps:
107
+ - name: Check npu and CANN info
108
+ run: |
109
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
110
+ npu-smi info
111
+ - name: Install uv
112
+ run: pip install uv
113
+ - name: Check initial pip list from image
114
+ run: |
115
+ uv pip list
116
+ - name: Checkout verl-project/verl repo
117
+ uses: actions/checkout@v4
118
+ with:
119
+ fetch-depth: 0
120
+ clean: true
121
+ - name: Install the current repository
122
+ run: |
123
+ uv pip install --no-deps -e .
124
+ - name: Check final pip list
125
+ run: |
126
+ uv pip list
127
+ - name: Prepare weights
128
+ run: |
129
+ ln -s /root/.cache/models ~/models
130
+ - name: Prepare GSM8K dataset
131
+ run: |
132
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
133
+ - name: Running the E2E test with fully_async_policy algorithm (FSDP2)
134
+ run: |
135
+ ray stop --force
136
+ bash tests/special_e2e/run_fully_async_policy.sh
137
+
138
+ # Test Megatron strategy
139
+ e2e_fully_async_policy_megatron_ascend:
140
+ if: github.repository_owner == 'verl-project'
141
+ needs: e2e_fully_async_policy_fsdp2_ascend
142
+ runs-on: linux-aarch64-a3-8
143
+ timeout-minutes: 60 # Increase this timeout value as needed
144
+ container:
145
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm
146
+ options: >-
147
+ --shm-size 16g
148
+ env:
149
+ HF_ENDPOINT: "https://hf-mirror.com"
150
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
151
+ ACTOR_STRATEGY: "megatron"
152
+ device_name: "npu"
153
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
154
+ UV_INDEX_STRATEGY: unsafe-best-match
155
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
156
+ UV_HTTP_TIMEOUT: 120
157
+ UV_NO_CACHE: "1"
158
+ UV_SYSTEM_PYTHON: "1"
159
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
160
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
161
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
162
+ steps:
163
+ - name: Check npu and CANN info
164
+ run: |
165
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
166
+ npu-smi info
167
+ - name: Install uv
168
+ run: pip install uv
169
+ - name: Check initial pip list from image
170
+ run: |
171
+ uv pip list
172
+ - name: Checkout verl-project/verl repo
173
+ uses: actions/checkout@v4
174
+ with:
175
+ fetch-depth: 0
176
+ clean: true
177
+ - name: Install the current repository
178
+ run: |
179
+ uv pip install --no-deps -e .
180
+ - name: Check final pip list
181
+ run: |
182
+ uv pip list
183
+ - name: Prepare weights
184
+ run: |
185
+ ln -s /root/.cache/models ~/models
186
+ - name: Prepare GSM8K dataset
187
+ run: |
188
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
189
+ - name: Running the E2E test with fully_async_policy algorithm (Megatron)
190
+ run: |
191
+ ray stop --force
192
+ VANILLA_MBRIDGE=True bash tests/special_e2e/run_fully_async_policy.sh
verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_opd.yml ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: e2e_fully_async_policy_opd
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - v0.*
8
+ paths:
9
+ - "**/*.py"
10
+ - "!**/*.md"
11
+ - "!**/*.sh"
12
+ - "!examples/*trainer*"
13
+ - "!tests/**"
14
+ - "!verl/trainer/main_*.py"
15
+ - "!verl/trainer/fsdp_sft_trainer.py"
16
+ - "verl/experimental/fully_async_policy"
17
+ - "verl/trainer/distillation"
18
+ pull_request:
19
+ branches:
20
+ - main
21
+ - v0.*
22
+ paths:
23
+ - "**/*.py"
24
+ - "!**/*.md"
25
+ - "!**/*.sh"
26
+ - "!examples/**"
27
+ - "!tests/**"
28
+ - "!verl/trainer/main_*.py"
29
+ - "!verl/trainer/fsdp_sft_trainer.py"
30
+ - "verl/experimental/fully_async_policy"
31
+ - "verl/trainer/distillation"
32
+ - ".github/workflows/e2e_fully_async_policy_opd.yml"
33
+ - "examples/data_preprocess/gsm8k.py"
34
+ - "examples/data_preprocess/geo3k.py"
35
+ - "tests/special_e2e/run_fully_async_policy_opd.sh"
36
+
37
+ # Cancel jobs on the same ref if a new one is triggered
38
+ concurrency:
39
+ group: ${{ github.workflow }}-${{ github.ref }}
40
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
41
+
42
+ # Declare permissions just read content.
43
+ permissions:
44
+ contents: read
45
+
46
+ env:
47
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
48
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
49
+
50
+ jobs:
51
+ setup:
52
+ if: github.repository_owner == 'verl-project'
53
+ runs-on: ubuntu-latest
54
+ outputs:
55
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
56
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
57
+ steps:
58
+ - uses: actions/checkout@v4
59
+ - id: create-runner
60
+ uses: volcengine/vemlp-github-runner@v1
61
+ with:
62
+ mode: "create"
63
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
64
+ mlp-image: "${{ env.IMAGE }}"
65
+
66
+ # Test Multi-Teacher OPD with Megatron strategy
67
+ e2e_fully_async_policy_opd_megatron:
68
+ needs: setup
69
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
70
+ timeout-minutes: 30
71
+ env:
72
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
73
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
74
+ HF_ENDPOINT: "https://hf-mirror.com"
75
+ HF_HUB_ENABLE_HF_TRANSFER: "0"
76
+ steps:
77
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
78
+ with:
79
+ fetch-depth: 0
80
+ - name: Install the current repository
81
+ run: |
82
+ pip3 install -r requirements-test.txt
83
+ pip3 install -r requirements.txt
84
+ pip3 install --no-deps -e .
85
+ pip3 install cupy-cuda13x==13.6.0
86
+ pip3 uninstall -y mbridge
87
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
88
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
89
+ pip3 install "nvidia-modelopt>=0.37.0"
90
+ - name: Check final pip list
91
+ run: |
92
+ pip3 list
93
+ - name: Prepare datasets
94
+ run: |
95
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
96
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k/ --local_save_dir ${HOME}/data/geo3k
97
+ - name: Running the E2E test with fully_async_policy + Multi-Teacher OPD (Megatron)
98
+ run: |
99
+ ray stop --force
100
+ bash tests/special_e2e/run_fully_async_policy_opd.sh
101
+
102
+ cleanup:
103
+ runs-on: ubuntu-latest
104
+ needs: [setup, e2e_fully_async_policy_opd_megatron]
105
+ if: always()
106
+ steps:
107
+ - id: destroy-runner
108
+ uses: volcengine/vemlp-github-runner@v1
109
+ with:
110
+ mode: "destroy"
111
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
112
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_fully_async_policy_trtllm.yml ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_fully_async_policy_trtllm
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ push:
38
+ branches:
39
+ - main
40
+ - v0.*
41
+ paths:
42
+ - "**/*.py"
43
+ - "!**/*.md"
44
+ - "!**/*.sh"
45
+ - "!examples/*trainer*"
46
+ - "!tests/**"
47
+ - "!verl/trainer/main_*.py"
48
+ - "!verl/trainer/fsdp_sft_trainer.py"
49
+ - "verl/workers/rollout/trtllm_rollout/**"
50
+ - "verl/experimental/fully_async_policy/**"
51
+ - "verl/checkpoint_engine/**"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "verl/workers/rollout/trtllm_rollout/**"
58
+ - "verl/experimental/fully_async_policy/**"
59
+ - "verl/checkpoint_engine/**"
60
+ - ".github/workflows/e2e_fully_async_policy_trtllm.yml"
61
+ - "tests/special_e2e/run_fully_async_policy.sh"
62
+ - "examples/data_preprocess/gsm8k.py"
63
+
64
+ # Cancel jobs on the same ref if a new one is triggered
65
+ concurrency:
66
+ group: ${{ github.workflow }}-${{ github.ref }}
67
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
68
+
69
+ # Declare permissions just read content.
70
+ permissions:
71
+ contents: read
72
+
73
+ env:
74
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:trtllm-1.3.0rc15"
75
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
76
+
77
+ jobs:
78
+ setup:
79
+ if: github.repository_owner == 'verl-project'
80
+ runs-on: ubuntu-latest
81
+ outputs:
82
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
83
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
84
+ steps:
85
+ - uses: actions/checkout@v4
86
+ - id: create-runner
87
+ uses: volcengine/vemlp-github-runner@v1
88
+ with:
89
+ mode: "create"
90
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
91
+ mlp-image: "${{ env.IMAGE }}"
92
+
93
+ trtllm_async_unit_tests:
94
+ needs: setup
95
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
96
+ timeout-minutes: 30
97
+ env:
98
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
99
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
100
+ HF_ENDPOINT: "https://hf-mirror.com"
101
+ HF_HUB_ENABLE_HF_TRANSFER: "0"
102
+ TORCH_CUDA_ARCH_LIST: "7.5;8.0;8.9;9.0;10.0;12.0+PTX"
103
+ steps:
104
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
105
+ with:
106
+ fetch-depth: 0
107
+ - name: Reinstall FlashInfer for runtime GPU arch
108
+ run: |
109
+ unset TORCH_CUDA_ARCH_LIST
110
+ pip3 install --force-reinstall --no-deps flashinfer-python
111
+ - name: Install the current repository
112
+ run: |
113
+ pip3 install pytest-asyncio
114
+ pip3 install -r requirements-test.txt
115
+ pip3 install --no-deps -e .
116
+ pip3 install --no-deps TransferQueue==0.1.8
117
+ - name: Run TRT-LLM async unit tests
118
+ run: |
119
+ unset TORCH_CUDA_ARCH_LIST
120
+ export TRTLLM_ENABLE_PDL=0
121
+ export TRTLLM_TEST_MODEL_PATH_ROOT="${HOME}/models"
122
+ ray stop --force
123
+ pytest -v -s --durations=20 \
124
+ tests/workers/rollout/rollout_trtllm/test_trtllm_abort.py
125
+
126
+ # Megatron multi-replica: 4 rollout GPUs split into 2 replicas × TP=2.
127
+ e2e_fully_async_policy_trtllm_megatron_multi_replica:
128
+ needs: setup
129
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
130
+ timeout-minutes: 20
131
+ env:
132
+ HTTP_PROXY: ${{ secrets.PROXY_HTTP }}
133
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
134
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
135
+ HF_ENDPOINT: "https://hf-mirror.com"
136
+ HF_HUB_ENABLE_HF_TRANSFER: "0"
137
+ ACTOR_STRATEGY: "megatron"
138
+ ROLLOUT_NAME: "trtllm"
139
+ GEN_TP: "2" # 4 rollout GPUs / TP=2 = 2 replicas
140
+ steps:
141
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
142
+ with:
143
+ fetch-depth: 0
144
+ - name: Install the current repository
145
+ run: |
146
+ pip3 install -r requirements-test.txt
147
+ pip3 install -r requirements.txt
148
+ pip3 install --no-deps -e .
149
+ pip3 install cupy-cuda12x==14.0.1
150
+ pip3 uninstall -y mbridge
151
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
152
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
153
+ pip3 install "nvidia-modelopt>=0.37.0"
154
+ - name: Check final pip list
155
+ run: |
156
+ pip3 list
157
+ - name: Prepare GSM8K dataset
158
+ run: |
159
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
160
+ - name: Running TRT-LLM fully-async E2E test with Megatron (multi-replica, 2×TP=2)
161
+ run: |
162
+ ray stop --force
163
+ bash tests/special_e2e/run_fully_async_policy.sh \
164
+ data.max_response_length=128 \
165
+ actor_rollout_ref.rollout.n=2 \
166
+ actor_rollout_ref.rollout.gpu_memory_utilization=0.1 \
167
+ actor_rollout_ref.actor.ppo_mini_batch_size=4 \
168
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=1536
169
+
170
+ cleanup:
171
+ runs-on: ubuntu-latest
172
+ needs: [setup, trtllm_async_unit_tests, e2e_fully_async_policy_trtllm_megatron_multi_replica]
173
+ if: always()
174
+ steps:
175
+ - id: destroy-runner
176
+ uses: volcengine/vemlp-github-runner@v1
177
+ with:
178
+ mode: "destroy"
179
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
180
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_one_step_off_policy.yml ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_one_step_off_policy
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ - "!**/*.md"
46
+ - "!**/*.sh"
47
+ # Other entrypoints
48
+ - "!examples/*trainer*"
49
+ - "!tests/**"
50
+ - "!verl/trainer/main_*.py"
51
+ - "!verl/trainer/fsdp_sft_trainer.py"
52
+ - "verl/experimental/one_step_off_policy"
53
+ pull_request:
54
+ branches:
55
+ - main
56
+ - v0.*
57
+ paths:
58
+ - "**/*.py"
59
+ - "!**/*.md"
60
+ - "!**/*.sh"
61
+ # Other entrypoints
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py"
66
+ # Home
67
+ - "verl/experimental/one_step_off_policy"
68
+ # Entrypoints
69
+ - ".github/workflows/e2e_one_step_off_policy.yml"
70
+ - "examples/data_preprocess/gsm8k.py"
71
+ - "tests/special_e2e/run_one_step_off_policy.sh"
72
+
73
+ # Cancel jobs on the same ref if a new one is triggered
74
+ concurrency:
75
+ group: ${{ github.workflow }}-${{ github.ref }}
76
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
77
+
78
+ # Declare permissions just read content.
79
+ permissions:
80
+ contents: read
81
+
82
+ env:
83
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
84
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
85
+
86
+ jobs:
87
+ setup:
88
+ if: github.repository_owner == 'verl-project'
89
+ runs-on: ubuntu-latest
90
+ outputs:
91
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
92
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
93
+ steps:
94
+ - uses: actions/checkout@v4
95
+ - id: create-runner
96
+ uses: volcengine/vemlp-github-runner@v1
97
+ with:
98
+ mode: "create"
99
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
100
+ mlp-image: "${{ env.IMAGE }}"
101
+
102
+ # Test FSDP2 strategy
103
+ e2e_one_step_off_policy_fsdp2:
104
+ needs: setup
105
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
106
+ timeout-minutes: 10 # Increase timeout for async training
107
+ env:
108
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
109
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
110
+ HF_ENDPOINT: "https://hf-mirror.com"
111
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
112
+ ACTOR_STRATEGY: "fsdp2"
113
+ steps:
114
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
115
+ with:
116
+ fetch-depth: 0
117
+ - name: Install the current repository
118
+ run: |
119
+ pip3 install -r requirements-test.txt
120
+ pip3 install --no-deps -e .
121
+ pip3 install --no-deps TransferQueue==0.1.8
122
+ pip3 install cupy-cuda13x==13.6.0
123
+ - name: Check final pip list
124
+ run: |
125
+ pip3 list
126
+ - name: Prepare GSM8K dataset
127
+ run: |
128
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
129
+ - name: Running the E2E test with one_step_off_policy algorithm (FSDP2)
130
+ run: |
131
+ ray stop --force
132
+ bash tests/special_e2e/run_one_step_off_policy.sh
133
+
134
+ # Test Megatron strategy
135
+ e2e_one_step_off_policy_megatron:
136
+ needs: [setup, e2e_one_step_off_policy_fsdp2]
137
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
138
+ timeout-minutes: 10 # Increase timeout for async training
139
+ env:
140
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
141
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
142
+ HF_ENDPOINT: "https://hf-mirror.com"
143
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
144
+ ACTOR_STRATEGY: "megatron"
145
+ steps:
146
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
147
+ with:
148
+ fetch-depth: 0
149
+ - name: Install the current repository
150
+ run: |
151
+ pip3 install -r requirements-test.txt
152
+ pip3 install -r requirements.txt
153
+ pip3 install --no-deps -e .
154
+ pip3 install cupy-cuda13x==13.6.0
155
+ pip3 uninstall -y mbridge
156
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
157
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
158
+ pip3 install "nvidia-modelopt>=0.37.0"
159
+ - name: Check final pip list
160
+ run: |
161
+ pip3 list
162
+ - name: Prepare GSM8K dataset
163
+ run: |
164
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
165
+ - name: Running the E2E test with one_step_off_policy algorithm (Megatron)
166
+ run: |
167
+ ray stop --force
168
+ bash tests/special_e2e/run_one_step_off_policy.sh
169
+
170
+ cleanup:
171
+ runs-on: ubuntu-latest
172
+ needs:
173
+ [setup, e2e_one_step_off_policy_fsdp2, e2e_one_step_off_policy_megatron]
174
+ if: always()
175
+ steps:
176
+ - id: destroy-runner
177
+ uses: volcengine/vemlp-github-runner@v1
178
+ with:
179
+ mode: "destroy"
180
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
181
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_one_step_off_policy_ascend.yml ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_one_step_off_policy_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ - "!**/*.md"
46
+ - "!**/*.sh"
47
+ # Other entrypoints
48
+ - "!examples/*trainer*"
49
+ - "!tests/**"
50
+ - "!verl/trainer/main_*.py"
51
+ - "!verl/trainer/fsdp_sft_trainer.py"
52
+ - "verl/experimental/one_step_off_policy"
53
+ pull_request:
54
+ branches:
55
+ - main
56
+ - v0.*
57
+ paths:
58
+ - "**/*.py"
59
+ - "!**/*.md"
60
+ - "!**/*.sh"
61
+ # Other entrypoints
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py"
66
+ # Home
67
+ - "verl/experimental/one_step_off_policy"
68
+ # Entrypoints
69
+ - ".github/workflows/e2e_one_step_off_policy_ascend.yml"
70
+ - "examples/data_preprocess/gsm8k.py"
71
+ - "tests/special_e2e/run_one_step_off_policy.sh"
72
+
73
+ # Cancel jobs on the same ref if a new one is triggered
74
+ concurrency:
75
+ group: ${{ github.workflow }}-${{ github.ref }}
76
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
77
+
78
+ # Declare permissions just read content.
79
+ permissions:
80
+ contents: read
81
+
82
+ jobs:
83
+ # Test FSDP2 strategy
84
+ e2e_one_step_off_policy_fsdp2_ascend:
85
+ if: github.repository_owner == 'verl-project'
86
+ runs-on: linux-aarch64-a3-8
87
+ timeout-minutes: 60 # Increase this timeout value as needed
88
+ container:
89
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm
90
+ options: >-
91
+ --shm-size 16g
92
+ env:
93
+ HF_ENDPOINT: "https://hf-mirror.com"
94
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
95
+ ACTOR_STRATEGY: "fsdp2"
96
+ device_name: "npu"
97
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
98
+ UV_INDEX_STRATEGY: unsafe-best-match
99
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
100
+ UV_HTTP_TIMEOUT: 120
101
+ UV_NO_CACHE: "1"
102
+ UV_SYSTEM_PYTHON: "1"
103
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
104
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
105
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
106
+ steps:
107
+ - name: Check npu and CANN info
108
+ run: |
109
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
110
+ npu-smi info
111
+ - name: Install uv
112
+ run: pip install uv
113
+ - name: Check initial pip list from image
114
+ run: |
115
+ uv pip list
116
+ - name: Checkout verl-project/verl repo
117
+ uses: actions/checkout@v4
118
+ with:
119
+ fetch-depth: 0
120
+ clean: true
121
+ - name: Install the current repository
122
+ run: |
123
+ uv pip install --no-deps -e .
124
+ - name: Check final pip list
125
+ run: |
126
+ uv pip list
127
+ - name: Prepare weights
128
+ run: |
129
+ ln -s /root/.cache/models ~/models
130
+ - name: Prepare GSM8K dataset
131
+ run: |
132
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
133
+ - name: Running the E2E test with one_step_off_policy algorithm (FSDP2)
134
+ run: |
135
+ ray stop --force
136
+ bash tests/special_e2e/run_one_step_off_policy.sh
137
+
138
+ # Test Megatron strategy
139
+ e2e_one_step_off_policy_megatron_ascend:
140
+ if: github.repository_owner == 'verl-project'
141
+ needs: e2e_one_step_off_policy_fsdp2_ascend
142
+ runs-on: linux-aarch64-a3-8
143
+ timeout-minutes: 60 # Increase this timeout value as needed
144
+ container:
145
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-a3-ubuntu22.04-py3.11-vllm
146
+ options: >-
147
+ --shm-size 16g
148
+ env:
149
+ HF_ENDPOINT: "https://hf-mirror.com"
150
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
151
+ ACTOR_STRATEGY: "megatron"
152
+ device_name: "npu"
153
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
154
+ UV_INDEX_STRATEGY: unsafe-best-match
155
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
156
+ UV_HTTP_TIMEOUT: 120
157
+ UV_NO_CACHE: "1"
158
+ UV_SYSTEM_PYTHON: "1"
159
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
160
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
161
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
162
+ steps:
163
+ - name: Check npu and CANN info
164
+ run: |
165
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
166
+ npu-smi info
167
+ - name: Install uv
168
+ run: pip install uv
169
+ - name: Check initial pip list from image
170
+ run: |
171
+ uv pip list
172
+ - name: Checkout verl-project/verl repo
173
+ uses: actions/checkout@v4
174
+ with:
175
+ fetch-depth: 0
176
+ clean: true
177
+ - name: Install the current repository
178
+ run: |
179
+ uv pip install --no-deps -e .
180
+ - name: Check final pip list
181
+ run: |
182
+ uv pip list
183
+ - name: Prepare weights
184
+ run: |
185
+ ln -s /root/.cache/models ~/models
186
+ - name: Prepare GSM8K dataset
187
+ run: |
188
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
189
+ - name: Running the E2E test with one_step_off_policy algorithm (Megatron)
190
+ run: |
191
+ ray stop --force
192
+ export PYTHONPATH=$PYTHONPATH:/Megatron-LM
193
+ VANILLA_MBRIDGE=True bash tests/special_e2e/run_one_step_off_policy.sh
verl_0720_main/verl/.github/workflows/e2e_ppo_grpo_trainer_trtllm.yml ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_trtllm
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # Recipes
48
+ - "!recipe/**"
49
+ # FSDP
50
+ - "!verl/workers/**/*dp_*.py"
51
+ pull_request:
52
+ branches:
53
+ - main
54
+ - v0.*
55
+ paths:
56
+ - "**/*.py"
57
+ # Other entrypoints
58
+ - "!docker/**"
59
+ # Docs
60
+ - "!**/*.md"
61
+ - "!docs/**"
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py"
66
+ # Recipes
67
+ - "!recipe/**"
68
+ # FSDP
69
+ - "!verl/workers/**/*dp_*.py"
70
+ # Entrypoints
71
+ - "verl/workers/rollout/trtllm_rollout/**"
72
+ - "tests/workers/rollout/rollout_trtllm/**"
73
+ - ".github/workflows/e2e_ppo_grpo_trainer_trtllm.yml"
74
+ - "examples/data_preprocess/gsm8k.py"
75
+ - "examples/data_preprocess/geo3k.py"
76
+ - "examples/data_preprocess/dapo_multiturn_w_tool.py"
77
+ - "examples/data_preprocess/aime2024_multiturn_w_tool.py"
78
+ - "examples/grpo_trainer/run_qwen3_8b_megatron.sh"
79
+ - "examples/grpo_trainer/run_qwen3_30b_a3b_megatron.sh"
80
+ # add back when ppo flow is ready
81
+ # - "tests/special_e2e/run_ppo_trainer_megatron.sh"
82
+ # - "verl/trainer/main_ppo.py"
83
+ # - "verl/trainer/config/ppo_megatron_trainer.yaml"
84
+
85
+ # Cancel jobs on the same ref if a new one is triggered
86
+ concurrency:
87
+ group: ${{ github.workflow }}-${{ github.ref }}
88
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
89
+
90
+ # Declare permissions just read content.
91
+ permissions:
92
+ contents: read
93
+
94
+ env:
95
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:trtllm-1.3.0rc15"
96
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
97
+
98
+ jobs:
99
+ setup:
100
+ if: github.repository_owner == 'verl-project'
101
+ runs-on: ubuntu-latest
102
+ outputs:
103
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
104
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
105
+ steps:
106
+ - uses: actions/checkout@v4
107
+ - id: create-runner
108
+ uses: volcengine/vemlp-github-runner@v1
109
+ with:
110
+ mode: "create"
111
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
112
+ mlp-image: "${{ env.IMAGE }}"
113
+
114
+ trtllm_unit_tests:
115
+ needs: setup
116
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
117
+ timeout-minutes: 30 # Increase this timeout value as needed
118
+ env:
119
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
120
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
121
+ HF_ENDPOINT: "https://hf-mirror.com"
122
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
123
+ TORCH_CUDA_ARCH_LIST: "7.5;8.0;8.9;9.0;10.0;12.0+PTX"
124
+ steps:
125
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126
+ with:
127
+ fetch-depth: 0
128
+ - name: Reinstall FlashInfer for runtime GPU arch
129
+ run: |
130
+ unset TORCH_CUDA_ARCH_LIST
131
+ pip3 install --force-reinstall --no-deps flashinfer-python
132
+ - name: Install the current repository
133
+ run: |
134
+ pip3 install pytest-asyncio
135
+ pip3 install -r requirements-test.txt
136
+ pip3 install --no-deps -e .
137
+ pip3 install --no-deps TransferQueue==0.1.8
138
+ - name: Check final pip list
139
+ run: |
140
+ pip3 list
141
+ - name: Run TRTLLM unit tests
142
+ run: |
143
+ unset TORCH_CUDA_ARCH_LIST # Let TRT-LLM CUTLASS DSL auto-detect runtime GPU arch
144
+ export TRTLLM_ENABLE_PDL=0 # Disable Programmatic Dependent Launch (uses SM 9.0 griddepcontrol)
145
+ export TRTLLM_TEST_MODEL_PATH_ROOT="${HOME}/models"
146
+ ray stop --force
147
+ pytest -v -s --durations=20 \
148
+ tests/workers/rollout/rollout_trtllm/test_adapter.py \
149
+ tests/workers/rollout/rollout_trtllm/test_async_server.py \
150
+ tests/workers/rollout/rollout_trtllm/test_inter_node_rollout.py \
151
+ tests/workers/rollout/rollout_trtllm/test_trtllm_rollout_utils.py
152
+
153
+ e2e_grpo_trainer_megatron-qwen2:
154
+ needs: setup
155
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
156
+ timeout-minutes: 30 # Increase this timeout value as needed
157
+ env:
158
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
159
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
160
+ HF_ENDPOINT: "https://hf-mirror.com"
161
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
162
+ TORCH_CUDA_ARCH_LIST: "7.5;8.0;8.9;9.0;10.0;12.0+PTX"
163
+ steps:
164
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
165
+ with:
166
+ fetch-depth: 0
167
+ - name: Reinstall FlashInfer for runtime GPU arch
168
+ run: |
169
+ unset TORCH_CUDA_ARCH_LIST
170
+ pip3 install --force-reinstall --no-deps flashinfer-python
171
+ - name: Install the current repository
172
+ run: |
173
+ pip3 install -r requirements-test.txt
174
+ pip3 install -r requirements.txt
175
+ pip3 install --no-deps -e .
176
+ pip3 uninstall -y mbridge
177
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
178
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
179
+ pip3 install "nvidia-modelopt>=0.37.0"
180
+ - name: Check final pip list
181
+ run: |
182
+ pip3 list
183
+ - name: Prepare GSM8K dataset
184
+ run: |
185
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k --local_save_dir ${PWD}/data/gsm8k
186
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (Qwen)
187
+ run: |
188
+ unset TORCH_CUDA_ARCH_LIST # Let TRT-LLM CUTLASS DSL auto-detect runtime GPU arch
189
+ export TRTLLM_ENABLE_PDL=0 # Disable Programmatic Dependent Launch (uses SM 9.0 griddepcontrol)
190
+ ray stop --force
191
+ ACTOR_TP=2 \
192
+ ACTOR_PP=1 \
193
+ ROLLOUT_TP=2 \
194
+ INFER_BACKEND=trtllm \
195
+ MODEL_PATH="${HOME}/models/Qwen/Qwen2.5-0.5B-Instruct" \
196
+ bash examples/grpo_trainer/run_qwen3_8b_megatron.sh \
197
+ trainer.total_training_steps=1 \
198
+ data.train_batch_size=32 \
199
+ data.max_prompt_length=128 \
200
+ data.max_response_length=64 \
201
+ actor_rollout_ref.rollout.n=1 \
202
+ actor_rollout_ref.actor.ppo_mini_batch_size=32 \
203
+ actor_rollout_ref.rollout.max_num_seqs=32 \
204
+ actor_rollout_ref.rollout.max_num_batched_tokens=1024 \
205
+ actor_rollout_ref.rollout.max_model_len=256 \
206
+ data.train_files="['${PWD}/data/gsm8k/train.parquet']" \
207
+ data.val_files="['${PWD}/data/gsm8k/test.parquet']" \
208
+ trainer.logger='["console"]'
209
+ - name: clean up
210
+ run: |
211
+ rm -rf checkpoints
212
+ e2e_grpo_trainer_megatron-vlm:
213
+ needs: setup
214
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
215
+ timeout-minutes: 30 # Increase this timeout value as needed
216
+ env:
217
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
218
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
219
+ HF_ENDPOINT: "https://hf-mirror.com"
220
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
221
+ TORCH_CUDA_ARCH_LIST: "7.5;8.0;8.9;9.0;10.0;12.0+PTX"
222
+ steps:
223
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
224
+ with:
225
+ fetch-depth: 0
226
+ - name: Reinstall FlashInfer for runtime GPU arch
227
+ run: |
228
+ unset TORCH_CUDA_ARCH_LIST
229
+ pip3 install --force-reinstall --no-deps flashinfer-python
230
+ - name: Install the current repository
231
+ run: |
232
+ pip3 install -r requirements-test.txt
233
+ pip3 install --no-deps -e .
234
+ pip3 install --no-deps TransferQueue==0.1.8
235
+ pip3 install qwen_vl_utils
236
+ pip3 install mathruler
237
+ pip3 install msgspec
238
+ pip3 uninstall -y mbridge
239
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
240
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
241
+ pip3 install "nvidia-modelopt>=0.37.0"
242
+ - name: Check final pip list
243
+ run: |
244
+ pip3 list
245
+ - name: Prepare GEO3K dataset
246
+ run: |
247
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k --local_save_dir ${PWD}/data/geo3k
248
+ - name: Running GEO3K E2E training tests with FSDP on 8 L20 GPUs (VLM)
249
+ run: |
250
+ ray stop --force
251
+ ROLLOUT_TP=2 \
252
+ INFER_BACKEND=trtllm \
253
+ MODEL_PATH="${HOME}/models/Qwen/Qwen3-VL-2B-Instruct" \
254
+ bash examples/grpo_trainer/run_qwen2_5_vl_7b_fsdp.sh \
255
+ trainer.total_training_steps=1 \
256
+ data.train_batch_size=8 \
257
+ data.max_response_length=64 \
258
+ actor_rollout_ref.actor.ppo_mini_batch_size=8 \
259
+ actor_rollout_ref.actor.ppo_max_token_len_per_gpu=2048 \
260
+ actor_rollout_ref.rollout.n=2 \
261
+ actor_rollout_ref.rollout.gpu_memory_utilization=0.35 \
262
+ actor_rollout_ref.rollout.max_model_len=2048 \
263
+ actor_rollout_ref.rollout.max_num_seqs=16 \
264
+ actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=2048 \
265
+ data.train_files="['${PWD}/data/geo3k/train.parquet']" \
266
+ data.val_files="['${PWD}/data/geo3k/test.parquet']" \
267
+ trainer.logger='["console"]'
268
+ - name: clean up
269
+ run: |
270
+ rm -rf checkpoints
271
+ - name: Prepare GSM8K dataset (data_preprocess)
272
+ run: |
273
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k --local_save_dir ${PWD}/data/gsm8k
274
+ - name: Running GRPO E2E with FP8 TRT-LLM rollout (Qwen3-0.6B, gsm8k)
275
+ run: |
276
+ unset TORCH_CUDA_ARCH_LIST # Let TRT-LLM CUTLASS DSL auto-detect runtime GPU arch
277
+ export TRTLLM_ENABLE_PDL=0 # Disable Programmatic Dependent Launch (uses SM 9.0 griddepcontrol)
278
+ ray stop --force
279
+ export INFER_TP=2 ACTOR_TP=2 ACTOR_PP=2 ACTOR_VPP=2 ACTOR_EP=1 ACTOR_CP=2 REF_TP=2 REF_PP=2 REF_VPP=2 REF_EP=1 REF_CP=2 GEN_MOE_TP=null GEN_MOE_EP=null
280
+ export NNODES=1 GPUS_PER_NODE=8 TRTLLM_MOE_BACKEND=TRITON
281
+ export DATA_DIR=${PWD} DAPO_MATH_TRAIN=${PWD}/data/gsm8k/train.parquet AIME_VAL=${PWD}/data/gsm8k/test.parquet MODEL_PATH=${HOME}/models/Qwen/Qwen3-0.6B
282
+ INFER_BACKEND=trtllm ROLLOUT_QUANTIZATION=fp8 bash examples/grpo_trainer/run_qwen3_30b_a3b_megatron.sh \
283
+ reward_model.reward_kwargs.overlong_buffer_cfg.len=258 \
284
+ reward_model.reward_kwargs.max_resp_len=512 \
285
+ data.max_prompt_length=128 \
286
+ data.max_response_length=64 \
287
+ data.train_batch_size=32 \
288
+ actor_rollout_ref.rollout.n=1 \
289
+ actor_rollout_ref.rollout.max_num_seqs=16 \
290
+ actor_rollout_ref.rollout.max_num_batched_tokens=1024 \
291
+ actor_rollout_ref.rollout.max_model_len=1024 \
292
+ actor_rollout_ref.actor.megatron.override_transformer_config.moe_grouped_gemm=False \
293
+ actor_rollout_ref.actor.megatron.override_transformer_config.moe_permute_fusion=False \
294
+ trainer.total_training_steps=1 \
295
+ trainer.logger='["console"]'
296
+ - name: clean up
297
+ run: |
298
+ rm -rf checkpoints
299
+
300
+ cleanup:
301
+ runs-on: ubuntu-latest
302
+ needs: [setup, trtllm_unit_tests, e2e_grpo_trainer_megatron-qwen2, e2e_grpo_trainer_megatron-vlm]
303
+ if: always()
304
+ steps:
305
+ - id: destroy-runner
306
+ uses: volcengine/vemlp-github-runner@v1
307
+ with:
308
+ mode: "destroy"
309
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
310
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer.yml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: e2e_ppo_trainer
2
+
3
+ on:
4
+ # Trigger the workflow on push or pull request,
5
+ # but only for the main branch
6
+ # For push, for now only anti-patterns are specified so it is more conservative
7
+ # and achieves higher coverage.
8
+ push:
9
+ branches:
10
+ - main
11
+ - v0.*
12
+ paths:
13
+ - "**/*.py"
14
+ # Other entrypoints
15
+ - "!verl/trainer/fsdp_sft_trainer.py"
16
+
17
+ # Megatron
18
+ - "!verl/workers/**/megatron_*.py"
19
+
20
+ pull_request:
21
+ branches:
22
+ - main
23
+ - v0.*
24
+ paths:
25
+ - "**/*.py"
26
+ # Other entrypoints
27
+ - "!**/*.md"
28
+ - "!docker/**"
29
+ - "!examples/**"
30
+ - "!tests/**"
31
+ - "!verl/trainer/main_*.py"
32
+ - "!verl/trainer/fsdp_sft_trainer.py"
33
+ # Docs
34
+ - "!docs/**"
35
+
36
+ # Megatron
37
+ - "!verl/workers/**/megatron_*.py"
38
+ # Entrypoints
39
+ - ".github/workflows/e2e_ppo_trainer.yml"
40
+ - "examples/data_preprocess/gsm8k.py"
41
+ - "examples/data_preprocess/geo3k.py"
42
+ - "tests/special_e2e/ppo_trainer"
43
+ - "verl/trainer/main_ppo.py"
44
+ - "verl/trainer/config/ppo_trainer.yaml"
45
+
46
+ # Cancel jobs on the same ref if a new one is triggered
47
+ concurrency:
48
+ group: ${{ github.workflow }}-${{ github.ref }}
49
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
50
+
51
+ # Declare permissions just read content.
52
+ permissions:
53
+ contents: read
54
+
55
+ jobs:
56
+ pre_commit_for_ppo:
57
+ runs-on: ubuntu-latest
58
+ strategy:
59
+ matrix:
60
+ python-version: ["3.12"]
61
+ steps:
62
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
63
+ - name: Set up Python ${{ matrix.python-version }}
64
+ uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
65
+ with:
66
+ python-version: ${{ matrix.python-version }}
67
+ - name: Install the current repository
68
+ run: |
69
+ pip install pre-commit hydra-core
70
+ pip3 install --no-deps -e .
71
+ - name: Check final pip list
72
+ run: |
73
+ pip3 list
74
+ - name: Set ruff --output-format=github
75
+ run: |
76
+ sed -i 's/--output-format=full/--output-format=github/' .pre-commit-config.yaml
77
+ git add .pre-commit-config.yaml
78
+ - uses: pre-commit/action@v3.0.1
79
+ with:
80
+ extra_args: "" # Overriding default "--all-files"
81
+
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang.yml ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_sglang
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
47
+ - "!verl/workers/**/*dp_*.py"
48
+ - "!verl/utils/fsdp_utils.py"
49
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
50
+ - "!verl/model_merger/fsdp_model_merger.py"
51
+ pull_request:
52
+ branches:
53
+ - main
54
+ - v0.*
55
+ paths:
56
+ - "**/*.py"
57
+ # Other entrypoints
58
+ - "!docker/**"
59
+ # Docs
60
+ - "!**/*.md"
61
+ - "!docs/**"
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
66
+ - "!verl/workers/**/*dp_*.py"
67
+ - "!verl/utils/fsdp_utils.py"
68
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
69
+ - "!verl/model_merger/fsdp_model_merger.py"
70
+ # Entrypoints
71
+ - "verl/worksers/rollout/sglang_rollout/*"
72
+ - ".github/workflows/e2e_ppo_trainer_megatron_sglang.yml"
73
+ - "examples/data_preprocess/gsm8k.py"
74
+ - "examples/data_preprocess/geo3k.py"
75
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
76
+ - "verl/trainer/main_ppo.py"
77
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
78
+
79
+ # Cancel jobs on the same ref if a new one is triggered
80
+ concurrency:
81
+ group: ${{ github.workflow }}-${{ github.ref }}
82
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
83
+
84
+ # Declare permissions just read content.
85
+ permissions:
86
+ contents: read
87
+
88
+ env:
89
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:sgl0512.dev2"
90
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
91
+
92
+ jobs:
93
+ setup:
94
+ if: github.repository_owner == 'verl-project'
95
+ runs-on: ubuntu-latest
96
+ outputs:
97
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
98
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
99
+ steps:
100
+ - uses: actions/checkout@v4
101
+ - id: create-runner
102
+ uses: volcengine/vemlp-github-runner@v1
103
+ with:
104
+ mode: "create"
105
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
106
+ mlp-image: "${{ env.IMAGE }}"
107
+
108
+ e2e_ppo_trainer_megatron-deepseek:
109
+ needs: setup
110
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
111
+ timeout-minutes: 60 # Increase this timeout value as needed
112
+ env:
113
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
114
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
115
+ HF_ENDPOINT: "https://hf-mirror.com"
116
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
117
+ ENGINE: sglang
118
+ steps:
119
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
120
+ with:
121
+ fetch-depth: 0
122
+ - name: Install the current repository
123
+ run: |
124
+ pip3 install -r requirements-test.txt
125
+ pip3 uninstall -y mbridge
126
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
127
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
128
+ pip3 install "nvidia-modelopt>=0.37.0"
129
+ pip3 install --no-deps -e .
130
+ pip3 install --no-deps TransferQueue==0.1.8
131
+ - name: Check final pip list
132
+ run: |
133
+ pip3 list
134
+ - name: Prepare GSM8K dataset
135
+ run: |
136
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
137
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (DeepSeek)
138
+ run: |
139
+ ray stop --force
140
+ OPTIM_MEMORY_EFFICIENT=True ENGINE=sglang SAVE_FREQ=1 MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct bash tests/special_e2e/run_ppo_trainer_megatron.sh
141
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (DeepSeek)
142
+ run: |
143
+ ray stop --force
144
+ export VLLM_USE_V1=1
145
+ ray start --head
146
+ ENGINE=sglang MODE=async RESUME_MODE=auto MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct TOTAL_TRAIN_STEPS=2 bash tests/special_e2e/run_ppo_trainer_megatron.sh
147
+ - name: Profiling GRPO GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (Deepseek)
148
+ run: |
149
+ ray stop --force
150
+ PROFILE_ENABLE=True ENGINE=sglang ADV_ESTIMATOR=grpo USE_DYNAMIC_BSZ=False MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct bash tests/special_e2e/run_ppo_trainer_megatron.sh
151
+ if [ -z "$( ls -A '/tmp/ray/session_latest/logs/nsight/' )" ]; then
152
+ echo "[ERROR] not found any profiling files"
153
+ exit 1
154
+ else
155
+ echo "[SUCCESS] profile success"
156
+ fi
157
+ - name: clean up
158
+ run: |
159
+ rm -rf checkpoints
160
+
161
+ # Qwen3-0.6B: dense, tie_word_embeddings=True
162
+ e2e_ppo_trainer_megatron-qwen3:
163
+ needs: setup
164
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
165
+ timeout-minutes: 60 # Increase this timeout value as needed
166
+ env:
167
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
168
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
169
+ HF_ENDPOINT: "https://hf-mirror.com"
170
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
171
+ ENGINE: sglang
172
+ steps:
173
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
174
+ with:
175
+ fetch-depth: 0
176
+ - name: Install the current repository
177
+ run: |
178
+ pip3 install -r requirements-test.txt
179
+ pip3 install -r requirements.txt
180
+ pip3 install --no-deps -e .
181
+ pip3 uninstall -y mbridge
182
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
183
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
184
+ pip3 install "nvidia-modelopt>=0.37.0"
185
+ - name: Check final pip list
186
+ run: |
187
+ pip3 list
188
+ - name: Prepare GSM8K dataset
189
+ run: |
190
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
191
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (Qwen3) testing learning rate scheduler
192
+ run: |
193
+ ray stop --force
194
+ ALL_OFFLOAD=True VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 LR_WARMUP_STEPS=1 TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B bash tests/special_e2e/run_ppo_trainer_megatron.sh
195
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with FP8 rollout
196
+ run: |
197
+ ray stop --force
198
+ export VLLM_USE_V1=1
199
+ ROLLOUT_QUANTIZATION=fp8 TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B bash tests/special_e2e/run_ppo_trainer_megatron.sh
200
+ - name: clean up
201
+ run: |
202
+ rm -rf checkpoints
203
+
204
+ cleanup:
205
+ runs-on: ubuntu-latest
206
+ needs:
207
+ [setup, e2e_ppo_trainer_megatron-deepseek, e2e_ppo_trainer_megatron-qwen3]
208
+ if: always()
209
+ steps:
210
+ - id: destroy-runner
211
+ uses: volcengine/vemlp-github-runner@v1
212
+ with:
213
+ mode: "destroy"
214
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
215
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_2.yml ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_sglang_2
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
47
+ - "!verl/workers/**/*dp_*.py"
48
+ - "!verl/utils/fsdp_utils.py"
49
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
50
+ - "!verl/model_merger/fsdp_model_merger.py"
51
+ pull_request:
52
+ branches:
53
+ - main
54
+ - v0.*
55
+ paths:
56
+ - "**/*.py"
57
+ # Other entrypoints
58
+ - "!docker/**"
59
+ # Docs
60
+ - "!**/*.md"
61
+ - "!docs/**"
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
66
+ - "!verl/workers/**/*dp_*.py"
67
+ - "!verl/utils/fsdp_utils.py"
68
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
69
+ - "!verl/model_merger/fsdp_model_merger.py"
70
+ # Entrypoints
71
+ - "verl/worksers/rollout/sglang_rollout/*"
72
+ - ".github/workflows/e2e_ppo_trainer_megatron_sglang.yml"
73
+ - "examples/data_preprocess/gsm8k.py"
74
+ - "examples/data_preprocess/geo3k.py"
75
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
76
+ - "verl/trainer/main_ppo.py"
77
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
78
+
79
+ # Cancel jobs on the same ref if a new one is triggered
80
+ concurrency:
81
+ group: ${{ github.workflow }}-${{ github.ref }}
82
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
83
+
84
+ # Declare permissions just read content.
85
+ permissions:
86
+ contents: read
87
+
88
+ env:
89
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:sgl0512.dev2"
90
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
91
+
92
+ jobs:
93
+ setup:
94
+ if: github.repository_owner == 'verl-project'
95
+ runs-on: ubuntu-latest
96
+ outputs:
97
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
98
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
99
+ steps:
100
+ - uses: actions/checkout@v4
101
+ - id: create-runner
102
+ uses: volcengine/vemlp-github-runner@v1
103
+ with:
104
+ mode: "create"
105
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
106
+ mlp-image: "${{ env.IMAGE }}"
107
+
108
+ e2e_ppo_trainer_fsdp_sglang:
109
+ needs: setup
110
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
111
+ timeout-minutes: 40 # Increase this timeout value as needed
112
+ env:
113
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
114
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
115
+ HF_ENDPOINT: "https://hf-mirror.com"
116
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
117
+ steps:
118
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
119
+ with:
120
+ fetch-depth: 0
121
+ - name: Install the current repository
122
+ run: |
123
+ pip3 install -r requirements-test.txt
124
+ pip3 install --no-deps -e .
125
+ pip3 install --no-deps TransferQueue==0.1.8
126
+ - name: Check final pip list
127
+ run: |
128
+ pip3 list
129
+ - name: Prepare gsm8k dataset
130
+ run: |
131
+ ray stop --force
132
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
133
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm and save ckpt
134
+ run: |
135
+ ray stop --force
136
+ ENGINE=sglang bash tests/special_e2e/ppo_trainer/run_function_reward.sh
137
+
138
+ e2e_ppo_trainer_fsdp-qwen2_5vl-3b:
139
+ needs: setup
140
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
141
+ timeout-minutes: 60 # Increase this timeout value as needed
142
+ env:
143
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
144
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
145
+ HF_ENDPOINT: "https://hf-mirror.com"
146
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
147
+ steps:
148
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
149
+ with:
150
+ fetch-depth: 0
151
+ - name: Install the current repository
152
+ run: |
153
+ pip3 install -r requirements-test.txt
154
+ pip3 install -r requirements.txt
155
+ pip3 install --no-deps -e .
156
+ - name: Check final pip list
157
+ run: |
158
+ pip3 list
159
+ # Geo3k
160
+ - name: Prepare GEO3K dataset
161
+ run: |
162
+ ray stop --force
163
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k/
164
+ - name: Running GEO3K VLM E2E training tests on 8 L20 GPUs with rmpad using function rm
165
+ run: |
166
+ ray stop --force
167
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
168
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
169
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
170
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
171
+ ENGINE=sglang ROLLOUT_MODE=async GPU_MEMORY_UTILIZATION=0.6 ACTOR_FSDP_PARAM_OFFLOAD=True \
172
+ ACTOR_FSDP_OPTIMIZER_OFFLOAD=True REF_FSDP_PARAM_OFFLOAD=True \
173
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
174
+ - name: Running GEO3K VLM E2E with rmpad using torch fused kernel (Qwen2.5-VL)
175
+ run: |
176
+ ray stop --force
177
+ FUSED_KERNELS=True TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
178
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
179
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
180
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
181
+ ENGINE=sglang ROLLOUT_MODE=async GPU_MEMORY_UTILIZATION=0.6 ACTOR_FSDP_PARAM_OFFLOAD=True \
182
+ ACTOR_FSDP_OPTIMIZER_OFFLOAD=True REF_FSDP_PARAM_OFFLOAD=True \
183
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
184
+ - name: Running GEO3K VLM E2E with rmpad using triton fused kernel (Qwen2.5-VL)
185
+ run: |
186
+ ray stop --force
187
+ FUSED_KERNELS=True FUSED_KERNEL_BACKEND=triton \
188
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
189
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
190
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
191
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
192
+ ENGINE=sglang ROLLOUT_MODE=async GPU_MEMORY_UTILIZATION=0.6 ACTOR_FSDP_PARAM_OFFLOAD=True \
193
+ ACTOR_FSDP_OPTIMIZER_OFFLOAD=True REF_FSDP_PARAM_OFFLOAD=True \
194
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
195
+
196
+ cleanup:
197
+ runs-on: ubuntu-latest
198
+ needs:
199
+ [setup, e2e_ppo_trainer_fsdp-qwen2_5vl-3b, e2e_ppo_trainer_fsdp_sglang]
200
+ if: always()
201
+ steps:
202
+ - id: destroy-runner
203
+ uses: volcengine/vemlp-github-runner@v1
204
+ with:
205
+ mode: "destroy"
206
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
207
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_2_ascend.yml ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_sglang_2_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
47
+ - "!verl/workers/**/*dp_*.py"
48
+ - "!verl/utils/fsdp_utils.py"
49
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
50
+ - "!verl/model_merger/fsdp_model_merger.py"
51
+ pull_request:
52
+ branches:
53
+ - main
54
+ - v0.*
55
+ paths:
56
+ - "**/*.py"
57
+ # Other entrypoints
58
+ - "!docker/**"
59
+ # Docs
60
+ - "!**/*.md"
61
+ - "!docs/**"
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
66
+ - "!verl/workers/**/*dp_*.py"
67
+ - "!verl/utils/fsdp_utils.py"
68
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
69
+ - "!verl/model_merger/fsdp_model_merger.py"
70
+ # Entrypoints
71
+ - "verl/worksers/rollout/sglang_rollout/*"
72
+ - ".github/workflows/e2e_ppo_trainer_megatron_sglang_2_ascend.yml"
73
+ - "examples/data_preprocess/gsm8k.py"
74
+ - "examples/data_preprocess/geo3k.py"
75
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
76
+ - "verl/trainer/main_ppo.py"
77
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
78
+
79
+ # Cancel jobs on the same ref if a new one is triggered
80
+ concurrency:
81
+ group: ${{ github.workflow }}-${{ github.ref }}
82
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
83
+
84
+ # Declare permissions just read content.
85
+ permissions:
86
+ contents: read
87
+
88
+ jobs:
89
+ e2e_ppo_trainer_fsdp_sglang_ascend:
90
+ if: github.repository_owner == 'verl-project'
91
+ runs-on: linux-aarch64-a3-8
92
+ timeout-minutes: 90 # Increase this timeout value as needed
93
+ container:
94
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann8.5.0-torch_npu2.8.0post2-a3-ubuntu22.04-py3.11-sglang
95
+ options: >-
96
+ --shm-size 16g
97
+ env:
98
+ HF_ENDPOINT: "https://hf-mirror.com"
99
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
100
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "1"
101
+ ASCEND_RT_VISIBLE_DEVICES: "0,1,2,3,4,5,6,7"
102
+ HCCL_HOST_SOCKET_PORT_RANGE: "60000-60050"
103
+ HCCL_NPU_SOCKET_PORT_RANGE: "61000-61050"
104
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
105
+ UV_INDEX_STRATEGY: unsafe-best-match
106
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
107
+ UV_HTTP_TIMEOUT: 120
108
+ UV_NO_CACHE: "1"
109
+ UV_SYSTEM_PYTHON: "1"
110
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
111
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
112
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
113
+ steps:
114
+ - name: Check npu and CANN info
115
+ run: |
116
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
117
+ npu-smi info
118
+ - name: Install uv
119
+ run: pip install uv
120
+ - name: Check initial pip list from image
121
+ run: |
122
+ uv pip list
123
+ - name: Checkout verl-project/verl repo
124
+ uses: actions/checkout@v4
125
+ with:
126
+ fetch-depth: 0
127
+ clean: true
128
+ - name: Install the current repository
129
+ run: |
130
+ uv pip install pytest pytest-asyncio
131
+ uv pip install --no-deps --no-build-isolation -e .
132
+ - name: Check final pip list
133
+ run: |
134
+ uv pip list
135
+ - name: Prepare weights
136
+ run: |
137
+ ln -s /root/.cache/models ~/models
138
+ - name: Prepare GSM8K dataset
139
+ run: |
140
+ ray stop --force
141
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
142
+ - name: Running GSM8K E2E training tests on 8 NPUs with rmpad using function rm and save ckpt
143
+ run: |
144
+ ray stop --force
145
+ ENGINE=sglang bash tests/special_e2e/ppo_trainer/run_function_reward.sh
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_sglang_ascend.yml ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_sglang_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
47
+ - "!verl/workers/**/*dp_*.py"
48
+ - "!verl/utils/fsdp_utils.py"
49
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
50
+ - "!verl/model_merger/fsdp_model_merger.py"
51
+ pull_request:
52
+ branches:
53
+ - main
54
+ - v0.*
55
+ paths:
56
+ - "**/*.py"
57
+ # Other entrypoints
58
+ - "!docker/**"
59
+ # Docs
60
+ - "!**/*.md"
61
+ - "!docs/**"
62
+ - "!examples/**"
63
+ - "!tests/**"
64
+ - "!verl/trainer/main_*.py"
65
+ - "!verl/trainer/fsdp_sft_trainer.py" # FSDP
66
+ - "!verl/workers/**/*dp_*.py"
67
+ - "!verl/utils/fsdp_utils.py"
68
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
69
+ - "!verl/model_merger/fsdp_model_merger.py"
70
+ # Entrypoints
71
+ - "verl/worksers/rollout/sglang_rollout/*"
72
+ - ".github/workflows/e2e_ppo_trainer_megatron_sglang_ascend.yml"
73
+ - "examples/data_preprocess/gsm8k.py"
74
+ - "examples/data_preprocess/geo3k.py"
75
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
76
+ - "verl/trainer/main_ppo.py"
77
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
78
+
79
+ # Cancel jobs on the same ref if a new one is triggered
80
+ concurrency:
81
+ group: ${{ github.workflow }}-${{ github.ref }}
82
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
83
+
84
+ # Declare permissions just read content.
85
+ permissions:
86
+ contents: read
87
+
88
+ jobs:
89
+ e2e_ppo_trainer_megatron-deepseek_ascend:
90
+ if: github.repository_owner == 'verl-project'
91
+ runs-on: linux-aarch64-a3-8
92
+ timeout-minutes: 90 # Increase this timeout value as needed
93
+ container:
94
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann8.5.0-torch_npu2.8.0post2-a3-ubuntu22.04-py3.11-sglang
95
+ options: >-
96
+ --shm-size 16g
97
+ env:
98
+ HF_ENDPOINT: "https://hf-mirror.com"
99
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
100
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "1"
101
+ ASCEND_RT_VISIBLE_DEVICES: "0,1,2,3,4,5,6,7"
102
+ HCCL_HOST_SOCKET_PORT_RANGE: "60000-60050"
103
+ HCCL_NPU_SOCKET_PORT_RANGE: "61000-61050"
104
+ ENGINE: sglang
105
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
106
+ UV_INDEX_STRATEGY: unsafe-best-match
107
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
108
+ UV_HTTP_TIMEOUT: 120
109
+ UV_NO_CACHE: "1"
110
+ UV_SYSTEM_PYTHON: "1"
111
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
112
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
113
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
114
+ steps:
115
+ - name: Check npu and CANN info
116
+ run: |
117
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
118
+ npu-smi info
119
+ - name: Install uv
120
+ run: pip install uv
121
+ - name: Check initial pip list from image
122
+ run: |
123
+ uv pip list
124
+ - name: Checkout verl-project/verl repo
125
+ uses: actions/checkout@v4
126
+ with:
127
+ fetch-depth: 0
128
+ clean: true
129
+ - name: Install the current repository
130
+ run: |
131
+ uv pip install pytest pytest-asyncio
132
+ uv pip install --no-deps --no-build-isolation -e .
133
+ - name: Check final pip list
134
+ run: |
135
+ uv pip list
136
+ - name: Prepare weights
137
+ run: |
138
+ ln -s /root/.cache/models ~/models
139
+ - name: Prepare GSM8K dataset
140
+ run: |
141
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
142
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 NPUs with Megatron (DeepSeek)
143
+ run: |
144
+ ray stop --force
145
+ VANILLA_MBRIDGE=True OPTIM_MEMORY_EFFICIENT=True ENGINE=sglang COMMON_VPP=NULL USE_REMOVE_PADDING=True SAVE_FREQ=1 MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct bash tests/special_e2e/run_ppo_trainer_megatron.sh
146
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 NPUs with Megatron (DeepSeek)
147
+ run: |
148
+ ray stop --force
149
+ export VLLM_USE_V1=1
150
+ ray start --head
151
+ VANILLA_MBRIDGE=True ENGINE=sglang MODE=async RESUME_MODE=auto COMMON_VPP=NULL USE_REMOVE_PADDING=True MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct TOTAL_TRAIN_STEPS=2 bash tests/special_e2e/run_ppo_trainer_megatron.sh
152
+ - name: Profiling GRPO GSM8K E2E training tests with 3D parallelism on 8 NPUs with Megatron (Deepseek)
153
+ run: |
154
+ ray stop --force
155
+ VANILLA_MBRIDGE=True PROFILE_ENABLE=True ENGINE=sglang ADV_ESTIMATOR=grpo USE_DYNAMIC_BSZ=False USE_REMOVE_PADDING=True MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct bash tests/special_e2e/run_ppo_trainer_megatron.sh
156
+ if [ -z "$( ls -A "${HOME}/profiling" )" ]; then
157
+ echo "[ERROR] not found any profiling files"
158
+ exit 1
159
+ else
160
+ echo "[SUCCESS] profile success"
161
+ fi
162
+ - name: clean up
163
+ run: |
164
+ rm -rf checkpoints
165
+ rm -rf "${HOME}/profiling"
166
+
167
+ # Qwen3-0.6B: dense, tie_word_embeddings=True
168
+ e2e_ppo_trainer_megatron-qwen3:
169
+ if: github.repository_owner == 'verl-project'
170
+ runs-on: linux-aarch64-a3-8
171
+ timeout-minutes: 90 # Increase this timeout value as needed
172
+ container:
173
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann8.5.0-torch_npu2.8.0post2-a3-ubuntu22.04-py3.11-sglang
174
+ options: >-
175
+ --shm-size 16g
176
+ env:
177
+ HF_ENDPOINT: "https://hf-mirror.com"
178
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
179
+ RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "1"
180
+ ASCEND_RT_VISIBLE_DEVICES: "0,1,2,3,4,5,6,7"
181
+ HCCL_HOST_SOCKET_PORT_RANGE: "60000-60050"
182
+ HCCL_NPU_SOCKET_PORT_RANGE: "61000-61050"
183
+ ENGINE: sglang
184
+ UV_EXTRA_INDEX_URL: "https://repo.huaweicloud.com/ascend/repos/pypi"
185
+ UV_INDEX_STRATEGY: unsafe-best-match
186
+ UV_INSECURE_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
187
+ UV_HTTP_TIMEOUT: 120
188
+ UV_NO_CACHE: "1"
189
+ UV_SYSTEM_PYTHON: "1"
190
+ UV_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
191
+ PIP_INDEX_URL: "http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple"
192
+ PIP_TRUSTED_HOST: "cache-service.nginx-pypi-cache.svc.cluster.local"
193
+ steps:
194
+ - name: Check npu and CANN info
195
+ run: |
196
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
197
+ npu-smi info
198
+ - name: Install uv
199
+ run: pip install uv
200
+ - name: Check initial pip list from image
201
+ run: |
202
+ uv pip list
203
+ - name: Checkout verl-project/verl repo
204
+ uses: actions/checkout@v4
205
+ with:
206
+ fetch-depth: 0
207
+ clean: true
208
+ - name: Install the current repository
209
+ run: |
210
+ uv pip install pytest pytest-asyncio
211
+ uv pip install --no-deps --no-build-isolation -e .
212
+ - name: Check final pip list
213
+ run: |
214
+ uv pip list
215
+ - name: Prepare weights
216
+ run: |
217
+ ln -s /root/.cache/models ~/models
218
+ - name: Prepare GSM8K dataset
219
+ run: |
220
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
221
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 NPUs with Megatron (Qwen3) testing learning rate scheduler
222
+ run: |
223
+ ray stop --force
224
+ VANILLA_MBRIDGE=True ALL_OFFLOAD=True USE_REMOVE_PADDING=True VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 LR_WARMUP_STEPS=1 TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B bash tests/special_e2e/run_ppo_trainer_megatron.sh
225
+ - name: clean up
226
+ run: |
227
+ rm -rf checkpoints
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm.yml ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_vllm
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # FSDP
48
+ - "!verl/workers/**/*dp_*.py"
49
+ - "!verl/utils/fsdp_utils.py"
50
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
51
+ - "!verl/model_merger/fsdp_model_merger.py"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "**/*.py"
58
+ # Other entrypoints
59
+ - "!docker/**"
60
+ # Docs
61
+ - "!**/*.md"
62
+ - "!docs/**"
63
+ - "!examples/**"
64
+ - "!tests/**"
65
+ - "!verl/trainer/main_*.py"
66
+ - "!verl/trainer/fsdp_sft_trainer.py"
67
+ # FSDP
68
+ - "!verl/workers/**/*dp_*.py"
69
+ - "!verl/utils/fsdp_utils.py"
70
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
71
+ - "!verl/model_merger/fsdp_model_merger.py"
72
+ # Entrypoints
73
+ - ".github/workflows/e2e_ppo_trainer_megatron_vllm.yml"
74
+ - "examples/data_preprocess/gsm8k.py"
75
+ - "examples/data_preprocess/geo3k.py"
76
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
77
+ - "verl/trainer/main_ppo.py"
78
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
79
+
80
+ # Cancel jobs on the same ref if a new one is triggered
81
+ concurrency:
82
+ group: ${{ github.workflow }}-${{ github.ref }}
83
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
84
+
85
+ # Declare permissions just read content.
86
+ permissions:
87
+ contents: read
88
+
89
+ env:
90
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
91
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
92
+
93
+ jobs:
94
+ setup:
95
+ if: github.repository_owner == 'verl-project'
96
+ runs-on: ubuntu-latest
97
+ outputs:
98
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
99
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
100
+ steps:
101
+ - uses: actions/checkout@v4
102
+ - id: create-runner
103
+ uses: volcengine/vemlp-github-runner@v1
104
+ with:
105
+ mode: "create"
106
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
107
+ mlp-image: "${{ env.IMAGE }}"
108
+
109
+ # deepseek-ai/deepseek-coder-1.3b-instruct: dense, tie_word_embeddings=False
110
+ e2e_ppo_trainer_megatron-deepseek:
111
+ needs: setup
112
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
113
+ timeout-minutes: 60 # Increase this timeout value as needed
114
+ env:
115
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
116
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
117
+ HF_ENDPOINT: "https://hf-mirror.com"
118
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
119
+ steps:
120
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
121
+ with:
122
+ fetch-depth: 0
123
+ - name: Install the current repository
124
+ run: |
125
+ pip3 install -r requirements-test.txt
126
+ pip3 install -r requirements.txt
127
+ pip3 install --no-deps -e .
128
+ pip3 uninstall -y mbridge
129
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
130
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
131
+ pip3 install "nvidia-modelopt>=0.37.0"
132
+ pip3 install math-verify
133
+ - name: Check final pip list
134
+ run: |
135
+ pip3 list
136
+ - name: Prepare GSM8K dataset
137
+ run: |
138
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
139
+ # Full training save&load
140
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron, use Megatron-Bridge e2e to pre-load and save (Deepseek)
141
+ run: |
142
+ ray stop --force
143
+ ALL_OFFLOAD=True SAVE_FREQ=1 MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct COMMON_PP=4 COMMON_VPP=null COMMON_CP=1 USE_MBRIDGE=True USE_DIST_CKPT=False \
144
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh
145
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron, use Megatron-Bridge e2e to pre-load and save (Deepseek)
146
+ run: |
147
+ ray stop --force
148
+ RESUME_MODE=auto MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct TOTAL_TRAIN_STEPS=2 SAVE_FREQ=1 COMMON_PP=4 COMMON_VPP=null COMMON_CP=1 USE_MBRIDGE=True USE_DIST_CKPT=False \
149
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh
150
+ # LoRA training save&load
151
+ - name: clean up and install Megatron-Bridge
152
+ run: |
153
+ rm -rf checkpoints
154
+ pip3 uninstall -y mbridge
155
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
156
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
157
+ pip3 install "nvidia-modelopt>=0.37.0"
158
+ pip3 install transformers==5.3.0
159
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron, use Megatron-Bridge LoRA e2e to pre-load and save (Deepseek)
160
+ run: |
161
+ ray stop --force
162
+ ALL_OFFLOAD=True SAVE_FREQ=1 MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct COMMON_PP=4 LORA_RANK=8 COMMON_VPP=null COMMON_CP=1 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False USE_DIST_CKPT=False \
163
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh
164
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron, use Megatron-Bridge LoRA e2e to pre-load and save (Deepseek)
165
+ run: |
166
+ ray stop --force
167
+ RESUME_MODE=auto MODEL_ID=deepseek-ai/deepseek-coder-1.3b-instruct TOTAL_TRAIN_STEPS=2 SAVE_FREQ=1 COMMON_PP=4 LORA_RANK=8 COMMON_VPP=null COMMON_CP=1 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False USE_DIST_CKPT=False \
168
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh
169
+ - name: clean up
170
+ run: |
171
+ rm -rf checkpoints
172
+
173
+ # Qwen3-0.6B: dense, tie_word_embeddings=True
174
+ e2e_ppo_trainer_megatron-qwen3:
175
+ needs: setup
176
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
177
+ timeout-minutes: 60 # Increase this timeout value as needed
178
+ env:
179
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
180
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
181
+ HF_ENDPOINT: "https://hf-mirror.com"
182
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
183
+ steps:
184
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
185
+ with:
186
+ fetch-depth: 0
187
+ - name: Install the current repository
188
+ run: |
189
+ pip3 install -r requirements-test.txt
190
+ pip3 install --no-deps -e .
191
+ pip3 install --no-deps TransferQueue==0.1.8
192
+ pip3 uninstall -y mbridge
193
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
194
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
195
+ pip3 install "nvidia-modelopt>=0.37.0"
196
+ pip3 install math-verify
197
+ - name: Check final pip list
198
+ run: |
199
+ pip3 list
200
+ - name: Prepare GSM8K dataset
201
+ run: |
202
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
203
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron (Qwen3) testing learning rate scheduler
204
+ run: |
205
+ ray stop --force
206
+ ALL_OFFLOAD=True VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 LR_WARMUP_STEPS=1 TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B bash tests/special_e2e/run_ppo_trainer_megatron.sh
207
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with FP8 rollout
208
+ run: |
209
+ ray stop --force
210
+ export VLLM_USE_V1=1
211
+ ROLLOUT_QUANTIZATION=fp8 TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B bash tests/special_e2e/run_ppo_trainer_megatron.sh
212
+ - name: Install Megatron-LM and Megatron-Bridge for Megatron-FSDP
213
+ run: |
214
+ pip3 uninstall -y mbridge
215
+ pip3 install --no-deps --no-build-isolation git+https://github.com/NVIDIA/Megatron-LM.git@0823c73
216
+ pip3 install --no-deps --no-build-isolation git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e
217
+ pip3 install "nvidia-modelopt>=0.37.0"
218
+ - name: Running GSM8K E2E PPO training tests on 8 L20 GPUs with Megatron-FSDP (Qwen3)
219
+ run: |
220
+ ray stop --force
221
+ ALL_OFFLOAD=False USE_MBRIDGE=True VANILLA_MBRIDGE=False USE_MEGATRON_FSDP=True \
222
+ TOTAL_TRAIN_STEPS=2 MODEL_ID=Qwen/Qwen3-0.6B \
223
+ COMMON_PP=1 COMMON_VPP=null COMMON_CP=1 COMMON_TP=1 INFER_TP=1 \
224
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh \
225
+ ++actor_rollout_ref.actor.megatron.override_transformer_config.gradient_accumulation_fusion=False \
226
+ ++actor_rollout_ref.ref.megatron.override_transformer_config.gradient_accumulation_fusion=False \
227
+ ++critic.megatron.override_transformer_config.gradient_accumulation_fusion=False
228
+ - name: clean up
229
+ run: |
230
+ rm -rf checkpoints
231
+
232
+ cleanup:
233
+ runs-on: ubuntu-latest
234
+ needs:
235
+ [setup, e2e_ppo_trainer_megatron-deepseek, e2e_ppo_trainer_megatron-qwen3]
236
+ if: always()
237
+ steps:
238
+ - id: destroy-runner
239
+ uses: volcengine/vemlp-github-runner@v1
240
+ with:
241
+ mode: "destroy"
242
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
243
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_2.yml ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_vllm_2
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # FSDP
48
+ - "!verl/workers/**/*dp_*.py"
49
+ - "!verl/utils/fsdp_utils.py"
50
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
51
+ - "!verl/model_merger/fsdp_model_merger.py"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "**/*.py"
58
+ # Other entrypoints
59
+ - "!docker/**"
60
+ # Docs
61
+ - "!**/*.md"
62
+ - "!docs/**"
63
+ - "!examples/**"
64
+ - "!tests/**"
65
+ - "!verl/trainer/main_*.py"
66
+ - "!verl/trainer/fsdp_sft_trainer.py"
67
+ # FSDP
68
+ - "!verl/workers/**/*dp_*.py"
69
+ - "!verl/utils/fsdp_utils.py"
70
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
71
+ - "!verl/model_merger/fsdp_model_merger.py"
72
+ # Entrypoints
73
+ - ".github/workflows/e2e_ppo_trainer_megatron_vllm_2.yml"
74
+ - "examples/data_preprocess/gsm8k.py"
75
+ - "examples/data_preprocess/geo3k.py"
76
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
77
+ - "verl/trainer/main_ppo.py"
78
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
79
+
80
+ # Cancel jobs on the same ref if a new one is triggered
81
+ concurrency:
82
+ group: ${{ github.workflow }}-${{ github.ref }}
83
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
84
+
85
+ # Declare permissions just read content.
86
+ permissions:
87
+ contents: read
88
+
89
+ env:
90
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
91
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
92
+
93
+ jobs:
94
+ setup:
95
+ if: github.repository_owner == 'verl-project'
96
+ runs-on: ubuntu-latest
97
+ outputs:
98
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
99
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
100
+ steps:
101
+ - uses: actions/checkout@v4
102
+ - id: create-runner
103
+ uses: volcengine/vemlp-github-runner@v1
104
+ with:
105
+ mode: "create"
106
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
107
+ mlp-image: "${{ env.IMAGE }}"
108
+
109
+ e2e_ppo_trainer_megatron-moe-expert-parallel:
110
+ needs: setup
111
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
112
+ timeout-minutes: 60 # Increase this timeout value as needed
113
+ env:
114
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
115
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
116
+ HF_ENDPOINT: "https://hf-mirror.com"
117
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
118
+ steps:
119
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
120
+ with:
121
+ fetch-depth: 0
122
+ - name: Install the current repository
123
+ run: |
124
+ pip3 install -r requirements-test.txt
125
+ pip3 install -r requirements.txt
126
+ pip3 install --no-deps -e .
127
+ pip3 uninstall -y mbridge
128
+ pip3 install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
129
+ pip3 install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
130
+ pip3 install "nvidia-modelopt>=0.37.0"
131
+ - name: Check final pip list
132
+ run: |
133
+ pip3 list
134
+ - name: Prepare GSM8K dataset
135
+ run: |
136
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
137
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron-Bridge (Qwen3-30B-A3B-Instruct-2507)
138
+ run: |
139
+ ray stop --force
140
+ ADV_ESTIMATOR=grpo USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen2moe_minimal.json \
141
+ PPO_MAX_TOKEN_LEN=1024 FWD_MAX_TOKEN_LEN=1024 \
142
+ MAX_PROMPT_LENGTH=512 MAX_RESPONSE_LENGTH=512 \
143
+ MODEL_ID=Qwen/Qwen3-30B-A3B-Instruct-2507 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False \
144
+ COMMON_PP=2 COMMON_VPP=null COMMON_CP=1 COMMON_TP=4 COMMON_EP=4 COMMON_ETP=1 INFER_TP=8 \
145
+ USE_DIST_CKPT=False ALL_OFFLOAD=True SKIP_SAVE_HF_MODEL=1 bash tests/special_e2e/run_ppo_trainer_megatron.sh
146
+ - name: Running GSM8K E2E training tests with 3D parallelism with FP8 rollout on 8 L20 GPUs with Megatron-Bridge (Qwen3-30B-A3B-Instruct-2507)
147
+ run: |
148
+ ray stop --force
149
+ ADV_ESTIMATOR=grpo USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen2moe_minimal.json \
150
+ PPO_MAX_TOKEN_LEN=1024 FWD_MAX_TOKEN_LEN=1024 \
151
+ MAX_PROMPT_LENGTH=512 MAX_RESPONSE_LENGTH=512 \
152
+ MODEL_ID=Qwen/Qwen3-30B-A3B-Instruct-2507 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False \
153
+ COMMON_PP=2 COMMON_VPP=null COMMON_CP=1 COMMON_TP=4 COMMON_EP=4 COMMON_ETP=1 INFER_TP=2 \
154
+ USE_DIST_CKPT=False ALL_OFFLOAD=True SKIP_SAVE_HF_MODEL=1 ROLLOUT_QUANTIZATION=fp8 bash tests/special_e2e/run_ppo_trainer_megatron.sh
155
+ - name: clean up
156
+ run: |
157
+ rm -rf checkpoints
158
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 L20 GPUs with Megatron-Bridge LoRA (Qwen3-30B-A3B-Instruct-2507)
159
+ run: |
160
+ ray stop --force
161
+ ADV_ESTIMATOR=grpo USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen2moe_minimal.json \
162
+ PPO_MAX_TOKEN_LEN=1024 FWD_MAX_TOKEN_LEN=1024 \
163
+ MAX_PROMPT_LENGTH=512 MAX_RESPONSE_LENGTH=512 LORA_RANK=8 CRITIC_LORA_RANK=8 \
164
+ MODEL_ID=Qwen/Qwen3-30B-A3B-Instruct-2507 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False \
165
+ COMMON_PP=2 COMMON_VPP=null COMMON_CP=1 COMMON_TP=4 COMMON_EP=2 COMMON_ETP=1 INFER_TP=8 \
166
+ USE_DIST_CKPT=False LORA_MERGE=True ALL_OFFLOAD=True SKIP_SAVE_HF_MODEL=1 bash tests/special_e2e/run_ppo_trainer_megatron.sh
167
+ - name: clean up
168
+ run: |
169
+ rm -rf checkpoints
170
+
171
+ e2e_ppo_trainer_fsdp_vllm:
172
+ needs: setup
173
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
174
+ timeout-minutes: 60 # Increase this timeout value as needed
175
+ env:
176
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
177
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
178
+ HF_ENDPOINT: "https://hf-mirror.com"
179
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
180
+ steps:
181
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
182
+ with:
183
+ fetch-depth: 0
184
+ - name: Install the current repository
185
+ run: |
186
+ pip3 install -r requirements-test.txt
187
+ pip3 install --no-deps -e .
188
+ pip3 install --no-deps TransferQueue==0.1.8
189
+ - name: Check final pip list
190
+ run: |
191
+ pip3 list
192
+ - name: Prepare GSM8K dataset
193
+ run: |
194
+ ray stop --force
195
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
196
+ # Function RM
197
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm with validation and saving (FSDP_SIZE=8)
198
+ run: |
199
+ ray stop --force
200
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp-size8" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
201
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm after resuming
202
+ run: |
203
+ ray stop --force
204
+ RESUME_MODE=auto VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp-size8" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
205
+ - name: Test merging FSDP checkpoints (Qwen Actor)
206
+ run: |
207
+ exp_name="qwen2.5-0.5b-function-reward-minimal-fsdp-size8"
208
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
209
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm with validation and saving (DDP_SIZE=2, FSDP_SIZE=4)
210
+ run: |
211
+ ray stop --force
212
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True FSDP_SIZE=4 USE_KL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
213
+ - name: Test merging DDP+FSDP checkpoints (Qwen Actor)
214
+ run: |
215
+ exp_name="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4"
216
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
217
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm with validation and saving (FSDP2)
218
+ run: |
219
+ ray stop --force
220
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8" STRATEGY=fsdp2 bash tests/special_e2e/ppo_trainer/run_function_reward.sh
221
+ - name: Test merging FSDP2 checkpoints (Qwen Actor)
222
+ run: |
223
+ exp_name="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8"
224
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
225
+ - name: Running GSM8K E2E without rmpad using function rm
226
+ run: |
227
+ ray stop --force
228
+ RM_PAD=False bash tests/special_e2e/ppo_trainer/run_function_reward.sh
229
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm (GRPO)
230
+ run: |
231
+ ray stop --force
232
+ CUSTOM_REWARD_FN=True ADV_ESTIMATOR=grpo USE_KL=True bash tests/special_e2e/ppo_trainer/run_function_reward.sh
233
+ # - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm (ReMax)
234
+ # run: |
235
+ # ray stop --force
236
+ # ADV_ESTIMATOR=remax USE_KL=True bash tests/special_e2e/ppo_trainer/run_function_reward.sh
237
+ # LoRA tests
238
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with grpo lora using function rm with use_shm
239
+ run: |
240
+ ray stop --force
241
+ ADV_ESTIMATOR=grpo USE_SHM=True LORA_RANK=32 LOAD_FORMAT=safetensors bash tests/special_e2e/ppo_trainer/run_function_reward.sh
242
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with grpo lora using function rm with use_shm and layered_summon
243
+ run: |
244
+ ray stop --force
245
+ ADV_ESTIMATOR=grpo USE_SHM=True LORA_RANK=32 LOAD_FORMAT=safetensors LAYERED_SUMMON=True TOTAL_TRAIN_STEPS=1 SAVE_FREQ=1 FSDP_SIZE=4 VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
246
+ - name: Test GRPO LoRA checkpoints merging function
247
+ run: |
248
+ export EXP_NAME="qwen2.5-0.5b-function-reward-minimal"
249
+ ls checkpoints/verl-test/${EXP_NAME}/global_step_1/actor
250
+ cat checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/huggingface/config.json
251
+ python3 -m verl.model_merger merge --backend fsdp --local_dir checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/ --target_dir checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/huggingface
252
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with grpo lora using function rm with use_shm and layered_summon with fsdp2
253
+ run: |
254
+ ray stop --force
255
+ ADV_ESTIMATOR=grpo USE_SHM=True LORA_RANK=32 LOAD_FORMAT=safetensors LAYERED_SUMMON=True STRATEGY=fsdp2 bash tests/special_e2e/ppo_trainer/run_function_reward.sh
256
+
257
+ e2e_ppo_trainer_fsdp-qwen2_5vl-3b:
258
+ needs: setup
259
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
260
+ timeout-minutes: 40 # Increase this timeout value as needed
261
+ env:
262
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
263
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
264
+ HF_ENDPOINT: "https://hf-mirror.com"
265
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
266
+ steps:
267
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
268
+ with:
269
+ fetch-depth: 0
270
+ - name: Install the current repository
271
+ run: |
272
+ pip3 install -r requirements-test.txt
273
+ pip3 install --no-deps -e .
274
+ pip3 install --no-deps TransferQueue==0.1.8
275
+ - name: Check final pip list
276
+ run: |
277
+ pip3 list
278
+ # Geo3k
279
+ - name: Prepare GEO3K dataset
280
+ run: |
281
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k/
282
+ - name: Running GEO3K VLM GRPO E2E training tests on 8 L20 GPUs with rmpad using function rm
283
+ run: |
284
+ ray stop --force
285
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
286
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
287
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
288
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
289
+ SP_SIZE=2 \
290
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
291
+
292
+ - name: Running GEO3K VLM PPO E2E training tests on 8 L20 GPUs with rmpad using function rm
293
+ run: |
294
+ ray stop --force
295
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
296
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
297
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
298
+ ADV_ESTIMATOR=gae RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
299
+ SP_SIZE=2 \
300
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
301
+ - name: Running GEO3K VLM GRPO E2E lora training tests on 8 L20 GPUs with rmpad using function rm
302
+ run: |
303
+ ray stop --force
304
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
305
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
306
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
307
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
308
+ SP_SIZE=2 \
309
+ LORA_RANK=32 LORA_EXCLUDE=".*visual.*" \
310
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
311
+
312
+ cleanup:
313
+ runs-on: ubuntu-latest
314
+ needs:
315
+ [
316
+ setup,
317
+ e2e_ppo_trainer_megatron-moe-expert-parallel,
318
+ e2e_ppo_trainer_fsdp-qwen2_5vl-3b,
319
+ e2e_ppo_trainer_fsdp_vllm,
320
+ ]
321
+ if: always()
322
+ steps:
323
+ - id: destroy-runner
324
+ uses: volcengine/vemlp-github-runner@v1
325
+ with:
326
+ mode: "destroy"
327
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
328
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_2_ascend.yml ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_vllm_2_ascend
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # FSDP
48
+ - "!verl/workers/**/*dp_*.py"
49
+ - "!verl/utils/fsdp_utils.py"
50
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
51
+ - "!verl/model_merger/fsdp_model_merger.py"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "**/*.py"
58
+ # Other entrypoints
59
+ - "!docker/**"
60
+ # Docs
61
+ - "!**/*.md"
62
+ - "!docs/**"
63
+ - "!examples/**"
64
+ - "!tests/**"
65
+ - "!verl/trainer/main_*.py"
66
+ - "!verl/trainer/fsdp_sft_trainer.py"
67
+ # FSDP
68
+ - "!verl/workers/**/*dp_*.py"
69
+ - "!verl/utils/fsdp_utils.py"
70
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
71
+ - "!verl/model_merger/fsdp_model_merger.py"
72
+ # Entrypoints
73
+ - ".github/workflows/e2e_ppo_trainer_megatron_vllm_2_ascend.yml"
74
+ - "examples/data_preprocess/gsm8k.py"
75
+ - "examples/data_preprocess/geo3k.py"
76
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
77
+ - "verl/trainer/main_ppo.py"
78
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
79
+
80
+ # Cancel jobs on the same ref if a new one is triggered
81
+ concurrency:
82
+ group: ${{ github.workflow }}-${{ github.ref }}
83
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
84
+
85
+ # Declare permissions just read content.
86
+ permissions:
87
+ contents: read
88
+
89
+ jobs:
90
+ e2e_ppo_trainer_fsdp_vllm_ascend:
91
+ if: github.repository_owner == 'verl-project'
92
+ runs-on: linux-aarch64-a2b3-8
93
+ timeout-minutes: 90 # Increase this timeout value as needed
94
+ container:
95
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-910b-ubuntu22.04-py3.11-vllm
96
+ options: >-
97
+ --shm-size 16g
98
+ env:
99
+ HF_ENDPOINT: "https://hf-mirror.com"
100
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
101
+ steps:
102
+ - name: Check npu and CANN info
103
+ run: |
104
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
105
+ npu-smi info
106
+ - name: Check initial pip list from image
107
+ run: |
108
+ pip list
109
+ - name: Checkout verl-project/verl repo
110
+ uses: actions/checkout@v4
111
+ with:
112
+ fetch-depth: 0
113
+ clean: true
114
+ - name: Install the current repository
115
+ run: |
116
+ pip install --no-deps -e .
117
+ - name: Check final pip list
118
+ run: |
119
+ pip list
120
+ - name: Prepare weights
121
+ run: |
122
+ ln -s /root/.cache/models ~/models
123
+ - name: Prepare GSM8K dataset
124
+ run: |
125
+ python examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/.cache/datasets/openai/gsm8k
126
+ # Function RM
127
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm with validation and saving (DDP_SIZE=2, FSDP_SIZE=4)
128
+ run: |
129
+ ray stop --force
130
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True FSDP_SIZE=4 USE_KL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
131
+ - name: Test merging DDP+FSDP checkpoints (Qwen Actor)
132
+ run: |
133
+ exp_name="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4"
134
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
135
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm with validation and saving (FSDP2)
136
+ run: |
137
+ ray stop --force
138
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8" STRATEGY=fsdp2 bash tests/special_e2e/ppo_trainer/run_function_reward.sh
139
+ - name: Test merging FSDP2 checkpoints (Qwen Actor)
140
+ run: |
141
+ exp_name="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8"
142
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
143
+ - name: Running GSM8K E2E without rmpad using function rm
144
+ run: |
145
+ ray stop --force
146
+ RM_PAD=False bash tests/special_e2e/ppo_trainer/run_function_reward.sh
147
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with rmpad using function rm (GRPO)
148
+ run: |
149
+ ray stop --force
150
+ CUSTOM_REWARD_FN=True ADV_ESTIMATOR=grpo USE_KL=True bash tests/special_e2e/ppo_trainer/run_function_reward.sh
151
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with grpo lora using function rm with use_shm and layered_summon
152
+ run: |
153
+ ray stop --force
154
+ ADV_ESTIMATOR=grpo USE_SHM=True LORA_RANK=32 LOAD_FORMAT=safetensors LAYERED_SUMMON=True TOTAL_TRAIN_STEPS=1 SAVE_FREQ=1 FSDP_SIZE=4 VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
155
+ - name: Test GRPO LoRA checkpoints merging function
156
+ run: |
157
+ export EXP_NAME="qwen2.5-0.5b-function-reward-minimal"
158
+ ls checkpoints/verl-test/${EXP_NAME}/global_step_1/actor
159
+ cat checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/huggingface/config.json
160
+ python3 -m verl.model_merger merge --backend fsdp --local_dir checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/ --target_dir checkpoints/verl-test/${EXP_NAME}/global_step_1/actor/huggingface
161
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with grpo lora using function rm with use_shm and layered_summon with fsdp2
162
+ run: |
163
+ ray stop --force
164
+ ADV_ESTIMATOR=grpo USE_SHM=True LORA_RANK=32 LOAD_FORMAT=safetensors LAYERED_SUMMON=True STRATEGY=fsdp2 bash tests/special_e2e/ppo_trainer/run_function_reward.sh
165
+
166
+ e2e_ppo_trainer_fsdp-qwen2_5vl-3b_ascend:
167
+ if: github.repository_owner == 'verl-project'
168
+ runs-on: linux-aarch64-a2b3-8
169
+ timeout-minutes: 60 # Increase this timeout value as needed
170
+ container:
171
+ image: swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/ascend-ci/verl/verl:latest-cann9.0.0-torch_npu2.9.0post2-910b-ubuntu22.04-py3.11-vllm
172
+ options: >-
173
+ --shm-size 16g
174
+ env:
175
+ HF_ENDPOINT: "https://hf-mirror.com"
176
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
177
+ steps:
178
+ - name: Check npu and CANN info
179
+ run: |
180
+ cat /usr/local/Ascend/ascend-toolkit/latest/"$(uname -i)"-linux/ascend_toolkit_install.info
181
+ npu-smi info
182
+ - name: Check initial pip list from image
183
+ run: |
184
+ pip list
185
+ - name: Checkout verl-project/verl repo
186
+ uses: actions/checkout@v4
187
+ with:
188
+ fetch-depth: 0
189
+ clean: true
190
+ - name: Install the current repository
191
+ run: |
192
+ pip install --no-deps -e .
193
+ pip install trl==0.26.0
194
+ - name: Check final pip list
195
+ run: |
196
+ pip list
197
+ - name: Prepare weights
198
+ run: |
199
+ ln -s /root/.cache/models ~/models
200
+ # Geo3k
201
+ - name: Prepare GEO3K dataset
202
+ run: |
203
+ python examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/.cache/datasets/hiyouga/geometry3k
204
+ - name: Running GEO3K VLM GRPO E2E training tests on 8 L20 GPUs with rmpad using function rm
205
+ run: |
206
+ ray stop --force
207
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
208
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
209
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
210
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
211
+ SP_SIZE=2 \
212
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
213
+ - name: Running GEO3K VLM PPO E2E training tests on 8 L20 GPUs with rmpad using function rm
214
+ run: |
215
+ ray stop --force
216
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
217
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
218
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
219
+ ADV_ESTIMATOR=gae RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
220
+ SP_SIZE=2 \
221
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
222
+ - name: Running GEO3K VLM GRPO E2E lora training tests on 8 L20 GPUs with rmpad using function rm
223
+ run: |
224
+ ray stop --force
225
+ TRAIN_FILES=$HOME/data/geo3k/train.parquet VAL_FILES=$HOME/data/geo3k/test.parquet \
226
+ MAX_PROMPT_LEN=1536 MAX_RESPONSE_LEN=1536 \
227
+ MODEL_ID=Qwen/Qwen2.5-VL-3B-Instruct \
228
+ ADV_ESTIMATOR=grpo RM_PAD=True USE_KL=True ENABLE_CHUNKED_PREFILL=False \
229
+ SP_SIZE=2 \
230
+ LORA_RANK=32 LORA_EXCLUDE=".*visual.*" \
231
+ bash tests/special_e2e/ppo_trainer/run_function_reward.sh
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_megatron_vllm_rocm.yml ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_megatron_vllm_rocm
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # FSDP
48
+ - "!verl/workers/**/*dp_*.py"
49
+ - "!verl/utils/fsdp_utils.py"
50
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
51
+ - "!verl/model_merger/fsdp_model_merger.py"
52
+ pull_request:
53
+ branches:
54
+ - main
55
+ - v0.*
56
+ paths:
57
+ - "**/*.py"
58
+ # Other entrypoints
59
+ - "!docker/**"
60
+ # Docs
61
+ - "!**/*.md"
62
+ - "!docs/**"
63
+ - "!examples/**"
64
+ - "!tests/**"
65
+ - "!verl/trainer/main_*.py"
66
+ - "!verl/trainer/fsdp_sft_trainer.py"
67
+ # FSDP
68
+ - "!verl/workers/**/*dp_*.py"
69
+ - "!verl/utils/fsdp_utils.py"
70
+ - "!verl/utils/checkpoint/fsdp_checkpoint_manager.py"
71
+ - "!verl/model_merger/fsdp_model_merger.py"
72
+ # Entrypoints
73
+ - ".github/workflows/e2e_ppo_trainer_megatron_vllm_rocm.yml"
74
+ - "examples/data_preprocess/gsm8k.py"
75
+ - "examples/data_preprocess/geo3k.py"
76
+ - "tests/special_e2e/run_ppo_trainer_megatron.sh"
77
+ - "verl/trainer/main_ppo.py"
78
+ - "verl/trainer/config/ppo_megatron_trainer.yaml"
79
+
80
+ # Cancel jobs on the same ref if a new one is triggered
81
+ concurrency:
82
+ group: ${{ github.workflow }}-${{ github.ref }}
83
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
84
+
85
+ # Declare permissions just read content.
86
+ permissions:
87
+ contents: read
88
+
89
+ jobs:
90
+ e2e_ppo_trainer_fsdp_vllm_rocm:
91
+ if: github.repository_owner == 'verl-project'
92
+ runs-on: [rocm-mi300]
93
+ timeout-minutes: 60 # Increase this timeout value as needed
94
+ container:
95
+ image: "verlai/verl:rocm702-vllm020-te210-20260518"
96
+ options: >-
97
+ --device /dev/kfd
98
+ --device /dev/dri
99
+ --privileged
100
+ --group-add video
101
+ --cap-add SYS_PTRACE
102
+ --security-opt seccomp=unconfined
103
+ --shm-size 2048g
104
+ --ulimit memlock=-1
105
+ --ulimit stack=67108864
106
+ -v /data/models:/root/models
107
+ -v /data/data:/root/data
108
+ env:
109
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
110
+ # GitHub container jobs force HOME=/github/home. Our data is mounted under
111
+ # /root and the verl scripts reference $HOME, so pin HOME back to /root to
112
+ # match the local `docker run` behavior and the volume mounts above.
113
+ HOME: "/root"
114
+ steps:
115
+ - name: Check ROCm and GPU info
116
+ run: |
117
+ rocm-smi || true
118
+ rocminfo || true
119
+ - name: Check initial pip list from image
120
+ run: |
121
+ pip list
122
+ - name: Checkout verl-project/verl repo
123
+ uses: actions/checkout@v4
124
+ with:
125
+ fetch-depth: 0
126
+ clean: true
127
+ - name: Install the current repository
128
+ run: |
129
+ pip install --no-deps -e .
130
+ pip install --no-deps TransferQueue==0.1.8
131
+ - name: Check final pip list
132
+ run: |
133
+ pip list
134
+ - name: Prepare GSM8K dataset
135
+ run: |
136
+ ray stop --force
137
+ python3 examples/data_preprocess/gsm8k.py --local_dir ${HOME}/models/hf_data/gsm8k
138
+ # Function RM
139
+ - name: Running GSM8K E2E training tests on 8 MI300 GPUs with rmpad using function rm with validation and saving (FSDP_SIZE=8)
140
+ run: |
141
+ ray stop --force
142
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp-size8" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
143
+ - name: Running GSM8K E2E training tests on 8 MI300 GPUs with rmpad using function rm after resuming
144
+ run: |
145
+ ray stop --force
146
+ RESUME_MODE=auto VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp-size8" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
147
+ - name: Test merging FSDP checkpoints (Qwen Actor)
148
+ run: |
149
+ exp_name="qwen2.5-0.5b-function-reward-minimal-fsdp-size8"
150
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
151
+ - name: Running GSM8K E2E training tests on 8 MI300 GPUs with rmpad using function rm with validation and saving (DDP_SIZE=2, FSDP_SIZE=4)
152
+ run: |
153
+ ray stop --force
154
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True FSDP_SIZE=4 USE_KL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4" bash tests/special_e2e/ppo_trainer/run_function_reward.sh
155
+ - name: Test merging DDP+FSDP checkpoints (Qwen Actor)
156
+ run: |
157
+ exp_name="qwen2.5-0.5b-function-reward-minimal-ddp-size2-fsdp-size4"
158
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
159
+ - name: Running GSM8K E2E training tests on 8 MI300 GPUs with rmpad using function rm with validation and saving (FSDP2)
160
+ run: |
161
+ ray stop --force
162
+ VAL_BEFORE_TRAIN=True TEST_FREQ=1 SAVE_FREQ=1 SAVE_HF_MODEL=True VERL_EXP_NAME="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8" STRATEGY=fsdp2 bash tests/special_e2e/ppo_trainer/run_function_reward.sh
163
+ - name: Test merging FSDP2 checkpoints (Qwen Actor)
164
+ run: |
165
+ exp_name="qwen2.5-0.5b-function-reward-minimal-fsdp2-size8"
166
+ python -m verl.model_merger test --backend fsdp --local_dir checkpoints/verl-test/${exp_name}/global_step_1/actor --test_hf_dir checkpoints/verl-test/${exp_name}/global_step_1/actor/huggingface
167
+ - name: Running GSM8K E2E without rmpad using function rm
168
+ run: |
169
+ ray stop --force
170
+ RM_PAD=False bash tests/special_e2e/ppo_trainer/run_function_reward.sh
171
+ - name: Running GSM8K E2E training tests on 8 MI300 GPUs with rmpad using function rm (GRPO)
172
+ run: |
173
+ ray stop --force
174
+ CUSTOM_REWARD_FN=True ADV_ESTIMATOR=grpo USE_KL=True bash tests/special_e2e/ppo_trainer/run_function_reward.sh
175
+ - name: Clean up
176
+ run: |
177
+ rm -rf checkpoints
178
+
179
+ e2e_ppo_trainer_megatron-moe-expert-parallel_rocm:
180
+ if: github.repository_owner == 'verl-project'
181
+ runs-on: [rocm-mi300]
182
+ timeout-minutes: 60 # Increase this timeout value as needed
183
+ container:
184
+ image: "verlai/verl:rocm702-vllm020-te210-20260518"
185
+ options: >-
186
+ --device /dev/kfd
187
+ --device /dev/dri
188
+ --privileged
189
+ --group-add video
190
+ --cap-add SYS_PTRACE
191
+ --security-opt seccomp=unconfined
192
+ --shm-size 2048g
193
+ --ulimit memlock=-1
194
+ --ulimit stack=67108864
195
+ -v /data/models:/root/models
196
+ -v /data/data:/root/data
197
+ env:
198
+ HF_HUB_ENABLE_HF_TRANSFER: "0"
199
+ HOME: "/root"
200
+ steps:
201
+ - name: Check ROCm and GPU info
202
+ run: |
203
+ rocm-smi || true
204
+ rocminfo || true
205
+ - name: Check initial pip list from image
206
+ run: |
207
+ pip list
208
+ - name: Checkout verl-project/verl repo
209
+ uses: actions/checkout@v4
210
+ with:
211
+ fetch-depth: 0
212
+ clean: true
213
+ - name: Install the current repository
214
+ run: |
215
+ pip install --no-deps -e .
216
+ pip install --no-deps TransferQueue==0.1.8
217
+ pip uninstall -y mbridge
218
+ pip install git+https://github.com/NVIDIA-NeMo/Megatron-Bridge.git@e2cfe7e --ignore-requires-python --no-deps --no-build-isolation
219
+ pip install git+https://github.com/NVIDIA/Megatron-LM.git@0823c73 --ignore-requires-python --no-deps --no-build-isolation
220
+ pip install "nvidia-modelopt>=0.37.0"
221
+ - name: Check final pip list
222
+ run: |
223
+ pip list
224
+ - name: Prepare GSM8K dataset
225
+ run: |
226
+ ray stop --force
227
+ python3 examples/data_preprocess/gsm8k.py --local_dir ${HOME}/models/hf_data/gsm8k
228
+ - name: Running GSM8K E2E training tests with 3D parallelism on 8 MI300 GPUs with Megatron-Bridge (Qwen3-30B-A3B-Instruct-2507)
229
+ run: |
230
+ ray stop --force
231
+ ADV_ESTIMATOR=grpo USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen2moe_minimal.json \
232
+ PPO_MAX_TOKEN_LEN=1024 FWD_MAX_TOKEN_LEN=1024 \
233
+ MAX_PROMPT_LENGTH=512 MAX_RESPONSE_LENGTH=512 \
234
+ MODEL_ID=Qwen/Qwen3-30B-A3B-Instruct-2507 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False \
235
+ COMMON_PP=2 COMMON_VPP=null COMMON_CP=1 COMMON_TP=4 COMMON_EP=4 COMMON_ETP=1 INFER_TP=8 \
236
+ USE_DIST_CKPT=False ALL_OFFLOAD=True SKIP_SAVE_HF_MODEL=1 \
237
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh \
238
+ global_profiler.tool=null actor_rollout_ref.actor.profiler.tool=null actor_rollout_ref.ref.profiler.tool=null actor_rollout_ref.rollout.profiler.tool=null critic.profiler.tool=null
239
+ - name: Running GSM8K E2E training tests with 3D parallelism with FP8 rollout on 8 MI300 GPUs with Megatron-Bridge (Qwen3-30B-A3B-Instruct-2507)
240
+ run: |
241
+ ray stop --force
242
+ ADV_ESTIMATOR=grpo USE_DUMMY_MODEL=True DUMMY_MODEL_CONFIG_PATH=tests/special_e2e/ppo_trainer/expert_parallel/qwen2moe_minimal.json \
243
+ PPO_MAX_TOKEN_LEN=1024 FWD_MAX_TOKEN_LEN=1024 \
244
+ MAX_PROMPT_LENGTH=512 MAX_RESPONSE_LENGTH=512 \
245
+ MODEL_ID=Qwen/Qwen3-30B-A3B-Instruct-2507 USE_MBRIDGE=True VANILLA_MBRIDGE=False VALUE_VANILLA_MBRIDGE=False \
246
+ COMMON_PP=2 COMMON_VPP=null COMMON_CP=1 COMMON_TP=4 COMMON_EP=4 COMMON_ETP=1 INFER_TP=2 \
247
+ USE_DIST_CKPT=False ALL_OFFLOAD=True SKIP_SAVE_HF_MODEL=1 ROLLOUT_QUANTIZATION=fp8 \
248
+ bash tests/special_e2e/run_ppo_trainer_megatron.sh \
249
+ global_profiler.tool=null actor_rollout_ref.actor.profiler.tool=null actor_rollout_ref.ref.profiler.tool=null actor_rollout_ref.rollout.profiler.tool=null critic.profiler.tool=null
250
+ - name: clean up
251
+ run: |
252
+ rm -rf checkpoints
253
+
254
+ cleanup_rocm:
255
+ needs:
256
+ - e2e_ppo_trainer_fsdp_vllm_rocm
257
+ - e2e_ppo_trainer_megatron-moe-expert-parallel_rocm
258
+ if: ${{ always() && github.repository_owner == 'verl-project' }}
259
+ runs-on: [rocm-mi300]
260
+ container:
261
+ image: "verlai/verl:rocm702-vllm020-te210-20260518"
262
+ steps:
263
+ - name: Clean up leftover checkpoints
264
+ run: |
265
+ rm -rf checkpoints
verl_0720_main/verl/.github/workflows/e2e_ppo_trainer_veomni_vllm.yml ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Tests layout
2
+
3
+ # Each folder under tests/ corresponds to a test category for a sub-namespace in verl. For instance:
4
+ # - `tests/trainer` for testing functionality related to `verl/trainer`
5
+ # - `tests/models` for testing functionality related to `verl/models`
6
+ # - ...
7
+
8
+ # There are a few folders with `special_` prefix, created for special purposes:
9
+ # - `special_distributed`: unit tests that must run with multiple GPUs
10
+ # - `special_e2e`: end-to-end tests with training/generation scripts
11
+ # - `special_npu`: tests for NPUs
12
+ # - `special_sanity`: a suite of quick sanity tests
13
+ # - `special_standalone`: a set of test that are designed to run in dedicated environments
14
+
15
+ # Accelerators for tests
16
+ # - By default tests are run with GPU available, except for the ones under `special_npu`, and any test script whose name ends with `on_cpu.py`.
17
+ # - For test scripts with `on_cpu.py` name suffix would be tested on CPU resources in linux environment.
18
+
19
+ # # Workflow layout
20
+
21
+ # All CI tests are configured by yaml files in `.github/workflows/`. Here's an overview of all test configs:
22
+ # 1. A list of always triggered CPU sanity tests: `check-pr-title.yml`, `secrets_scan.yml`, `check-pr-title,yml`, `pre-commit.yml`, `doc.yml`
23
+ # 2. Some heavy multi-GPU unit tests, such as `model.yml`, `vllm.yml`, `sgl.yml`
24
+ # 3. End-to-end tests: `e2e_*.yml`
25
+ # 4. Unit tests
26
+ # - `cpu_unit_tests.yml`, run pytest on all scripts with file name pattern `tests/**/test_*_on_cpu.py`
27
+ # - `gpu_unit_tests.yml`, run pytest on all scripts with file without the `on_cpu.py` suffix.
28
+ # - Since cpu/gpu unit tests by default runs all tests under `tests`, please make sure tests are manually excluded in them when
29
+ # - new workflow yaml is added to `.github/workflows`
30
+ # - new tests are added to workflow mentioned in 2.
31
+
32
+ name: e2e_ppo_trainer_veomni_vllm
33
+
34
+ on:
35
+ # Trigger the workflow on push or pull request,
36
+ # but only for the main branch.
37
+ # For push, for now only anti-patterns are specified so it is more conservative
38
+ # and achieves higher coverage.
39
+ push:
40
+ branches:
41
+ - main
42
+ - v0.*
43
+ paths:
44
+ - "**/*.py"
45
+ # Other entrypoints
46
+ - "!verl/trainer/fsdp_sft_trainer.py"
47
+ # Megatron
48
+ - "!verl/workers/**/megatron_*.py"
49
+ pull_request:
50
+ branches:
51
+ - main
52
+ - v0.*
53
+ paths:
54
+ - "**/*.py"
55
+ # Other entrypoints
56
+ - "!docker/**"
57
+ # Docs
58
+ - "!**/*.md"
59
+ - "!docs/**"
60
+ - "!examples/**"
61
+ - "!tests/**"
62
+ - "!verl/trainer/main_*.py"
63
+ - "!verl/trainer/fsdp_sft_trainer.py"
64
+ # Megatron
65
+ - "!verl/workers/**/megatron_*.py"
66
+ # Entrypoints
67
+ - ".github/workflows/e2e_ppo_trainer_veomni_vllm.yml"
68
+ - "examples/data_preprocess/gsm8k.py"
69
+ - "examples/data_preprocess/geo3k.py"
70
+ - "tests/special_e2e/run_ppo_trainer_veomni.sh"
71
+ - "verl/trainer/main_ppo.py"
72
+ - "verl/trainer/config/ppo_trainer.yaml"
73
+
74
+ # Cancel jobs on the same ref if a new one is triggered
75
+ concurrency:
76
+ group: ${{ github.workflow }}-${{ github.ref }}
77
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
78
+
79
+ # Declare permissions just read content.
80
+ permissions:
81
+ contents: read
82
+
83
+ env:
84
+ IMAGE: "verl-ci-cn-beijing.cr.volces.com/verlai/verl:vllm023.dev1"
85
+ DYNAMIC_RUNNER_ENDPOINT: "https://sd10g3clalm04ug7alq90.apigateway-cn-beijing.volceapi.com/runner"
86
+
87
+ jobs:
88
+ setup:
89
+ if: github.repository_owner == 'verl-project'
90
+ runs-on: ubuntu-latest
91
+ outputs:
92
+ runner-label: ${{ steps.create-runner.outputs.runner-label }}
93
+ mlp-task-id: ${{ steps.create-runner.outputs.mlp-task-id }}
94
+ steps:
95
+ - uses: actions/checkout@v4
96
+ - id: create-runner
97
+ uses: volcengine/vemlp-github-runner@v1
98
+ with:
99
+ mode: "create"
100
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
101
+ mlp-image: "${{ env.IMAGE }}"
102
+
103
+ e2e_ppo_trainer_veomni_vllm:
104
+ needs: setup
105
+ runs-on: ["${{ needs.setup.outputs.runner-label || 'L20x8' }}"]
106
+ timeout-minutes: 60 # Increase this timeout value as needed
107
+ env:
108
+ HTTPS_PROXY: ${{ secrets.PROXY_HTTPS }}
109
+ NO_PROXY: "localhost,127.0.0.1,hf-mirror.com"
110
+ HF_ENDPOINT: "https://hf-mirror.com"
111
+ HF_HUB_ENABLE_HF_TRANSFER: "0" # This is more stable
112
+ steps:
113
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
114
+ with:
115
+ fetch-depth: 0
116
+ - name: Install the current repository
117
+ run: |
118
+ pip3 install -r requirements-test.txt
119
+ pip3 install -r requirements.txt
120
+ pip3 install --no-deps -e .
121
+ pip3 install veomni==0.1.11 --ignore-requires-python --no-deps --index-url https://pypi.org/simple/
122
+ pip3 install transformers==5.3.0
123
+ - name: Check final pip list
124
+ run: |
125
+ pip3 list
126
+ - name: Prepare GSM8K dataset
127
+ run: |
128
+ ray stop --force
129
+ python3 examples/data_preprocess/gsm8k.py --local_dataset_path ${HOME}/models/hf_data/gsm8k
130
+ - name: Prepare GEO3K dataset
131
+ run: |
132
+ ray stop --force
133
+ python3 examples/data_preprocess/geo3k.py --local_dataset_path ${HOME}/models/hf_data/hiyouga/geometry3k/
134
+ - name: Running GSM8K E2E training tests on 8 L20 GPUs with veomni engine (FSDP_SIZE=4, USP=2)
135
+ run: |
136
+ ray stop --force
137
+ FSDP_SIZE=4 SP_SIZE=2 bash tests/special_e2e/run_ppo_trainer_veomni.sh
138
+ - name: Running GEO3K E2E training tests on 8 L20 GPUs with veomni engine (FSDP_SIZE=8, USP=1)
139
+ run: |
140
+ ray stop --force
141
+ MODEL_ID=Qwen/Qwen3-VL-2B-Instruct TRAIN_FILES=${HOME}/data/geo3k/train.parquet VAL_FILES=${HOME}/data/gsm8k/test.parquet FSDP_SIZE=8 SP_SIZE=1 bash tests/special_e2e/run_ppo_trainer_veomni.sh
142
+ - name: Test export unfused experts
143
+ run: |
144
+ torchrun --nproc_per_node=8 tests/utils/veomni/test_special_export_unfused_experts.py
145
+
146
+ cleanup:
147
+ runs-on: ubuntu-latest
148
+ needs:
149
+ [
150
+ setup,
151
+ e2e_ppo_trainer_veomni_vllm,
152
+ ]
153
+ if: always()
154
+ steps:
155
+ - id: destroy-runner
156
+ uses: volcengine/vemlp-github-runner@v1
157
+ with:
158
+ mode: "destroy"
159
+ faas-url: "${{ env.DYNAMIC_RUNNER_ENDPOINT }}"
160
+ mlp-task-id: "${{ needs.setup.outputs.mlp-task-id }}"