Skip to content

Refactor vLLM generation [3/N]: Decouple profiling from trainer#4717

Merged
albertvillanova merged 8 commits into
huggingface:mainfrom
albertvillanova:refactor-profiling
Dec 19, 2025
Merged

Refactor vLLM generation [3/N]: Decouple profiling from trainer#4717
albertvillanova merged 8 commits into
huggingface:mainfrom
albertvillanova:refactor-profiling

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Dec 18, 2025

Copy link
Copy Markdown
Member

Refactor vLLM generation [3/N]: Decouple profiling from trainer.

Refactor profiling to remove the strong coupling to the trainer instance.

With this refactor, profiling_context now acts as a lightweight factory that builds a ProfilingContext instance populated with the relevant caller metadata (e.g. the trainer or other higher-level component). This object can be passed explicitly to composite attribute classes or downstream method calls, without requiring access to the full trainer. The callee can then enter the provided ProfilingContext as a context manager to measure and report execution duration in a uniform way, while remaining fully decoupled from the trainer implementation.

See relevant comment in:

Before:

  • profiling_context was tightly coupled to Trainer class
  • Required passing entire trainer instance
  • Mixed timing and logging concerns

After:

  • Created ProfilingContext class that's completely decoupled from Trainer
  • Takes only the data it needs via constructor parameters
  • Clean separation of concerns

@albertvillanova albertvillanova marked this pull request as ready for review December 19, 2025 07:02
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, in my understanding you don't need [1/N] and [2/N] to be merged before

Comment thread trl/extras/profiling.py Outdated
if "wandb" in trainer.args.report_to and wandb.run is not None and trainer.accelerator.is_main_process:
wandb.log(profiling_metrics)
context_name = f"{trainer.__class__.__name__}.{name}"
step = trainer.state.global_step if hasattr(trainer, "state") else None

@qgallouedec qgallouedec Dec 19, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe quick question here, when doesn't Trainer have a state?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm fixing that... Just "forced" the possibility of being None, but it is not necessary indeed.

@albertvillanova

Copy link
Copy Markdown
Member Author

Thanks, in my understanding you don't need [1/N] and [2/N] to be merged before

No, indeed I will update 1/N once this PR is merged.

@albertvillanova albertvillanova merged commit 29a39ab into huggingface:main Dec 19, 2025
7 of 9 checks passed
songhappy pushed a commit to songhappy/trl that referenced this pull request Apr 20, 2026
…ingface#4717)

Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com>
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