I just recently switch over to Google colab for the GPU, and I’m getting the following error for my notebook

  
      github.com
  
  
    maxmatical/pytorch-projects/blob/generative-models/DCGAN_with_GPU_Google_Colab.ipynb 5
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "DCGAN with GPU - Google Colab.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",


  This file has been truncated. show original

  
  
    
    
  
  


I have set my NNs to cuda, as well as all the variables, but I’m still getting the error
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-28-3334654f75a5> in <module>()
     32         # loss for fake images
     33         z = torch.randn(bs, 100).view(-1, 100, 1,1) # 100 is input channels for G
---> 34         fake_img = G(z)
     35         outputs = D(fake_img).view(-1,1,1,1)
     36         d_loss_fake = criterion(outputs, fake_labels)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

<ipython-input-10-ff06956ca9a4> in forward(self, input)
     42         self.tanh = nn.Tanh()
     43     def forward(self, input):
---> 44         out = self.relu(self.bn1(self.deconv1(input)))
     45         out = self.relu(self.bn2(self.deconv2(out)))
     46         out = self.relu(self.bn3(self.deconv3(out)))

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input, output_size)
    689         return F.conv_transpose2d(
    690             input, self.weight, self.bias, self.stride, self.padding,
--> 691             output_padding, self.groups, self.dilation)
    692 
    693 

RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'

NVM solved, one of the variables wasn’t set to CUDA. I forgot there were two z’s in the training