Updated on 2026-09-03 GMT+08:00

Preparing the Training Scripts

For details about the training script files used for model training, see Training Scripts (Qwen3-8B), Training Scripts (Qwen2.5-VL-32B-Instruct), and Training Scripts (Qwen3-30B-A3B). You need to create an SH file by referring to this section and upload it to your OBS bucket.

Example of the file structure within the OBS bucket:
obs://verl/verl-a2/run_train_8b.sh
obs://verl/verl-a2/run_qwen3-8b_npu_ma.sh
obs://verl/verl-a2/run_train_32b.sh
obs://verl/verl-a2/run_qwen2_5_vl_32b_npu_ma.sh
obs://verl/verl-a2/run_train_30b.sh
obs://verl/verl-a2/run_qwen3_30b_a3b_npu_ma.sh
Table 1 Training scripts

Model

Training Script

Script Description

Qwen3-8B

run_train_8b.sh

Training job startup script, which handles data preprocessing, starting the training job, and outputting training logs.

run_qwen3-8b_npu_ma.sh

Used to start the VeRL reinforcement learning training job.

Qwen2.5-VL-32B-Instruct

run_train_32b.sh

Training job startup script, which handles data preprocessing, starting the training job, and outputting training logs.

run_qwen2_5_vl_32b_npu_ma.sh

Used to start the VeRL reinforcement learning training job.

Qwen3-30B-A3B

run_train_30b.sh

Training job startup script, which handles data preprocessing, starting the training job, and outputting training logs.

run_qwen3_30b_a3b_npu_ma.sh

Used to start the VeRL reinforcement learning training job.

Path Description

The paths involved in the training script files are defined as follows:

  • /home/ma-user/work: The local code directory configured when creating the ModelArts training job. This can be customized, but the paths specified in the scripts must perfectly match the paths set during training job creation.
  • /verl-a2: The name of the OBS folder used to store code, datasets, and model weights. This can be customized.
  • /output_dir: The cloud mount path configured when mounting OBS during the training job creation. It is used to save preprocessed data, checkpoints, and training logs. This can be customized.
  • /home/ma-user/verl: The pre-installed verl code repository built into the container image. No modifications are required.

Parameter Description

Parameter

Description

Example Value

data.train_files

Training set after preprocessing

~/dataset/gsm8k/precessed/train.parquet

data.val_files

Validation set after preprocessing

~/dataset/gsm8k/precessed/test.parquet

actor_rollout_ref.model.path

Hugging Face model path, which can also be a path in the container.

~/models/Qwen3-8B

trainer.n_gpus_per_node

Number of NPUs per node.

8

trainer.nnodes

Compute nodes required for training.

2

algorithm.adv_estimator

Reinforcement learning policy algorithm.

grpo

data.train_batch_size

Sampling batch size per training iteration.

16

data.max_prompt_length

Maximum prompt length.

2048

data.max_response_length

Maximum response length.

4096

actor_rollout_ref.rollout.tensor_model_parallel_size

Model segmentation during vLLM inference.

2

actor_rollout_ref.nccl_timeout

Communication timeout interval. Set this parameter based on the memory access requirements.

7200

actor_rollout_ref.rollout.n

Number of importance sampling times.

2

trainer.save_freq

Checkpoint saving frequency, measured in training steps.

50

trainer.test_freq

Validation frequency, measured in training steps.

50

trainer.total_epochs

Number of training epochs. One epoch is when the model traverses the entire training set once.

1

trainer.total_training_steps

Number of training steps. One step is when the model completes one forward pass, one backward pass, and one parameter update.

100

For details about more parameters, see the official VeRL documentation.

Training Scripts (Qwen3-8B)

