Skip to content

Conversation

parambharat
Copy link
Contributor

What does this PR do?

This PR adds a new WeaveCallback that integrates TRL trainers with W&B Weave to trace of model predictions and evaluations during training.

Key features:

  • Tracing Mode: Logs prompts and model completions to weave to simplify debugging.
  • Evaluation Mode: Logs predictions with custom scoring functions and summary metrics
  • Uses Weave's EvaluationLogger for consistent, structured data logging

Changes:

  • Added WeaveCallback class in trl/trainer/callbacks.py
  • Added is_weave_available() utility in trl/import_utils.py
  • Exported WeaveCallback in trl/trainer/__init__.py

Usage:

# Tracing mode (predictions only)
weave_callback = WeaveCallback(trainer=trainer)

# Evaluation mode (predictions + custom scoring)
weave_callback = WeaveCallback(
    trainer=trainer,
    scorers={"accuracy": accuracy_scorer}
)
trainer.add_callback(weave_callback)

The callback requires trainers to have an evaluation dataset with a "prompt" column and generates completions during evaluation steps for logging to Weave.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR. - @qgallouedec cc: @ayulockin

@parambharat parambharat marked this pull request as ready for review September 17, 2025 06:47
Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@qgallouedec qgallouedec changed the title feat: Add WeaveCallback for W&B Weave integration 🧶 feat: Add WeaveCallback for W&B Weave integration Sep 17, 2025
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec qgallouedec merged commit 08ea002 into huggingface:main Sep 18, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants