RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
yuhai-china opened this issue · 3 comments
when I try to run the following command:
python3.8 -m unittest discover -p "*UnitTest.py"
I get the error
======================================================================
ERROR: test_optimization_process (physo.physym.tests.free_const_UnitTest.FreeConstUtilsTest)
Traceback (most recent call last):
File "/home/cloudyu/git/PhySO/physo/physym/tests/free_const_UnitTest.py", line 153, in test_optimization_process
MSE_before_opti_0 = data_conversion_inv(torch.mean((prog0(X) - y_target0) ** 2))
File "/home/cloudyu/git/PhySO/physo/physym/program.py", line 275, in call
return self.execute(X=X)
File "/home/cloudyu/git/PhySO/physo/physym/program.py", line 245, in execute
y = self.candidate_wrapper(lambda X: self.execute_wo_wrapper(X), X)
File "/home/cloudyu/git/PhySO/physo/physym/program.py", line 675, in
candidate_wrapper = lambda func, X : func(X)
File "/home/cloudyu/git/PhySO/physo/physym/program.py", line 245, in
y = self.candidate_wrapper(lambda X: self.execute_wo_wrapper(X), X)
File "/home/cloudyu/git/PhySO/physo/physym/program.py", line 228, in execute_wo_wrapper
y = Exec.ExecuteProgram(input_var_data = X,
File "/home/cloudyu/git/PhySO/physo/physym/execute.py", line 60, in ExecuteProgram
res = token.function(*args)
File "/home/cloudyu/git/PhySO/physo/physym/functions.py", line 193, in protected_div
return torch.where(torch.abs(x2) > 0.001, torch.divide(x1, x2), 1.)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Hi Yuhai,
This is due to parts of my test code not being adapted to the GPU.
I'm working on a fix that should be available very shortly (I will post here when it is available).
In the meantime you can install the cpu version of pytorch if you're to play with the code and it should work.
Cheers.
Wassim
Hi Yuhai,
I have updated the main branch. It now supports cuda !
You can pull the latest version of the main branch and it should work (I have tested on a GPU).
Please let me know if the issue was also fixed on your side so I can close this issue !
Wassim
PS: However you should note that in my experience even on a very very high end gpu cuda acceleration is slower than using a CPU because the bottleneck is free constant optimization.
Hi Wassim
thank you for so quick response.
I solve the probelm by set env var on my Ubuntu server:
export CUDA_VISIBLE_DEVICES=
then the script run sucessful on CPU