歡迎來到 TensorDict 文件!¶
TensorDict 是一個字典式類,它繼承了張量(tensor)的屬性,例如索引、形狀操作、裝置轉換等。
您可以直接從 PyPI 安裝 tensordict(有關安裝說明,請參見下文的專用部分)。
$ pip install tensordict
TensorDict 的主要目的是透過抽象定製化操作來使程式碼庫更易讀和模組化。
>>> for i, tensordict in enumerate(dataset):
... # the model reads and writes tensordicts
... tensordict = model(tensordict)
... loss = loss_module(tensordict)
... loss.backward()
... optimizer.step()
... optimizer.zero_grad()
透過這種級別的抽象,可以回收一個訓練迴圈用於高度異構的任務。訓練迴圈的每個單獨步驟(資料收集和轉換、模型預測、損失計算等)都可以針對當前用例進行定製,而不會影響其他步驟。例如,上述示例可以輕鬆地用於分類和分割任務,以及許多其他任務。
安裝¶
TensorDict 的釋出與 PyTorch 同步,因此請務必使用最新版本的 PyTorch 來享受該庫的最新功能(儘管核心功能保證向後相容 pytorch>=1.13)。可以透過以下方式安裝 nightly 版本:
$ pip install tensordict-nightly
或者,如果您願意為該庫做出貢獻,可以透過 git clone 進行安裝。
$ cd path/to/root
$ git clone https://github.com/pytorch/tensordict
$ cd tensordict
$ pip install -e .
教程¶
基礎知識¶
tensordict.nn¶
資料載入¶
目錄¶
- 概述
- 在分散式設定中使用 TensorDict
- 追蹤 TensorDictModule
- 儲存 TensorDict 和 tensorclass 物件
- API 參考
- tensordict 包
- tensordict.nn 包
- TensorDictModuleBase
- TensorDictModule
- ProbabilisticTensorDictModule
- ProbabilisticTensorDictSequential
- TensorDictSequential
- TensorDictModuleWrapper
- CudaGraphModule
- WrapModule
- InteractionType
- set_interaction_type
- set_composite_lp_aggregate
- composite_lp_aggregate
- as_tensordict_module
- 整合
- 編譯 TensorDictModules
- 分佈
- 工具
- tensorclass