|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field |
|
from typing import Optional |
|
|
|
from transformers import TrainingArguments |
|
|
|
|
|
@dataclass |
|
class OnlineDPOConfig(TrainingArguments): |
|
r""" |
|
Configuration class for the [`OnlineDPOTrainer`]. |
|
|
|
Using [`~transformers.HfArgumentParser`] we can turn this class into |
|
[argparse](https://docs.python.org/3/library/argparse#module-argparse) arguments that can be specified on the |
|
command line. |
|
|
|
Parameters: |
|
learning_rate (`float`, *optional*, defaults to `5e-7`): |
|
Initial learning rate for [`AdamW`] optimizer. The default value replaces that of |
|
[`~transformers.TrainingArguments`]. |
|
reward_model_path (`str` or `None`, *optional*, defaults to `None`): |
|
Path to the reward model. Either `judge` or `reward_model_path` must be set, but not both. |
|
judge (`str` or `None`, *optional*, defaults to `None`): |
|
Name of the judge to use. Either `judge` or `reward_model_path` must be set, but not both. |
|
max_new_tokens (`int`, *optional*, defaults to `64`): |
|
Maximum number of tokens to generate per completion. |
|
max_length (`int`, *optional*, defaults to `256`): |
|
Maximum total length of the sequence (prompt + completion) used to compute log probabilities. If the |
|
sequence exceeds this limit, the leftmost tokens will be truncated to preserve as much of the completion as |
|
possible. |
|
temperature (`float`, *optional*, defaults to `0.9`): |
|
Temperature for sampling. The higher the temperature, the more random the completions. |
|
missing_eos_penalty (`float` or `None`, *optional*, defaults to `None`): |
|
Penalty applied to the score when the model fails to generate an EOS token. This is useful to encourage |
|
to generate completions shorter than the maximum length (`max_new_tokens`). The penalty must be a positive |
|
value. |
|
beta (`float` or `list[float]`, *optional*, defaults to `0.1`): |
|
Parameter controlling the deviation from the reference model. Higher Ξ² means less deviation from the |
|
reference model. For the IPO loss (`loss_type="ipo"`), Ξ² is the regularization parameter denoted by Ο in |
|
the [paper](https://huggingface.co/papers/2310.12036). If a list of floats is provided then the Ξ² is |
|
selected for each new epoch and the last Ξ² is used for the rest of the epochs. |
|
loss_type (`str`, *optional*, defaults to `"sigmoid"`): |
|
Type of loss to use. Possible values are: |
|
|
|
- `"sigmoid"`: sigmoid loss from the original [DPO](https://huggingface.co/papers/2305.18290) paper. |
|
- `"ipo"`: IPO loss from the [IPO](https://huggingface.co/papers/2310.12036) paper. |
|
|
|
dataset_num_proc (`int` or `None`, *optional*, defaults to `None`): |
|
Number of processes to use for processing the dataset. |
|
disable_dropout (`bool`, *optional*, defaults to `True`): |
|
Whether to disable dropout in the model and reference model. |
|
use_vllm (`bool`, *optional*, defaults to `False`): |
|
Whether to use vLLM for generating completions. Requires vLLM to be installed (`pip install vllm`). |
|
gpu_memory_utilization (`float`, *optional*, defaults to `0.55`): |
|
The vLLM memory utilization. The default value is 0.55. |
|
ds3_gather_for_generation (`bool`, *optional*, defaults to `True`): |
|
This setting applies to DeepSpeed ZeRO-3. If enabled, the policy model weights are gathered for generation, |
|
improving generation speed. However, disabling this option allows training models that exceed the VRAM |
|
capacity of a single GPU, albeit at the cost of slower generation. |
|
""" |
|
|
|
learning_rate: float = field( |
|
default=5e-7, |
|
metadata={ |
|
"help": "Initial learning rate for `AdamW` optimizer. The default value replaces that of " |
|
"transformers.TrainingArguments." |
|
}, |
|
) |
|
reward_model_path: Optional[str] = field( |
|
default=None, |
|
metadata={ |
|
"help": "Path to the reward model. Either `judge` or `reward_model_path` must be set, but not both." |
|
}, |
|
) |
|
judge: Optional[str] = field( |
|
default=None, |
|
metadata={ |
|
"help": "Name of the judge to use. Either `judge` or `reward_model_path` must be set, but not both." |
|
}, |
|
) |
|
max_new_tokens: int = field( |
|
default=64, |
|
metadata={"help": "Maximum number of tokens to generate per completion."}, |
|
) |
|
max_length: int = field( |
|
default=512, |
|
metadata={ |
|
"help": "Maximum total length of the sequence (prompt + completion) used to compute log probabilities. If " |
|
"the sequence exceeds this limit, the leftmost tokens will be truncated to preserve as much of the " |
|
"completion as possible." |
|
}, |
|
) |
|
temperature: float = field( |
|
default=0.9, |
|
metadata={"help": "Temperature for sampling. The higher the temperature, the more random the completions."}, |
|
) |
|
missing_eos_penalty: Optional[float] = field( |
|
default=None, |
|
metadata={ |
|
"help": "Penalty applied to the score when the model fails to generate an EOS token. This is useful to " |
|
"encourage to generate completions shorter than the maximum length (`max_new_tokens`). The penalty must be " |
|
"a positive value." |
|
}, |
|
) |
|
beta: list[float] = field( |
|
default_factory=lambda: [0.1], |
|
metadata={ |
|
"help": "Parameter controlling the deviation from the reference model. Higher Ξ² means less deviation from " |
|
"the reference model. For the IPO loss (`loss_type='ipo'`), Ξ² is the regularization parameter denoted by " |
|
"Ο in the [paper](https://huggingface.co/papers/2310.12036). If a list of floats is provided then the Ξ² " |
|
"is selected for each new epoch and the last Ξ² is used for the rest of the epochs." |
|
}, |
|
) |
|
loss_type: str = field( |
|
default="sigmoid", |
|
metadata={ |
|
"help": "Type of loss to use.", |
|
"choices": ["sigmoid", "ipo"], |
|
}, |
|
) |
|
dataset_num_proc: Optional[int] = field( |
|
default=None, |
|
metadata={"help": "Number of processes to use for processing the dataset."}, |
|
) |
|
disable_dropout: bool = field( |
|
default=True, |
|
metadata={"help": "Whether to disable dropout in the model."}, |
|
) |
|
use_vllm: bool = field( |
|
default=False, |
|
metadata={ |
|
"help": "Whether to use vLLM for generating completions. Requires vLLM to be installed " |
|
"(`pip install vllm`)." |
|
}, |
|
) |
|
gpu_memory_utilization: Optional[float] = field( |
|
default=0.55, |
|
metadata={ |
|
"help": "The vLLM memory utilization. The default value is 0.55.", |
|
}, |
|
) |
|
ds3_gather_for_generation: bool = field( |
|
default=True, |
|
metadata={ |
|
"help": "This setting applies to DeepSpeed ZeRO-3. If enabled, the policy model weights are gathered for " |
|
"generation, improving generation speed. However, disabling this option allows training models that " |
|
"exceed the VRAM capacity of a single GPU, albeit at the cost of slower generation." |
|
}, |
|
) |
|
|
|
def __post_init__(self): |
|
super().__post_init__() |
|
if hasattr(self.beta, "__len__") and len(self.beta) == 1: |
|
self.beta = self.beta[0] |
|
|