deepxde simple example with cuda error using pytorch backend. #1027
Unanswered
udemirezen
asked this question in
Q&A
Replies: 1 comment 3 replies
-
|
What is your Pytorch version? Is your CUDA correctly installed? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I triend to run the code below from the documentation
`import deepxde as dde
import numpy as np
def ode(t, y):
dy_dt = dde.grad.jacobian(y, t)
d2y_dt2 = dde.grad.hessian(y, t)
return d2y_dt2 - 10 * dy_dt + 9 * y - 5 * t
def func(t):
return 50 / 81 + t * 5 / 9 - 2 * np.exp(t) + (31 / 81) * np.exp(9 * t)
geom = dde.geometry.TimeDomain(0, 0.25)
def boundary_l(t, on_initial):
return on_initial and np.isclose(t[0], 0)
def bc_func1(inputs, outputs, X):
return outputs + 1
def bc_func2(inputs, outputs, X):
return dde.grad.jacobian(outputs, inputs, i=0, j=None) - 2
ic1 = dde.icbc.IC(geom, lambda x: -1, lambda _, on_initial: on_initial)
ic2 = dde.icbc.OperatorBC(geom, bc_func2, boundary_l)
data = dde.data.TimePDE(geom, ode, [ic1, ic2], 16, 2, solution=func, num_test=500)
layer_size = [1] + [50] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile(
"adam", lr=0.001, metrics=["l2 relative error"], loss_weights=[0.01, 1, 1]
)
losshistory, train_state = model.train(iterations=10000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)`
when i run the code from note book, I get the error
`Training model...
0 [1.94e-03, 1.00e+00, 4.25e+00] [1.66e-03, 1.00e+00, 4.25e+00] [1.00e+00]
AssertionError Traceback (most recent call last)
Input In [11], in <cell line: 45>()
40 model = dde.Model(data, net)
41 model.compile(
42 "adam", lr=0.001, metrics=["l2 relative error"], loss_weights=[0.01, 1, 1]
43 )
---> 45 losshistory, train_state = model.train(iterations=10000)
47 dde.saveplot(losshistory, train_state, issave=True, isplot=True)
File ~/.local/lib/python3.9/site-packages/deepxde/utils/internal.py:22, in timing..wrapper(*args, **kwargs)
19 @wraps(f)
20 def wrapper(*args, **kwargs):
21 ts = timeit.default_timer()
---> 22 result = f(*args, **kwargs)
23 te = timeit.default_timer()
24 print("%r took %f s\n" % (f.name, te - ts))
File ~/.local/lib/python3.9/site-packages/deepxde/model.py:594, in Model.train(self, iterations, batch_size, display_every, disregard_previous_best, callbacks, model_restore_path, model_save_path, epochs)
592 if iterations is None:
593 raise ValueError("No iterations for {}.".format(self.opt_name))
--> 594 self._train_sgd(iterations, display_every)
595 self.callbacks.on_train_end()
597 print("")
File ~/.local/lib/python3.9/site-packages/deepxde/model.py:611, in Model._train_sgd(self, iterations, display_every)
606 self.callbacks.on_batch_begin()
608 self.train_state.set_data_train(
609 *self.data.train_next_batch(self.batch_size)
610 )
--> 611 self._train_step(
612 self.train_state.X_train,
613 self.train_state.y_train,
614 self.train_state.train_aux_vars,
615 )
617 self.train_state.epoch += 1
618 self.train_state.step += 1
File ~/.local/lib/python3.9/site-packages/deepxde/model.py:511, in Model._train_step(self, inputs, targets, auxiliary_vars)
508 self.train_step(inputs, targets, auxiliary_vars)
509 elif backend_name in ["pytorch", "paddle"]:
510 # TODO: auxiliary_vars
--> 511 self.train_step(inputs, targets)
512 elif backend_name == "jax":
513 # TODO: auxiliary_vars
514 self.params, self.opt_state = self.train_step(
515 self.params, self.opt_state, inputs, targets
516 )
File ~/.local/lib/python3.9/site-packages/deepxde/model.py:333, in Model._compile_pytorch..train_step(inputs, targets)
330 total_loss.backward()
331 return total_loss
--> 333 self.opt.step(closure)
334 if self.lr_scheduler is not None:
335 self.lr_scheduler.step()
File /usr/local/lib/python3.9/dist-packages/torch/optim/optimizer.py:109, in Optimizer._hook_for_profile..profile_hook_step..wrapper(*args, **kwargs)
107 profile_name = "Optimizer.step#{}.step".format(obj.class.name)
108 with torch.autograd.profiler.record_function(profile_name):
--> 109 return func(*args, **kwargs)
File /usr/local/lib/python3.9/dist-packages/torch/autograd/grad_mode.py:27, in _DecoratorContextManager.call..decorate_context(*args, **kwargs)
24 @functools.wraps(func)
25 def decorate_context(*args, **kwargs):
26 with self.clone():
---> 27 return func(*args, **kwargs)
File /usr/local/lib/python3.9/dist-packages/torch/optim/adam.py:157, in Adam.step(self, closure)
153 max_exp_avg_sqs.append(state['max_exp_avg_sq'])
155 state_steps.append(state['step'])
--> 157 adam(params_with_grad,
158 grads,
159 exp_avgs,
160 exp_avg_sqs,
161 max_exp_avg_sqs,
162 state_steps,
163 amsgrad=group['amsgrad'],
164 beta1=beta1,
165 beta2=beta2,
166 lr=group['lr'],
167 weight_decay=group['weight_decay'],
168 eps=group['eps'],
169 maximize=group['maximize'],
170 foreach=group['foreach'],
171 capturable=group['capturable'])
173 return loss
File /usr/local/lib/python3.9/dist-packages/torch/optim/adam.py:213, in adam(params, grads, exp_avgs, exp_avg_sqs, max_exp_avg_sqs, state_steps, foreach, capturable, amsgrad, beta1, beta2, lr, weight_decay, eps, maximize)
210 else:
211 func = _single_tensor_adam
--> 213 func(params,
214 grads,
215 exp_avgs,
216 exp_avg_sqs,
217 max_exp_avg_sqs,
218 state_steps,
219 amsgrad=amsgrad,
220 beta1=beta1,
221 beta2=beta2,
222 lr=lr,
223 weight_decay=weight_decay,
224 eps=eps,
225 maximize=maximize,
226 capturable=capturable)
File /usr/local/lib/python3.9/dist-packages/torch/optim/adam.py:255, in _single_tensor_adam(params, grads, exp_avgs, exp_avg_sqs, max_exp_avg_sqs, state_steps, amsgrad, beta1, beta2, lr, weight_decay, eps, maximize, capturable)
253 assert param.is_cuda and step_t.is_cuda, "If capturable=True, params and state_steps must be CUDA tensors."
254 else:
--> 255 assert not step_t.is_cuda, "If capturable=False, state_steps should not be CUDA tensors."
257 # update step
258 step_t += 1
AssertionError: If capturable=False, state_steps should not be CUDA tensors.`
but when I use CPU it works fine.
What is the problem here?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions