my model and data on cuda but get all tensors to be on the same device, but found at least two devices, cuda:0 and cpu

Issue

This Content is from Stack Overflow. Question asked by Yohanna Yerima

I am trying to run inference on my model weight modified tensors from the result of training with STDP, however, I encounter this error message even after placing my model on Cuda and if run on ‘cpu’, I get NotImplementationError.

bindsnet.pipeline.environment_pipeline, bindsnet.pipeline.dataloader_pipeline, bindsnet.pipeline.action, bindsnet.pipeline, bindsnet.evaluation.evaluation, bindsnet.evaluation, bindsnet.conversion.nodes, bindsnet.conversion.topology, bindsnet.conversion.conversion, bindsnet.conversion, bindsnet, self_models.modified_bindsnet, self_models

Run on time: 2022-09-19 10:13:57.515296

Arguments:
gpu : True
seed : 0
dataset : MNIST
batch_size : 1
n_epochs : 2
n_test : None
update_interval : 500
n_neurons : 900
exc : 22.5
inh : 22.5
theta_plus : 0.05
pattern_time : 250
network : DiehlAndCook2015
dt : 1.0
n_workers : -1
pretrained_snn :
test_acc_every_batch : False
train_acc_batches : 200
devices : 0
test_only : False
pretrained_ann :
lr_interval : 0.00 0.00 0.00
log : False
n_inpt : 784
norm : 78.4
tc_theta_decay : 10000000.0
inpt_shape : None
nu : (0, 0.01)
wmax : 1.0
wmin : 0.0Traceback (most recent call last):

File Z:workspacestdp-nmnist-mainsnn_2.py:424 in
model = DiehlAndCook2015(n_inpt = 784, n_neurons = 900, exc = 22.5, inh = 22.5, dt = 1.0, norm = 78.4,

File Z:workspacestdp-nmnist-mainbindsnetmodelsmodels.py:198 in init
self.add_layer(exc_layer, name=”Ae”)

File Z:workspacestdp-nmnist-mainbindsnetnetworknetwork.py:130 in add_layer
layer.set_batch_size(self.batch_size)

File Z:workspacestdp-nmnist-mainbindsnetnetworknodes.py:1144 in set_batch_size
self.v = self.rest * torch.ones(batch_size, *self.shape, device=self.v.device)

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpuenter image description here



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?