EleutherAI/gpt-neo

IndexError: index out of range in self

dzlab opened this issue · 1 comments

dzlab commented

Describe the bug
I'm trying to generate a long text just to play with the library on colab with TPU runtime (or without)

To Reproduce
Steps to reproduce the behavior:

  1. Install transformers pip install transformers
  2. Import pipeline from transformers import pipeline
  3. Download model generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B')
  4. Generate text
prompt = "Once upon a time"
generator(prompt, do_sample=True, min_length=50, max_length=4000)

I get this error after very long time

Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-13-db32a0d013d2>](https://localhost:8080/#) in <module>()
      1 prompt = "Once upon a time"
----> 2 generator(prompt, do_sample=True, min_length=50, max_length=4000)

14 frames
[/usr/local/lib/python3.7/dist-packages/transformers/pipelines/text_generation.py](https://localhost:8080/#) in __call__(self, text_inputs, **kwargs)
    169               ids of the generated text.
    170         """
--> 171         return super().__call__(text_inputs, **kwargs)
    172 
    173     def preprocess(self, prompt_text, prefix="", handle_long_generation=None, **generate_kwargs):

[/usr/local/lib/python3.7/dist-packages/transformers/pipelines/base.py](https://localhost:8080/#) in __call__(self, inputs, num_workers, batch_size, *args, **kwargs)
   1004             return self.iterate(inputs, preprocess_params, forward_params, postprocess_params)
   1005         else:
-> 1006             return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
   1007 
   1008     def run_multi(self, inputs, preprocess_params, forward_params, postprocess_params):

[/usr/local/lib/python3.7/dist-packages/transformers/pipelines/base.py](https://localhost:8080/#) in run_single(self, inputs, preprocess_params, forward_params, postprocess_params)
   1011     def run_single(self, inputs, preprocess_params, forward_params, postprocess_params):
   1012         model_inputs = self.preprocess(inputs, **preprocess_params)
-> 1013         model_outputs = self.forward(model_inputs, **forward_params)
   1014         outputs = self.postprocess(model_outputs, **postprocess_params)
   1015         return outputs

[/usr/local/lib/python3.7/dist-packages/transformers/pipelines/base.py](https://localhost:8080/#) in forward(self, model_inputs, **forward_params)
    921                 with inference_context():
    922                     model_inputs = self._ensure_tensor_on_device(model_inputs, device=self.device)
--> 923                     model_outputs = self._forward(model_inputs, **forward_params)
    924                     model_outputs = self._ensure_tensor_on_device(model_outputs, device=torch.device("cpu"))
    925             else:

[/usr/local/lib/python3.7/dist-packages/transformers/pipelines/text_generation.py](https://localhost:8080/#) in _forward(self, model_inputs, **generate_kwargs)
    204             input_ids = None
    205         prompt_text = model_inputs.pop("prompt_text")
--> 206         generated_sequence = self.model.generate(input_ids=input_ids, **generate_kwargs)  # BS x SL
    207         return {"generated_sequence": generated_sequence, "input_ids": input_ids, "prompt_text": prompt_text}
    208 

[/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py](https://localhost:8080/#) in decorate_context(*args, **kwargs)
     26         def decorate_context(*args, **kwargs):
     27             with self.__class__():
---> 28                 return func(*args, **kwargs)
     29         return cast(F, decorate_context)
     30 

[/usr/local/lib/python3.7/dist-packages/transformers/generation_utils.py](https://localhost:8080/#) in generate(self, inputs, max_length, min_length, do_sample, early_stopping, num_beams, temperature, top_k, top_p, repetition_penalty, bad_words_ids, bos_token_id, pad_token_id, eos_token_id, length_penalty, no_repeat_ngram_size, encoder_no_repeat_ngram_size, num_return_sequences, max_time, max_new_tokens, decoder_start_token_id, use_cache, num_beam_groups, diversity_penalty, prefix_allowed_tokens_fn, logits_processor, stopping_criteria, output_attentions, output_hidden_states, output_scores, return_dict_in_generate, forced_bos_token_id, forced_eos_token_id, remove_invalid_values, synced_gpus, **model_kwargs)
   1208                 return_dict_in_generate=return_dict_in_generate,
   1209                 synced_gpus=synced_gpus,
-> 1210                 **model_kwargs,
   1211             )
   1212 

[/usr/local/lib/python3.7/dist-packages/transformers/generation_utils.py](https://localhost:8080/#) in sample(self, input_ids, logits_processor, stopping_criteria, logits_warper, max_length, pad_token_id, eos_token_id, output_attentions, output_hidden_states, output_scores, return_dict_in_generate, synced_gpus, **model_kwargs)
   1712                 return_dict=True,
   1713                 output_attentions=output_attentions,
-> 1714                 output_hidden_states=output_hidden_states,
   1715             )
   1716 

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1100         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1101                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102             return forward_call(*input, **kwargs)
   1103         # Do not call functions when jit is used
   1104         full_backward_hooks, non_full_backward_hooks = [], []

[/usr/local/lib/python3.7/dist-packages/transformers/models/gpt_neo/modeling_gpt_neo.py](https://localhost:8080/#) in forward(self, input_ids, past_key_values, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict)
    752             output_attentions=output_attentions,
    753             output_hidden_states=output_hidden_states,
--> 754             return_dict=return_dict,
    755         )
    756         hidden_states = transformer_outputs[0]

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1100         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1101                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102             return forward_call(*input, **kwargs)
   1103         # Do not call functions when jit is used
   1104         full_backward_hooks, non_full_backward_hooks = [], []

[/usr/local/lib/python3.7/dist-packages/transformers/models/gpt_neo/modeling_gpt_neo.py](https://localhost:8080/#) in forward(self, input_ids, past_key_values, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict)
    579         if inputs_embeds is None:
    580             inputs_embeds = self.wte(input_ids)
--> 581         position_embeds = self.wpe(position_ids)
    582         hidden_states = inputs_embeds + position_embeds
    583 

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1100         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1101                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102             return forward_call(*input, **kwargs)
   1103         # Do not call functions when jit is used
   1104         full_backward_hooks, non_full_backward_hooks = [], []

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/sparse.py](https://localhost:8080/#) in forward(self, input)
    158         return F.embedding(
    159             input, self.weight, self.padding_idx, self.max_norm,
--> 160             self.norm_type, self.scale_grad_by_freq, self.sparse)
    161 
    162     def extra_repr(self) -> str:

[/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py](https://localhost:8080/#) in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
   2042         # remove once script supports set_grad_enabled
   2043         _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
-> 2044     return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
   2045 
   2046 

IndexError: index out of range in self

Screenshots
image

Environment (please complete the following information):

  • Colab
  • TPU runtime and also None
dzlab commented

@StellaAthena how should i generate very long text, I see the same error above for 5k, 4k and 3k. The text generation worked only for max_length=2000 or less.

Side question: is english the only supported language?