diff --git a/trl/trainer/grpo_config.py b/trl/trainer/grpo_config.py index f9edc2a3e05..2d97d67bd8e 100644 --- a/trl/trainer/grpo_config.py +++ b/trl/trainer/grpo_config.py @@ -258,9 +258,20 @@ class GRPOConfig(TrainingArguments): `trackio`. num_completions_to_print (`int`, *optional*): Number of completions to print with `rich`. If `None`, all completions are logged. - wandb_log_unique_prompts (`bool`, *optional*, defaults to `False`): - Whether to log unique prompts in wandb. If `True`, only unique prompts are logged. If `False`, all prompts - are logged. + log_unique_prompts (`bool`, *optional*, defaults to `False`): + Whether to log unique prompts. If `True`, only unique prompts are logged. If `False`, all prompts are + logged. + + > Deprecated arguments + + wandb_log_unique_prompts (`bool`, *optional*): + + + + Parameter `wandb_log_unique_prompts` is deprecated and will be removed in version 0.27.0. Use + `log_unique_prompts` instead. + + """ _VALID_DICT_FIELDS = TrainingArguments._VALID_DICT_FIELDS + ["model_init_kwargs"] @@ -681,14 +692,19 @@ class GRPOConfig(TrainingArguments): default=None, metadata={"help": "Number of completions to print with `rich`. If `None`, all completions are logged."}, ) - wandb_log_unique_prompts: bool | None = field( + log_unique_prompts: bool = field( default=False, metadata={ - "help": "Whether to log unique prompts in wandb. If `True`, only unique prompts are logged. If `False`, " - "all prompts are logged." + "help": "Whether to log unique prompts. If `True`, only unique prompts are logged. If `False`, all prompts are logged." }, ) + # Deprecated arguments + wandb_log_unique_prompts: bool | None = field( + default=None, + metadata={"help": "Deprecated, use `log_unique_prompts` instead."}, + ) + def __post_init__(self): self.bf16 = not (self.fp16) if self.bf16 is None else self.bf16 @@ -751,3 +767,12 @@ def __post_init__(self): if self.delta is not None and self.use_liger_kernel: raise ValueError("Liger kernel does not support two-sided GRPO loss yet.") + + if self.wandb_log_unique_prompts is not None: + warnings.warn( + "The `wandb_log_unique_prompts` argument is deprecated and will be removed in version 0.27.0. Please " + "use `log_unique_prompts` instead.", + FutureWarning, + stacklevel=2, + ) + self.log_unique_prompts = self.wandb_log_unique_prompts diff --git a/trl/trainer/grpo_trainer.py b/trl/trainer/grpo_trainer.py index 856a7aad224..6b245b3511c 100644 --- a/trl/trainer/grpo_trainer.py +++ b/trl/trainer/grpo_trainer.py @@ -532,7 +532,7 @@ def cast_outputs_to_original_dtype(module, args, output): self._metrics = {"train": defaultdict(list), "eval": defaultdict(list)} self._total_train_tokens = 0 self.log_completions = args.log_completions - self.wandb_log_unique_prompts = args.wandb_log_unique_prompts + self.log_unique_prompts = args.log_unique_prompts self.num_completions_to_print = args.num_completions_to_print # Keep logs sized to the generation batch to record only outputs from the latest model update. self._logs = { @@ -1973,7 +1973,7 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None: else: df = df_base - if self.wandb_log_unique_prompts: + if self.log_unique_prompts: df = df.drop_duplicates(subset=["prompt"]) logging_backend.log({"completions": logging_backend.Table(dataframe=df)}) diff --git a/trl/trainer/rloo_config.py b/trl/trainer/rloo_config.py index 6a101ae0583..eb893c604c8 100644 --- a/trl/trainer/rloo_config.py +++ b/trl/trainer/rloo_config.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import warnings from dataclasses import dataclass, field from transformers import TrainingArguments @@ -191,9 +192,20 @@ class RLOOConfig(TrainingArguments): `trackio`. num_completions_to_print (`int`, *optional*): Number of completions to print with `rich`. If `None`, all completions are logged. - wandb_log_unique_prompts (`bool`, *optional*, defaults to `False`): - Whether to log unique prompts in wandb. If `True`, only unique prompts are logged. If `False`, all prompts - are logged. + log_unique_prompts (`bool`, *optional*, defaults to `False`): + Whether to log unique prompts. If `True`, only unique prompts are logged. If `False`, all prompts are + logged. + + > Deprecated arguments + + wandb_log_unique_prompts (`bool`, *optional*): + + + + Parameter `wandb_log_unique_prompts` is deprecated and will be removed in version 0.27.0. Use + `log_unique_prompts` instead. + + """ _VALID_DICT_FIELDS = TrainingArguments._VALID_DICT_FIELDS + ["model_init_kwargs"] @@ -530,14 +542,20 @@ class RLOOConfig(TrainingArguments): default=None, metadata={"help": "Number of completions to print with `rich`. If `None`, all completions are logged."}, ) - wandb_log_unique_prompts: bool | None = field( + log_unique_prompts: bool = field( default=False, metadata={ - "help": "Whether to log unique prompts in wandb. If `True`, only unique prompts are logged. If `False`, " - "all prompts are logged." + "help": "Whether to log unique prompts. If `True`, only unique prompts are logged. If `False`, all " + "prompts are logged." }, ) + # Deprecated arguments + wandb_log_unique_prompts: bool | None = field( + default=None, + metadata={"help": "Deprecated, use `log_unique_prompts` instead."}, + ) + def __post_init__(self): self.bf16 = not (self.fp16) if self.bf16 is None else self.bf16 @@ -586,3 +604,12 @@ def __post_init__(self): "RLOO requires at least 2 generations per prompt to calculate the advantages. You provided " f"{self.num_generations}, which is less than the minimum required." ) + + if self.wandb_log_unique_prompts is not None: + warnings.warn( + "The `wandb_log_unique_prompts` argument is deprecated and will be removed in version 0.27.0. Please " + "use `log_unique_prompts` instead.", + FutureWarning, + stacklevel=2, + ) + self.log_unique_prompts = self.wandb_log_unique_prompts diff --git a/trl/trainer/rloo_trainer.py b/trl/trainer/rloo_trainer.py index e2c38a03555..7203862fa1d 100644 --- a/trl/trainer/rloo_trainer.py +++ b/trl/trainer/rloo_trainer.py @@ -449,7 +449,7 @@ def __init__( self._metrics = {"train": defaultdict(list), "eval": defaultdict(list)} self._total_train_tokens = 0 self.log_completions = args.log_completions - self.wandb_log_unique_prompts = args.wandb_log_unique_prompts + self.log_unique_prompts = args.log_unique_prompts self.num_completions_to_print = args.num_completions_to_print # Keep logs sized to the generation batch to record only outputs from the latest model update. self._logs = { @@ -1564,7 +1564,7 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None: else: df = df_base - if self.wandb_log_unique_prompts: + if self.log_unique_prompts: df = df.drop_duplicates(subset=["prompt"]) logging_backend.log({"completions": logging_backend.Table(dataframe=df)})