|
| 1 | +# Copyright 2020-2025 The HuggingFace Team. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from dataclasses import dataclass, field |
| 16 | + |
| 17 | +from transformers import TrainingArguments |
| 18 | + |
| 19 | + |
| 20 | +@dataclass |
| 21 | +class PRMConfig(TrainingArguments): |
| 22 | + r""" |
| 23 | + Configuration class for the [`experimental.prm.PRMTrainer`]. |
| 24 | +
|
| 25 | + This class includes only the parameters that are specific to PRM training. For a full list of training arguments, |
| 26 | + please refer to the [`~transformers.TrainingArguments`] documentation. Note that default values in this class may |
| 27 | + differ from those in [`~transformers.TrainingArguments`]. |
| 28 | +
|
| 29 | + Using [`~transformers.HfArgumentParser`] we can turn this class into |
| 30 | + [argparse](https://docs.python.org/3/library/argparse#module-argparse) arguments that can be specified on the |
| 31 | + command line. |
| 32 | +
|
| 33 | + Parameters: |
| 34 | + max_length (`int` or `None`, *optional*, defaults to `1024`): |
| 35 | + Maximum length of the sequences (prompt + completion) used for truncation. |
| 36 | + max_prompt_length (`int` or `None`, *optional*, defaults to `512`): |
| 37 | + Maximum length of the prompt used for truncation. |
| 38 | + max_completion_length (`int`, *optional*): |
| 39 | + Maximum length of the completion used for truncation. The completion is the concatenation of the steps. |
| 40 | + disable_dropout (`bool`, *optional*, defaults to `True`): |
| 41 | + Whether to disable dropout in the model. |
| 42 | + step_separator (`str`, *optional*, defaults to `"\n"`): |
| 43 | + Separator used to separate each step of the reasoning process. |
| 44 | + train_on_last_step_only (`bool`, *optional*, defaults to `False`): |
| 45 | + Whether to train only on the last step. |
| 46 | + dataset_num_proc (`int`, *optional*): |
| 47 | + Number of processes to use for processing the dataset. |
| 48 | + """ |
| 49 | + |
| 50 | + # Parameters whose default values are overridden from TrainingArguments |
| 51 | + learning_rate: float = field( |
| 52 | + default=1e-5, |
| 53 | + metadata={"help": "The initial learning rate for AdamW."}, |
| 54 | + ) |
| 55 | + logging_steps: float = field( |
| 56 | + default=10, |
| 57 | + metadata={ |
| 58 | + "help": "Log every X updates steps. Should be an integer or a float in range `[0,1)`. If smaller than 1, " |
| 59 | + "will be interpreted as ratio of total training steps." |
| 60 | + }, |
| 61 | + ) |
| 62 | + gradient_checkpointing: bool = field( |
| 63 | + default=True, |
| 64 | + metadata={ |
| 65 | + "help": "If True, use gradient checkpointing to save memory at the expense of slower backward pass." |
| 66 | + }, |
| 67 | + ) |
| 68 | + bf16: bool | None = field( |
| 69 | + default=None, |
| 70 | + metadata={ |
| 71 | + "help": "Whether to use bf16 (mixed) precision instead of 32-bit. Requires Ampere or higher NVIDIA " |
| 72 | + "architecture or Intel XPU or using CPU (use_cpu) or Ascend NPU. If not set, it defaults to `True` if " |
| 73 | + "`fp16` is not set." |
| 74 | + }, |
| 75 | + ) |
| 76 | + |
| 77 | + max_length: int | None = field( |
| 78 | + default=1024, |
| 79 | + metadata={"help": "Maximum length of the sequences (prompt + completion) used for truncation."}, |
| 80 | + ) |
| 81 | + max_prompt_length: int | None = field( |
| 82 | + default=512, |
| 83 | + metadata={"help": "Maximum length of the prompt used for truncation."}, |
| 84 | + ) |
| 85 | + max_completion_length: int | None = field( |
| 86 | + default=None, |
| 87 | + metadata={ |
| 88 | + "help": "Maximum length of the completion used for truncation. The completion is the concatenation of the " |
| 89 | + "steps." |
| 90 | + }, |
| 91 | + ) |
| 92 | + disable_dropout: bool = field( |
| 93 | + default=True, |
| 94 | + metadata={"help": "Whether to disable dropout in the model and reference model."}, |
| 95 | + ) |
| 96 | + step_separator: str = field( |
| 97 | + default="\n", |
| 98 | + metadata={"help": "Separator used to separate each step of the reasoning process."}, |
| 99 | + ) |
| 100 | + train_on_last_step_only: bool = field( |
| 101 | + default=False, |
| 102 | + metadata={"help": "Whether to train only on the last step."}, |
| 103 | + ) |
| 104 | + dataset_num_proc: int | None = field( |
| 105 | + default=None, |
| 106 | + metadata={"help": "Number of processes to use for processing the dataset."}, |
| 107 | + ) |
| 108 | + |
| 109 | + def __post_init__(self): |
| 110 | + self.bf16 = not (self.fp16) if self.bf16 is None else self.bf16 |
| 111 | + |
| 112 | + super().__post_init__() |
0 commit comments