Skip to content

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

Open
@onbigion13

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions