The expanded size of the tensor (150) must match the existing size (503) at non-singleton dimension 0.  Target sizes: [150].  Tensor sizes: [503]

This is my code:

from transformers import GPTNeoXForCausalLM, AutoTokenizer
import torch

model = GPTNeoXForCausalLM.from_pretrained(
  "EleutherAI/pythia-70m-deduped",
  revision="step3000",
  cache_dir="./pythia-70m-deduped/step3000",
)

tokenizer = AutoTokenizer.from_pretrained(
  "EleutherAI/pythia-70m-deduped",
  revision="step3000",
  cache_dir="./pythia-70m-deduped/step3000",
)

def infer_llm(template, model, tokenizer, scratchpad):
    
    # Preparing prompt from the template
    input = template.format(scratchpad=scratchpad)
    print("LLM prompt:" + input)

    #Use GPU if available
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

    #Inferencing
    input_ids = tokenizer.encode(input, return_tensors="pt").to(device)
    outputs = model.generate(input_ids=input_ids, max_length=150, num_beams=4, early_stopping=True)
    return tokenizer.decode(outputs[0])

Any idea about how to fix this?
No lo sé