RuntimeError: view size is not compatible with input tensor's size and stride
nikolamilosevic86 opened this issue · 3 comments
Hello, I am trying to run Multi-BioNER on my machine on the cloud with GPU. I could not install torch as in requeirements.txt file, as it seems to be old version and not supported on my system (Ubuntu), but I installed new pytorch and torch-vision. However, when I run
./run_lm-lstm-crf5.sh
I am getting the following error:
File "/home/ubuntu/Multi-BioNER/model/utils.py", line 66, in switch
catvec = torch.cat([vec1.view(-1, 1), vec2.view(-1, 1)], dim=1)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
The full log of the run and error is here:
ubuntu@ip-XXX-XX-XX-XXX:~/Multi-BioNER$ ./run_lm-lstm-crf5.sh
setting:
Namespace(batch_size=10, caseless=True, char_dim=30, char_hidden=300, char_layer s=1, checkpoint='./checkpoint/', clip_grad=5.0, co_train=False, dev_file=['data_ bioner_5/BC2GM-IOBES/devel.tsv', 'data_bioner_5/BC4CHEMD-IOBES/devel.tsv', 'data _bioner_5/BC5CDR-IOBES/devel.tsv', 'data_bioner_5/NCBI-disease-IOBES/devel.tsv', 'data_bioner_5/JNLPBA-IOBES/devel.tsv'], drop_out=0.5, emb_file='data_bioner_5/ wikipedia-pubmed-and-PMC-w2v.txt', epoch=500, eva_matrix='fa', fine_tune=False, gpu=0, high_way=False, highway_layers=1, lambda0=1, least_iters=50, load_check_p oint='', load_opt=False, lr=0.01, lr_decay=0.05, mini_count=5, momentum=0.9, out put_annotation=False, patience=30, rand_embedding=False, shrink_embedding=True, small_crf=True, start_epoch=0, test_file=['data_bioner_5/BC2GM-IOBES/test.tsv', 'data_bioner_5/BC4CHEMD-IOBES/test.tsv', 'data_bioner_5/BC5CDR-IOBES/test.tsv', 'data_bioner_5/NCBI-disease-IOBES/test.tsv', 'data_bioner_5/JNLPBA-IOBES/test.ts v'], train_file=['data_bioner_5/BC2GM-IOBES/merge.tsv', 'data_bioner_5/BC4CHEMD- IOBES/merge.tsv', 'data_bioner_5/BC5CDR-IOBES/merge.tsv', 'data_bioner_5/NCBI-di sease-IOBES/merge.tsv', 'data_bioner_5/JNLPBA-IOBES/merge.tsv'], unk='unk', upda te='sgd', word_dim=200, word_hidden=300, word_layers=1)
loading corpus
constructing coding table
constructing coding table
constructing coding table
constructing coding table
constructing coding table
feature size: '26220'
loading embedding
/home/ubuntu/Multi-BioNER/model/utils.py:779: UserWarning: nn.init.uniform is no w deprecated in favor of nn.init.uniform_.
nn.init.uniform(input_embedding, -bias, bias)
embedding size: '68437'
constructing dataset
building model
/home/ubuntu/anaconda3/lib/python3.6/site-packages/torch/nn/modules/rnn.py:50: U serWarning: dropout option adds dropout after all but last recurrent layer, so n on-zero dropout expects num_layers greater than 1, but got dropout=0.5 and num_l ayers=1
"num_layers={}".format(dropout, num_layers))
/home/ubuntu/Multi-BioNER/model/utils.py:797: UserWarning: nn.init.uniform is no w deprecated in favor of nn.init.uniform_.
nn.init.uniform(weight, -bias, bias)
/home/ubuntu/Multi-BioNER/model/utils.py:800: UserWarning: nn.init.uniform is no w deprecated in favor of nn.init.uniform_.
nn.init.uniform(weight, -bias, bias)
/home/ubuntu/Multi-BioNER/model/utils.py:786: UserWarning: nn.init.uniform is no w deprecated in favor of nn.init.uniform_.
nn.init.uniform(input_linear.weight, -bias, bias)
device: 0
- Tot it 20 (epoch 0): 0%| | 0/1 [00:00<?, ?it/s] /pytorch/aten/src/ATen/native/cuda/LegacyDefinitions.cpp:66: UserWarning: masked _select received a mask with dtype torch.uint8, this behavior is now deprecated, please use a mask with dtype torch.bool instead.
Traceback (most recent call last):
File "train_wc.py", line 263, in <module>
loss = crit_ner(scores, tg_v, mask_v)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/torch/nn/modules/modu le.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubuntu/Multi-BioNER/model/crf.py", line 309, in forward
partition = utils.switch(partition, cur_partition, mask[idx].view(bat_size, 1).expand(bat_size, self.tagset_size)).view(bat_size, -1)
File "/home/ubuntu/Multi-BioNER/model/utils.py", line 66, in switch
catvec = torch.cat([vec1.view(-1, 1), vec2.view(-1, 1)], dim=1)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
How to prevent this error from happening?
Hello, thank you for your interest in our work.
Please refer to the previous issue: #8
Is that still the case that the repo supports only torch 0.3? Is 0.3.1 ok? As I can't use pip for 0.3.0. Also, that is quite ancient, given pytorch is over 1.5. version at the moment. Is there any plans to upgrade the support for newer pytorch versions?
0.3.1 should be ok.
Thanks for your suggestions. We will think about upgrading.