Closed spate141 closed 4 years ago
I think you flipped model and tokenizer at the beginning. It should be
from transformers import BartTokenizer, BartForConditionalGeneration
tokenizer = BartTokenizer.from_pretrained('/Downloads/facebook-bart-large-cnn')
model = BartForConditionalGeneration.from_pretrained('/Downloads/facebook-bart-large-cnn')
Pls reopen if there is another issue!
Damn, this was embarrassing bug on my end. Thank you! 🍻
Environment info
transformers
version: 3.1.0Who can help
Information
BartTokenizer, BartForConditionalGeneration
'facebook/bart-large-cnn'
and saved later after using.save_pretrained(tmp_model_dir)
command.The problem arises when using:
The tasks I am working on is:
To reproduce
Steps to reproduce the behavior:
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, kwargs) 720 result = self._slow_forward(*input, *kwargs) 721 else: --> 722 result = self.forward(input, kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),
~/anaconda3/lib/python3.7/site-packages/transformers/modeling_bart.py in forward(self, input_ids, attention_mask, encoder_outputs, decoder_input_ids, decoder_attention_mask, past_key_values, labels, use_cache, output_attentions, output_hidden_states, return_dict, **unused) 1074 output_attentions=output_attentions, 1075 output_hidden_states=output_hidden_states, -> 1076 return_dict=return_dict, 1077 ) 1078 lm_logits = F.linear(outputs[0], self.model.shared.weight, bias=self.final_logits_bias)
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, kwargs) 720 result = self._slow_forward(*input, *kwargs) 721 else: --> 722 result = self.forward(input, kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),
~/anaconda3/lib/python3.7/site-packages/transformers/modeling_bart.py in forward(self, input_ids, attention_mask, decoder_input_ids, encoder_outputs, decoder_attention_mask, past_key_values, use_cache, output_attentions, output_hidden_states, return_dict, **kwargs) 904 decoder_input_ids=decoder_input_ids, 905 decoder_padding_mask=decoder_attention_mask, --> 906 causal_mask_dtype=self.shared.weight.dtype, 907 ) 908 else:
~/anaconda3/lib/python3.7/site-packages/transformers/modeling_bart.py in _prepare_bart_decoder_inputs(config, input_ids, decoder_input_ids, decoder_padding_mask, causal_mask_dtype) 146 pad_token_id = config.pad_token_id 147 if decoder_input_ids is None: --> 148 decoder_input_ids = shift_tokens_right(input_ids, pad_token_id) 149 bsz, tgt_len = decoder_input_ids.size() 150 if decoder_padding_mask is None:
~/anaconda3/lib/python3.7/site-packages/transformers/modeling_bart.py in shift_tokens_right(input_ids, pad_token_id) 204 def shift_tokens_right(input_ids, pad_token_id): 205 """Shift input ids one token to the right, and wrap the last non pad token (usually)."""
--> 206 prev_output_tokens = input_ids.clone()
207 index_of_eos = (input_ids.ne(pad_token_id).sum(dim=1) - 1).unsqueeze(-1)
208 prev_output_tokens[:, 0] = input_ids.gather(1, index_of_eos).squeeze()
AttributeError: 'list' object has no attribute 'clone'