TRL 文档

其他

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始入门

其他

profiling_decorator

trl.extras.profiling.profiling_decorator

< >

( func: <内置函数 callable> )

参数

  • func (callable) — 要进行性能分析的函数。

用于分析函数性能并使用 extras.profiling.profiling_context() 记录执行时间的装饰器。

示例

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

< >

( trainer: Trainer name: str )

参数

  • trainer (~transformers.Trainer) — Trainer 对象。
  • name (str) — 要进行性能分析的代码块的名称。用作记录字典中的键。

用于分析代码块性能的上下文管理器函数。如果启用,结果将记录到 Weights & Biases。

示例

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
< > 在 GitHub 上更新