pytorch算子torch.arange在CPU?GPU?NPU中支持數(shù)據(jù)類型格式
正文
CPU(Central Processing Unit):中央處理器 GPU(Graphics Processing Unit):圖形處理器 NPU(Neural Network Processing Unit):神經(jīng)網(wǎng)絡(luò)處理器,是基于神經(jīng)網(wǎng)絡(luò)算法與加速的新型處理器總稱。
一、 torch.arange() 和 torch.range() 的用法
pytorch官網(wǎng)介紹:
torch.arange(start,end,step) 用于產(chǎn)生一個從start開始,到end結(jié)束(注意不包括end),步長為step的Tensor, 并且可以設(shè)置 Tensor 的 device 和 dtype
torch.arange 與 torch.range 功能及其相似,不同之處在于 torch.range(start,end,step) 生成的 Tensor, 包括 end
如:
a=torch.arange(1, 7, 2) b=torch.range(1, 7, 2) print(a) print(b)
輸出:
tensor([1, 3, 5]) tensor([1., 3., 5., 7.])
但是建議使用 torch.arange ,因為 torch.range 即將被pytorch 移除:
二、 torch.arange 支持的數(shù)據(jù)類型格式
只考慮 float 類型
cpu 不支持 float16,支持 float32 和 float64 cpu 支持 float16 、float32 和 float64 npu 不支持 float16 和 float64 ,只支持 float32
事實上 npu 基本不支持所有的 64位類型,包括 int64 和 float64,與算子無關(guān)。當然cpu 是支持 16位數(shù)據(jù)類型的,只是 torch.arange 不支持而已。
驗證代碼如下:
import torch # CPU a=torch.arange(1, 10, 2,device="cpu",dtype=torch.float16) # 不可以 a=torch.arange(1, 10, 2,device="cpu",dtype=torch.float32) # 可以 a=torch.arange(1, 10, 2,device="cpu",dtype=torch.float64) # 可以 # GPU a=torch.arange(1, 10, 2, device="cuda:0",dtype=torch.float16) # 可以 a=torch.arange(1, 10, 2, device="cuda:0",dtype=torch.float32) # 可以 a=torch.arange(1, 10, 2, device="cuda:0",dtype=torch.float64) # 可以 # NPU a=torch.arange(1, 10, 2, device="npu:0",dtype=torch.float16) # 不可以 a=torch.arange(1, 10, 2, device="npu:0",dtype=torch.float32) # 可以 a=torch.arange(1, 10, 2, device="npu:0",dtype=torch.float64) # 不可以 print(a)
以上就是pytorch算子torch.arange在CPU GPU NPU中支持數(shù)據(jù)類型格式的詳細內(nèi)容,更多關(guān)于pytorch算子支持數(shù)據(jù)類型格式的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python實現(xiàn)兩個list求交集,并集,差集的方法示例
這篇文章主要介紹了Python實現(xiàn)兩個list求交集,并集,差集的方法,結(jié)合實例形式分析了Python使用intersection、union及difference方法實現(xiàn)兩個集合list的交集、并集與差集操作技巧,需要的朋友可以參考下2018-08-08Python使用selenium + headless chrome獲取網(wǎng)頁內(nèi)容的方法示例
這篇文章主要介紹了Python使用selenium + headless chrome獲取網(wǎng)頁內(nèi)容的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10