Error while running lesson 4 notebook

Error while running lesson 4 notebook.
Corresponding code is

em_sz = 200  # size of each embedding vector
nh = 500     # number of hidden activations per layer
nl = 3       # number of layers
opt_fn = partial(optim.Adam, betas=(0.7, 0.99))
learner = md.get_model(opt_fn, em_sz, nh, nl,
               dropouti=0.05, dropout=0.05, wdrop=0.1, dropoute=0.02, dropouth=0.05)
learner.reg_fn = partial(seq2seq_reg, alpha=2, beta=1)
learner.clip=0.3

The error occurs while running

learner.fit(3e-3, 4, wds=1e-6, cycle_len=1, cycle_mult=2)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-23-357a8890c905> in <module>()
----> 1 learner.fit(3e-3, 4, wds=1e-6, cycle_len=1, cycle_mult=2)

~/svara/learn/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    300         self.sched = None
    301         layer_opt = self.get_layer_opt(lrs, wds)
--> 302         return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    303 
    304     def warm_up(self, lr, wds=None):

~/svara/learn/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    247             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    248             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 249             swa_eval_freq=swa_eval_freq, **kwargs)
    250 
    251     def get_layer_groups(self): return self.models.get_layer_groups()

~/svara/learn/fastai/courses/dl1/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, visualize, **kwargs)
    139             batch_num += 1
    140             for cb in callbacks: cb.on_batch_begin()
--> 141             loss = model_stepper.step(V(x),V(y), epoch)
    142             avg_loss = avg_loss * avg_mom + loss * (1-avg_mom)
    143             debias_loss = avg_loss / (1 - avg_mom**batch_num)

~/svara/learn/fastai/courses/dl1/fastai/model.py in step(self, xs, y, epoch)
     48     def step(self, xs, y, epoch):
     49         xtra = []
---> 50         output = self.m(*xs)
     51         if isinstance(output,tuple): output,*xtra = output
     52         if self.fp16: self.m.zero_grad()

~/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

~/.local/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
     90     def forward(self, input):
     91         for module in self._modules.values():
---> 92             input = module(input)
     93         return input
     94 

~/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

~/svara/learn/fastai/courses/dl1/fastai/lm_rnn.py in forward(self, input)
    104                 with warnings.catch_warnings():
    105                     warnings.simplefilter("ignore")
--> 106                     raw_output, new_h = rnn(raw_output, self.hidden[l])
    107                 new_hidden.append(new_h)
    108                 raw_outputs.append(raw_output)

~/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

~/svara/learn/fastai/courses/dl1/fastai/rnn_reg.py in forward(self, *args)
    122         """
    123         self._setweights()
--> 124         return self.module.forward(*args)
    125 
    126 class EmbeddingDropout(nn.Module):

~/.local/lib/python3.6/site-packages/torch/nn/modules/rnn.py in forward(self, input, hx)
    177         if batch_sizes is None:
    178             result = _impl(input, hx, self._flat_weights, self.bias, self.num_layers,
--> 179                            self.dropout, self.training, self.bidirectional, self.batch_first)
    180         else:
    181             result = _impl(input, batch_sizes, hx, self._flat_weights, self.bias,

RuntimeError: shape '[1000000, 1]' is invalid for input of size 2000

Ran the notebook without any changes. But this error crops up.

2 Likes

Same here :frowning:

2 Likes

Same :confused:

Did anyone find the solution to this ?

Same here.

See also:

and:

I fixed error this by downgrading pytorch to version 0.4.1

ie

pip3 install torch==0.4.1

Machine config here