generated from fastai/nbdev_template
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪪 Adds profiling decorators for GRPOTrainer (#2889)
* adds profiling decorator * naming + precommit * style * revert inclusion of slider table * revert 2 * revert3 * revert4 * revert 5 fml --------- Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
- Loading branch information
1 parent
9b3c5bf
commit a92e00e
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2025 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import functools | ||
import time | ||
|
||
from transformers import is_wandb_available | ||
|
||
|
||
if is_wandb_available(): | ||
import wandb | ||
|
||
|
||
def profiling_decorator(func): | ||
""" | ||
Decorator to profile a function and log the time taken to execute it. | ||
""" | ||
|
||
@functools.wraps(func) | ||
def wrapper(self, *args, **kwargs): | ||
start_time = time.perf_counter() | ||
result = func(self, *args, **kwargs) | ||
end_time = time.perf_counter() | ||
duration = end_time - start_time | ||
|
||
if "wandb" in self.args.report_to and wandb.run is not None and self.accelerator.is_main_process: | ||
wandb.log({f"profiling/Time taken: {self.__class__.__name__}.{func.__name__}": duration}) | ||
return result | ||
|
||
return wrapper |
This file contains 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