diff --git a/DK wind speed forecasting/WeatherGCNet with gamma/model_dk.py b/DK wind speed forecasting/WeatherGCNet with gamma/model_dk.py index 68b9036..96a1418 100644 --- a/DK wind speed forecasting/WeatherGCNet with gamma/model_dk.py +++ b/DK wind speed forecasting/WeatherGCNet with gamma/model_dk.py @@ -75,7 +75,10 @@ def forward(self, x): f_in = x.contiguous().view(N, C * T, V) adj_mat = None - self.A = self.A.cuda(x.get_device()) + # x.get_device() returns -1 for a CPU tensor, and .cuda() forces CUDA + # regardless, so this raised "Device index must not be negative" on any + # machine without a GPU. .to() follows whichever device x is already on. + self.A = self.A.to(x.device) adj_mat = self.B[:,:] + self.gamma * self.A[:,:] adj_mat_min = torch.min(adj_mat) adj_mat_max = torch.max(adj_mat) diff --git a/DK wind speed forecasting/WeatherGCNet/model_dk.py b/DK wind speed forecasting/WeatherGCNet/model_dk.py index 08459ac..5f10773 100644 --- a/DK wind speed forecasting/WeatherGCNet/model_dk.py +++ b/DK wind speed forecasting/WeatherGCNet/model_dk.py @@ -76,7 +76,10 @@ def forward(self, x): f_in = x.contiguous().view(N, C * T, V) adj_mat = None - self.A = self.A.cuda(x.get_device()) + # x.get_device() returns -1 for a CPU tensor, and .cuda() forces CUDA + # regardless, so this raised "Device index must not be negative" on any + # machine without a GPU. .to() follows whichever device x is already on. + self.A = self.A.to(x.device) adj_mat = self.B[:,:] + self.A[:,:] adj_mat_min = torch.min(adj_mat) adj_mat_max = torch.max(adj_mat) diff --git a/NL wind speed forecasting/WeatherGCNet with gamma/model_nl.py b/NL wind speed forecasting/WeatherGCNet with gamma/model_nl.py index 2ceb277..46146c3 100644 --- a/NL wind speed forecasting/WeatherGCNet with gamma/model_nl.py +++ b/NL wind speed forecasting/WeatherGCNet with gamma/model_nl.py @@ -77,7 +77,10 @@ def forward(self, x): f_in = x.contiguous().view(N, C * T, V) adj_mat = None - self.A = self.A.cuda(x.get_device()) + # x.get_device() returns -1 for a CPU tensor, and .cuda() forces CUDA + # regardless, so this raised "Device index must not be negative" on any + # machine without a GPU. .to() follows whichever device x is already on. + self.A = self.A.to(x.device) adj_mat = self.B[:,:] + self.gamma * self.A[:,:] adj_mat_min = torch.min(adj_mat) adj_mat_max = torch.max(adj_mat) diff --git a/NL wind speed forecasting/WeatherGCNet/model_nl.py b/NL wind speed forecasting/WeatherGCNet/model_nl.py index 89ec71b..5d11bad 100644 --- a/NL wind speed forecasting/WeatherGCNet/model_nl.py +++ b/NL wind speed forecasting/WeatherGCNet/model_nl.py @@ -74,7 +74,10 @@ def forward(self, x): f_in = x.contiguous().view(N, C * T, V) adj_mat = None - self.A = self.A.cuda(x.get_device()) + # x.get_device() returns -1 for a CPU tensor, and .cuda() forces CUDA + # regardless, so this raised "Device index must not be negative" on any + # machine without a GPU. .to() follows whichever device x is already on. + self.A = self.A.to(x.device) adj_mat = self.B[:,:] + self.A[:,:] adj_mat_min = torch.min(adj_mat) adj_mat_max = torch.max(adj_mat)