Skip to content

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

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

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

Conversation

@albertvillanova
Copy link
Member

@albertvillanova albertvillanova commented Dec 18, 2025

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

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.

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.

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

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
Copy link
Member

@qgallouedec qgallouedec Dec 19, 2025

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
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
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
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