Issues with using cuda and float tensor
I have some code, and when I run it, I get the following error: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #2 'other'

From this error message, I assume there a problem with pushing my models to the GPU. However, I am not sure precisely where the problem lies. 

I will place the code wherein I think the problem may lie at the end of this question. Could someone please describe what the error exactly means and how to fix it? Any help is much appreciated. 

class VGG(nn.Module):
    '''
    VGG model 
    '''
    def __init__(self, features): # features represents the layers array
        super(VGG, self).__init__()
        self.features = features
        self.classifier = nn.Sequential(
            nn.Dropout(),
            nn.Linear(512,512),
            nn.ReLU(True),
            nn.Dropout(),
            nn.Linear(512, 512),
            nn.ReLU(True),
            nn.Linear(512, 10),
        )
         # Initialize weights
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                m.weight.data.normal_(0, math.sqrt(2. / n))
                m.bias.data.zero_()


    def forward(self, x): # x is the image, we run x through the layers
        print("Running through features")
        x = self.features(x) # runs through all features, where each feature is a function
        print("Finsihed features, going to classifier")
        x = x.view(x.size(0), -1) 
        # after running through features, does sequential steps to finally classify
        x = self.classifier(x)
        return x


def make_layers(cfg, batch_norm=False):
   # print("Making layers!")
    layers = []
    in_channels = 3
    for v in cfg:
        if v == 'M':
            layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        else:
            conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
            if batch_norm:
                layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)]
            else:
                layers += [conv2d, nn.ReLU(inplace=True)]
            in_channels = v
            rlstm =RLSTM(v)
            rlstm.input_to_state = torch.nn.DataParallel(rlstm.input_to_state)
            rlstm.state_to_state = torch.nn.DataParallel(rlstm.state_to_state)
            rlstm=rlstm.cuda()
            layers+=[rlstm]

    return nn.Sequential(*layers)

class RLSTM(nn.Module):
    def __init__(self,ch):
       # torch.set_default_tensor_type('torch.cuda.FloatTensor')
        super(RLSTM,self).__init__()
        self.ch=ch
        self.input_to_state = torch.nn.Conv2d(self.ch,4*self.ch,kernel_size=(1,3),padding=(0,1))
        self.state_to_state = torch.nn.Conv2d(self.ch,4*self.ch,kernel_size=(1,3),padding=(0,1)) # error is here: hidPrev is an array - not a valid number of input channel
       # self.input_to_state = self.input_to_state.cuda()
        #self.state_to_state = self.state_to_state.cuda()

    def forward(self, image):
      #  print("going in row forward")
        global current
        global _layer
        global isgates
        size = image.size()
        print("size: "+str(size))
        b = size[0]
        indvs = list(image.split(1,0)) # split up the batch into individual images
        #print(indvs[0].size())
        tensor_array = []
        for i in range(b):
            current = 0
            _layer = []
            isgates = []
            print(len(tensor_array))
            tensor_array.append(self.RowLSTM(indvs[i]))

        seq=tuple(tensor_array)
        trans = torch.cat(seq,0)
        print(trans.size())
        return trans.cuda() # trying to make floattensor error go away 
    def RowLSTM(self, image): 
    #    print("going in rowlstm")
        global current
        global _layer
        global isgates


        # input-to-state (K_is * x_i) : 3x1 convolution. generate 4h x n x n tensor. 4hxnxn tensor contains all i -&gt; s info

    # the input to state convolution should only be computed one time 
        if current==0:
            n = image.size()[2]
            ch=image.size()[1]
           # input_to_state = torch.nn.Conv2d(ch,4*ch,kernel_size=(1,3),padding=(0,1))
          #  print("about to do convolution")
            isgates = self.splitIS(self.input_to_state(image)) # convolve, then split into gates (4 per row)

            cell=RowLSTMCell(0,torch.randn(ch,n,1),torch.randn(ch,n,1),torch.randn(ch,n,1),torch.randn(ch,n,1),torch.randn(ch,n,1),torch.randn(ch,n,1))
            # now have dummy, learnable variables for first row
            _layer.append(cell)
            print("layeres: "+str(len(_layer)))
        else:   
            Cell_prev = _layer[current-1] # access previous row
            hidPrev = Cell_prev.getHiddenState() 
            ch = image.size()[1] 
        #   print("about to apply conv1d")
           # state_to_state = torch.nn.Conv2d(ch,4*ch,kernel_size=(1,3),padding=(0,1)) # error is here: hidPrev is an array - not a valid number of input channel
        #   print("applied conv1d") 
            prevHid=Cell_prev.getHiddenState()
            ssgates = self.splitSS(self.state_to_state(prevHid.unsqueeze(0))) #need to unsqueeze (Ex: currently 16x5, need to make 1x16x5)
            gates = self.addGates(isgates,ssgates,current)
            # split gates
            ig, og, fg, gg = gates[0], gates[1], gates[2], gates[3] # into four, ADD SIGMOID!
            cell = RowLSTMCell(Cell_prev,ig,og,fg,gg,0,0)
            cell.compute()
            _layer.append(cell)
        # attempting to eliminate requirement of getting size

        #print(current)
        try:
            print("adding one to current")
            current+=1
            y=(isgates[0][0][1][current])

            return self.RowLSTM(image) #expecting floattensor, but gets cuda floattensor

        except Exception as error:
            print(error)
            concats=[]
            print(len(_layer))
            for cell in _layer:
                tensor=torch.unsqueeze(cell.h,0)
                concats.append(tensor)
            seq=tuple(concats)

            print("non catted tensor: "+str(tensor.size()))
            tense=torch.cat(seq,3)
            print("catted lstm tensor "+str(tense.size()))
            return tensor


The code runs, but when trying to go through the try/except block,  the error is thrown. I am guessing the mistake lies somewhere here? 

Edit: Using print statements to see where the program exactly terminates, it seems that there is a mistake in code that I have note posted yet! I will post that now, it looks like the error is in the compute() function, since the statement "finished computing" never gets printed. 

class RowLSTMCell(): #inherit torch.nn.LSTM?
    def __init__(self,prev_row, i, o, f, g, c, h):
        #super(RowLSTMCell,self).__init__()
        self.c=c

        #self.c = self.c.cuda()
        self.h=h
       # self.h = self.h.cuda()
        self.i=i
        self.i = self.i.cuda()
        self.o=o
        self.o = self.o.cuda()
        self.g=g
        self.g = self.g.cuda()
        self.f=f
        self.f = self.f.cuda()
        self.prev_row=prev_row 
    def getStateSize(self):
        return self._state_size

    def getOutputSize(self):
        return self._output_size

    def compute(self):
        print("computing")
        c_prev = self.prev_row.getCellState()
        h_prev = self.prev_row.getHiddenState()

        self.c = self.f * c_prev + self.i * self.g
        self.h = torch.tanh(self.c) * self.o
        print("finished computing")
    def getHiddenState(self):
        return self.h

    def getCellState(self):
        return self.c


self.c and self.h were not cuda! I guess you really have to make sure that each tensor is using cuda. I just put .cuda() at the end of self.c and self.h's computation in the compute() method. 
