Refactor vLLM generation [3/N]: Decouple profiling from trainer#4717
Merged
albertvillanova merged 8 commits intohuggingface:mainfrom Dec 19, 2025
Merged
Refactor vLLM generation [3/N]: Decouple profiling from trainer#4717albertvillanova merged 8 commits intohuggingface:mainfrom
albertvillanova merged 8 commits intohuggingface:mainfrom
Conversation
|
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
approved these changes
Dec 19, 2025
Member
qgallouedec
left a comment
There was a problem hiding this comment.
Thanks, in my understanding you don't need [1/N] and [2/N] to be merged before
qgallouedec
reviewed
Dec 19, 2025
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 |
Member
There was a problem hiding this comment.
maybe quick question here, when doesn't Trainer have a state?
Member
Author
There was a problem hiding this comment.
I'm fixing that... Just "forced" the possibility of being None, but it is not necessary indeed.
Member
Author
No, indeed I will update 1/N once this PR is merged. |
qgallouedec
approved these changes
Dec 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor vLLM generation [3/N]: Decouple profiling from trainer.
Refactor profiling to remove the strong coupling to the trainer instance.
With this refactor,
profiling_contextnow acts as a lightweight factory that builds aProfilingContextinstance 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 providedProfilingContextas 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_contextwas tightly coupled toTrainerclassAfter:
ProfilingContextclass that's completely decoupled fromTrainer