Why can't self defined layers run on GPUs



def forward( self, x ):
start = time.time()
out = self.Rconv2d( x )
cost = time.time()-start
out = self.maxpool1( out )
out = self.block1( out )
out = self.block2( out )
out = self.block3( out )
out = F.avg_pool2d( out, 7 )
out = out.view( out.size(0), -1 )
out = self.out_layer( out )
total_cost = time.time()-start

print(cost/total_cost)
return out

最后使用time模块查看该层执行效率,发现这个变换层模块占了模型99.9%的时间

From Google translate:

Finally, use the time module to check the execution efficiency of this layer and find that this transformation layer module accounts for 99.9% of the model’s time

Could you please use an online translate service, so that we could support you? :slight_smile:

Custom layers can run on the GPU. However, since CUDA operations are asynchronous, you would have to synchronize the code via torch.cuda.synchronize() before starting and stopping the timer.

Also, please post code snippets by wrapping them into three backticks ```, which makes debugging easier.

1 Like

thanks for your reply. l will check my code