You need to prepare two training script files: run_train_8b.sh and run_qwen3-8b_npu_ma.sh.

  • run_train_8b.sh is the training job startup script, which handles data preprocessing, starting the training task, and outputting training logs. When executed, the run_train_8b.sh script automatically calls the data preprocessing script gsm8k.py and the VeRL training script run_qwen3-8b_npu_ma.sh.
    The content of the run_train_8b.sh script is as follows:
    #!/bin/bash
    set -e
    export HCCL_IF_BASE_PORT=61000
    export HCCL_NPU_SOCKET_PORT_RANGE="61000-61050"
    export HCCL_EXEC_TIMEOUT=60000
    export HCCL_CONNECT_TIMEOUT=7200
    unset https_proxy http_proxy proxy ASCEND_RT_VISIBLE_DEVICES
    source /usr/local/Ascend/ascend-toolkit/set_env.sh
    source /usr/local/Ascend/nnal/atb/set_env.sh
    export NNODES=${VC_WORKER_NUM:-1}
    export NGPUS_PER_NODE=${MA_NUM_GPUS:-8}
    export MASTER_ADDR="${VC_WORKER_HOSTS%%,*}"
    export DOMAIN_IP=$(python -c "import socket; print(socket.gethostbyname('${MASTER_ADDR}'))")
    export MASTER_NODE_IP="${DOMAIN_IP}"
    export MASTER_NODE_PORT="6699"
    export USE_OPTIMIZED_MODEL=0
    export VLLM_VERSION=0.16.0
    export PYTHONPATH="/home/ma-user/Megatron-LM:/home/ma-user/vllm${PYTHONPATH:+:${PYTHONPATH}}"
    MAX_WAIT_SECONDS=900
    CHECK_INTERVAL=3
    get_current_ip() {
        local ip
        ip=$(ip -4 addr | grep -v '127.0.0.1' | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 2>/dev/null)
        if [[ -z "$ip" ]]; then
            ip=$(ip -4 addr | grep -v '127.0.0.1' | awk '/inet/ {gsub(/\/.*/,""); print $2}' | head -n1 2>/dev/null)
        fi
        echo "${ip:-}"
    }
    CURRENT_IP=$(get_current_ip)
    if [[ -z "$CURRENT_IP" ]]; then
        echo "Failed to obtain the IP address of the current node."
        exit 1
    fi
    echo "current ip: $CURRENT_IP, master ip: $MASTER_NODE_IP"
    if [ "$CURRENT_IP" = "$MASTER_NODE_IP" ]; then
        echo "start Ray master node..."
        ray stop --force
        ray start --head --port="$MASTER_NODE_PORT"
        elapsed_seconds=0
        echo "wait $NNODES nodes..."
        while true; do
            current_node_num=$(ray status | grep -c "node_" || echo 0)
            if ! [[ "$current_node_num" =~ ^[0-9]+$ ]]; then
                current_node_num=0
            fi
            echo "current_node_num: $current_node_num"
            if [ "$current_node_num" -ge "$NNODES" ]; then
                echo "all $NNODES workers node is ready."
                break
            fi
            if [ "$elapsed_seconds" -ge "$MAX_WAIT_SECONDS" ]; then
                echo "timeout ($MAX_WAIT_SECONDS s), current_node_num: $current_node_num"
                ray stop --force
                exit 1
            fi
            sleep "$CHECK_INTERVAL"
            elapsed_seconds=$((elapsed_seconds + CHECK_INTERVAL))
        done
        echo "start job......"
        RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}  # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can also be customized.
        OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}               # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
        cd ${RAY_DATA_HOME}
        if [ ! -d "$OUTPUT_DIR/dataset/gsm8k/precessed" ]; then
            python3 gsm8k.py --local_dir "$OUTPUT_DIR/dataset/gsm8k/precessed"
        fi
        cp ${RAY_DATA_HOME}/run_qwen3-8b_npu_ma.sh /home/ma-user/verl/examples/grpo_trainer/run_qwen3-8b_npu_ma.sh
        cd /home/ma-user/verl
        bash examples/grpo_trainer/run_qwen3-8b_npu_ma.sh
    else
        echo "start workers, connect to master: $MASTER_NODE_IP:$MASTER_NODE_PORT"
        ray start \
            --address="${MASTER_NODE_IP}:${MASTER_NODE_PORT}"
    fi
  • The run_qwen3-8b_npu_ma.sh script is used to start the VeRL reinforcement learning training job. Path Description describes the paths requiring modification.
    The content of the run_qwen3-8b_npu_ma.sh script is as follows:
    set -x
    project_name='GRPO-Qwen3'
    exp_name='GRPO-Qwen3-8B-npu'
    gen_tp=2
    RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}                     # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can be customized.
    OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}                                  # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
    MODEL_PATH=${MODEL_PATH:-"${RAY_DATA_HOME}/models/Qwen3-8B"}                     # .../models/Qwen3-8B is the OBS folder where the model is stored, which can be customized.
    CKPTS_DIR=${CKPTS_DIR:-"${OUTPUT_DIR}/ckpts/${project_name}/${exp_name}"}        # .../ckpts is the OBS folder where training outputs are saved, which can be customized.
    TRAIN_FILE=${TRAIN_FILE:-"${OUTPUT_DIR}/dataset/gsm8k/precessed/train.parquet"}  # .../dataset/gsm8k is the OBS folder where the GSM8K training data is stored, which can be customized. /precessed/train.parquet is the preprocessed training data and does not need to be modified.
    TEST_FILE=${TEST_FILE:-"${OUTPUT_DIR}/dataset/gsm8k/precessed/test.parquet"}     # .../dataset/gsm8k is the OBS folder where the GSM8K training data is stored, which can be customized. /precessed/test.parquet is the preprocessed test data and does not need to be modified.
    python3 -m verl.trainer.main_ppo \
        algorithm.adv_estimator=grpo \
        data.train_files="${TRAIN_FILE}" \
        data.val_files="${TEST_FILE}" \
        data.train_batch_size=16 \
        data.max_prompt_length=2048 \
        data.max_response_length=4096 \
        data.filter_overlong_prompts=True \
        data.truncation='error' \
        actor_rollout_ref.model.path=${MODEL_PATH} \
        actor_rollout_ref.actor.optim.lr=1e-6 \
        actor_rollout_ref.model.use_remove_padding=True \
        actor_rollout_ref.actor.ppo_mini_batch_size=8 \
        actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.actor.use_kl_loss=True \
        actor_rollout_ref.actor.kl_loss_coef=0.001 \
        actor_rollout_ref.actor.kl_loss_type=low_var_kl \
        actor_rollout_ref.actor.entropy_coeff=0 \
        actor_rollout_ref.actor.use_torch_compile=False \
        actor_rollout_ref.nccl_timeout=7200 \
        actor_rollout_ref.ref.use_torch_compile=False \
        actor_rollout_ref.model.enable_gradient_checkpointing=True \
        actor_rollout_ref.actor.fsdp_config.param_offload=True \
        actor_rollout_ref.actor.fsdp_config.optimizer_offload=True \
        actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.rollout.tensor_model_parallel_size=${gen_tp} \
        actor_rollout_ref.rollout.name=vllm \
        actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \
        actor_rollout_ref.rollout.n=2 \
        actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.ref.fsdp_config.param_offload=True \
        actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=4096 \
        algorithm.use_kl_in_reward=False \
        trainer.critic_warmup=0 \
        trainer.logger=console \
        trainer.project_name="${project_name}" \
        trainer.experiment_name="${exp_name}" \
        trainer.n_gpus_per_node=${NGPUS_PER_NODE} \
        trainer.nnodes=${NNODES} \
        trainer.default_local_dir=${CKPTS_DIR} \
        trainer.resume_mode=auto \
        actor_rollout_ref.actor.fsdp_config.forward_prefetch=True \
        actor_rollout_ref.ref.fsdp_config.forward_prefetch=True \
        ++actor_rollout_ref.actor.entropy_from_logits_with_chunking=True \
        ++actor_rollout_ref.ref.entropy_from_logits_with_chunking=True \
        trainer.val_before_train=True \
        trainer.save_freq=50 \
        trainer.test_freq=50 \
        trainer.total_epochs=1 \
        trainer.total_training_steps=100 2>&1 | tee ${OUTPUT_DIR}/run_qwen3-8b_npu_ma.log
    
    sleep 20s
    if tail -n 100 ${OUTPUT_DIR}/run_qwen3-8b_npu_ma.log | grep -q 'Final validation metrics'; then
        exit 0
    else
        exit 1
    fi

