Skip to content

Commit f0d3abe

Browse files
authored
Backend pytorch: Update the code to use GPU by default (#1530)
1 parent 4b8ee44 commit f0d3abe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

deepxde/backend/pytorch/tensor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
# An alternative way is to use GPU by default if GPU is available, which is similar to
1717
# TensorFlow.
1818
if torch.cuda.is_available():
19-
torch.set_default_tensor_type(torch.cuda.FloatTensor)
19+
if Version(torch.__version__) >= Version("2.1.0"):
20+
torch.set_default_device("cuda")
21+
else:
22+
torch.set_default_tensor_type(torch.cuda.FloatTensor)
2023

2124

2225
lib = torch

0 commit comments

Comments
 (0)