quark0 / darts

Differentiable architecture search for convolutional and recurrent networks
https://arxiv.org/abs/1806.09055
Apache License 2.0
3.92k stars 843 forks source link

"TypeError: Iteration over 0-d tensor" #106

Open ilia10000 opened 5 years ago

ilia10000 commented 5 years ago

I'm trying to run the RNN search on custom data. I changed the datafiles in data/penn/ and ran the usual command from the rnn directory: python train_search.py --unrolled I get the following output and error: Experiment dir : search-EXP-20190731-110155 torch.Size([667, 256]) torch.Size([89, 256]) torch.Size([2302, 10]) torch.Size([60194, 1]) 07/31 11:02:04 AM param size: 1813545 07/31 11:02:04 AM initial genotype: 07/31 11:02:04 AM Genotype(recurrent=[('relu', 0), ('relu', 1), ('tanh', 2), ('identity', 3), ('tanh', 3), ('relu', 5), ('identity', 6), ('identity', 0)], concat=range(1, 9)) 07/31 11:02:04 AM Args: Namespace(alpha=0, arch_lr=0.003, arch_wdecay=0.001, batch_size=256, beta=0.001, bptt=35, clip=0.25, continue_train=False, cuda=True, data='../data/penn/', dropout=0.75, dropoute=0, dropouth=0.25, dropouti=0.2, dropoutx=0.75, emsize=300, epochs=50, gpu=0, log_interval=50, lr=20, max_seq_len_delta=20, nhid=300, nhidlast=300, nonmono=5, save='search-EXP-20190731-110155', seed=3, single_gpu=True, small_batch_size=256, unrolled=True, wdecay=5e-07) 07/31 11:02:04 AM Model total parameters: 1813545 Traceback (most recent call last): File "train_search.py", line 272, in <module> train() File "train_search.py", line 203, in train hidden[s_id] = repackage_hidden(hidden[s_id]) File "/home/isucholu/darts/rnn/utils.py", line 12, in repackage_hidden return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in <genexpr> return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in repackage_hidden return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in <genexpr> return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in repackage_hidden return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in <genexpr> return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in repackage_hidden return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in <genexpr> return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/darts/rnn/utils.py", line 12, in repackage_hidden return tuple(repackage_hidden(v) for v in h) File "/home/isucholu/.local/lib/python3.5/site-packages/torch/tensor.py", line 422, in __iter__ raise TypeError('iteration over a 0-d tensor') TypeError: iteration over a 0-d tensor For context, my training data consists of one word per line for ~100k lines. Are there some changes I need to make to the parameters to run the search on my data?

pingguokiller commented 5 years ago

I get the same error. I think the reason is the pytorch version. However, pytorth0.3.1 match cuda8.0. And My computer is ubuntu18.04.3,which can't install cuda8.0.

Catosine commented 5 years ago

Do you try with torch.unsqueeze() ? This function could change the dimention.

ThomasCassimon commented 5 years ago

I encountered a similar problem when running with python 3.7, running with python 3.6 fixed the issue for me!

anujmhr commented 4 years ago

https://github.com/quark0/darts/blob/f276dd346a09ae3160f8e3aca5c7b193fda1da37/rnn/utils.py#L9-L13 For pytorch v1.5.0, replacing this piece of code solved the problem for me.

    if isinstance(h, torch.Tensor):
        return h.detach()
    else:
        return tuple(repackage_hidden(v) for v in h) 

Taken from: https://github.com/pytorch/examples/blob/e7870c1fd4706174f52a796521382c9342d4373f/word_language_model/main.py#L112-L118