Training Scripts (Qwen2.5-VL-32B-Instruct)

You need to prepare two training script files: run_train_32b.sh and run_qwen3-8b_npu_ma.sh.
  • run_train_32b.sh is the training job startup script, which handles data preprocessing, starting the training task, and outputting training logs. When executed, the run_train_32b.sh script automatically calls the data preprocessing script geometry3k.py and the VeRL training script run_qwen2_5_vl_32b_npu_ma.sh.
    The content of the run_train_32b.sh script is as follows:
    #!/bin/bash
    set -e
    export HCCL_IF_BASE_PORT=61000
    export HCCL_NPU_SOCKET_PORT_RANGE="61000-61050"
    export HCCL_EXEC_TIMEOUT=60000
    export HCCL_CONNECT_TIMEOUT=7200
    unset https_proxy http_proxy proxy ASCEND_RT_VISIBLE_DEVICES
    source /usr/local/Ascend/ascend-toolkit/set_env.sh
    source /usr/local/Ascend/nnal/atb/set_env.sh
    # Change the values as needed.
    export NNODES=${VC_WORKER_NUM:-2}
    export NGPUS_PER_NODE=${MA_NUM_GPUS:-8}
    export MASTER_ADDR="${VC_WORKER_HOSTS%%,*}"
    export DOMAIN_IP=$(python -c "import socket; print(socket.gethostbyname('${MASTER_ADDR}'))")
    export MASTER_NODE_IP="${DOMAIN_IP}"
    export MASTER_NODE_PORT="6699"
    export USE_OPTIMIZED_MODEL=0
    export VLLM_VERSION=0.16.0
    export PYTHONPATH="/home/ma-user/Megatron-LM:/home/ma-user/vllm${PYTHONPATH:+:${PYTHONPATH}}"
    MAX_WAIT_SECONDS=900
    CHECK_INTERVAL=3
    get_current_ip() {
        local ip
        ip=$(ip -4 addr | grep -v '127.0.0.1' | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 2>/dev/null)
        if [[ -z "$ip" ]]; then
            ip=$(ip -4 addr | grep -v '127.0.0.1' | awk '/inet/ {gsub(/\/.*/,""); print $2}' | head -n1 2>/dev/null)
        fi
        echo "${ip:-}"
    }
    CURRENT_IP=$(get_current_ip)
    if [[ -z "$CURRENT_IP" ]]; then
        echo "Failed to obtain the IP address of the current node."
        exit 1
    fi
    echo "current ip: $CURRENT_IP, master ip: $MASTER_NODE_IP"
    if [ "$CURRENT_IP" = "$MASTER_NODE_IP" ]; then
        echo "start Ray master node..."
        ray stop --force
        ray start --head --port="$MASTER_NODE_PORT"
        elapsed_seconds=0
        echo "wait $NNODES nodes..."
        while true; do
            current_node_num=$(ray status | grep -c "node_" || echo 0)
            if ! [[ "$current_node_num" =~ ^[0-9]+$ ]]; then
                current_node_num=0
            fi
            echo "current_node_num: $current_node_num"
            if [ "$current_node_num" -ge "$NNODES" ]; then
                echo "all $NNODES workers node is ready."
                break
            fi
            if [ "$elapsed_seconds" -ge "$MAX_WAIT_SECONDS" ]; then
                echo "timeout ($MAX_WAIT_SECONDS s), current_node_num: $current_node_num"
                ray stop --force
                exit 1
            fi
            sleep "$CHECK_INTERVAL"
            elapsed_seconds=$((elapsed_seconds + CHECK_INTERVAL))
        done
        echo "start job......"
        RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}  # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can also be customized.
        OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}               # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
        cd ${RAY_DATA_HOME}
        if [ ! -d "$OUTPUT_DIR/dataset/geometry3k/precessed" ]; then
            python3 geometry3k.py --local_dir "$OUTPUT_DIR/dataset/geometry3k/precessed"
        fi
        cp ${RAY_DATA_HOME}/run_qwen2_5_vl_32b_npu_ma.sh /home/ma-user/verl/examples/grpo_trainer/run_qwen2_5_vl_32b_npu_ma.sh
        cd /home/ma-user/verl
        bash examples/grpo_trainer/run_qwen2_5_vl_32b_npu_ma.sh
    else
        echo "start workers, connect to master: $MASTER_NODE_IP:$MASTER_NODE_PORT"
        ray start \
            --address="${MASTER_NODE_IP}:${MASTER_NODE_PORT}"
    fi
  • The run_qwen2_5_vl_32b_npu_ma.sh script is used to start the VeRL reinforcement learning training job. Path Description describes the paths requiring modification.

    The content of the runqwen2_5_vl_32b_npu_ma.sh script is as follows:

    set -x
    project_name='GRPO-Qwen2_5'
    exp_name='GRPO-Qwen2_5-VL-32B-npu'
    RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}                          # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can be customized.
    OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}                                      # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
    MODEL_PATH=${MODEL_PATH:-"${RAY_DATA_HOME}/models/Qwen2.5-VL-32B-Instruct"}           # .../models/Qwen2.5-VL-32B-Instruct is the OBS folder where the model is stored, which can be customized.
    CKPTS_DIR=${CKPTS_DIR:-"${OUTPUT_DIR}/ckpts/${project_name}/${exp_name}"}             # .../ckpts is the OBS folder where training outputs are saved, which can be customized.
    TRAIN_FILE=${TRAIN_FILE:-"${OUTPUT_DIR}/dataset/geometry3k/precessed/train.parquet"}  # .../dataset/geometry3k is the OBS folder where the Geometry3K training data is stored, which can be customized. /precessed/train.parquet is the preprocessed training data and does not need to be modified.
    TEST_FILE=${TEST_FILE:-"${OUTPUT_DIR}/dataset/geometry3k/precessed/test.parquet"}     # .../dataset/geometry3k is the OBS folder where the Geometry3K training data is stored, which can be customized. /precessed/test.parquet is the preprocessed test data and does not need to be modified.
    ENGINE=${1:-vllm}
    # Some models are optimized by vllm ascend. While in some case, e.g. rlhf training, 
    # the optimized model may not be suitable. In this case, set this value to 0 to disable the optimized model.
    export USE_OPTIMIZED_MODEL=0
    python3 -m verl.trainer.main_ppo \
        algorithm.adv_estimator=grpo \
        data.train_files="${TRAIN_FILE}" \
        data.val_files="${TEST_FILE}" \
        data.train_batch_size=16 \
        data.max_prompt_length=2048 \
        data.max_response_length=4096 \
        data.filter_overlong_prompts=True \
        data.truncation='error' \
        data.image_key=images \
        actor_rollout_ref.model.path="${MODEL_PATH}" \
        actor_rollout_ref.actor.optim.lr=1e-6 \
        actor_rollout_ref.model.use_remove_padding=True \
        actor_rollout_ref.actor.ppo_mini_batch_size=16 \
        actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.actor.use_kl_loss=True \
        actor_rollout_ref.actor.kl_loss_coef=0.01 \
        actor_rollout_ref.actor.kl_loss_type=low_var_kl \
        actor_rollout_ref.actor.entropy_coeff=0 \
        actor_rollout_ref.actor.use_torch_compile=False \
        actor_rollout_ref.nccl_timeout=7200 \
        actor_rollout_ref.model.enable_gradient_checkpointing=True \
        actor_rollout_ref.actor.fsdp_config.param_offload=True \
        actor_rollout_ref.actor.fsdp_config.optimizer_offload=True \
        actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.rollout.tensor_model_parallel_size=8 \
        actor_rollout_ref.rollout.name=$ENGINE \
        actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \
        actor_rollout_ref.rollout.enable_chunked_prefill=False \
        actor_rollout_ref.rollout.enforce_eager=True \
        actor_rollout_ref.rollout.free_cache_engine=True \
        actor_rollout_ref.rollout.n=2 \
        actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.ref.fsdp_config.param_offload=True \
        actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=4096 \
        algorithm.use_kl_in_reward=False \
        trainer.critic_warmup=0 \
        trainer.logger=console \
        trainer.project_name="${project_name}" \
        trainer.experiment_name="${exp_name}" \
        trainer.n_gpus_per_node=${NGPUS_PER_NODE} \
        trainer.nnodes=${NNODES} \
        trainer.default_local_dir=${CKPTS_DIR} \
        trainer.save_freq=50 \
        trainer.test_freq=50 \
        trainer.total_epochs=1 \
        trainer.total_training_steps=100
     2>&1 | tee ${OUTPUT_DIR}/run_qwen2_5_vl_32b_npu_ma.log
    
    sleep 20s
    if tail -n 100 ${OUTPUT_DIR}/run_qwen2_5_vl_32b_npu_ma.log | grep -q 'Final validation metrics'; then
        exit 0
    else
        exit 1
    fi

