Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions trl/trainer/grpo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,19 @@ class GRPOConfig(TrainingArguments):
`trackio`.
num_completions_to_print (`int`, *optional*):
Number of completions to print with `rich`. If `None`, all completions 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.
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.
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
Comment thread
qgallouedec marked this conversation as resolved.
Outdated

<Deprecated version="0.26.0">

Parameter `wandb_log_unique_prompts` is deprecated and will be removed in version 0.x.0. Use
`log_unique_prompts` instead.

</Deprecated>
"""

_VALID_DICT_FIELDS = TrainingArguments._VALID_DICT_FIELDS + ["model_init_kwargs"]
Expand Down Expand Up @@ -671,13 +681,16 @@ 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."
},
)
wandb_log_unique_prompts: bool | None = field(
Comment thread
qgallouedec marked this conversation as resolved.
default=False,
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
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
Expand Down Expand Up @@ -741,3 +754,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 False:
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
warnings.warn(
"The `wandb_log_unique_prompts` argument is deprecated and will be removed in version 0.x.0. Please use "
"`log_unique_prompts` instead.",
FutureWarning,
stacklevel=2,
)
self.log_unique_prompts = self.wandb_log_unique_prompts
4 changes: 2 additions & 2 deletions trl/trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -1969,7 +1969,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)})
Expand Down
29 changes: 26 additions & 3 deletions trl/trainer/rloo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,9 +192,19 @@ class RLOOConfig(TrainingArguments):
`trackio`.
num_completions_to_print (`int`, *optional*):
Number of completions to print with `rich`. If `None`, all completions 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.
wandb_log_unique_prompts (`bool`, *optional*, defaults to `False`):
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
Whether to log unique prompts in wandb. If `True`, only unique prompts are logged. If `False`, all prompts
are logged.
Comment thread
qgallouedec marked this conversation as resolved.
Outdated

<Deprecated version="0.26.0">

Parameter `wandb_log_unique_prompts` is deprecated and will be removed in version 0.x.0. Use
`log_unique_prompts` instead.

</Deprecated>
"""

_VALID_DICT_FIELDS = TrainingArguments._VALID_DICT_FIELDS + ["model_init_kwargs"]
Expand Down Expand Up @@ -520,13 +531,16 @@ 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."
},
)
wandb_log_unique_prompts: bool | None = field(
default=False,
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
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
Expand Down Expand Up @@ -576,3 +590,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 False:
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
warnings.warn(
"The `wandb_log_unique_prompts` argument is deprecated and will be removed in version 0.x.0. Please use "
"`log_unique_prompts` instead.",
FutureWarning,
stacklevel=2,
)
self.log_unique_prompts = self.wandb_log_unique_prompts
4 changes: 2 additions & 2 deletions trl/trainer/rloo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)})
Expand Down
Loading