Delete verl_0720_main/9b.sh
Browse files- verl_0720_main/9b.sh +0 -1083
verl_0720_main/9b.sh
DELETED
|
@@ -1,1083 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
|
| 3 |
-
set -x
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
export TRAIN_SP=1
|
| 7 |
-
export QWEN35_FLA_BACKEND=disabled
|
| 8 |
-
export MAX_PROMPT_LENGTH=8192
|
| 9 |
-
export MAX_RESPONSE_LENGTH=22768
|
| 10 |
-
export MAX_ASSISTANT_RESPONSE_LENGTH=16384
|
| 11 |
-
export MAX_TOOL_RESPONSE_LENGTH=8192
|
| 12 |
-
export ACTOR_MAX_TOKEN_LEN_PER_GPU=32768
|
| 13 |
-
export LOG_PROB_MAX_TOKEN_LEN_PER_GPU=32768
|
| 14 |
-
export ROLLOUT_MAX_NUM_BATCHED_TOKENS=32768
|
| 15 |
-
export ACTOR_STRATEGY=fsdp2
|
| 16 |
-
export OFFLOAD=True
|
| 17 |
-
export ENTROPY_FROM_LOGITS_WITH_CHUNKING=True
|
| 18 |
-
export ENTROPY_FROM_LOGITS_CHUNK_SIZE=256
|
| 19 |
-
export ENTROPY_CHECKPOINTING=False
|
| 20 |
-
export USE_FUSED_KERNELS=True
|
| 21 |
-
export FUSED_KERNEL_BACKEND=torch
|
| 22 |
-
export ENABLE_ACTIVATION_OFFLOAD=${ENABLE_ACTIVATION_OFFLOAD:-True}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
npu-smi info || true
|
| 26 |
-
pip install --upgrade pip
|
| 27 |
-
pip uninstall -y moxing-framework || true
|
| 28 |
-
|
| 29 |
-
# ================= 路径配置 =================
|
| 30 |
-
SCRIPT_DIR=/verl_0720_main
|
| 31 |
-
if [ -f "${SCRIPT_DIR}/verl/requirements-npu.txt" ]; then
|
| 32 |
-
DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
|
| 33 |
-
elif [ -f "${SCRIPT_DIR}/requirements-npu.txt" ]; then
|
| 34 |
-
DEFAULT_WORK_DIR=${SCRIPT_DIR}
|
| 35 |
-
else
|
| 36 |
-
DEFAULT_WORK_DIR=${SCRIPT_DIR}/verl
|
| 37 |
-
fi
|
| 38 |
-
WORK_DIR=${WORK_DIR:-${DEFAULT_WORK_DIR}}
|
| 39 |
-
INSTALL_DIR=${INSTALL_DIR:-/home/ma-user}
|
| 40 |
-
BKGS=${BKGS:-//bkgs}
|
| 41 |
-
chmod 755 "${INSTALL_DIR}"
|
| 42 |
-
|
| 43 |
-
# Nanoclaw 自定义包已随 WORK_DIR 提供:nanoclaw_recipe。
|
| 44 |
-
|
| 45 |
-
GCC_INSTALL_PREFIX=${GCC_INSTALL_PREFIX:-/home/ma-user/gcc-11.3.0}
|
| 46 |
-
COMPILED_GCC_ARCHIVE_PATH=${COMPILED_GCC_ARCHIVE_PATH:-//gcc-11.3.0-compiled-aarch64.tar.gz}
|
| 47 |
-
|
| 48 |
-
echo "--> 正在从缓存恢复 GCC 11.3.0..."
|
| 49 |
-
tar -xzf "${COMPILED_GCC_ARCHIVE_PATH}" -C /home/ma-user/
|
| 50 |
-
export PATH=${GCC_INSTALL_PREFIX}/bin:${PATH}
|
| 51 |
-
export LD_LIBRARY_PATH=${GCC_INSTALL_PREFIX}/lib64:${GCC_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH:-}
|
| 52 |
-
export CC=${GCC_INSTALL_PREFIX}/bin/gcc
|
| 53 |
-
export CXX=${GCC_INSTALL_PREFIX}/bin/g++
|
| 54 |
-
echo "--> 验证 GCC 版本:"
|
| 55 |
-
gcc --version
|
| 56 |
-
|
| 57 |
-
cd "${BKGS}"
|
| 58 |
-
cp jemalloc-5.3.0.tar.bz2 "${INSTALL_DIR}"
|
| 59 |
-
|
| 60 |
-
VLLM_LATEST_PKGS=${VLLM_LATEST_PKGS:-/pkgs}
|
| 61 |
-
rm -rf "${INSTALL_DIR}/vllm" "${INSTALL_DIR}/vllm-ascend"
|
| 62 |
-
cp -r "${VLLM_LATEST_PKGS}/vllm" "${INSTALL_DIR}"
|
| 63 |
-
cp -r "${VLLM_LATEST_PKGS}/vllm-ascend" "${INSTALL_DIR}"
|
| 64 |
-
|
| 65 |
-
CANN_BKGS=${CANN_BKGS:-/cann_0527}
|
| 66 |
-
cp "${CANN_BKGS}/Ascend-cann-toolkit_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
|
| 67 |
-
cp "${CANN_BKGS}/Ascend-cann-910b-ops_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
|
| 68 |
-
cp "${CANN_BKGS}/Ascend-cann-nnal_9.0.0_linux-aarch64.run" "${INSTALL_DIR}"
|
| 69 |
-
|
| 70 |
-
echo "################"
|
| 71 |
-
echo "## set verl env"
|
| 72 |
-
echo "################"
|
| 73 |
-
|
| 74 |
-
cd "${INSTALL_DIR}"
|
| 75 |
-
|
| 76 |
-
chmod +x Ascend-cann-toolkit_9.0.0_linux-aarch64.run
|
| 77 |
-
bash Ascend-cann-toolkit_9.0.0_linux-aarch64.run --install --quiet
|
| 78 |
-
source "${INSTALL_DIR}/Ascend/ascend-toolkit/set_env.sh"
|
| 79 |
-
|
| 80 |
-
chmod +x Ascend-cann-910b-ops_9.0.0_linux-aarch64.run
|
| 81 |
-
bash Ascend-cann-910b-ops_9.0.0_linux-aarch64.run --install --quiet
|
| 82 |
-
|
| 83 |
-
chmod +x Ascend-cann-nnal_9.0.0_linux-aarch64.run
|
| 84 |
-
bash Ascend-cann-nnal_9.0.0_linux-aarch64.run --install --quiet
|
| 85 |
-
source "${INSTALL_DIR}/Ascend/nnal/atb/set_env.sh"
|
| 86 |
-
|
| 87 |
-
export ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME}
|
| 88 |
-
export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:${LD_LIBRARY_PATH:-}
|
| 89 |
-
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
|
| 90 |
-
|
| 91 |
-
pip3 install torch==2.9.0
|
| 92 |
-
pip3 install pyyaml setuptools
|
| 93 |
-
pip3 install torch-npu==2.9.0
|
| 94 |
-
pip3 install torchvision==0.24.0 torchaudio==2.9.0
|
| 95 |
-
|
| 96 |
-
ASCEND_TOOLKIT_PYTHON_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/python/site-packages
|
| 97 |
-
export PYTHONPATH=${PYTHONPATH:-}:${INSTALL_DIR}:${ASCEND_TOOLKIT_PYTHON_PATH}
|
| 98 |
-
pip install pybind11==2.13.6
|
| 99 |
-
|
| 100 |
-
cd "${INSTALL_DIR}/vllm"
|
| 101 |
-
VLLM_TARGET_DEVICE=empty pip install .
|
| 102 |
-
|
| 103 |
-
cd "${INSTALL_DIR}/vllm-ascend"
|
| 104 |
-
pip install -e .
|
| 105 |
-
export VLLM_LOGGING_LEVEL=INFO
|
| 106 |
-
|
| 107 |
-
cd "${INSTALL_DIR}"
|
| 108 |
-
tar -xvf jemalloc-5.3.0.tar.bz2
|
| 109 |
-
cd jemalloc-5.3.0
|
| 110 |
-
./configure --prefix="${INSTALL_DIR}"
|
| 111 |
-
make -j"$(nproc)"
|
| 112 |
-
make install
|
| 113 |
-
export LD_PRELOAD=${INSTALL_DIR}/lib/libjemalloc.so.2:${LD_PRELOAD:-}
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
# ================= 安装 Triton-Ascend 3.2.1 =================
|
| 119 |
-
# 1. 卸载 triton(增加 -y 自动确认)
|
| 120 |
-
pip uninstall -y triton
|
| 121 |
-
|
| 122 |
-
# 2. 卸载 triton-ascend(增加 -y 自动确认)
|
| 123 |
-
pip uninstall -y triton-ascend
|
| 124 |
-
pip install --no-cache-dir --force-reinstall triton==3.5.0
|
| 125 |
-
pip install --no-deps triton_ascend-3.2.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
# ================= 安装新版 VERL =================
|
| 129 |
-
cd "${WORK_DIR}"
|
| 130 |
-
pip install -r requirements-npu.txt
|
| 131 |
-
# NPU requirements 明确要求 numpy<2;editable 安装不能再次按 setup.py 把 NumPy升级到 2.x。
|
| 132 |
-
python3 -m pip install -e . --no-deps
|
| 133 |
-
pip install --upgrade 'urllib3==1.26.11'
|
| 134 |
-
pip install loguru
|
| 135 |
-
pip install tree_sitter==0.21.3
|
| 136 |
-
pip install tree-sitter-java==0.21.0
|
| 137 |
-
pip install tree-sitter-javascript==0.21.4
|
| 138 |
-
|
| 139 |
-
ACL_PATH=/home/ma-user/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
|
| 140 |
-
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ACL_PATH}
|
| 141 |
-
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
|
| 142 |
-
|
| 143 |
-
pip uninstall -y transformers || true
|
| 144 |
-
pip install transformers==5.3.0
|
| 145 |
-
pip install accelerate==1.13.0 mathruler
|
| 146 |
-
pip install jsonargparse
|
| 147 |
-
pip install deepdiff sympy html2text requests bs4 mpmath swanlab PandoraBox json_repair openai httpx
|
| 148 |
-
|
| 149 |
-
# 稳定版只允许 SP=1:不安装普通 FLA,也不进入尚未完成 NPU 适配的 Ulysses CP。
|
| 150 |
-
if [ "${TRAIN_SP}" != "1" ]; then
|
| 151 |
-
echo "ERROR: the long-sequence all-optimization profile requires TRAIN_SP=1; got ${TRAIN_SP}." >&2
|
| 152 |
-
exit 2
|
| 153 |
-
fi
|
| 154 |
-
export NANOCLAW_REQUIRE_FLA=0
|
| 155 |
-
echo "--> Stable SP1: flash-linear-attention is disabled; Qwen3.5 will not build an Ulysses CP context."
|
| 156 |
-
|
| 157 |
-
# Transformers 5.x 会经 sklearn 间接导入 pandas/scipy。固定同一套 NumPy ABI,
|
| 158 |
-
# 避免出现 "numpy.dtype size changed"。这些版本均支持 Python 3.11/aarch64。
|
| 159 |
-
NUMPY_VERSION=${NUMPY_VERSION:-1.26.4}
|
| 160 |
-
PANDAS_VERSION=${PANDAS_VERSION:-2.2.3}
|
| 161 |
-
SCIPY_VERSION=${SCIPY_VERSION:-1.14.1}
|
| 162 |
-
SKLEARN_VERSION=${SKLEARN_VERSION:-1.6.1}
|
| 163 |
-
python3 -m pip install --no-cache-dir --force-reinstall \
|
| 164 |
-
"numpy==${NUMPY_VERSION}" \
|
| 165 |
-
"pandas==${PANDAS_VERSION}" \
|
| 166 |
-
"scipy==${SCIPY_VERSION}" \
|
| 167 |
-
"scikit-learn==${SKLEARN_VERSION}"
|
| 168 |
-
|
| 169 |
-
python3 - <<'PY' || exit 2
|
| 170 |
-
import numpy
|
| 171 |
-
import pandas
|
| 172 |
-
import scipy
|
| 173 |
-
import sklearn
|
| 174 |
-
import sys
|
| 175 |
-
import transformers
|
| 176 |
-
import vllm
|
| 177 |
-
|
| 178 |
-
fla_version = "disabled-sp1"
|
| 179 |
-
|
| 180 |
-
print(
|
| 181 |
-
"[python_stack_preflight] "
|
| 182 |
-
f"python={sys.executable} "
|
| 183 |
-
f"numpy={numpy.__version__} "
|
| 184 |
-
f"pandas={pandas.__version__} "
|
| 185 |
-
f"scipy={scipy.__version__} "
|
| 186 |
-
f"sklearn={sklearn.__version__} "
|
| 187 |
-
f"transformers={transformers.__version__} "
|
| 188 |
-
f"vllm={vllm.__version__} "
|
| 189 |
-
f"fla={fla_version}"
|
| 190 |
-
)
|
| 191 |
-
print(
|
| 192 |
-
"[python_stack_paths] "
|
| 193 |
-
f"numpy={numpy.__file__} "
|
| 194 |
-
f"pandas={pandas.__file__}"
|
| 195 |
-
)
|
| 196 |
-
PY
|
| 197 |
-
pip list
|
| 198 |
-
|
| 199 |
-
# ================= 检查 Nanoclaw recipe =================
|
| 200 |
-
if [ ! -f "${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" ]; then
|
| 201 |
-
echo "ERROR: Nanoclaw recipe not found: ${WORK_DIR}/nanoclaw_recipe/nanoclaw.py" >&2
|
| 202 |
-
exit 2
|
| 203 |
-
fi
|
| 204 |
-
test -f "${WORK_DIR}/nanoclaw_recipe/__init__.py"
|
| 205 |
-
|
| 206 |
-
# Qwen3.5 MRoPE position_ids 是 3/4 轴张量。未应用此补丁时,NPU
|
| 207 |
-
# FlashAttention 会把 seqLen 重复累计(例如 T=10131、sum(seqLen)=30393)。
|
| 208 |
-
QWEN35_MONKEY_PATCH_FILE=${WORK_DIR}/verl/models/transformers/monkey_patch.py
|
| 209 |
-
if [ ! -f "${QWEN35_MONKEY_PATCH_FILE}" ] || ! grep -q "def _normalize_fa_position_ids" "${QWEN35_MONKEY_PATCH_FILE}"; then
|
| 210 |
-
echo "ERROR: Qwen3.5 FlashAttention position_ids normalization patch is missing: ${QWEN35_MONKEY_PATCH_FILE}" >&2
|
| 211 |
-
echo "Upload the modified verl/ directory together with this standalone script." >&2
|
| 212 |
-
exit 2
|
| 213 |
-
fi
|
| 214 |
-
|
| 215 |
-
# Nanoclaw 会在首次模型调用前写入 rollout metadata。旧 ToolAgentLoop 因此
|
| 216 |
-
# 未复制 min/max_global_steps,导致完整训练 step 后在 metrics 阶段把 None 转 int 崩溃。
|
| 217 |
-
TOOL_AGENT_LOOP_FILE=${WORK_DIR}/verl/experimental/agent_loop/tool_agent_loop.py
|
| 218 |
-
TRAINER_BASE_FILE=${WORK_DIR}/verl/trainer/ppo/v1/trainer_base.py
|
| 219 |
-
if [ ! -f "${TOOL_AGENT_LOOP_FILE}" ] || ! grep -q "output_min_global_steps" "${TOOL_AGENT_LOOP_FILE}"; then
|
| 220 |
-
echo "ERROR: Nanoclaw rollout version metadata merge fix is missing: ${TOOL_AGENT_LOOP_FILE}" >&2
|
| 221 |
-
exit 2
|
| 222 |
-
fi
|
| 223 |
-
if [ ! -f "${TRAINER_BASE_FILE}" ] || ! grep -q "def resolve_model_version" "${TRAINER_BASE_FILE}"; then
|
| 224 |
-
echo "ERROR: PPO metrics None-version fallback fix is missing: ${TRAINER_BASE_FILE}" >&2
|
| 225 |
-
exit 2
|
| 226 |
-
fi
|
| 227 |
-
|
| 228 |
-
# 31K 长序列必须使用分块 LM-head;如果训练机只上传了 shell 而没有对应的
|
| 229 |
-
# VERL Qwen3.5 fused backend,则在启动 Ray 前直接失败,避免数十分钟后才 OOM。
|
| 230 |
-
QWEN35_MODEL_PATCH_FILE=${WORK_DIR}/verl/models/transformers/qwen3_5.py
|
| 231 |
-
FUSED_LINEAR_FILE=${WORK_DIR}/verl/utils/experimental/torch_functional.py
|
| 232 |
-
if [ ! -f "${QWEN35_MODEL_PATCH_FILE}" ] || ! grep -q "def forward_with_torch_backend" "${QWEN35_MODEL_PATCH_FILE}"; then
|
| 233 |
-
echo "ERROR: Qwen3.5 fused Torch backend is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
|
| 234 |
-
exit 2
|
| 235 |
-
fi
|
| 236 |
-
if ! grep -q "vocab_weights.full_tensor().to(hidden_states.device)" "${QWEN35_MODEL_PATCH_FILE}"; then
|
| 237 |
-
echo "ERROR: Qwen3.5 FSDP2 CPU-offload fused LM-head device-staging fix is missing: ${QWEN35_MODEL_PATCH_FILE}" >&2
|
| 238 |
-
exit 2
|
| 239 |
-
fi
|
| 240 |
-
if [ ! -f "${FUSED_LINEAR_FILE}" ] || ! grep -q "class FusedLinearForPPO" "${FUSED_LINEAR_FILE}"; then
|
| 241 |
-
echo "ERROR: chunked FusedLinearForPPO is missing: ${FUSED_LINEAR_FILE}" >&2
|
| 242 |
-
exit 2
|
| 243 |
-
fi
|
| 244 |
-
|
| 245 |
-
ACTIVATION_OFFLOAD_FILE=${WORK_DIR}/verl/utils/activation_offload.py
|
| 246 |
-
if [ ! -f "${ACTIVATION_OFFLOAD_FILE}" ] || ! grep -q "Missing offload mapping for group" "${ACTIVATION_OFFLOAD_FILE}"; then
|
| 247 |
-
echo "ERROR: FSDP2 checkpoint activation-offload on-demand reload fix is missing: ${ACTIVATION_OFFLOAD_FILE}" >&2
|
| 248 |
-
exit 2
|
| 249 |
-
fi
|
| 250 |
-
|
| 251 |
-
# ================= PLOG =================
|
| 252 |
-
ma_vj_name=$(echo "${MA_VJ_NAME}" | sed 's:ma-job:modelarts-job:g')
|
| 253 |
-
task_name=worker-${VC_TASK_INDEX}
|
| 254 |
-
task_plog_path=${MA_LOG_DIR}/${ma_vj_name}/${task_name}
|
| 255 |
-
mkdir -p "${task_plog_path}"
|
| 256 |
-
export ASCEND_PROCESS_LOG_PATH=${task_plog_path}/${VC_TASK_INDEX}
|
| 257 |
-
echo "plog path: ${ASCEND_PROCESS_LOG_PATH}"
|
| 258 |
-
|
| 259 |
-
MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-${VC_TASK_INDEX}.${MA_VJ_NAME}
|
| 260 |
-
MASTER_PORT=${PORT}
|
| 261 |
-
MA_CURRENT_INSTANCE_NAME=${MA_CURRENT_INSTANCE_NAME}
|
| 262 |
-
|
| 263 |
-
cd "${WORK_DIR}"
|
| 264 |
-
|
| 265 |
-
mkdir -p /cache/ray_tmp
|
| 266 |
-
|
| 267 |
-
echo "Cleaning up old Ray processes..."
|
| 268 |
-
ray stop --force || true
|
| 269 |
-
sleep 5
|
| 270 |
-
rm -rf /cache/ray_tmp/*
|
| 271 |
-
pkill -9 -f raylet || true
|
| 272 |
-
pkill -9 -f plasma_store || true
|
| 273 |
-
pkill -9 -f gcs_server || true
|
| 274 |
-
echo "Waiting 20s for NPU/Ray resources to be released..."
|
| 275 |
-
npu-smi info || true
|
| 276 |
-
sleep 20
|
| 277 |
-
|
| 278 |
-
# ================= NPU / HCCL / Ray 环境 =================
|
| 279 |
-
export NON_MEGATRON=true
|
| 280 |
-
export MULTI_STREAM_MEMORY_REUSE=2
|
| 281 |
-
export OMP_NUM_THREADS=1
|
| 282 |
-
export PYTORCH_NPU_ALLOC_CONF=${PYTORCH_NPU_ALLOC_CONF:-max_split_size_mb:512}
|
| 283 |
-
export VLLM_LOGGING_LEVEL=INFO
|
| 284 |
-
export RAY_DEDUP_LOGS=0
|
| 285 |
-
export HCCL_EXEC_TIMEOUT=${HCCL_EXEC_TIMEOUT:-3600}
|
| 286 |
-
export HCCL_LOG_LEVEL=${HCCL_LOG_LEVEL:-WARN}
|
| 287 |
-
export HCCL_CONNECT_TIMEOUT=${HCCL_CONNECT_TIMEOUT:-3600}
|
| 288 |
-
export HCCL_EVENT_TIMEOUT=${HCCL_EVENT_TIMEOUT:-7200}
|
| 289 |
-
export ACL_DEVICE_SYNC_TIMEOUT=${ACL_DEVICE_SYNC_TIMEOUT:-7200}
|
| 290 |
-
export GLOO_SOCKET_TIMEOUT=${GLOO_SOCKET_TIMEOUT:-7200}
|
| 291 |
-
|
| 292 |
-
# 关键:降低 HCCL buffer,增加 socket 端口范围,缓解 HcclAllreduce ra socket batch connect failed。
|
| 293 |
-
export HCCL_BUFFSIZE=${HCCL_BUFFSIZE:-300}
|
| 294 |
-
export P2P_HCCL_BUFFSIZE=${P2P_HCCL_BUFFSIZE:-64}
|
| 295 |
-
export HCCL_HOST_SOCKET_PORT_RANGE=${HCCL_HOST_SOCKET_PORT_RANGE:-60000-60050}
|
| 296 |
-
export HCCL_NPU_SOCKET_PORT_RANGE=${HCCL_NPU_SOCKET_PORT_RANGE:-61000-61050}
|
| 297 |
-
|
| 298 |
-
export CUDA_DEVICE_MAX_CONNECTIONS=1
|
| 299 |
-
export VLLM_ASCEND_ENABLE_NZ=${VLLM_ASCEND_ENABLE_NZ:-0}
|
| 300 |
-
export HCCL_OP_EXPANSION_MODE=${HCCL_OP_EXPANSION_MODE:-AIV}
|
| 301 |
-
export VLLM_ENGINE_ITERATION_TIMEOUT_S=${VLLM_ENGINE_ITERATION_TIMEOUT_S:-3600}
|
| 302 |
-
export WANDB_MODE=${WANDB_MODE:-disabled}
|
| 303 |
-
export PYTHONUNBUFFERED=1
|
| 304 |
-
export TASK_QUEUE_ENABLE=${TASK_QUEUE_ENABLE:-1}
|
| 305 |
-
export COMBINED_ENABLE=${COMBINED_ENABLE:-1}
|
| 306 |
-
export TOKENIZERS_PARALLELISM=false
|
| 307 |
-
export CLOSE_MATMUL_K_SHIFT=${CLOSE_MATMUL_K_SHIFT:-1}
|
| 308 |
-
export ATB_MATMUL_SHUFFLE_K_ENABLE=${ATB_MATMUL_SHUFFLE_K_ENABLE:-0}
|
| 309 |
-
export HCCL_DETERMINISTIC=${HCCL_DETERMINISTIC:-true}
|
| 310 |
-
export VLLM_ENABLE_V1_MULTIPROCESSING=${VLLM_ENABLE_V1_MULTIPROCESSING:-0}
|
| 311 |
-
export VLLM_USE_V1=${VLLM_USE_V1:-1}
|
| 312 |
-
export ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3}
|
| 313 |
-
export HYDRA_FULL_ERROR=1
|
| 314 |
-
export RAY_gcs_server_rpc_server_thread_num=${RAY_gcs_server_rpc_server_thread_num:-32}
|
| 315 |
-
export RAY_gcs_server_request_timeout_seconds=${RAY_gcs_server_request_timeout_seconds:-600}
|
| 316 |
-
export RAY_timeout_ms=${RAY_timeout_ms:-600000}
|
| 317 |
-
export RAY_worker_register_timeout_seconds=${RAY_worker_register_timeout_seconds:-600}
|
| 318 |
-
export RAY_USAGE_STATS_ENABLED=0
|
| 319 |
-
export VERL_REUSE_AGENT_LOOP=${VERL_REUSE_AGENT_LOOP:-1}
|
| 320 |
-
|
| 321 |
-
ulimit -n 65536
|
| 322 |
-
|
| 323 |
-
# Ray 不要覆盖 ASCEND_RT_VISIBLE_DEVICES;VERL 内部按 local_rank 选卡。
|
| 324 |
-
export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
|
| 325 |
-
|
| 326 |
-
# ================= 路径与数据配置 =================
|
| 327 |
-
HDFS_ROOT=${HDFS_ROOT:-$PWD}
|
| 328 |
-
DATA_ROOT=${DATA_ROOT:-/nanoclawRL_temp_ckpt}
|
| 329 |
-
|
| 330 |
-
# Nanoclaw 数据输入支持两种目录,优先推荐 0625 扁平格式:
|
| 331 |
-
# base_tasks/data_*/env_builder.py
|
| 332 |
-
# base_tasks/data_*/prompts.md
|
| 333 |
-
# base_tasks/data_*/workplace_verifier.py
|
| 334 |
-
# base_tasks/data_*/manifest.json
|
| 335 |
-
# 也兼容旧格式:base_tasks/tasks/data_* + base_tasks/scripts|scrips/data_*。
|
| 336 |
-
DEFAULT_NANOCLAW_BASE_TASKS=${DEFAULT_NANOCLAW_BASE_TASKS:-/exported_new_data}
|
| 337 |
-
train_base_tasks=${TRAIN_DATA_PATH:-${BASE_TASKS:-${DEFAULT_NANOCLAW_BASE_TASKS}}}
|
| 338 |
-
val_base_tasks=${VAL_DATA_PATH:-${VAL_BASE_TASKS:-${train_base_tasks}}}
|
| 339 |
-
train_files="['$train_base_tasks']"
|
| 340 |
-
test_files="['$val_base_tasks']"
|
| 341 |
-
|
| 342 |
-
if [ ! -d "${train_base_tasks}" ]; then
|
| 343 |
-
echo "ERROR: Nanoclaw TRAIN_DATA_PATH/BASE_TASKS directory not found: ${train_base_tasks}" >&2
|
| 344 |
-
exit 2
|
| 345 |
-
fi
|
| 346 |
-
if [ ! -d "${val_base_tasks}" ]; then
|
| 347 |
-
echo "ERROR: Nanoclaw VAL_DATA_PATH/VAL_BASE_TASKS directory not found: ${val_base_tasks}" >&2
|
| 348 |
-
exit 2
|
| 349 |
-
fi
|
| 350 |
-
|
| 351 |
-
model_path=${MODEL_PATH:-/Qwen3___5-9B}
|
| 352 |
-
verifier_model_path=${VERIFIER_MODEL_PATH:-/Qwen3___5-9B}
|
| 353 |
-
# 纯 VERL engine 路线:不要使用 MindSpeed-MM YAML。
|
| 354 |
-
unset MM_CONFIG_FILE || true
|
| 355 |
-
|
| 356 |
-
# Nanoclaw 工具配置
|
| 357 |
-
tool_config_path=${TOOL_CONFIG_PATH:-nanoclaw_recipe/nanoclaw_tool_config.yaml}
|
| 358 |
-
nanoclaw_task_glob=${NANOCLAW_TASK_GLOB:-data_*}
|
| 359 |
-
nanoclaw_task_ids=${NANOCLAW_TASK_IDS:-}
|
| 360 |
-
# 多机训练必须用所有节点都能访问的共享目录;不要用 /tmp,否则 reward worker 可能跨节点找不到 workspace。
|
| 361 |
-
nanoclaw_temp_root=${NANOCLAW_TEMP_ROOT:-/nanoclawRL_temp_workplace_v14_qwen35_9b_sp1_fsdp2_31k_longseq_allopt}
|
| 362 |
-
# 默认保留每个 step/data_sample 的目录,方便复盘每条 GRPO 采样;磁盘紧张时手动设 NANOCLAW_CLEANUP_WORKSPACES=True。
|
| 363 |
-
nanoclaw_cleanup_workspaces=${NANOCLAW_CLEANUP_WORKSPACES:-False}
|
| 364 |
-
nanoclaw_keep_failed_workspaces=${NANOCLAW_KEEP_FAILED_WORKSPACES:-False}
|
| 365 |
-
nanoclaw_env_builder_timeout=${NANOCLAW_ENV_BUILDER_TIMEOUT:-120}
|
| 366 |
-
nanoclaw_verifier_timeout=${NANOCLAW_VERIFIER_TIMEOUT:-3600}
|
| 367 |
-
nanoclaw_reward_score_mode=${NANOCLAW_REWARD_SCORE_MODE:-ratio}
|
| 368 |
-
nanoclaw_allow_bash=${NANOCLAW_ALLOW_BASH:-True}
|
| 369 |
-
nanoclaw_max_steps=${NANOCLAW_MAX_STEPS:-}
|
| 370 |
-
nanoclaw_require_final_answer=${NANOCLAW_REQUIRE_FINAL_ANSWER:-True}
|
| 371 |
-
nanoclaw_final_answer_bonus_enable=${NANOCLAW_FINAL_ANSWER_BONUS_ENABLE:-False}
|
| 372 |
-
nanoclaw_final_answer_bonus_score=${NANOCLAW_FINAL_ANSWER_BONUS_SCORE:-0.0}
|
| 373 |
-
nanoclaw_turn_penalty_only_positive_score=${NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE:-False}
|
| 374 |
-
nanoclaw_assistant_turn_penalty=${NANOCLAW_ASSISTANT_TURN_PENALTY:-0.0}
|
| 375 |
-
nanoclaw_duplicate_tool_call_penalty=${NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY:-0.0}
|
| 376 |
-
nanoclaw_repeated_response_penalty=${NANOCLAW_REPEATED_RESPONSE_PENALTY:-0.0}
|
| 377 |
-
nanoclaw_repeated_response_min_chars=${NANOCLAW_REPEATED_RESPONSE_MIN_CHARS:-50}
|
| 378 |
-
nanoclaw_repeated_response_min_consecutive_repeats=${NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS:-5}
|
| 379 |
-
nanoclaw_mask_looping_responses=${NANOCLAW_MASK_LOOPING_RESPONSES:-True}
|
| 380 |
-
nanoclaw_mask_only_positive_advantage=${NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE:-True}
|
| 381 |
-
nanoclaw_mask_budget_exhausted_last_turn=${NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN:-True}
|
| 382 |
-
nanoclaw_mask_duplicate_tool_result_turns=${NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS:-True}
|
| 383 |
-
nanoclaw_mask_error_tool_result_turns=${NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS:-True}
|
| 384 |
-
|
| 385 |
-
# verify_workplace.py 如需调用本地 OpenAI-compatible API,可用这些变量传入 reward。
|
| 386 |
-
# 默认假设 5 机 40 卡:前 4 个节点加入 Ray 训练,第 5 个节点部署 verifier/vLLM API。
|
| 387 |
-
verifier_api_node_rank=${VERIFIER_API_NODE_RANK:-4}
|
| 388 |
-
verifier_api_port=${VERIFIER_API_PORT:-8000}
|
| 389 |
-
verifier_api_host=${VERIFIER_API_HOST:-${MA_VJ_NAME}-${MA_TASK_NAME}-${verifier_api_node_rank}.${MA_VJ_NAME}}
|
| 390 |
-
verifier_api_start_cmd=${VERIFIER_API_START_CMD:-}
|
| 391 |
-
verifier_api_bind_host=${VERIFIER_API_BIND_HOST:-0.0.0.0}
|
| 392 |
-
# 9B verifier 默认使用整台 8 卡节点:两份 TP4 副本由 vLLM 内置 DP 统一服务。
|
| 393 |
-
# 如需单副本 TP8,可设置 VERIFIER_API_TP=8 VERIFIER_API_DP=1。
|
| 394 |
-
verifier_api_tp=${VERIFIER_API_TP:-4}
|
| 395 |
-
verifier_api_dp=${VERIFIER_API_DP:-2}
|
| 396 |
-
verifier_api_devices=${VERIFIER_API_DEVICES:-0,1,2,3,4,5,6,7}
|
| 397 |
-
verifier_api_distributed_executor_backend=${VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND:-mp}
|
| 398 |
-
verifier_api_max_model_len=${VERIFIER_API_MAX_MODEL_LEN:-32768}
|
| 399 |
-
verifier_api_max_num_batched_tokens=${VERIFIER_API_MAX_NUM_BATCHED_TOKENS:-32768}
|
| 400 |
-
verifier_api_max_num_seqs=${VERIFIER_API_MAX_NUM_SEQS:-160}
|
| 401 |
-
verifier_api_gpu_memory_utilization=${VERIFIER_API_GPU_MEMORY_UTILIZATION:-0.70}
|
| 402 |
-
verifier_api_enforce_eager=${VERIFIER_API_ENFORCE_EAGER:-0}
|
| 403 |
-
verifier_api_enable_graph_mode=${VERIFIER_API_ENABLE_GRAPH_MODE:-1}
|
| 404 |
-
verifier_api_enable_prefix_caching=${VERIFIER_API_ENABLE_PREFIX_CACHING:-0}
|
| 405 |
-
verifier_api_startup_timeout=${VERIFIER_API_STARTUP_TIMEOUT:-1800}
|
| 406 |
-
verifier_api_log=${VERIFIER_API_LOG:-logs/vllm-verifier-api.log}
|
| 407 |
-
mock_api_base=${MOCK_API_BASE:-http://${verifier_api_host}:${verifier_api_port}/v1}
|
| 408 |
-
mock_api_key=${MOCK_API_KEY:-dummy_key}
|
| 409 |
-
mock_model_name=${MOCK_MODEL_NAME:-qwen3_5_9b_verifier}
|
| 410 |
-
# verify_workplace.py 内部 OpenAI/httpx 单次请求超时;reward API 排队时宁可多等,不要轻易误判 0 分。
|
| 411 |
-
mock_api_timeout=${MOCK_API_TIMEOUT:-1800}
|
| 412 |
-
mock_api_connect_timeout=${MOCK_API_CONNECT_TIMEOUT:-300}
|
| 413 |
-
# 强制 verifier/OpenAI judge 请求关闭 thinking,sitecustomize 会自动注入 extra_body.chat_template_kwargs.enable_thinking=False。
|
| 414 |
-
nanoclaw_force_no_thinking=${NANOCLAW_FORCE_NO_THINKING:-1}
|
| 415 |
-
nanoclaw_force_max_tokens=${NANOCLAW_FORCE_MAX_TOKENS:-50}
|
| 416 |
-
# 默认控制台只打一行 reward 摘要;如需每项 details,设 NANOCLAW_REWARD_PRINT_DETAILS=1。
|
| 417 |
-
nanoclaw_reward_print_details=${NANOCLAW_REWARD_PRINT_DETAILS:-0}
|
| 418 |
-
# verifier API 是单独节点,默认低并发,避免 RewardLoopWorker 同时打爆 API 导致排队超时。
|
| 419 |
-
reward_num_workers=${REWARD_NUM_WORKERS:-52}
|
| 420 |
-
|
| 421 |
-
project_name=${PROJECT_NAME:-qwen3.5-9b_nanoclaw_grpo_verl_0720}
|
| 422 |
-
experiment_name=${EXPERIMENT_NAME:-qwen3.5-9b_nanoclaw_grpo_sp1_fsdp2_31k_longseq_allopt_lr1e6_fixedkl1e-3}
|
| 423 |
-
default_local_dir=${DEFAULT_LOCAL_DIR:-$DATA_ROOT/checkpoint/$experiment_name}
|
| 424 |
-
start_time=$(date +%Y%m%d)_$(date +%H%M%S)
|
| 425 |
-
mkdir -p logs "${default_local_dir}"
|
| 426 |
-
|
| 427 |
-
# ================= 算法与并行参数 =================
|
| 428 |
-
adv_estimator=grpo
|
| 429 |
-
max_turns=${MAX_TURNS:-35}
|
| 430 |
-
max_prompt_length=${MAX_PROMPT_LENGTH:-8192}
|
| 431 |
-
max_response_length=${MAX_RESPONSE_LENGTH:-22768}
|
| 432 |
-
max_assistant_response_length=${MAX_ASSISTANT_RESPONSE_LENGTH:-16384}
|
| 433 |
-
max_tool_response_length=${MAX_TOOL_RESPONSE_LENGTH:-8192}
|
| 434 |
-
max_model_len=$((max_prompt_length + max_response_length))
|
| 435 |
-
|
| 436 |
-
# MindSpeed 配置仅作为训练意图参考;以下均使用最新版 VERL 的原生字段。
|
| 437 |
-
actor_lr=${ACTOR_LR:-1e-6}
|
| 438 |
-
actor_lr_scheduler_type=${ACTOR_LR_SCHEDULER_TYPE:-constant}
|
| 439 |
-
actor_lr_warmup_steps_ratio=${ACTOR_LR_WARMUP_STEPS_RATIO:-0.0}
|
| 440 |
-
actor_weight_decay=${ACTOR_WEIGHT_DECAY:-0.01}
|
| 441 |
-
actor_adam_beta1=${ACTOR_ADAM_BETA1:-0.9}
|
| 442 |
-
actor_adam_beta2=${ACTOR_ADAM_BETA2:-0.95}
|
| 443 |
-
actor_clip_grad=${ACTOR_CLIP_GRAD:-1.0}
|
| 444 |
-
actor_ppo_epochs=${ACTOR_PPO_EPOCHS:-1}
|
| 445 |
-
actor_shuffle=${ACTOR_SHUFFLE:-False}
|
| 446 |
-
actor_entropy_coeff=${ACTOR_ENTROPY_COEFF:-0.0}
|
| 447 |
-
actor_clip_ratio_low=${ACTOR_CLIP_RATIO_LOW:-0.2}
|
| 448 |
-
actor_clip_ratio_high=${ACTOR_CLIP_RATIO_HIGH:-0.2}
|
| 449 |
-
# MindSpeed 配置没有 Dual-Clip PPO 对应项,保留该 27B 脚本原来的 C=10。
|
| 450 |
-
actor_clip_ratio_c=${ACTOR_CLIP_RATIO_C:-10.0}
|
| 451 |
-
|
| 452 |
-
# YAML 的 fixed init_kl_coef + low_var_kl 对应 VERL 的 reward-KL 路径。
|
| 453 |
-
algorithm_gamma=${ALGORITHM_GAMMA:-1.0}
|
| 454 |
-
algorithm_lam=${ALGORITHM_LAM:-0.95}
|
| 455 |
-
use_kl_in_reward=${USE_KL_IN_REWARD:-True}
|
| 456 |
-
kl_penalty=${KL_PENALTY:-low_var_kl}
|
| 457 |
-
kl_ctrl_type=${KL_CTRL_TYPE:-fixed}
|
| 458 |
-
kl_coef=${KL_COEF:-0.001}
|
| 459 |
-
# 关闭 actor-KL,避免与 reward-KL 重复惩罚。
|
| 460 |
-
actor_use_kl_loss=${ACTOR_USE_KL_LOSS:-False}
|
| 461 |
-
actor_kl_loss_coef=${ACTOR_KL_LOSS_COEF:-0.001}
|
| 462 |
-
actor_kl_loss_type=${ACTOR_KL_LOSS_TYPE:-low_var_kl}
|
| 463 |
-
|
| 464 |
-
train_batch_size=${TRAIN_BATCH_SIZE:-64}
|
| 465 |
-
ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE:-16}
|
| 466 |
-
n_resp_per_prompt=${N_RESP_PER_PROMPT:-8}
|
| 467 |
-
# 先压低验证,避免验证和训练稳定性混在一起。
|
| 468 |
-
n_resp_per_prompt_val=${N_RESP_PER_PROMPT_VAL:-1}
|
| 469 |
-
log_val_generations=${LOG_VAL_GENERATIONS:-10}
|
| 470 |
-
|
| 471 |
-
infer_tp=${INFER_TP:-4}
|
| 472 |
-
train_sp=${TRAIN_SP:-1}
|
| 473 |
-
offload=${OFFLOAD:-True}
|
| 474 |
-
|
| 475 |
-
# 长序列全优化版使用最新版 VERL 官方 Qwen3.5 路径采用的 FSDP2。
|
| 476 |
-
actor_strategy=${ACTOR_STRATEGY:-fsdp2}
|
| 477 |
-
fsdp_size=${FSDP_SIZE:-}
|
| 478 |
-
|
| 479 |
-
actor_pack=${ACTOR_PACK:-1}
|
| 480 |
-
logprob_pack=${LOGPROB_PACK:-2}
|
| 481 |
-
actor_max_token_len_per_gpu=${ACTOR_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * actor_pack + train_sp - 1) / train_sp))}
|
| 482 |
-
log_prob_max_token_len_per_gpu=${LOG_PROB_MAX_TOKEN_LEN_PER_GPU:-$(((max_model_len * logprob_pack + train_sp - 1) / train_sp))}
|
| 483 |
-
entropy_from_logits_with_chunking=${ENTROPY_FROM_LOGITS_WITH_CHUNKING:-True}
|
| 484 |
-
entropy_from_logits_chunk_size=${ENTROPY_FROM_LOGITS_CHUNK_SIZE:-256}
|
| 485 |
-
entropy_checkpointing=${ENTROPY_CHECKPOINTING:-False}
|
| 486 |
-
use_fused_kernels=${USE_FUSED_KERNELS:-True}
|
| 487 |
-
fused_kernel_backend=${FUSED_KERNEL_BACKEND:-torch}
|
| 488 |
-
enable_activation_offload=${ENABLE_ACTIVATION_OFFLOAD:-True}
|
| 489 |
-
rollout_max_num_batched_tokens=${ROLLOUT_MAX_NUM_BATCHED_TOKENS:-32384}
|
| 490 |
-
rollout_gpu_memory_utilization=${ROLLOUT_GPU_MEMORY_UTILIZATION:-0.60}
|
| 491 |
-
update_weights_bucket_mb=${UPDATE_WEIGHTS_BUCKET_MB:-2048}
|
| 492 |
-
|
| 493 |
-
# Qwen 官方推荐:Instruct/non-thinking reasoning tasks
|
| 494 |
-
rollout_temperature=${ROLLOUT_TEMPERATURE:-0.6}
|
| 495 |
-
rollout_top_p=${ROLLOUT_TOP_P:-0.95}
|
| 496 |
-
rollout_top_k=${ROLLOUT_TOP_K:-20}
|
| 497 |
-
rollout_min_p=${ROLLOUT_MIN_P:-0.0}
|
| 498 |
-
rollout_presence_penalty=${ROLLOUT_PRESENCE_PENALTY:-0.0}
|
| 499 |
-
rollout_frequency_penalty=${ROLLOUT_FREQUENCY_PENALTY:-0.0}
|
| 500 |
-
rollout_repetition_penalty=${ROLLOUT_REPETITION_PENALTY:-1.0}
|
| 501 |
-
|
| 502 |
-
echo "DEBUG: max_response_length=${max_response_length}, max_assistant_response_length=${max_assistant_response_length}, max_model_len=${max_model_len}"
|
| 503 |
-
echo "DEBUG: max_turns=${max_turns}"
|
| 504 |
-
echo "DEBUG: max_tool_response_length=${max_tool_response_length}"
|
| 505 |
-
echo "DEBUG: entropy_chunking=${entropy_from_logits_with_chunking}, entropy_chunk_size=${entropy_from_logits_chunk_size}, entropy_checkpointing=${entropy_checkpointing}"
|
| 506 |
-
echo "DEBUG: fused_lmhead=${use_fused_kernels}, fused_backend=${fused_kernel_backend}, activation_offload=${enable_activation_offload}"
|
| 507 |
-
echo "DEBUG: train_batch_size=${train_batch_size}, ppo_mini_batch_size=${ppo_mini_batch_size}, n=${n_resp_per_prompt}"
|
| 508 |
-
echo "DEBUG: train_sp=${train_sp}, infer_tp=${infer_tp}, actor_strategy=${actor_strategy}, fsdp_size=${fsdp_size:-<default>}"
|
| 509 |
-
echo "DEBUG: Qwen3.5 Ulysses FLA required=${NANOCLAW_REQUIRE_FLA}, backend=${QWEN35_FLA_BACKEND} (TRAIN_SP=${train_sp})"
|
| 510 |
-
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}"
|
| 511 |
-
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}"
|
| 512 |
-
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}"
|
| 513 |
-
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}"
|
| 514 |
-
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}"
|
| 515 |
-
|
| 516 |
-
val_before_train=${VAL_BEFORE_TRAIN:-False}
|
| 517 |
-
trainer_use_v1=${TRAINER_USE_V1:-True}
|
| 518 |
-
test_freq=${TEST_FREQ:-5000}
|
| 519 |
-
save_freq=${SAVE_FREQ:-2}
|
| 520 |
-
|
| 521 |
-
# ================= 分布式 =================
|
| 522 |
-
export TOTAL_NNODES=${TOTAL_NNODES:-5}
|
| 523 |
-
export TRAIN_NNODES=${TRAIN_NNODES:-4}
|
| 524 |
-
export NNODES=${NNODES:-${TRAIN_NNODES}}
|
| 525 |
-
export NODE_RANK=${VC_TASK_INDEX}
|
| 526 |
-
export NPUS_PER_NODE=${NPUS_PER_NODE:-8}
|
| 527 |
-
export WORLD_SIZE=$((NPUS_PER_NODE * NNODES))
|
| 528 |
-
|
| 529 |
-
export MASTER_ADDR=${MA_VJ_NAME}-${MA_TASK_NAME}-0.${MA_VJ_NAME}
|
| 530 |
-
export MASTER_PORT=${MASTER_PORT:-6167}
|
| 531 |
-
export DASHBOARD_PORT=${DASHBOARD_PORT:-8191}
|
| 532 |
-
export RAY_PORT=${RAY_PORT:-6167}
|
| 533 |
-
|
| 534 |
-
readonly SOCKET_IFNAME=${SOCKET_IFNAME:-eth0}
|
| 535 |
-
export HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME:-${SOCKET_IFNAME}}
|
| 536 |
-
export GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME:-${SOCKET_IFNAME}}
|
| 537 |
-
export CURRENT_IP=$(ifconfig ${SOCKET_IFNAME} | grep -Eo 'inet (addr:)?([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $NF}')
|
| 538 |
-
export RAY_NODE_IP=${MA_CURRENT_IP:-${CURRENT_IP}}
|
| 539 |
-
|
| 540 |
-
export ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES:-$(seq -s, 0 $((NPUS_PER_NODE - 1)))}
|
| 541 |
-
|
| 542 |
-
cat <<EOF
|
| 543 |
-
DEBUG: MASTER_ADDR=${MASTER_ADDR}
|
| 544 |
-
DEBUG: MASTER_PORT=${MASTER_PORT}
|
| 545 |
-
DEBUG: RAY_PORT=${RAY_PORT}
|
| 546 |
-
DEBUG: MA_CURRENT_IP=${MA_CURRENT_IP}
|
| 547 |
-
DEBUG: CURRENT_IP=${CURRENT_IP}
|
| 548 |
-
DEBUG: RAY_NODE_IP=${RAY_NODE_IP}
|
| 549 |
-
DEBUG: ASCEND_RT_VISIBLE_DEVICES=${ASCEND_RT_VISIBLE_DEVICES}
|
| 550 |
-
DEBUG: HCCL_SOCKET_IFNAME=${HCCL_SOCKET_IFNAME}
|
| 551 |
-
DEBUG: GLOO_SOCKET_IFNAME=${GLOO_SOCKET_IFNAME}
|
| 552 |
-
DEBUG: TOTAL_NNODES=${TOTAL_NNODES}
|
| 553 |
-
DEBUG: TRAIN_NNODES=${TRAIN_NNODES}
|
| 554 |
-
DEBUG: VERIFIER_API_NODE_RANK=${verifier_api_node_rank}
|
| 555 |
-
DEBUG: MOCK_API_BASE=${mock_api_base}
|
| 556 |
-
DEBUG: MOCK_MODEL_NAME=${mock_model_name}
|
| 557 |
-
DEBUG: MOCK_API_TIMEOUT=${mock_api_timeout}
|
| 558 |
-
DEBUG: NANOCLAW_FORCE_NO_THINKING=${nanoclaw_force_no_thinking}
|
| 559 |
-
DEBUG: NANOCLAW_FORCE_MAX_TOKENS=${nanoclaw_force_max_tokens}
|
| 560 |
-
DEBUG: NANOCLAW_REWARD_PRINT_DETAILS=${nanoclaw_reward_print_details}
|
| 561 |
-
DEBUG: NANOCLAW_REQUIRE_FINAL_ANSWER=${nanoclaw_require_final_answer}
|
| 562 |
-
DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_ENABLE=${nanoclaw_final_answer_bonus_enable}
|
| 563 |
-
DEBUG: NANOCLAW_FINAL_ANSWER_BONUS_SCORE=${nanoclaw_final_answer_bonus_score}
|
| 564 |
-
DEBUG: NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE=${nanoclaw_turn_penalty_only_positive_score}
|
| 565 |
-
DEBUG: NANOCLAW_ASSISTANT_TURN_PENALTY=${nanoclaw_assistant_turn_penalty}
|
| 566 |
-
DEBUG: NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY=${nanoclaw_duplicate_tool_call_penalty}
|
| 567 |
-
DEBUG: NANOCLAW_REPEATED_RESPONSE_PENALTY=${nanoclaw_repeated_response_penalty}
|
| 568 |
-
DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CHARS=${nanoclaw_repeated_response_min_chars}
|
| 569 |
-
DEBUG: NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_repeated_response_min_consecutive_repeats}
|
| 570 |
-
DEBUG: NANOCLAW_MASK_LOOPING_RESPONSES=${nanoclaw_mask_looping_responses}
|
| 571 |
-
DEBUG: NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE=${nanoclaw_mask_only_positive_advantage}
|
| 572 |
-
DEBUG: NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN=${nanoclaw_mask_budget_exhausted_last_turn}
|
| 573 |
-
DEBUG: NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS=${nanoclaw_mask_duplicate_tool_result_turns}
|
| 574 |
-
DEBUG: NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS=${nanoclaw_mask_error_tool_result_turns}
|
| 575 |
-
DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CHARS=${nanoclaw_looping_response_min_chars}
|
| 576 |
-
DEBUG: NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS=${nanoclaw_looping_response_min_consecutive_repeats}
|
| 577 |
-
DEBUG: VERIFIER_API_TP=${verifier_api_tp}
|
| 578 |
-
DEBUG: VERIFIER_API_DP=${verifier_api_dp}
|
| 579 |
-
DEBUG: VERIFIER_API_DEVICES=${verifier_api_devices}
|
| 580 |
-
DEBUG: VERIFIER_API_DISTRIBUTED_EXECUTOR_BACKEND=${verifier_api_distributed_executor_backend}
|
| 581 |
-
DEBUG: VERIFIER_API_MAX_NUM_SEQS=${verifier_api_max_num_seqs}
|
| 582 |
-
DEBUG: VERIFIER_API_ENFORCE_EAGER=${verifier_api_enforce_eager}
|
| 583 |
-
DEBUG: VERIFIER_API_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
|
| 584 |
-
DEBUG: REWARD_NUM_WORKERS=${reward_num_workers}
|
| 585 |
-
EOF
|
| 586 |
-
|
| 587 |
-
if [ "${NODE_RANK}" = "${verifier_api_node_rank}" ]; then
|
| 588 |
-
echo "--> [Verifier API Node] This node is reserved for vLLM/OpenAI-compatible verifier API."
|
| 589 |
-
echo "--> [Verifier API Node] API base: ${mock_api_base}"
|
| 590 |
-
export VLLM_ENABLE_GRAPH_MODE=${verifier_api_enable_graph_mode}
|
| 591 |
-
mkdir -p "$(dirname "${verifier_api_log}")"
|
| 592 |
-
if [ -n "${verifier_api_start_cmd}" ]; then
|
| 593 |
-
echo "--> [Verifier API Node] Running VERIFIER_API_START_CMD..."
|
| 594 |
-
bash -lc "${verifier_api_start_cmd}" &
|
| 595 |
-
verifier_api_pid=$!
|
| 596 |
-
else
|
| 597 |
-
echo "--> [Verifier API Node] Starting default vLLM verifier API..."
|
| 598 |
-
verifier_api_device_count=$(awk -F',' '{print NF}' <<<"${verifier_api_devices}")
|
| 599 |
-
verifier_api_expected_device_count=$((verifier_api_tp * verifier_api_dp))
|
| 600 |
-
if [ "${verifier_api_device_count}" -ne "${verifier_api_expected_device_count}" ]; then
|
| 601 |
-
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
|
| 602 |
-
exit 2
|
| 603 |
-
fi
|
| 604 |
-
export ASCEND_RT_VISIBLE_DEVICES=${verifier_api_devices}
|
| 605 |
-
verifier_api_args=(
|
| 606 |
-
--model "${verifier_model_path}"
|
| 607 |
-
--tokenizer "${verifier_model_path}"
|
| 608 |
-
--host "${verifier_api_bind_host}"
|
| 609 |
-
--port "${verifier_api_port}"
|
| 610 |
-
--served-model-name "${mock_model_name}"
|
| 611 |
-
--tensor-parallel-size "${verifier_api_tp}"
|
| 612 |
-
--data-parallel-size "${verifier_api_dp}"
|
| 613 |
-
--distributed-executor-backend "${verifier_api_distributed_executor_backend}"
|
| 614 |
-
--dtype bfloat16
|
| 615 |
-
--max-model-len "${verifier_api_max_model_len}"
|
| 616 |
-
--max-num-batched-tokens "${verifier_api_max_num_batched_tokens}"
|
| 617 |
-
--max-num-seqs "${verifier_api_max_num_seqs}"
|
| 618 |
-
--gpu-memory-utilization "${verifier_api_gpu_memory_utilization}"
|
| 619 |
-
--trust-remote-code
|
| 620 |
-
)
|
| 621 |
-
if [ "${verifier_api_enforce_eager}" = "1" ] || [ "${verifier_api_enforce_eager}" = "true" ] || [ "${verifier_api_enforce_eager}" = "True" ]; then
|
| 622 |
-
verifier_api_args+=(--enforce-eager)
|
| 623 |
-
fi
|
| 624 |
-
if [ "${verifier_api_enable_prefix_caching}" = "1" ] || [ "${verifier_api_enable_prefix_caching}" = "true" ] || [ "${verifier_api_enable_prefix_caching}" = "True" ]; then
|
| 625 |
-
verifier_api_args+=(--enable-prefix-caching)
|
| 626 |
-
fi
|
| 627 |
-
echo "--> [Verifier API Node] Command: python3 -m vllm.entrypoints.openai.api_server ${verifier_api_args[*]}"
|
| 628 |
-
python3 -m vllm.entrypoints.openai.api_server "${verifier_api_args[@]}" >"${verifier_api_log}" 2>&1 &
|
| 629 |
-
verifier_api_pid=$!
|
| 630 |
-
fi
|
| 631 |
-
|
| 632 |
-
echo "--> [Verifier API Node] vLLM API pid=${verifier_api_pid}, log=${verifier_api_log}"
|
| 633 |
-
echo "--> [Verifier API Node] Waiting for ${mock_api_base}/models ..."
|
| 634 |
-
python3 - "${mock_api_base}/models" "${verifier_api_startup_timeout}" "${verifier_api_log}" "${verifier_api_pid}" <<'PY'
|
| 635 |
-
import os
|
| 636 |
-
import sys
|
| 637 |
-
import time
|
| 638 |
-
import urllib.request
|
| 639 |
-
from pathlib import Path
|
| 640 |
-
|
| 641 |
-
url = sys.argv[1]
|
| 642 |
-
timeout = float(sys.argv[2])
|
| 643 |
-
log_path = Path(sys.argv[3])
|
| 644 |
-
pid = int(sys.argv[4]) if len(sys.argv) > 4 and sys.argv[4] else None
|
| 645 |
-
started = time.time()
|
| 646 |
-
last_error = None
|
| 647 |
-
while time.time() - started < timeout:
|
| 648 |
-
if pid is not None:
|
| 649 |
-
try:
|
| 650 |
-
os.kill(pid, 0)
|
| 651 |
-
except OSError:
|
| 652 |
-
print(f"ERROR: verifier API process exited early: pid={pid}", file=sys.stderr)
|
| 653 |
-
if log_path.is_file():
|
| 654 |
-
print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
|
| 655 |
-
sys.exit(1)
|
| 656 |
-
try:
|
| 657 |
-
with urllib.request.urlopen(url, timeout=5) as response:
|
| 658 |
-
if 200 <= response.status < 300:
|
| 659 |
-
print(f"READY: {url}", file=sys.stderr)
|
| 660 |
-
sys.exit(0)
|
| 661 |
-
except Exception as exc:
|
| 662 |
-
last_error = exc
|
| 663 |
-
time.sleep(5)
|
| 664 |
-
print(f"ERROR: timed out waiting for {url}; last_error={last_error}", file=sys.stderr)
|
| 665 |
-
if log_path.is_file():
|
| 666 |
-
print("\n".join(log_path.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
|
| 667 |
-
sys.exit(1)
|
| 668 |
-
PY
|
| 669 |
-
verifier_readiness_rc=$?
|
| 670 |
-
if [ "${verifier_readiness_rc}" -ne 0 ]; then
|
| 671 |
-
echo "ERROR: verifier API readiness check failed with rc=${verifier_readiness_rc}." >&2
|
| 672 |
-
if kill -0 "${verifier_api_pid}" 2>/dev/null; then
|
| 673 |
-
kill "${verifier_api_pid}" 2>/dev/null || true
|
| 674 |
-
fi
|
| 675 |
-
wait "${verifier_api_pid}" 2>/dev/null || true
|
| 676 |
-
exit "${verifier_readiness_rc}"
|
| 677 |
-
fi
|
| 678 |
-
|
| 679 |
-
echo "--> [Verifier API Node] Ready. Keeping node alive."
|
| 680 |
-
wait "${verifier_api_pid}"
|
| 681 |
-
verifier_api_rc=$?
|
| 682 |
-
if [ "${verifier_api_rc}" -ne 0 ]; then
|
| 683 |
-
echo "ERROR: verifier API exited with rc=${verifier_api_rc}; log=${verifier_api_log}" >&2
|
| 684 |
-
fi
|
| 685 |
-
exit "${verifier_api_rc}"
|
| 686 |
-
fi
|
| 687 |
-
|
| 688 |
-
export TMPDIR=/cache/ray_tmp
|
| 689 |
-
export HCCL_ASYNC_ERROR_HANDLING=${HCCL_ASYNC_ERROR_HANDLING:-0}
|
| 690 |
-
|
| 691 |
-
wait_for_ray_npu_resources() {
|
| 692 |
-
expected_npu=$1
|
| 693 |
-
timeout_seconds=${2:-900}
|
| 694 |
-
begin_ts=$(date +%s)
|
| 695 |
-
|
| 696 |
-
while true; do
|
| 697 |
-
total_npu=$(python3 - <<'PY' 2>/dev/null
|
| 698 |
-
import ray
|
| 699 |
-
|
| 700 |
-
try:
|
| 701 |
-
ray.init(address="auto", ignore_reinit_error=True, logging_level="ERROR")
|
| 702 |
-
print(int(ray.cluster_resources().get("NPU", 0)))
|
| 703 |
-
ray.shutdown()
|
| 704 |
-
except Exception:
|
| 705 |
-
print(0)
|
| 706 |
-
PY
|
| 707 |
-
)
|
| 708 |
-
total_npu=${total_npu:-0}
|
| 709 |
-
now_ts=$(date +%s)
|
| 710 |
-
elapsed=$((now_ts - begin_ts))
|
| 711 |
-
|
| 712 |
-
echo "Ray NPU resources: ${total_npu}/${expected_npu}, elapsed=${elapsed}s"
|
| 713 |
-
ray status || true
|
| 714 |
-
|
| 715 |
-
if [ "${total_npu}" -ge "${expected_npu}" ]; then
|
| 716 |
-
echo "Ray cluster is ready: ${total_npu}/${expected_npu} NPU resources registered."
|
| 717 |
-
break
|
| 718 |
-
fi
|
| 719 |
-
|
| 720 |
-
if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
|
| 721 |
-
echo "ERROR: Timed out waiting for Ray NPU resources: ${total_npu}/${expected_npu}" >&2
|
| 722 |
-
return 1
|
| 723 |
-
fi
|
| 724 |
-
|
| 725 |
-
sleep 5
|
| 726 |
-
done
|
| 727 |
-
}
|
| 728 |
-
|
| 729 |
-
wait_for_verifier_api() {
|
| 730 |
-
api_url="${mock_api_base}/models"
|
| 731 |
-
timeout_seconds=${VERIFIER_API_CLIENT_WAIT_TIMEOUT:-1800}
|
| 732 |
-
begin_ts=$(date +%s)
|
| 733 |
-
last_diag_ts=0
|
| 734 |
-
while true; do
|
| 735 |
-
verifier_check_output=$(python3 - "${api_url}" <<'PY' 2>&1
|
| 736 |
-
import socket
|
| 737 |
-
import sys
|
| 738 |
-
import urllib.parse
|
| 739 |
-
import urllib.request
|
| 740 |
-
|
| 741 |
-
url = sys.argv[1]
|
| 742 |
-
parsed = urllib.parse.urlparse(url)
|
| 743 |
-
host = parsed.hostname
|
| 744 |
-
port = parsed.port or (443 if parsed.scheme == "https" else 80)
|
| 745 |
-
print(f"check url={url} host={host} port={port}")
|
| 746 |
-
try:
|
| 747 |
-
infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
|
| 748 |
-
print("dns=" + ",".join(sorted({item[4][0] for item in infos})))
|
| 749 |
-
except Exception as exc:
|
| 750 |
-
print(f"dns_error={type(exc).__name__}: {exc}")
|
| 751 |
-
raise SystemExit(1)
|
| 752 |
-
try:
|
| 753 |
-
with socket.create_connection((host, port), timeout=5):
|
| 754 |
-
print("tcp=ok")
|
| 755 |
-
except Exception as exc:
|
| 756 |
-
print(f"tcp_error={type(exc).__name__}: {exc}")
|
| 757 |
-
raise SystemExit(1)
|
| 758 |
-
try:
|
| 759 |
-
with urllib.request.urlopen(url, timeout=10) as response:
|
| 760 |
-
print(f"http_status={response.status}")
|
| 761 |
-
raise SystemExit(0 if 200 <= response.status < 300 else 1)
|
| 762 |
-
except Exception as exc:
|
| 763 |
-
print(f"http_error={type(exc).__name__}: {exc}")
|
| 764 |
-
raise SystemExit(1)
|
| 765 |
-
PY
|
| 766 |
-
)
|
| 767 |
-
check_rc=$?
|
| 768 |
-
if [ "${check_rc}" = "0" ]; then
|
| 769 |
-
echo "Verifier API is ready: ${api_url}"
|
| 770 |
-
echo "${verifier_check_output}"
|
| 771 |
-
break
|
| 772 |
-
fi
|
| 773 |
-
now_ts=$(date +%s)
|
| 774 |
-
elapsed=$((now_ts - begin_ts))
|
| 775 |
-
echo "Waiting for verifier API: ${api_url}, elapsed=${elapsed}s"
|
| 776 |
-
if [ $((now_ts - last_diag_ts)) -ge 60 ]; then
|
| 777 |
-
last_diag_ts=${now_ts}
|
| 778 |
-
echo "--- verifier API check diagnostics ---"
|
| 779 |
-
echo "${verifier_check_output}"
|
| 780 |
-
echo "--- expected verifier node: rank=${verifier_api_node_rank}, host=${verifier_api_host}, port=${verifier_api_port} ---"
|
| 781 |
-
echo "--- check verifier node log: ${verifier_api_log} ---"
|
| 782 |
-
echo "--------------------------------------"
|
| 783 |
-
fi
|
| 784 |
-
if [ "${elapsed}" -ge "${timeout_seconds}" ]; then
|
| 785 |
-
echo "ERROR: Timed out waiting for verifier API: ${api_url}" >&2
|
| 786 |
-
echo "Last verifier API diagnostics:" >&2
|
| 787 |
-
echo "${verifier_check_output}" >&2
|
| 788 |
-
return 1
|
| 789 |
-
fi
|
| 790 |
-
sleep 10
|
| 791 |
-
done
|
| 792 |
-
}
|
| 793 |
-
|
| 794 |
-
# ================= Nanoclaw workspace 根目录 =================
|
| 795 |
-
mkdir -p "${nanoclaw_temp_root}"
|
| 796 |
-
if ! touch "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" 2>/dev/null; then
|
| 797 |
-
echo "ERROR: Cannot write NANOCLAW_TEMP_ROOT: ${nanoclaw_temp_root}" >&2
|
| 798 |
-
exit 2
|
| 799 |
-
fi
|
| 800 |
-
rm -f "${nanoclaw_temp_root}/.nanoclaw_write_test_${NODE_RANK}" || true
|
| 801 |
-
if [[ "${nanoclaw_temp_root}" == /tmp/* ]]; then
|
| 802 |
-
echo "WARNING: NANOCLAW_TEMP_ROOT is under /tmp. Multi-node reward workers may not see rollout workspaces." >&2
|
| 803 |
-
echo "WARNING: Prefer a shared path, e.g. ${DATA_ROOT}/nanoclaw_workspaces" >&2
|
| 804 |
-
fi
|
| 805 |
-
echo "DEBUG: Nanoclaw train_base_tasks=${train_base_tasks}"
|
| 806 |
-
echo "DEBUG: Nanoclaw val_base_tasks=${val_base_tasks}"
|
| 807 |
-
echo "DEBUG: Nanoclaw task_glob=${nanoclaw_task_glob}, task_ids=${nanoclaw_task_ids:-<all>}"
|
| 808 |
-
echo "DEBUG: Nanoclaw temp_root=${nanoclaw_temp_root}, cleanup=${nanoclaw_cleanup_workspaces}, keep_failed=${nanoclaw_keep_failed_workspaces}"
|
| 809 |
-
|
| 810 |
-
# ================= 生成 Ray runtime env =================
|
| 811 |
-
RUNTIME_ENV_FILE=${WORK_DIR}/verl_engine_runtime_env.generated.yaml
|
| 812 |
-
cat > "${RUNTIME_ENV_FILE}" <<YAML
|
| 813 |
-
working_dir: ./
|
| 814 |
-
excludes: ["/.git/", "/logs/", "/checkpoint/"]
|
| 815 |
-
env_vars:
|
| 816 |
-
TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
|
| 817 |
-
CUDA_DEVICE_MAX_CONNECTIONS: "1"
|
| 818 |
-
HCCL_HOST_SOCKET_PORT_RANGE: "${HCCL_HOST_SOCKET_PORT_RANGE}"
|
| 819 |
-
HCCL_NPU_SOCKET_PORT_RANGE: "${HCCL_NPU_SOCKET_PORT_RANGE}"
|
| 820 |
-
HCCL_CONNECT_TIMEOUT: "${HCCL_CONNECT_TIMEOUT}"
|
| 821 |
-
HCCL_EXEC_TIMEOUT: "${HCCL_EXEC_TIMEOUT}"
|
| 822 |
-
HCCL_EVENT_TIMEOUT: "${HCCL_EVENT_TIMEOUT}"
|
| 823 |
-
HCCL_LOG_LEVEL: "${HCCL_LOG_LEVEL}"
|
| 824 |
-
HCCL_BUFFSIZE: "${HCCL_BUFFSIZE}"
|
| 825 |
-
P2P_HCCL_BUFFSIZE: "${P2P_HCCL_BUFFSIZE}"
|
| 826 |
-
VLLM_USE_V1: "${VLLM_USE_V1}"
|
| 827 |
-
VLLM_ENABLE_GRAPH_MODE: "${verifier_api_enable_graph_mode}"
|
| 828 |
-
VLLM_ASCEND_ENABLE_NZ: "${VLLM_ASCEND_ENABLE_NZ}"
|
| 829 |
-
VLLM_ENABLE_V1_MULTIPROCESSING: "${VLLM_ENABLE_V1_MULTIPROCESSING}"
|
| 830 |
-
VLLM_ENGINE_ITERATION_TIMEOUT_S: "${VLLM_ENGINE_ITERATION_TIMEOUT_S}"
|
| 831 |
-
RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES: "${RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES}"
|
| 832 |
-
TOKENIZERS_PARALLELISM: "false"
|
| 833 |
-
HYDRA_FULL_ERROR: "1"
|
| 834 |
-
PYTHONUNBUFFERED: "1"
|
| 835 |
-
RAY_DEDUP_LOGS: "0"
|
| 836 |
-
WANDB_MODE: "${WANDB_MODE}"
|
| 837 |
-
MOCK_API_BASE: "${mock_api_base}"
|
| 838 |
-
MOCK_API_KEY: "${mock_api_key}"
|
| 839 |
-
MOCK_MODEL_NAME: "${mock_model_name}"
|
| 840 |
-
MOCK_API_TIMEOUT: "${mock_api_timeout}"
|
| 841 |
-
MOCK_API_CONNECT_TIMEOUT: "${mock_api_connect_timeout}"
|
| 842 |
-
NANOCLAW_FORCE_NO_THINKING: "${nanoclaw_force_no_thinking}"
|
| 843 |
-
NANOCLAW_FORCE_MAX_TOKENS: "${nanoclaw_force_max_tokens}"
|
| 844 |
-
NANOCLAW_REWARD_PRINT_DETAILS: "${nanoclaw_reward_print_details}"
|
| 845 |
-
NANOCLAW_REQUIRE_FINAL_ANSWER: "${nanoclaw_require_final_answer}"
|
| 846 |
-
NANOCLAW_FINAL_ANSWER_BONUS_ENABLE: "${nanoclaw_final_answer_bonus_enable}"
|
| 847 |
-
NANOCLAW_FINAL_ANSWER_BONUS_SCORE: "${nanoclaw_final_answer_bonus_score}"
|
| 848 |
-
NANOCLAW_TURN_PENALTY_ONLY_POSITIVE_SCORE: "${nanoclaw_turn_penalty_only_positive_score}"
|
| 849 |
-
NANOCLAW_ASSISTANT_TURN_PENALTY: "${nanoclaw_assistant_turn_penalty}"
|
| 850 |
-
NANOCLAW_DUPLICATE_TOOL_CALL_PENALTY: "${nanoclaw_duplicate_tool_call_penalty}"
|
| 851 |
-
NANOCLAW_REPEATED_RESPONSE_PENALTY: "${nanoclaw_repeated_response_penalty}"
|
| 852 |
-
NANOCLAW_REPEATED_RESPONSE_MIN_CHARS: "${nanoclaw_repeated_response_min_chars}"
|
| 853 |
-
NANOCLAW_REPEATED_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_repeated_response_min_consecutive_repeats}"
|
| 854 |
-
NANOCLAW_MASK_LOOPING_RESPONSES: "${nanoclaw_mask_looping_responses}"
|
| 855 |
-
NANOCLAW_MASK_ONLY_POSITIVE_ADVANTAGE: "${nanoclaw_mask_only_positive_advantage}"
|
| 856 |
-
NANOCLAW_MASK_BUDGET_EXHAUSTED_LAST_TURN: "${nanoclaw_mask_budget_exhausted_last_turn}"
|
| 857 |
-
NANOCLAW_MASK_DUPLICATE_TOOL_RESULT_TURNS: "${nanoclaw_mask_duplicate_tool_result_turns}"
|
| 858 |
-
NANOCLAW_MASK_ERROR_TOOL_RESULT_TURNS: "${nanoclaw_mask_error_tool_result_turns}"
|
| 859 |
-
NANOCLAW_LOOPING_RESPONSE_MIN_CHARS: "${nanoclaw_looping_response_min_chars}"
|
| 860 |
-
NANOCLAW_LOOPING_RESPONSE_MIN_CONSECUTIVE_REPEATS: "${nanoclaw_looping_response_min_consecutive_repeats}"
|
| 861 |
-
YAML
|
| 862 |
-
|
| 863 |
-
# ================= 启动 Ray 多机集群 =================
|
| 864 |
-
if [ "${NODE_RANK}" = "0" ]; then
|
| 865 |
-
echo "--> [Head Node] Starting Ray Head on ${CURRENT_IP}..."
|
| 866 |
-
ray start --head \
|
| 867 |
-
--node-ip-address=${RAY_NODE_IP} \
|
| 868 |
-
--port=${RAY_PORT} \
|
| 869 |
-
--dashboard-host=0.0.0.0 \
|
| 870 |
-
--dashboard-port=${DASHBOARD_PORT} \
|
| 871 |
-
--resources="{\"NPU\":${NPUS_PER_NODE}}" \
|
| 872 |
-
--disable-usage-stats \
|
| 873 |
-
--block &
|
| 874 |
-
|
| 875 |
-
sleep 10
|
| 876 |
-
wait_for_ray_npu_resources ${WORLD_SIZE} 900 || exit 1
|
| 877 |
-
wait_for_verifier_api || exit 1
|
| 878 |
-
else
|
| 879 |
-
echo "--> [Worker Node] Starting Ray Worker, connecting to ${MASTER_ADDR}:${RAY_PORT}..."
|
| 880 |
-
sleep 20
|
| 881 |
-
ray start --address=${MASTER_ADDR}:${RAY_PORT} \
|
| 882 |
-
--node-ip-address=${RAY_NODE_IP} \
|
| 883 |
-
--resources="{\"NPU\":${NPUS_PER_NODE}}" \
|
| 884 |
-
--disable-usage-stats \
|
| 885 |
-
--block &
|
| 886 |
-
sleep 10
|
| 887 |
-
fi
|
| 888 |
-
|
| 889 |
-
# ================= 训练参数数组 =================
|
| 890 |
-
training_args=(
|
| 891 |
-
python3 -m verl.trainer.main_ppo
|
| 892 |
-
+ray_kwargs.ray_init.address=auto
|
| 893 |
-
reward.num_workers=${reward_num_workers}
|
| 894 |
-
algorithm.adv_estimator=${adv_estimator}
|
| 895 |
-
algorithm.gamma=${algorithm_gamma}
|
| 896 |
-
algorithm.lam=${algorithm_lam}
|
| 897 |
-
algorithm.use_kl_in_reward=${use_kl_in_reward}
|
| 898 |
-
algorithm.kl_penalty=${kl_penalty}
|
| 899 |
-
algorithm.kl_ctrl.type=${kl_ctrl_type}
|
| 900 |
-
algorithm.kl_ctrl.kl_coef=${kl_coef}
|
| 901 |
-
data.train_files="${train_files}"
|
| 902 |
-
data.val_files="${test_files}"
|
| 903 |
-
data.return_raw_chat=True
|
| 904 |
-
data.return_multi_modal_inputs=False
|
| 905 |
-
data.image_key=images
|
| 906 |
-
data.shuffle=True
|
| 907 |
-
data.train_batch_size=${train_batch_size}
|
| 908 |
-
data.max_prompt_length=${max_prompt_length}
|
| 909 |
-
data.max_response_length=${max_response_length}
|
| 910 |
-
data.filter_overlong_prompts=True
|
| 911 |
-
data.truncation=error
|
| 912 |
-
data.custom_cls.path=pkg://nanoclaw_recipe.nanoclaw
|
| 913 |
-
data.custom_cls.name=CustomRLHFDataset
|
| 914 |
-
"data.tool_config_path=${tool_config_path}"
|
| 915 |
-
"+data.nanoclaw_task_glob=${nanoclaw_task_glob}"
|
| 916 |
-
"+data.nanoclaw_temp_root=${nanoclaw_temp_root}"
|
| 917 |
-
"+data.nanoclaw_cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
|
| 918 |
-
"+data.nanoclaw_keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
|
| 919 |
-
"+data.nanoclaw_env_builder_timeout=${nanoclaw_env_builder_timeout}"
|
| 920 |
-
"+data.nanoclaw_verifier_timeout=${nanoclaw_verifier_timeout}"
|
| 921 |
-
"+data.nanoclaw_reward_score_mode=${nanoclaw_reward_score_mode}"
|
| 922 |
-
"+data.nanoclaw_allow_bash=${nanoclaw_allow_bash}"
|
| 923 |
-
+data.apply_chat_template_kwargs.enable_thinking=True
|
| 924 |
-
reward.custom_reward_function.path=pkg://nanoclaw_recipe.nanoclaw
|
| 925 |
-
reward.custom_reward_function.name=compute_score
|
| 926 |
-
"+reward.custom_reward_function.reward_kwargs.cleanup_workspaces=${nanoclaw_cleanup_workspaces}"
|
| 927 |
-
"+reward.custom_reward_function.reward_kwargs.keep_failed_workspaces=${nanoclaw_keep_failed_workspaces}"
|
| 928 |
-
"+reward.custom_reward_function.reward_kwargs.verifier_timeout=${nanoclaw_verifier_timeout}"
|
| 929 |
-
"+reward.custom_reward_function.reward_kwargs.reward_score_mode=${nanoclaw_reward_score_mode}"
|
| 930 |
-
"+reward.custom_reward_function.reward_kwargs.require_final_answer=${nanoclaw_require_final_answer}"
|
| 931 |
-
"+reward.custom_reward_function.reward_kwargs.final_answer_bonus_enable=${nanoclaw_final_answer_bonus_enable}"
|
| 932 |
-
"+reward.custom_reward_function.reward_kwargs.final_answer_bonus_score=${nanoclaw_final_answer_bonus_score}"
|
| 933 |
-
"+reward.custom_reward_function.reward_kwargs.turn_penalty_only_positive_score=${nanoclaw_turn_penalty_only_positive_score}"
|
| 934 |
-
"+reward.custom_reward_function.reward_kwargs.assistant_turn_penalty=${nanoclaw_assistant_turn_penalty}"
|
| 935 |
-
"+reward.custom_reward_function.reward_kwargs.duplicate_tool_call_penalty=${nanoclaw_duplicate_tool_call_penalty}"
|
| 936 |
-
"+reward.custom_reward_function.reward_kwargs.repeated_response_penalty=${nanoclaw_repeated_response_penalty}"
|
| 937 |
-
"+reward.custom_reward_function.reward_kwargs.repeated_response_min_chars=${nanoclaw_repeated_response_min_chars}"
|
| 938 |
-
"+reward.custom_reward_function.reward_kwargs.repeated_response_min_consecutive_repeats=${nanoclaw_repeated_response_min_consecutive_repeats}"
|
| 939 |
-
"+reward.custom_reward_function.reward_kwargs.mock_api_base=${mock_api_base}"
|
| 940 |
-
"+reward.custom_reward_function.reward_kwargs.mock_api_key=${mock_api_key}"
|
| 941 |
-
"+reward.custom_reward_function.reward_kwargs.mock_model_name=${mock_model_name}"
|
| 942 |
-
"+reward.custom_reward_function.reward_kwargs.mock_api_timeout=${mock_api_timeout}"
|
| 943 |
-
"+reward.custom_reward_function.reward_kwargs.mock_api_connect_timeout=${mock_api_connect_timeout}"
|
| 944 |
-
actor_rollout_ref.model.path=${model_path}
|
| 945 |
-
actor_rollout_ref.model.use_remove_padding=True
|
| 946 |
-
actor_rollout_ref.model.enable_gradient_checkpointing=True
|
| 947 |
-
actor_rollout_ref.model.enable_activation_offload=${enable_activation_offload}
|
| 948 |
-
actor_rollout_ref.model.use_fused_kernels=${use_fused_kernels}
|
| 949 |
-
actor_rollout_ref.model.fused_kernel_options.impl_backend=${fused_kernel_backend}
|
| 950 |
-
actor_rollout_ref.actor.strategy=${actor_strategy}
|
| 951 |
-
actor_rollout_ref.ref.strategy=${actor_strategy}
|
| 952 |
-
actor_rollout_ref.actor.use_kl_loss=${actor_use_kl_loss}
|
| 953 |
-
actor_rollout_ref.actor.kl_loss_coef=${actor_kl_loss_coef}
|
| 954 |
-
actor_rollout_ref.actor.kl_loss_type=${actor_kl_loss_type}
|
| 955 |
-
actor_rollout_ref.actor.clip_ratio_low=${actor_clip_ratio_low}
|
| 956 |
-
actor_rollout_ref.actor.clip_ratio_high=${actor_clip_ratio_high}
|
| 957 |
-
actor_rollout_ref.actor.clip_ratio_c=${actor_clip_ratio_c}
|
| 958 |
-
actor_rollout_ref.actor.entropy_coeff=${actor_entropy_coeff}
|
| 959 |
-
actor_rollout_ref.actor.ppo_epochs=${actor_ppo_epochs}
|
| 960 |
-
actor_rollout_ref.actor.shuffle=${actor_shuffle}
|
| 961 |
-
actor_rollout_ref.actor.optim.lr=${actor_lr}
|
| 962 |
-
actor_rollout_ref.actor.optim.lr_scheduler_type=${actor_lr_scheduler_type}
|
| 963 |
-
actor_rollout_ref.actor.optim.lr_warmup_steps_ratio=${actor_lr_warmup_steps_ratio}
|
| 964 |
-
actor_rollout_ref.actor.optim.weight_decay=${actor_weight_decay}
|
| 965 |
-
"actor_rollout_ref.actor.optim.betas=[${actor_adam_beta1},${actor_adam_beta2}]"
|
| 966 |
-
actor_rollout_ref.actor.optim.clip_grad=${actor_clip_grad}
|
| 967 |
-
actor_rollout_ref.actor.use_dynamic_bsz=True
|
| 968 |
-
actor_rollout_ref.actor.ppo_mini_batch_size=${ppo_mini_batch_size}
|
| 969 |
-
actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${actor_max_token_len_per_gpu}
|
| 970 |
-
actor_rollout_ref.actor.ulysses_sequence_parallel_size=${train_sp}
|
| 971 |
-
actor_rollout_ref.actor.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
|
| 972 |
-
actor_rollout_ref.actor.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
|
| 973 |
-
actor_rollout_ref.actor.entropy_checkpointing=${entropy_checkpointing}
|
| 974 |
-
actor_rollout_ref.actor.fsdp_config.param_offload=${offload}
|
| 975 |
-
actor_rollout_ref.actor.fsdp_config.optimizer_offload=${offload}
|
| 976 |
-
actor_rollout_ref.actor.fsdp_config.offload_policy=${offload}
|
| 977 |
-
actor_rollout_ref.actor.fsdp_config.reshard_after_forward=True
|
| 978 |
-
actor_rollout_ref.actor.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
|
| 979 |
-
actor_rollout_ref.actor.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
|
| 980 |
-
actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
|
| 981 |
-
actor_rollout_ref.ref.fsdp_config.param_offload=${offload}
|
| 982 |
-
actor_rollout_ref.ref.fsdp_config.offload_policy=${offload}
|
| 983 |
-
actor_rollout_ref.ref.fsdp_config.reshard_after_forward=True
|
| 984 |
-
actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
|
| 985 |
-
actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
|
| 986 |
-
actor_rollout_ref.ref.ulysses_sequence_parallel_size=${train_sp}
|
| 987 |
-
actor_rollout_ref.ref.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
|
| 988 |
-
actor_rollout_ref.ref.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
|
| 989 |
-
actor_rollout_ref.ref.entropy_checkpointing=${entropy_checkpointing}
|
| 990 |
-
actor_rollout_ref.ref.fsdp_config.entropy_from_logits_with_chunking=${entropy_from_logits_with_chunking}
|
| 991 |
-
actor_rollout_ref.ref.fsdp_config.entropy_from_logits_chunk_size=${entropy_from_logits_chunk_size}
|
| 992 |
-
actor_rollout_ref.ref.fsdp_config.entropy_checkpointing=${entropy_checkpointing}
|
| 993 |
-
actor_rollout_ref.rollout.name=vllm
|
| 994 |
-
actor_rollout_ref.rollout.mode=async
|
| 995 |
-
actor_rollout_ref.rollout.calculate_log_probs=True
|
| 996 |
-
actor_rollout_ref.rollout.temperature=${rollout_temperature}
|
| 997 |
-
actor_rollout_ref.rollout.top_p=${rollout_top_p}
|
| 998 |
-
actor_rollout_ref.rollout.top_k=${rollout_top_k}
|
| 999 |
-
actor_rollout_ref.rollout.min_p=${rollout_min_p}
|
| 1000 |
-
actor_rollout_ref.rollout.presence_penalty=${rollout_presence_penalty}
|
| 1001 |
-
actor_rollout_ref.rollout.frequency_penalty=${rollout_frequency_penalty}
|
| 1002 |
-
actor_rollout_ref.rollout.repetition_penalty=${rollout_repetition_penalty}
|
| 1003 |
-
actor_rollout_ref.rollout.tensor_model_parallel_size=${infer_tp}
|
| 1004 |
-
actor_rollout_ref.rollout.max_model_len=${max_model_len}
|
| 1005 |
-
actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=${update_weights_bucket_mb}
|
| 1006 |
-
actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
|
| 1007 |
-
actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${log_prob_max_token_len_per_gpu}
|
| 1008 |
-
actor_rollout_ref.rollout.enable_chunked_prefill=True
|
| 1009 |
-
actor_rollout_ref.rollout.max_num_batched_tokens=${rollout_max_num_batched_tokens}
|
| 1010 |
-
actor_rollout_ref.rollout.free_cache_engine=True
|
| 1011 |
-
actor_rollout_ref.rollout.enforce_eager=False
|
| 1012 |
-
actor_rollout_ref.rollout.enable_prefix_caching=False
|
| 1013 |
-
actor_rollout_ref.rollout.multi_turn.enable=True
|
| 1014 |
-
actor_rollout_ref.rollout.multi_turn.max_user_turns=${max_turns}
|
| 1015 |
-
actor_rollout_ref.rollout.multi_turn.max_assistant_turns=${max_turns}
|
| 1016 |
-
actor_rollout_ref.rollout.multi_turn.max_assistant_response_length=${max_assistant_response_length}
|
| 1017 |
-
"actor_rollout_ref.rollout.multi_turn.tool_config_path=${tool_config_path}"
|
| 1018 |
-
actor_rollout_ref.rollout.multi_turn.format=qwen3_coder
|
| 1019 |
-
"actor_rollout_ref.rollout.multi_turn.max_tool_response_length=${max_tool_response_length}"
|
| 1020 |
-
actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_memory_utilization}
|
| 1021 |
-
actor_rollout_ref.rollout.n=${n_resp_per_prompt}
|
| 1022 |
-
actor_rollout_ref.rollout.val_kwargs.temperature=${rollout_temperature}
|
| 1023 |
-
actor_rollout_ref.rollout.val_kwargs.top_p=${rollout_top_p}
|
| 1024 |
-
actor_rollout_ref.rollout.val_kwargs.top_k=${rollout_top_k}
|
| 1025 |
-
actor_rollout_ref.rollout.val_kwargs.min_p=${rollout_min_p}
|
| 1026 |
-
actor_rollout_ref.rollout.val_kwargs.presence_penalty=${rollout_presence_penalty}
|
| 1027 |
-
actor_rollout_ref.rollout.val_kwargs.frequency_penalty=${rollout_frequency_penalty}
|
| 1028 |
-
actor_rollout_ref.rollout.val_kwargs.repetition_penalty=${rollout_repetition_penalty}
|
| 1029 |
-
actor_rollout_ref.rollout.val_kwargs.do_sample=True
|
| 1030 |
-
actor_rollout_ref.rollout.val_kwargs.n=${n_resp_per_prompt_val}
|
| 1031 |
-
actor_rollout_ref.actor.use_torch_compile=False
|
| 1032 |
-
actor_rollout_ref.ref.use_torch_compile=False
|
| 1033 |
-
actor_rollout_ref.actor.use_torch_compile=False
|
| 1034 |
-
actor_rollout_ref.ref.use_torch_compile=False
|
| 1035 |
-
actor_rollout_ref.actor.fsdp_config.use_torch_compile=False
|
| 1036 |
-
actor_rollout_ref.ref.fsdp_config.use_torch_compile=False
|
| 1037 |
-
critic.fsdp.use_torch_compile=False
|
| 1038 |
-
trainer.use_v1=${trainer_use_v1}
|
| 1039 |
-
trainer.critic_warmup=0
|
| 1040 |
-
trainer.balance_batch=True
|
| 1041 |
-
trainer.logger=['console','tensorboard']
|
| 1042 |
-
trainer.project_name=${project_name}
|
| 1043 |
-
trainer.experiment_name=${experiment_name}
|
| 1044 |
-
trainer.nnodes=${NNODES}
|
| 1045 |
-
trainer.n_gpus_per_node=${NPUS_PER_NODE}
|
| 1046 |
-
trainer.val_before_train=${val_before_train}
|
| 1047 |
-
trainer.log_val_generations=${log_val_generations}
|
| 1048 |
-
trainer.save_freq=${save_freq}
|
| 1049 |
-
trainer.default_local_dir=${default_local_dir}
|
| 1050 |
-
trainer.test_freq=${test_freq}
|
| 1051 |
-
trainer.total_epochs=10
|
| 1052 |
-
)
|
| 1053 |
-
|
| 1054 |
-
if [ -n "${fsdp_size}" ]; then
|
| 1055 |
-
training_args+=(
|
| 1056 |
-
actor_rollout_ref.actor.fsdp_config.fsdp_size=${fsdp_size}
|
| 1057 |
-
actor_rollout_ref.ref.fsdp_config.fsdp_size=${fsdp_size}
|
| 1058 |
-
)
|
| 1059 |
-
fi
|
| 1060 |
-
|
| 1061 |
-
if [ -n "${nanoclaw_task_ids}" ]; then
|
| 1062 |
-
training_args+=("+data.nanoclaw_task_ids=${nanoclaw_task_ids}")
|
| 1063 |
-
fi
|
| 1064 |
-
|
| 1065 |
-
if [ -n "${nanoclaw_max_steps}" ]; then
|
| 1066 |
-
training_args+=("+data.nanoclaw_max_steps=${nanoclaw_max_steps}")
|
| 1067 |
-
fi
|
| 1068 |
-
|
| 1069 |
-
# ================= 启动训练主进程:仅主节点执行 =================
|
| 1070 |
-
if [ "${NODE_RANK}" = "0" ]; then
|
| 1071 |
-
echo "--> [Head Node] Starting VERL unified engine training..."
|
| 1072 |
-
echo "DEBUG: runtime_env=${RUNTIME_ENV_FILE}"
|
| 1073 |
-
echo "DEBUG: entrypoint=${training_args[*]}"
|
| 1074 |
-
|
| 1075 |
-
ray job submit \
|
| 1076 |
-
--address="http://127.0.0.1:${DASHBOARD_PORT}" \
|
| 1077 |
-
--runtime-env="${RUNTIME_ENV_FILE}" \
|
| 1078 |
-
-- \
|
| 1079 |
-
"${training_args[@]}" 2>&1 | tee "logs/qwen3.5-nanoclaw-grpo-verl-engine-${start_time}.log"
|
| 1080 |
-
else
|
| 1081 |
-
echo "--> [Worker Node] Setup finished. Keeping node alive for Ray..."
|
| 1082 |
-
tail -f /dev/null
|
| 1083 |
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