Training Scripts (Qwen3-30B-A3B)

You need to prepare two training script files: run_train_30b.sh and run_qwen3_30b_a3b_npu_ma.sh.

  • run_train_30b.sh is the training job startup script, which handles data preprocessing, starting the training task, and outputting training logs. When executed, the run_train_30b.sh script automatically calls the data preprocessing script gsm8k.py and the VeRL training script run_qwen3_30b_a3b_npu_ma.sh.
    The content of the run_train_30b.sh script is as follows:
    #!/bin/bash
    set -e
    export HCCL_IF_BASE_PORT=61000
    export HCCL_NPU_SOCKET_PORT_RANGE="61000-61050"
    export HCCL_EXEC_TIMEOUT=60000
    export HCCL_CONNECT_TIMEOUT=7200
    unset https_proxy http_proxy proxy ASCEND_RT_VISIBLE_DEVICES
    source /usr/local/Ascend/ascend-toolkit/set_env.sh
    source /usr/local/Ascend/nnal/atb/set_env.sh
    export NNODES=${VC_WORKER_NUM:-1}
    export NGPUS_PER_NODE=${MA_NUM_GPUS:-8}
    export MASTER_ADDR="${VC_WORKER_HOSTS%%,*}"
    export DOMAIN_IP=$(python -c "import socket; print(socket.gethostbyname('${MASTER_ADDR}'))")
    export MASTER_NODE_IP="${DOMAIN_IP}"
    export MASTER_NODE_PORT="6699"
    export USE_OPTIMIZED_MODEL=0
    export VLLM_VERSION=0.16.0
    export PYTHONPATH="/home/ma-user/Megatron-LM:/home/ma-user/vllm${PYTHONPATH:+:${PYTHONPATH}}"
    MAX_WAIT_SECONDS=900
    CHECK_INTERVAL=3
    get_current_ip() {
        local ip
        ip=$(ip -4 addr | grep -v '127.0.0.1' | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 2>/dev/null)
        if [[ -z "$ip" ]]; then
            ip=$(ip -4 addr | grep -v '127.0.0.1' | awk '/inet/ {gsub(/\/.*/,""); print $2}' | head -n1 2>/dev/null)
        fi
        echo "${ip:-}"
    }
    CURRENT_IP=$(get_current_ip)
    if [[ -z "$CURRENT_IP" ]]; then
        echo "Failed to obtain the IP address of the current node."
        exit 1
    fi
    echo "current ip: $CURRENT_IP, master ip: $MASTER_NODE_IP"
    if [ "$CURRENT_IP" = "$MASTER_NODE_IP" ]; then
        echo "start Ray master node..."
        ray stop --force
        ray start --head --port="$MASTER_NODE_PORT"
        elapsed_seconds=0
        echo "wait $NNODES nodes..."
        while true; do
            current_node_num=$(ray status | grep -c "node_" || echo 0)
            if ! [[ "$current_node_num" =~ ^[0-9]+$ ]]; then
                current_node_num=0
            fi
            echo "current_node_num: $current_node_num"
            if [ "$current_node_num" -ge "$NNODES" ]; then
                echo "all $NNODES workers node is ready."
                break
            fi
            if [ "$elapsed_seconds" -ge "$MAX_WAIT_SECONDS" ]; then
                echo "timeout ($MAX_WAIT_SECONDS s), current_node_num: $current_node_num"
                ray stop --force
                exit 1
            fi
            sleep "$CHECK_INTERVAL"
            elapsed_seconds=$((elapsed_seconds + CHECK_INTERVAL))
        done
        echo "start job......"
        RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}  # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can also be customized.
        OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}               # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
        cd ${RAY_DATA_HOME}
        if [ ! -d "$OUTPUT_DIR/dataset/gsm8k/precessed" ]; then
            python3 gsm8k.py --local_dir "$OUTPUT_DIR/dataset/gsm8k/precessed"
        fi
        cp ${RAY_DATA_HOME}/run_qwen3_30b_a3b_npu_ma.sh /home/ma-user/verl/examples/grpo_trainer/run_qwen3_30b_a3b_npu_ma.sh
        cd /home/ma-user/verl
        cp verl/trainer/config/ppo_megatron_trainer.yaml .
        bash examples/grpo_trainer/run_qwen3_30b_a3b_npu_ma.sh
    else
        echo "start workers, connect to master: $MASTER_NODE_IP:$MASTER_NODE_PORT"
        ray start \
            --address="${MASTER_NODE_IP}:${MASTER_NODE_PORT}"
    fi
  • The run_qwen3_30b_a3b_npu_ma.sh script is used to start the VeRL reinforcement learning training job. Path Description describes the paths requiring modification.
    The content of the run_qwen3_30b_a3b_npu_ma.sh script is as follows:
    set -x
    project_name='GRPO-Qwen3'
    exp_name='GRPO-Qwen3-30B-A3B-npu'
    offload=True
    train_tp=4
    train_pp=2
    gen_tp=4
    RAY_DATA_HOME=${RAY_DATA_HOME:-"/home/ma-user/work/verl-a2"}                     # /home/ma-user/work is the local code directory configured when creating the ModelArts training job. This can be customized, but the path in the script must match the path set during training job creation. /verl-a2 is the name of the OBS folder used to store code, datasets, and model weights, which can be customized.
    OUTPUT_DIR=${OUTPUT_DIR:-"/output_dir/verl-a2"}                                  # /output_dir is the cloud mount path configured when mounting the OBS bucket (/verl-a2) during training job creation. It is used to save preprocessed data, checkpoints, and training logs, and can be customized.
    MODEL_PATH=${MODEL_PATH:-"${RAY_DATA_HOME}/models/Qwen3-30B-A3B"}                     # .../models/Qwen3-8B is the OBS folder where the model is stored, which can be customized.
    CKPTS_DIR=${CKPTS_DIR:-"${OUTPUT_DIR}/ckpts/${project_name}/${exp_name}"}        # .../ckpts is the OBS folder where training outputs are saved, which can be customized.
    TRAIN_FILE=${TRAIN_FILE:-"${OUTPUT_DIR}/dataset/gsm8k/precessed/train.parquet"}  # .../dataset/gsm8k is the OBS folder where the GSM8K training data is stored, which can be customized. /precessed/train.parquet is the preprocessed training data and does not need to be modified.
    TEST_FILE=${TEST_FILE:-"${OUTPUT_DIR}/dataset/gsm8k/precessed/test.parquet"}     # .../dataset/gsm8k is the OBS folder where the GSM8K training data is stored, which can be customized. /precessed/test.parquet is the preprocessed test data and does not need to be modified.
    
    python3 -m verl.trainer.main_ppo \
        --config-path=config \
        --config-name='ppo_megatron_trainer.yaml'\
        algorithm.adv_estimator=grpo \
        data.train_files="${TRAIN_FILE}" \
        data.val_files="${TEST_FILE}" \
        data.train_batch_size=32 \
        data.max_prompt_length=2048 \
        data.max_response_length=2048 \
        data.filter_overlong_prompts=True \
        data.truncation='error' \
        actor_rollout_ref.model.path=${MODEL_PATH} \
        actor_rollout_ref.actor.checkpoint.async_save=False \
        actor_rollout_ref.actor.optim.lr=1e-6 \
        actor_rollout_ref.model.use_remove_padding=True \
        actor_rollout_ref.actor.ppo_mini_batch_size=8 \
        actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.actor.megatron.param_offload=${offload} \
        actor_rollout_ref.actor.megatron.optimizer_offload=${offload} \
        actor_rollout_ref.actor.megatron.grad_offload=${offload} \
        actor_rollout_ref.actor.megatron.pipeline_model_parallel_size=${train_pp} \
        actor_rollout_ref.actor.megatron.tensor_model_parallel_size=${train_tp} \
        actor_rollout_ref.actor.megatron.expert_model_parallel_size=8 \
        actor_rollout_ref.actor.megatron.expert_tensor_parallel_size=1 \
        actor_rollout_ref.actor.use_kl_loss=True \
        actor_rollout_ref.actor.kl_loss_coef=0.001 \
        actor_rollout_ref.actor.kl_loss_type=low_var_kl \
        actor_rollout_ref.actor.entropy_coeff=0 \
        actor_rollout_ref.actor.use_torch_compile=False \
        actor_rollout_ref.actor.policy_loss.loss_mode=gspo \
        actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.rollout.tensor_model_parallel_size=${gen_tp} \
        actor_rollout_ref.rollout.name=vllm \
        actor_rollout_ref.rollout.gpu_memory_utilization=0.5 \
        actor_rollout_ref.rollout.n=4 \
        actor_rollout_ref.ref.use_torch_compile=False \
        actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=1 \
        actor_rollout_ref.ref.megatron.pipeline_model_parallel_size=${train_pp} \
        actor_rollout_ref.ref.megatron.tensor_model_parallel_size=${train_tp} \
        actor_rollout_ref.ref.megatron.expert_model_parallel_size=4 \
        actor_rollout_ref.ref.megatron.expert_tensor_parallel_size=1 \
        actor_rollout_ref.ref.megatron.param_offload=${offload} \
        actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes=4096 \
        reward.reward_manager.name=naive \
        actor_rollout_ref.ref.strategy=megatron \
        actor_rollout_ref.rollout.enforce_eager=True \
        ++actor_rollout_ref.ref.megatron.override_transformer_config.use_flash_attn=True \
        +actor_rollout_ref.actor.megatron.override_transformer_config.use_flash_attn=True \
        +actor_rollout_ref.actor.megatron.override_transformer_config.apply_rope_fusion=True \
        +actor_rollout_ref.actor.megatron.override_transformer_config.gradient_accumulation_fusion=True \
        +actor_rollout_ref.actor.megatron.override_transformer_config.use_fused_ring_attention_update=True \
        +actor_rollout_ref.actor.megatron.override_transformer_config.use_distributed_optimizer=True \
        +actor_rollout_ref.rollout.engine_kwargs.vllm.compilation_config.cudagraph_mode="FULL_AND_PIECEWISE" \
        algorithm.use_kl_in_reward=False \
        trainer.critic_warmup=0 \
        trainer.logger='["console"]' \
        trainer.project_name=${project_name} \
        trainer.experiment_name=${exp_name} \
        trainer.n_gpus_per_node=${NGPUS_PER_NODE} \
        trainer.nnodes=${NNODES} \
        trainer.default_local_dir=${CKPTS_DIR} \
        trainer.resume_mode=auto \
        trainer.val_before_train=False \
        trainer.save_freq=50 \
        trainer.test_freq=50 \
        trainer.total_epochs=1 \
        trainer.total_training_steps=50 \
        actor_rollout_ref.rollout.calculate_log_probs=True \
        actor_rollout_ref.actor.router_replay.mode=R3 \
        actor_rollout_ref.rollout.enable_rollout_routing_replay=True 2>&1 | tee ${OUTPUT_DIR}/run_qwen3_30b_a3b_npu_ma_r3.log
    
    sleep 20s
    if tail -n 100 ${OUTPUT_DIR}/run_qwen3_30b_a3b_npu_ma.log | grep -q 'Final validation metrics'; then
        exit 0
    else
        exit 1
    fi