Buckets:
Scripts Utilities
ScriptArguments[[trl.ScriptArguments]]
class trl.ScriptArgumentstrl.ScriptArgumentsstr,, optional) --
Path or name of the dataset to load. If datasets is provided, this will be ignored.
- dataset_config (
str, optional) -- Dataset configuration name. Corresponds to thenameargument of the load_dataset function. Ifdatasetsis provided, this will be ignored. - dataset_train_split (
str, optional, defaults to"train") -- Dataset split to use for training. Ifdatasetsis provided, this will be ignored. - dataset_test_split (
str, optional, defaults to"test") -- Dataset split to use for evaluation. Ifdatasetsis provided, this will be ignored. - dataset_streaming (
bool, optional, defaults toFalse) -- Whether to stream the dataset. If True, the dataset will be loaded in streaming mode. Ifdatasetsis provided, this will be ignored. - gradient_checkpointing_use_reentrant (
bool, optional, defaults toFalse) -- Whether to applyuse_reentrantfor gradient checkpointing. - ignore_bias_buffers (
bool, optional, defaults toFalse) -- Debug argument for distributed training. Fix for DDP issues with LM bias/mask buffers - invalid scalar type, inplace operation. See https://github.com/huggingface/transformers/issues/22482#issuecomment-1595790992.0
Arguments common to all scripts.
TrlParser[[trl.TrlParser]]
class trl.TrlParsertrl.TrlParserUnion[DataClassType, Iterable[DataClassType]], optional) --
Dataclass types to use for argument parsing.
- **kwargs -- Additional keyword arguments passed to the transformers.HfArgumentParser constructor.0
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.
Examples:
# config.yaml
env:
VAR1: value1
arg1: 23
# main.py
import os
from dataclasses import dataclass
from trl import TrlParser
@dataclass
class MyArguments:
arg1: int
arg2: str = "alpha"
parser = TrlParser(dataclass_types=[MyArguments])
training_args = parser.parse_args_and_config()
print(training_args, os.environ.get("VAR1"))
$ python main.py --config config.yaml
(MyArguments(arg1=23, arg2='alpha'),) value1
$ python main.py --arg1 5 --arg2 beta
(MyArguments(arg1=5, arg2='beta'),) None
parse_args_and_configtrl.TrlParser.parse_args_and_config
Parse command-line args and config file into instances of the specified dataclass types.
This method wraps transformers.HfArgumentParser.parse_args_into_dataclasses and also parses the config file
specified with the --config flag. The config file (in YAML format) provides argument values that replace the
default values in the dataclasses. Command line arguments can override values set by the config file. The
method also sets any environment variables specified in the env field of the config file.
parse_args_into_dataclassestrl.TrlParser.parse_args_into_dataclasses
- return_remaining_strings -- If true, also return a list of remaining argument strings.
- look_for_args_file -- If true, will look for a ".args" file with the same base name as the entry point script for this process, and will append its potential content to the command line args.
- args_filename -- If not None, will uses this file instead of the ".args" file specified in the previous argument.
- args_file_flag -- If not None, will look for a file in the command-line args specified with this flag. The flag can be specified multiple times and precedence is determined by the order (last one wins).0Tuple consisting of- the dataclass instances in the same order as they were passed to the initializer.abspath
- if applicable, an additional namespace for more (non-dataclass backed) arguments added to the parser after initialization.
- The potential list of remaining argument strings. (same as argparse.ArgumentParser.parse_known_args)
Parse command-line args into instances of the specified dataclass types.
This relies on argparse's ArgumentParser.parse_known_args. See the doc at:
docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args
set_defaults_with_configtrl.TrlParser.set_defaults_with_config
Overrides the parser's default values with those provided via keyword arguments, including for subparsers.
Any argument with an updated default will also be marked as not required if it was previously required.
Returns a list of strings that were not consumed by the parser.
get_dataset[[trl.get_dataset]]
trl.get_datasettrl.get_datasettest_split_size is
set.
Load a mixture of datasets based on the configuration.
Example:
from trl import DatasetMixtureConfig, get_dataset
from trl.scripts.utils import DatasetConfig
mixture_config = DatasetMixtureConfig(datasets=[DatasetConfig(path="trl-lib/tldr")])
dataset = get_dataset(mixture_config)
print(dataset)
DatasetDict({
train: Dataset({
features: ['prompt', 'completion'],
num_rows: 116722
})
})
DatasetConfig[[trl.scripts.utils.DatasetConfig]]
class trl.scripts.utils.DatasetConfigtrl.scripts.utils.DatasetConfigstr) --
Path or name of the dataset.
- name (
str, optional) -- Defining the name of the dataset configuration. - data_dir (
str, optional) -- Defining thedata_dirof the dataset configuration. If specified for the generic builders(csv, text etc.) or the Hub datasets anddata_filesisNone, the behavior is equal to passingos.path.join(data_dir, **)asdata_filesto reference all the files in a directory. - data_files (
strorSequenceorMapping, optional) -- Path(s) to source data file(s). - split (
str, optional, defaults to"train") -- Which split of the data to load. - columns (
list[str], optional) -- List of column names to select from the dataset. IfNone, all columns are selected.0
Configuration for a dataset.
This class matches the signature of load_dataset and the arguments are used directly in the load_dataset function. You can refer to the load_dataset documentation for more details.
DatasetMixtureConfig[[trl.DatasetMixtureConfig]]
class trl.DatasetMixtureConfigtrl.DatasetMixtureConfiglist[DatasetConfig]) --
List of dataset configurations to include in the mixture.
- streaming (
bool, optional, defaults toFalse) -- Whether to stream the datasets. IfTrue, the datasets will be loaded in streaming mode. - test_split_size (
float, optional) -- Size of the test split. Refer to thetest_sizeparameter in thetrain_test_splitfunction for more details. IfNone, the dataset will not be split into train and test sets.0
Configuration class for a mixture of datasets.
Using HfArgumentParser we can turn this class into argparse arguments that can be specified on the command line.
Usage:
When using the CLI, you can add the following section to your YAML config file:
datasets:
- path: ...
name: ...
data_dir: ...
data_files: ...
split: ...
columns: ...
- path: ...
name: ...
data_dir: ...
data_files: ...
split: ...
columns: ...
streaming: ...
test_split_size: ...
Xet Storage Details
- Size:
- 13.7 kB
- Xet hash:
- 4a3c212d3dc052805ab876bcd6de173da412c4c7dd1ae8b7e34aeea6b05d2df7
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.