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

3_parameter_efficient_finetuning/notebooks/finetune_sft_peft.ipynb inference error #175

Open
rkaunismaa opened this issue Jan 14, 2025 · 1 comment

Comments

@rkaunismaa
Copy link

In the last notebook cell, when attempting to run inference on the trained model, when we enter the following loop:

for prompt in prompts:
print(f" prompt:\n{prompt}")
print(f" response:\n{test_inference(prompt)}")
print("-" * 50)

the very first prompt fed into 'test_inference(prompt)' generates the following error:

'Input length of input_ids is 31, but max_length is set to 20. This can lead to unexpected behavior. ...'

@rkaunismaa
Copy link
Author

The fix is to add a value to max_length in the pipe statement:

Change ...

def test_inference(prompt):
prompt = pipe.tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tokenize=False,
add_generation_prompt=True,
)
outputs = pipe(
prompt,
)
return outputs[0]["generated_text"][len(prompt) :].strip()

To ...

def test_inference(prompt):
prompt = pipe.tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tokenize=False,
add_generation_prompt=True,
)
outputs = pipe(
prompt, max_length=512
)
return outputs[0]["generated_text"][len(prompt) :].strip()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant