marlbenchmark / off-policy

PyTorch implementations of popular off-policy multi-agent reinforcement learning algorithms, including QMix, VDN, MADDPG, and MATD3.
MIT License
386 stars 67 forks source link

fix(wzl): change [] to nn.ModuleList in MDDPG_Critic to avoid differe… #12

Open zerlinwang opened 1 year ago

zerlinwang commented 1 year ago

command

sh ./train_mpe_maddpg.sh

error

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

reason

self.q_outs = [init_(nn.Linear(self.hidden_size, 1)) for _ in range(num_q_outs)] self.to(device) In this way, the to(device) won’t transfer these parameters to the desired device.

ref

https://discuss.pytorch.org/t/is-it-mandatory-to-add-modules-to-modulelist-to-access-its-parameters/81622/7