Closed Yumeka999 closed 2 years ago
不是bug,你既然将Electra从base改成了small,就应当将secondary_encoder
的维度改成small的256,即:
secondary_encoder=RelativeTransformerEncoder(768, k_as_x=True),
--->
secondary_encoder=RelativeTransformerEncoder(256, k_as_x=True),
感谢何老师的指正!
Describe the bug open_base.py训练有bug
mat1 and mat2 shapes cannot be multiplied (800x256 and 768x1536)
Code to reproduce the issue
Describe the current behavior python open_base.py 运行报错 RuntimeError: mat1 and mat2 shapes cannot be multiplied (800x256 and 768x1536)
Expected behavior 程序正常训练
System information
Other info / logs Using GPUs: [0] Epoch 1 / 1: 1/24919 loss: 0.7001 ETA: 43 m 14 sTraceback (most recent call last): File "hanlp_train.py", line 135, in
eval_trn=False,
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/multi_task_learning.py", line 644, in fit
tasks)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/common/torch_component.py", line 295, in fit
overwrite=True))
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/multi_task_learning.py", line 287, in execute_training_loop
self.config)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/multi_task_learning.py", line 346, in fit_dataloader
outputdict, = self.feed_batch(batch, task_name)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/multi_task_learning.py", line 687, in feed_batch
decoder=self.model.decoders[task_name]),
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/tasks/init.py", line 182, in feed_batch
return decoder(h, batch=batch, mask=mask)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, kwargs)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/components/mtl/tasks/ner/tag_ner.py", line 35, in forward
contextualized_embeddings = self.secondary_encoder(contextualized_embeddings, mask=mask)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, *kwargs)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/layers/transformers/relative_transformer.py", line 309, in forward
x = layer(x, mask)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(input, kwargs)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/layers/transformers/relative_transformer.py", line 263, in forward
x = self.self_attn(x, mask)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, *kwargs)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/hanlp/layers/transformers/relative_transformer.py", line 135, in forward
qv = self.qv_linear(x) # batch_size x max_len x d_model2
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(input, **kwargs)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 103, in forward
return F.linear(input, self.weight, self.bias)
File "/home/xy/miniconda3/envs/py364_xy/lib/python3.6/site-packages/torch/nn/functional.py", line 1848, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (800x256 and 768x1536)