torch.accelerator.memory.memory_stats#
- torch.accelerator.memory.memory_stats(device_index=None, /)[原始碼]#
返回給定裝置索引的加速器裝置記憶體分配器統計資訊的字典。
此函式的返回值是一個統計字典,其中每個統計項都是一個非負整數。
核心統計資訊
"allocated.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 記憶體分配器接收到的分配請求數量。"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 已分配記憶體的大小。"segment.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 從裝置記憶體分配中預留的段數量。"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 已預留記憶體的大小。"active.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 活動記憶體塊的數量。"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 活動記憶體的大小。"inactive_split.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 非活動、不可釋放的記憶體塊的數量。"inactive_split_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}": 非活動、不可釋放的記憶體的大小。
對於這些核心統計資訊,值按以下方式細分。
記憶體池型別
all: 所有記憶體池的組合統計資訊。large_pool: 大型分配池的統計資訊(截至 2025 年 6 月,用於大小 >= 1MB 的分配)。small_pool: 小型分配池的統計資訊(截至 2025 年 6 月,用於大小 < 1MB 的分配)。
指標型別
current:此指標的當前值。peak:此指標的最大值。allocated:此指標的歷史總增長量。freed:此指標的歷史總減少量。
除了核心統計資料外,我們還提供了一些簡單的事件計數器
"num_alloc_retries": 導致快取重新整理並重試的裝置記憶體分配呼叫失敗次數。"num_ooms": 丟擲的記憶體不足錯誤數量。"num_sync_all_streams":synchronize_and_free_events呼叫次數。"num_device_alloc": 裝置記憶體分配呼叫次數。"num_device_free": 裝置記憶體釋放呼叫次數。
- 引數
device_index (
torch.device, str, int, optional) – 要定位的裝置索引。如果未給出,則預設使用torch.accelerator.current_device_index()。如果提供了torch.device或 str,則其型別必須與當前的 accelerator 裝置型別匹配。- 返回型別