TRL documentation
Other
You are viewing main version, which requires installation from source. If you'd like
regular pip install, checkout the latest stable version (v0.15.2).
Other
profiling_decorator
trl.extras.profiling.profiling_decorator
< source >( func: <built-in function callable> )
Decorator to profile a function and log execution time using extras.profiling.profiling_context().
Example:
from transformers import Trainer
from trl.extras.profiling import profiling_decorator
class MyTrainer(Trainer):
@profiling_decorator
def some_method(self):
A = np.random.rand(1000, 1000)
B = np.random.rand(1000, 1000)
# Code to profile: simulate a computationally expensive operation
result = A @ B
profiling_context
trl.extras.profiling.profiling_context
< source >( trainer: Trainer name: str )
A context manager function for profiling a block of code. Results are logged to Weights & Biases if enabled.
Example:
from transformers import Trainer
from trl.extras.profiling import profiling_context
class MyTrainer(Trainer):
def some_method(self):
A = np.random.rand(1000, 1000)
B = np.random.rand(1000, 1000)
with profiling_context(self, "matrix_multiplication"):
# Code to profile: simulate a computationally expensive operation
result = A @ B # Matrix multiplication