Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Huggingface Open r1 TrlParser Usage

From Leeroopedia


Field Value
Sources Repo (https://github.com/huggingface/open-r1), Doc (https://huggingface.co/docs/trl)
Domains NLP, Infrastructure
Last Updated 2026-02-08 00:00 GMT

Overview

Wrapper for TRL's TrlParser that parses CLI arguments and YAML configs into Open-R1's extended configuration dataclasses.

Description

This is a Wrapper Doc. Open-R1 defines custom config dataclasses extending TRL's base classes:

  • ScriptArguments — adds dataset_mixture support.
  • GRPOScriptArguments — adds reward_funcs, code_provider, cosine parameters, and repetition parameters.
  • SFTConfig — adds benchmarks, callbacks, chat_template, and hub_model_revision.
  • GRPOConfig — adds num_completions_to_print, system_prompt, and wandb settings.

TrlParser is invoked with a tuple of these dataclass types, and parse_args_and_config() returns a tuple of instances.

Usage

Use at the __main__ entry point of sft.py, grpo.py, or compute_pass_rate.py.

Code Reference

Source

Repository File Lines Description
open-r1 src/open_r1/sft.py L167-168 SFT usage
open-r1 src/open_r1/grpo.py L179-180 GRPO usage
open-r1 src/open_r1/configs.py L22-331 Config dataclasses

Signature

# SFT usage:
parser = TrlParser((ScriptArguments, SFTConfig, ModelConfig))
script_args, training_args, model_args = parser.parse_args_and_config()

# GRPO usage:
parser = TrlParser((GRPOScriptArguments, GRPOConfig, ModelConfig))
script_args, training_args, model_args = parser.parse_args_and_config()

Import

from trl import TrlParser, ModelConfig
from open_r1.configs import ScriptArguments, SFTConfig, GRPOConfig, GRPOScriptArguments

I/O Contract

Inputs

Input Type Description
CLI arguments or YAML config file path sys.argv / file path Raw command-line arguments or a --config flag pointing to a YAML file
Dataclass types tuple tuple[type, ...] Tuple of dataclass types to parse into (e.g., (ScriptArguments, SFTConfig, ModelConfig))

Outputs

Output Type Description
Config tuple tuple[ScriptArguments, TrainingConfig, ModelConfig] Validated, typed configuration objects controlling all aspects of the training run

Usage Examples

Invoking via CLI with accelerate:

accelerate launch src/open_r1/sft.py --config recipes/OpenR1-Distill-7B/sft/config_distill.yaml

This command launches the SFT training script. TrlParser reads the YAML config file specified by --config, merges it with dataclass defaults and any additional CLI flags, validates the result, and returns the typed config tuple to the training function.

Related Pages

Principle:Huggingface_Open_r1_Configuration_Parsing

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment