# Other

## profiling_decorator[[trl.extras.profiling.profiling_decorator]]

#### trl.extras.profiling.profiling_decorator[[trl.extras.profiling.profiling_decorator]]

[Source](https://github.com/huggingface/trl/blob/v0.26.1/trl/extras/profiling.py#L71)

Decorator to profile a function and log execution time using [extras.profiling.profiling_context()](/docs/trl/v0.26.1/en/others#trl.extras.profiling.profiling_context).

Example:
```python
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
```

**Parameters:**

func (`Callable`) : Function to be profiled.

## profiling_context[[trl.extras.profiling.profiling_context]]

#### trl.extras.profiling.profiling_context[[trl.extras.profiling.profiling_context]]

[Source](https://github.com/huggingface/trl/blob/v0.26.1/trl/extras/profiling.py#L31)

A context manager function for profiling a block of code. Results are logged to Weights & Biases or MLflow
depending on the trainer's configuration.

Example:
```python
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
```

**Parameters:**

trainer (`~transformers.Trainer`) : Trainer object.

name (`str`) : Name of the block to be profiled. Used as a key in the logged dictionary.

