d2l-pytorch icon indicating copy to clipboard operation
d2l-pytorch copied to clipboard

There's a bug in Ch10's “Implementation_of_Recurrent_Neural_Networks_from_Scratch”。

Open onbigion13 opened this issue 5 years ago • 0 comments

there is a runtime error when running the 7th code block. But I checked, the device type doesn't conflict each other. What's Wrong?

RuntimeError Traceback (most recent call last) in 1 state = init_rnn_state(X.shape[0], num_hiddens, ctx) 2 inputs = to_onehot(X.to(ctx), len(vocab)) ----> 3 params = get_params() 4 outputs, state_new = rnn(inputs, state, params) 5 len(outputs), outputs[0].shape, state_new[0].shape

in get_params() 9 10 # Hidden layer parameters ---> 11 W_xh = _one((num_inputs, num_hiddens)) 12 W_hh = _one((num_hiddens, num_hiddens)) 13 b_h = torch.zeros(num_hiddens, device=ctx)

in _one(shape) 6 def get_params(): 7 def one(shape): ----> 8 return torch.Tensor(size=shape, device=ctx).normal(std=0.01) 9 10 # Hidden layer parameters

RuntimeError: legacy constructor for device type: cpu was passed device type: cuda, but device type must be: cpu

onbigion13 avatar Jul 04 '20 02:07 onbigion13