Hi ChatGPT, I'm trying to generate some outputs using GPT-2 small, which has a context…
- User
Hi ChatGPT, I'm trying to generate some outputs using GPT-2 small, which has a context length of 1024. I passed a 16x1024 input id tensor to the model.generate function, but it says the embeddings are out of range. I'll post my code below and the error, can you please tell me what's wrong?
The code: tokenizer = GPT2Tokenizer.from_pretrained('gpt2') model = GPT2LMHeadModel.from_pretrained('gpt2').to('cpu') text = "Replace me by any text you'd like." encoded_input = np.load("label_testing.npy") retorched_labels = torch.from_numpy(encoded_input) sampled_preds = model.generate(inputs=retorched_labels, top_p=0.9, max_new_tokens=1024, min_new_tokens=1024, pad_token_id = -100)
The Error:
Traceback (most recent call last): File "/media/octavius/New Volume/knn_transformer/swap_hf_cache.py", line 20, in sampled_preds = model.generate(inputs=retorched_labels, top_p=0.9, max_new_tokens=1024, min_new_tokens=1024, pad_token_id = -100) File "/home/octavius/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/transformers/generation/utils.py", line 1576, in generate result = self._greedy_search( File "/home/octavius/.local/lib/python3.10/site-packages/transformers/generation/utils.py", line 2494, in _greedy_search outputs = self( File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 1305, in forward transformer_outputs = self.transformer( File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 1068, in forward inputs_embeds = self.wte(input_ids) File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/modules/sparse.py", line 163, in forward return F.embedding( File "/home/octavius/.local/lib/python3.10/site-packages/torch/nn/functional.py", line 2264, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) IndexError: index out of range in self
- Assistant
- User
Handled all of what you mentioned. Any other reasons?
- Assistant