Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 22 additions & 27 deletions trl/trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,12 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None:
self.num_completions_to_print,
)

logging_backends = []
if self.args.report_to and "wandb" in self.args.report_to and wandb.run is not None:
logging_backends.append(wandb)
if self.args.report_to and "trackio" in self.args.report_to:
logging_backends.append(trackio)

table = {
"step": [str(self.state.global_step)] * len(self._logs["prompt"]),
"prompt": self._logs["prompt"],
Expand All @@ -1950,34 +1956,23 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None:
df_base = pd.DataFrame(table)
images_raw = self._logs["images"] or []

for logging_backend in self.args.report_to:
if logging_backend == "wandb":
if images_raw:
images = []
for image_list in self._logs["images"]:
images.append([wandb.Image(image) for image in image_list])
df = pd.concat([df_base, pd.Series(images, name="image")], axis=1, copy=False)
else:
df = df_base

if self.wandb_log_unique_prompts:
df = df.drop_duplicates(subset=["prompt"])

wandb.log({"completions": wandb.Table(dataframe=df)})

if logging_backend == "trackio":
if images_raw:
# TODO: Implement once supported upstream https://github.com/gradio-app/trackio/issues/334
logger.info("Skipping image logging for Trackio")
df = df_base
# images = []
# for image_list in self._logs["images"]:
# images.append([trackio.Image(image) for image in image_list])
# df = pd.concat([df_base, pd.Series(images, name="image")], axis=1, copy=False)
Comment thread
qgallouedec marked this conversation as resolved.
else:
df = df_base
for logging_backend in logging_backends:
if images_raw:
images = []
for image_list in self._logs["images"]:
images.append([logging_backend.Image(image) for image in image_list])
df = pd.concat(
[df_base, pd.Series(images, name="image")],
axis=1,
copy=False,
)
else:
df = df_base

if self.wandb_log_unique_prompts:
df = df.drop_duplicates(subset=["prompt"])

trackio.log({"completions": trackio.Table(dataframe=df)})
logging_backend.log({"completions": logging_backend.Table(dataframe=df)})

# Ensure the model card is saved along with the checkpoint
def _save_checkpoint(self, model, trial):
Expand Down
49 changes: 22 additions & 27 deletions trl/trainer/rloo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,12 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None:
self.num_completions_to_print,
)

logging_backends = []
if self.args.report_to and "wandb" in self.args.report_to and wandb.run is not None:
logging_backends.append(wandb)
if self.args.report_to and "trackio" in self.args.report_to:
logging_backends.append(trackio)

table = {
"step": [str(self.state.global_step)] * len(self._logs["prompt"]),
"prompt": self._logs["prompt"],
Expand All @@ -1545,34 +1551,23 @@ def log(self, logs: dict[str, float], start_time: float | None = None) -> None:
df_base = pd.DataFrame(table)
images_raw = self._logs["images"] or []

for logging_backend in self.args.report_to:
if logging_backend == "wandb":
if images_raw:
images = []
for image_list in self._logs["images"]:
images.append([wandb.Image(image) for image in image_list])
df = pd.concat([df_base, pd.Series(images, name="image")], axis=1, copy=False)
else:
df = df_base

if self.wandb_log_unique_prompts:
df = df.drop_duplicates(subset=["prompt"])

wandb.log({"completions": wandb.Table(dataframe=df)})

if logging_backend == "trackio":
if images_raw:
# TODO: Implement once supported upstream https://github.com/gradio-app/trackio/issues/334
logger.info("Skipping image logging for Trackio")
df = df_base
# images = []
# for image_list in self._logs["images"]:
# images.append([trackio.Image(image) for image in image_list])
# df = pd.concat([df_base, pd.Series(images, name="image")], axis=1, copy=False)
else:
df = df_base
for logging_backend in logging_backends:
if images_raw:
images = []
for image_list in self._logs["images"]:
images.append([logging_backend.Image(image) for image in image_list])
df = pd.concat(
[df_base, pd.Series(images, name="image")],
axis=1,
copy=False,
)
else:
df = df_base

if self.wandb_log_unique_prompts:
df = df.drop_duplicates(subset=["prompt"])

trackio.log({"completions": trackio.Table(dataframe=df)})
logging_backend.log({"completions": logging_backend.Table(dataframe=df)})

# Ensure the model card is saved along with the checkpoint
def _save_checkpoint(self, model, trial):
Expand Down
Loading