MCPcopy Create free account
hub / github.com/AMAP-ML/EMF / TrlParser

Class TrlParser

trl/trl/scripts/utils.py:114–261  ·  view source on GitHub ↗

A subclass of [`transformers.HfArgumentParser`] designed for parsing command-line arguments with dataclass-backed configurations, while also supporting configuration file loading and environment variable management. Args: dataclass_types (`Union[DataClassType, Iterable[DataClas

Source from the content-addressed store, hash-verified

112
113
114class TrlParser(HfArgumentParser):
115 """
116 A subclass of [`transformers.HfArgumentParser`] designed for parsing command-line arguments with dataclass-backed
117 configurations, while also supporting configuration file loading and environment variable management.
118
119 Args:
120 dataclass_types (`Union[DataClassType, Iterable[DataClassType]]` or `None`, *optional*, defaults to `None`):
121 Dataclass types to use for argument parsing.
122 **kwargs:
123 Additional keyword arguments passed to the [`transformers.HfArgumentParser`] constructor.
124
125 Examples:
126
127 ```yaml
128 # config.yaml
129 env:
130 VAR1: value1
131 arg1: 23
132 ```
133
134 ```python
135 # main.py
136 import os
137 from dataclasses import dataclass
138 from trl import TrlParser
139
140
141 @dataclass
142 class MyArguments:
143 arg1: int
144 arg2: str = "alpha"
145
146
147 parser = TrlParser(dataclass_types=[MyArguments])
148 training_args = parser.parse_args_and_config()
149
150 print(training_args, os.environ.get("VAR1"))
151 ```
152
153 ```bash
154 $ python main.py --config config.yaml
155 (MyArguments(arg1=23, arg2='alpha'),) value1
156
157 $ python main.py --arg1 5 --arg2 beta
158 (MyArguments(arg1=5, arg2='beta'),) None
159 ```
160 """
161
162 def __init__(
163 self,
164 dataclass_types: Optional[Union[DataClassType, Iterable[DataClassType]]] = None,
165 **kwargs,
166 ):
167 # Make sure dataclass_types is an iterable
168 if dataclass_types is None:
169 dataclass_types = []
170 elif not isinstance(dataclass_types, Iterable):
171 dataclass_types = [dataclass_types]

Callers 15

grpo_vlm.pyFile · 0.90
dpo_vlm.pyFile · 0.90
sft_vlm.pyFile · 0.90
sft_video_llm.pyFile · 0.90
mainFunction · 0.90
dpo_online.pyFile · 0.90
mpo_vlm.pyFile · 0.90
nash_md.pyFile · 0.90
gkd.pyFile · 0.90
xpo.pyFile · 0.90
make_parserFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected