TRL 文件

其他

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

其它

profiling_decorator

trl.extras.profiling.profiling_decorator

< >

( func: <built-in function 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) — 要進行效能分析的程式碼塊的名稱。用作日誌字典中的鍵。

一個用於分析程式碼塊效能的上下文管理器函式。結果將根據 trainer 的配置記錄到 Weights & Biases 或 MLflow 中。

示例

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

© . This site is unofficial and not affiliated with Hugging Face, Inc.