Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeError: forward() got an unexpected keyword argument 'output_attention' #5454

Closed
1 task done
jiaohuix opened this issue Mar 28, 2023 · 3 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working triage

Comments

@jiaohuix
Copy link
Contributor

软件环境

- paddlepaddle: 
- paddlepaddle-gpu: 2.4.0.post112
- paddlenlp: 2.5.2.post0

重复问题

  • I have searched the existing issues

错误描述

我在训练transformer的时候遇到bug,报错代码中说多传了output_attention,在paddlenlp/transformers/model_outputs.py中,我将output_attentions=output_attentions注释掉后错误就消失了,哪位大佬能告诉我原因,感谢!! (之前ppnlp 2.1.1没有该错误)

Traceback (most recent call last):
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/distributed/spawn.py", line 361, in _func_wrapper
    result = func(*args)
  File "/home/aistudio/PaddleSeq/ppseq_cli/train.py", line 263, in main_worker
    scheduler=scheduler
  File "/home/aistudio/PaddleSeq/ppseq_cli/train.py", line 65, in train_one_epoch
    logits, sum_cost, avg_cost, token_num = criterion(model, sample)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 948, in call
    return self.forward(*inputs, **kwargs)
  File "/home/aistudio/PaddleSeq/ppseq/criterions/cross_entropy.py", line 12, in forward
    logits, attn = model(sample["src_tokens"], sample["prev_tokens"])
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 948, in call
    return self.forward(*inputs, **kwargs)
  File "/home/aistudio/PaddleSeq/ppseq/models/transformer/transformer_model.py", line 223, in forward
    encoder_out = self.forward_encoder(src_tokens)
  File "/home/aistudio/PaddleSeq/ppseq/models/transformer/transformer_model.py", line 189, in forward_encoder
    encoder_out=self.encoder(src_embed,src_mask)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 948, in call
    return self.forward(*inputs, **kwargs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlenlp/transformers/model_outputs.py", line 304, in _transformer_encoder_fwd
    output_attentions=output_attentions,
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 948, in call
    return self.forward(*inputs, **kwargs)
TypeError: forward() got an unexpected keyword argument 'output_attention

稳定复现步骤 & 代码

模型在 ppseq/models/transformer/transformer_model.py 下
git clone https://gitee.com/miugod/PaddleSeq.git
cd PaddleSeq
git checkout develop
pip install -r requirements.txt && pip install -e .

数据集:https://aistudio.baidu.com/aistudio/datasetdetail/203506

unzip datasets.zip
ppseq_train -c examples/iwslt14/configs/de_en.yaml

错误版本:
pip install paddlenlp --upgrade
sed -i "s/paddlenlp==2.1.1/paddlenlp>=2.1.1/g" setup.py
pip install -e .
ppseq_train -c examples/iwslt14/configs/de_en.yaml

@jiaohuix jiaohuix added the bug Something isn't working label Mar 28, 2023
@1649759610
Copy link
Contributor

可以验证下,升级到最新paddleNLP版本是否还有这个问题?

@jiaohuix
Copy link
Contributor Author

可以验证下,升级到最新paddleNLP版本是否还有这个问题?

您好,已经升级到最新版本了,这导致了报错(原先2.1.1不会):
45717f2d7ebe3265a2421545cc46fac

@xiehuanyi
Copy link

我也遇到了类似的问题,我使用gpt2和opt都遇到了forward方法没有labels这个参数的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

4 participants