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

Handle prompt-too-long error #61

Open
ccmaymay opened this issue Aug 18, 2022 · 0 comments
Open

Handle prompt-too-long error #61

ccmaymay opened this issue Aug 18, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ccmaymay
Copy link
Collaborator

From @nweir127:

If I feed the API text that is longer than the acceptable context window (2048 tokens) , the generator post processor currently crashes

A nice feature of the API would be to either give an appropriate error response or to perform front truncation

And a code snippet:

input_token_ids = tokenizer(text, return_tensors='pt')['input_ids']
max_context = model.config.n_positions - max_new_tokens
if hasattr(model.config, "n_positions") and input_token_ids.shape[1] > max_context:
    input_token_ids = input_token_ids[:, -max_context:]
    text = tokenizer.batch_decode(input_token_ids)[0]
    input_token_ids = tokenizer(text, return_tensors='pt')['input_ids']
@ccmaymay ccmaymay added the bug Something isn't working label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant