Quick Start
This guide provides four end-to-end examples covering text, vision-language, omni-modal, and video training tasks. Each example includes data preparation, model download, and training launch commands.
Make sure you have completed the Installation steps before proceeding.
Task 1: DAPO Math (Text)
Train Qwen3-4B on the dapo-math-17k math reasoning dataset using GRPO with 8 GPUs.
Data Preparation
Download the training dataset and (optionally) the evaluation dataset:
# Download training dataset (dapo-math-17k)
hf download --repo-type dataset zhuzilin/dapo-math-17k \
--local-dir /root/dapo-math-17k
# Download evaluation dataset (aime-2024)
hf download --repo-type dataset zhuzilin/aime-2024 \
--local-dir /root/aime-2024
# Add math instruction prefix to the aime evaluation dataset (in-place)
python scripts/tools/process_aime.py --input /root/aime-2024/aime-2024.jsonlThe training dataset is in .jsonl format and can be used directly — no conversion required. The evaluation dataset needs the above script to prepend an instruction prefix that guides the model to produce answers in \boxed{} format.
Model Download
hf download Qwen/Qwen3-4B --local-dir /root/Qwen3-4BLaunch Training
Since the model and dataset are both downloaded to the /root directory, you only need to set EXP_DIR=/root and the script will automatically locate them — no manual script editing required.
Persistent Storage
Make sure the /root directory is mounted to persistent storage on the host, otherwise data will be lost when the container is destroyed. See the Docker mount instructions in the Installation Guide.
cd /root/Relax
export EXP_DIR=/root
# Single node
bash scripts/training/text/run-qwen3-4B-8xgpu.sh
# Multi-node
bash -x scripts/entrypoint/spmd-multinode.sh scripts/training/text/run-qwen3-4B-8xgpu.shReward Method
This task uses the built-in dapo reward type (see relax/engine/rewards/math_dapo_utils.py). It employs rule-based answer extraction and symbolic math verification to evaluate correctness, assigning 1.0 for correct answers and 0.0 for incorrect ones.
Task 2: Open-R1 (Vision-Language)
Train Qwen3-VL-4B on the multimodal-open-r1-8k-verified image + text dataset using GRPO with 8 GPUs.
Data Preparation
Download the dataset and convert it to the Relax format:
# Download dataset
hf download --repo-type dataset lmms-lab/multimodal-open-r1-8k-verified \
--local-dir /root/multimodal-open-r1-8k-verified
# Convert to Relax format
python scripts/tools/process_openr1.py \
--input-dir /root/multimodal-open-r1-8k-verified/data/train-00000-of-00001.parquet \
--output-dir /root/multimodal-open-r1-8k-verified/data/train-00000-of-00001_converted_noextract.parquetThe conversion script reads the raw parquet, extracts problem, image, and solution fields, and produces a new parquet with prompt, image, and label columns in the format expected by Relax.
Model Download
hf download Qwen/Qwen3-VL-4B-Instruct --local-dir /root/Qwen3-VL-4B-InstructLaunch Training
Since the model and dataset are both downloaded to the /root directory, you only need to set EXP_DIR=/root and the script will automatically locate them — no manual script editing required.
cd /root/Relax
export EXP_DIR=/root
# Single node
bash scripts/training/multimodal/run-qwen3-vl-4B-8xgpu.sh
# Multi-node
bash -x scripts/entrypoint/spmd-multinode.sh scripts/training/multimodal/run-qwen3-vl-4B-8xgpu.shReward Method
This task uses the built-in openr1mm reward type (see relax/engine/rewards/openr1mm.py). It extracts the final answer from <answer>...</answer> tags in both the ground-truth and model output. Symbolic verification via math_verify is attempted first; string matching serves as a fallback.
Overview
openr1mm_accuracy_format adds independent answer accuracy and format scores, each in [0, 1], for a total reward in [0, 2]. Its implementation is relax/engine/rewards/openr1mm.py. It preserves the experimental XML/prefilled-think scoring behavior; the existing openr1mm reward and its native-channel support remain unchanged.
Accuracy compares the final response and reference answer, not intermediate reasoning. Explicit multiple-choice labels are checked before mathematical equivalence with math_verify. Format requires one nonempty <think>...</think> block followed by one nonempty <answer>...</answer> block. A prompt-prefilled <think> opener and an optional trailing <|im_end|> are supported. Accuracy and format are independent: a wrong answer with valid format earns 1, as can a correct answer without that format. This is not a general semantic judge; mathematical extraction and text normalization have limits.
Evaluation uses separate local 0/1 accuracy on MathVista-testmini and MMMU validation. It calls no external model, adds no format point, and does not run the training dynamic sampling filter. The upstream Open-R1-Multimodal evaluation uses a different lmms-eval/GPT-4o protocol, including MMMU-Pro. These local scores are not directly comparable to that protocol.
Prepare Evaluation Data
Run from the repository root in the existing Relax environment (huggingface_hub, pyarrow, and Pillow are used). Keep images and converted data on storage shared by the training workers. Set DATA_DIR to your dataset root.
First convert the OpenR1MM training parquet if necessary; the overlap audit expects its image column to contain a list of encoded image bytes:
python scripts/tools/process_openr1.py \
--input-dir "$DATA_DIR/multimodal-open-r1-8k-verified/data/train-00000-of-00001.parquet" \
--output-dir "$DATA_DIR/multimodal-open-r1-8k-verified/data/train-00000-of-00001_converted_noextract.parquet"Download only the required evaluation splits, then convert and audit against the actual training parquet:
python scripts/tools/process_openr1.py --mode download-eval --output-dir "$DATA_DIR/openr1mm-eval"
python scripts/tools/process_openr1.py --mode prepare-eval \
--source "$DATA_DIR/openr1mm-eval/source" \
--train "$DATA_DIR/multimodal-open-r1-8k-verified/data/train-00000-of-00001_converted_noextract.parquet" \
--output-dir "$DATA_DIR/openr1mm-eval"The download defaults pin MathVista to 2b6ad69445fbb5695c9b165475e8decdbeb97747 and MMMU to 876ce5cb130f7f7e290ce4d9984357737d4db5cf. Override with --mathvista-revision / --mmmu-revision if needed; sources.json records resolved revisions. The downloader rejects nonempty source directories with unknown or different revisions; use a fresh --output-dir directory when changing revisions. Interrupted downloads at the same revision can resume. The converter emits:
mathvista_testmini.parquetandmmmu_validation.parquet: full converted splits.mathvista_testmini_disjoint.parquetandmmmu_validation_disjoint.parquet: rows with no exact training-image overlap.overlap-report.json: full/disjoint counts and excluded source IDs.
Each row contains prompt, image, JSON-encoded label, and source id. MMMU image references in questions and options are expanded in occurrence order. Overlap means identical decoded RGB pixels and dimensions, even across different encodings. A row is excluded if any referenced image overlaps. This does not remove resized, near-duplicate, or semantically overlapping problems.
One preparation against the verified 8k training set retained 997/1000 MathVista and 900/900 MMMU rows. Counts depend on the training file. Processor/tokenizer prompt-length filtering can reduce them further (that run evaluated 992 MathVista rows). Always check actual evaluated counts, not just parquet counts.
Training and Evaluation Configuration
In your model-specific training recipe, use --rm-type openr1mm_accuracy_format. To add evaluation, append these flags to the training command (retain your existing topology, optimizer, and dataset settings):
--rm-type openr1mm_accuracy_format \
--custom-rm-path relax.engine.rewards.openr1mm.get_openr1mm_benchmark_reward \
--eval-config "$DATA_DIR/openr1mm-eval/eval.yaml" \
--eval-interval 20 \
--eval-temperature 0 \
--n-samples-per-eval-prompt 1 \
--eval-max-prompt-len 8192 \
--eval-max-response-len 8192 \
--eval-max-context-len 16384 \
--sglang-context-length 16384Leave --skip-eval-before-train unset to evaluate before the first update. The YAML selects the two disjoint parquets with greedy decoding and one response per question. The engine context limit must accommodate evaluation; raising it does not raise the training rollout limits.
The converter also writes eval.yaml with absolute dataset paths. Use the generated file with --eval-config; the paths must be accessible on every worker. Preserve your model's chat template and multimodal mapping (--input-key prompt --label-key label --multimodal-keys '{"image":"image"}' --apply-chat-template). The original process_openr1.py --input-dir ... --output-dir ... invocation remains supported; --mode train is the default.
The custom reward routes samples tagged eval_benchmark by this YAML to local accuracy; ordinary training samples still call get_openr1mm_accuracy_format_reward. Do not attach this reserved metadata to training samples. DAPO filtering may still be enabled for training with --dynamic-sampling-filter-path relax.engine.filters.dynamic_sampling_filters.check_reward_nonzero_std; it is separate from evaluation.
Scoring and Troubleshooting
The evaluation scorer isolates the final answer, accepts a choice letter or exact option text, and also accepts B. option text only when both the letter and option text match. Conflicting letters/content and lists of alternatives must not receive credit. This avoids the observed false drop when a model changes from B to B. $7. Free-form scoring uses normalized exact text, candidate aliases, numeric comparison with MathVista precision, and list comparison; units, prose, and symbolic equivalence are not generally normalized.
When a score drops, compare identical prompts/labels, effective sample counts, truncation, and final-answer styles before diagnosing model regression. Evaluate historical outputs with the same scorer version; changing only the newest point produces an incomparable curve. Training reward can exceed 1 because it includes format, while these eval metrics cannot.
Run CPU regression checks with:
python -m pytest tests/cpu/engine/rewards/test_openr1mm.py tests/cpu/tools/test_process_openr1.pyTask 3: AVQA (Omni-Modal: Image + Audio)
Train Qwen3-Omni-30B-A3B on the AVQA-R1-6K image + audio question answering dataset using GRPO with 16 GPUs (2 nodes).
Data Preparation
Download the dataset and convert it to the Relax format:
# Download dataset
hf download --repo-type dataset harryhsing/AVQA-R1-6K \
--local-dir /root/AVQA
tar -zxvf /root/AVQA/AVQA_R1.tar.gz -C /root/AVQA
# Convert to Relax format
# --md-dir points to the directory containing image and audio files,
# used to join relative paths into absolute paths (Optional, default to use relative paths).
python scripts/tools/process_avqa.py \
--input-dir /root/AVQA/AVQA_R1/train/omni_rl_format_train.json \
--output-dir /root/AVQA/AVQA_R1/train/omni_rl_format_train_convert.jsonl \
--md-dir /root/AVQA/AVQA_R1/train
python scripts/tools/process_avqa.py \
--input-dir /root/AVQA/AVQA_R1/valid/omni_rl_format_valid.json \
--output-dir /root/AVQA/AVQA_R1/valid/small_valid.jsonl \
--md-dir /root/AVQA/AVQA_R1/validThe conversion script reads the raw JSON, extracts problem, options, image, and audio fields, and produces a .jsonl file with prompt, image, audio, and label columns.
Model Download
hf download Qwen/Qwen3-Omni-30B-A3B-Instruct --local-dir /root/Qwen3-Omni-30B-A3B-Instruct
# Qwen3-Omni ships its chat_template in a standalone chat_template.json that
# AutoTokenizer does not auto-load. Merge it into tokenizer_config.json (skipped if already present).
python -c "import json,sys; m=sys.argv[1]; p=f'{m}/tokenizer_config.json'; tc=json.load(open(p)); ('chat_template' in tc) or (tc.update(chat_template=json.load(open(f'{m}/chat_template.json'))['chat_template']) or json.dump(tc, open(p,'w'), indent=2, ensure_ascii=False))" /root/Qwen3-Omni-30B-A3B-InstructLaunch Training
Since the model and dataset are both downloaded to the /root directory, you only need to set EXP_DIR=/root and the script will automatically locate them — no manual script editing required.
cd /root/Relax
export EXP_DIR=/root
# Single node (requires 16 GPUs on a single machine)
bash scripts/training/multimodal/run-qwen3-30B-A3B-omni-16xgpu.sh
# Multi-node (recommended: 2 nodes × 8 GPUs)
bash -x scripts/entrypoint/spmd-multinode.sh scripts/training/multimodal/run-qwen3-30B-A3B-omni-16xgpu.shReward Method
This task uses the built-in multiple_choice reward type (see relax/engine/rewards/multiple_choice.py). It extracts the answer from <answer>...</answer> tags and performs exact string matching against the ground truth, assigning 1.0 for correct and 0.0 for incorrect.
Task 4: NextQA (Video)
Train the Qwen3-Omni-30B-A3B model using the GRPO algorithm on the TinyLLaVA-Video-R1-NextQA video question-answering dataset with 16 GPUs (2 nodes).
Data Preparation
Download the dataset and convert it to Relax format:
# Download the dataset
hf download --repo-type dataset Zhang199/TinyLLaVA-Video-R1-training-data \
--local-dir /root/NextQA
# Unzip video files
unzip /root/NextQA/NextQA.zip -d /root/NextQA
# Convert to Relax format
python scripts/tools/process_nextqa.py \
--input-dir /root/NextQAThe conversion script reads the original JSON file, extracts the question, options, and video fields, and generates a .jsonl file containing prompt, video, and label columns.
Model Download
hf download Qwen/Qwen3-Omni-30B-A3B-Instruct --local-dir /root/Qwen3-Omni-30B-A3B-Instruct
# Qwen3-Omni ships its chat_template in a standalone chat_template.json that
# AutoTokenizer does not auto-load. Merge it into tokenizer_config.json (skipped if already present).
python -c "import json,sys; m=sys.argv[1]; p=f'{m}/tokenizer_config.json'; tc=json.load(open(p)); ('chat_template' in tc) or (tc.update(chat_template=json.load(open(f'{m}/chat_template.json'))['chat_template']) or json.dump(tc, open(p,'w'), indent=2, ensure_ascii=False))" /root/Qwen3-Omni-30B-A3B-InstructLaunch Training
Since both the model and dataset are downloaded to the /root directory, simply set EXP_DIR=/root and the script will automatically locate the corresponding paths without manually editing the script.
cd /root/Relax
export EXP_DIR=/root
# Single node (requires 16 GPUs on a single machine)
bash scripts/training/multimodal/run-qwen3-30B-A3B-omni-16xgpu-video.sh
# Multi-node (recommended: 2 nodes × 8 GPUs)
bash -x scripts/entrypoint/spmd-multinode.sh scripts/training/multimodal/run-qwen3-30B-A3B-omni-16xgpu-video.shReward Method
This task uses the built-in multiple_choice reward type (see relax/engine/rewards/multiple_choice.py). It extracts the answer from <answer>...</answer> tags and performs exact string matching against the ground truth, assigning 1.0 for correct and 0.0 for incorrect.
Verifying Training Progress
After launching any of the above tasks, you should see logs like:
Finish rollout 0/200
training step 0/200This indicates training is running successfully.
Export Model
Checkpoints saved by Relax are in Megatron DCP format. To convert them to Hugging Face weight format, use the convert_torch_dist_to_hf_bridge.py script:
python scripts/tools/convert_torch_dist_to_hf_bridge.py \
--input-dir /path/to/dcp_checkpoint \
--output-dir /path/to/hf_output \
--origin-hf-dir /path/to/original_hf_modelThe script automatically prepends the Relax repository root to PYTHONPATH. Megatron-LM and Megatron Bridge must still be available in the current environment.
To export directly to FP8 without first writing an intermediate BF16 HF checkpoint, enable streaming FP8 conversion:
python scripts/tools/convert_torch_dist_to_hf_bridge.py \
--input-dir /path/to/dcp_checkpoint \
--origin-hf-dir /path/to/original_hf_model \
--output-dir /path/to/hf_output_fp8 \
--fp8 \
--fp8-strategy block \
--fp8-block-size 128 128 \
--fp8-device cuda \
--fp8-max-shard-size-mb 4096Parameter descriptions:
| Parameter | Description |
|---|---|
--input-dir | Megatron DCP format checkpoint directory |
--output-dir | Output directory for converted HF weights |
--origin-hf-dir | Original HF safetensors directory, used for architecture, expected weight keys, and tokenizer files |
--force | Optional, force overwrite if output directory already exists |
Note (MTP-free RL checkpoints): When the source checkpoint has no MTP weights (e.g. an RL/SFT checkpoint trained without MTP) while the reference model's config enables MTP, the converter automatically reconciles the exported
model.safetensors.index.jsonwith the tensors actually written and supplements the missing MTP weights from--origin-hf-dir, so the exported model loads cleanly (including EAGLE speculative decoding). The same reconciliation is applied to online--save-hfexports.
For the FP8 strategy options, memory behavior, output format, and an 8-GPU SGLang launch command, see Model Checkpoint Conversion.
Next Steps
- Customize Training — Learn how to customize training scripts, parameters, reward functions, and multi-node launch
- Model Checkpoint Conversion — Export and serve trained checkpoints
- Configuration — Full parameter reference
- Architecture — Understand the system design
