欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pytorch cuda上tensor的定義 以及減少cpu的操作詳解

 更新時(shí)間:2020年06月23日 10:15:02   作者:枯葉蝶KYD  
這篇文章主要介紹了pytorch cuda上tensor的定義 以及減少cpu的操作詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

cuda上tensor的定義

a = torch.ones(1000,1000,3).cuda()

某一gpu上定義

cuda1 = torch.device('cuda:1')
b = torch.randn((1000,1000,1000),device=cuda1)

刪除某一變量

del a

在cpu定義tensor然后轉(zhuǎn)到gpu

torch.zeros().cuda()

直接在gpu上定義,這樣就減少了cpu的損耗

torch.cuda.FloatTensor(batch_size, self.hidden_dim, self.height, self.width).fill_(0)

補(bǔ)充知識(shí):pytorch cuda.FloatTensor->FloatTensor

錯(cuò)誤類型:

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)

定義殘差塊時(shí)定義在model的外面,在使用gpu進(jìn)行訓(xùn)練的時(shí)候,殘差塊的參數(shù)是torch.FloatTensor類型,

雖然使用了model.cuda(),但是只對model里面的參數(shù)在gpu部分,所以把殘差塊對應(yīng)的操作都在model的__init__(),

重新定義,即可解決問題

以上這篇pytorch cuda上tensor的定義 以及減少cpu的操作詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論