【问题标题】:RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)RuntimeError:索引应该在 cpu 上或与索引张量 (cpu) 在同一设备上
【发布时间】:2023-02-25 20:48:41
【问题描述】:

我尝试了所有可能的解决方案来解决这个问题......但仍然没有运气。这是我得到的错误。

    results = self.trainer.run_pretrain_routine(model)
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1239, in run_pretrain_routine
    self.train()
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 394, in train
    self.run_training_epoch()
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 491, in run_training_epoch
    batch_output = self.run_training_batch(batch, batch_idx)
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 839, in run_training_batch
    opt_closure_result = self.optimizer_closure(
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 1014, in optimizer_closure
    training_step_output = self.training_forward(split_batch, batch_idx, opt_idx,
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/env/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 1216, in training_forward
    output = self.model.training_step(*args)
  File "/mnt/beegfs/scratch/nahmed/eICU-GNN-LSTM_working/train_ns_lstmgnn.py", line 78, in training_step
    in_x = self.dataset.data.x[n_id].to(self.device)
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)```
I am trying to run the code in GPU in the HPC server. Please someone help.

【问题讨论】:

  • 您在这里到底不明白什么(错误很明显),您到底尝试了什么?
  • 通过像这样将设备显式分配给 cuda cuda = torch.device('cuda')...但是没有运气
  • 分配什么设备?该错误清楚地表明索引应该在 CPU 中,而不是在您的 CUDA 设备中。

标签: deep-learning pytorch gpu pytorch-lightning


【解决方案1】:

所以,我通过这个解决了它,self.dataset.data.x 应该与索引位于同一设备中。

in_x = self.dataset.data.x.to(n_id.device)[n_id].to(self.device)

希望它能帮助别人。

【讨论】:

    猜你喜欢
    • 2022-11-12
    • 2022-12-10
    • 2023-01-03
    • 2023-02-16
    • 2022-10-03
    • 2022-10-13
    • 1970-01-01
    • 2020-12-06
    • 2020-05-01
    相关资源
    最近更新 更多