Skip to content

CUDA pointer being compared to CPU pointer #1

Closed
@apoorvagnihotri

Description

@apoorvagnihotri

Got the following error during testing my network at https://github.com/k0pch4/big-little-net/.

torchtest\torchtest.py", line 151, in _var_change_helper
assert not torch.equal(p0, p1)
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #2 'other'

Code to replicate

import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable

from src import models
from helper import get_models

# set cpu for avoiding possible errors in torchtest
torch.device("cpu")

# get the model names
model_names = get_models(models)

import torchtest as tt
inputs = torch.rand(2, 3, 224, 224)
targets = torch.FloatTensor(2).uniform_(0, 1000).long()
# torch.randint(0, 2, (2, 1000,))
batch = [inputs, targets]
model = models.bl_resnet50()

# what are the variables?
print('Our list of parameters', [ np[0] for np in model.named_parameters() ])

# do they change after a training step?
#  let's run a train step and see
tt.assert_vars_change(
    model=model, 
    loss_fn=F.cross_entropy, 
    optim=torch.optim.Adam(model.parameters()),
    batch=batch)

Will add more details if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions