How to configure vllm to gracefully mark the too-long inputs without throwing? #16730
vadimkantorov
announced in
Q&A
Replies: 1 comment
|
Currently, vLLM raises an exception when input exceeds Option 1: Pre-filter inputs (recommended) from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
valid_prompts = []
for prompt in prompts:
tokens = tokenizer.encode(prompt)
if len(tokens) <= max_model_len:
valid_prompts.append(prompt)
else:
# Handle gracefully: truncate, skip, or log
print(f"Skipping prompt with {len(tokens)} tokens")
outputs = llm.generate(valid_prompts, sampling_params)Option 2: Truncate inputs truncated_prompts = []
for prompt in prompts:
tokens = tokenizer.encode(prompt)
if len(tokens) > max_model_len:
tokens = tokens[:max_model_len] # Keep first N tokens
prompt = tokenizer.decode(tokens, skip_special_tokens=True)
truncated_prompts.append(prompt)
outputs = llm.generate(truncated_prompts, sampling_params)Option 3: Increase max_model_len llm = LLM(model=model_name, max_model_len=8192)Regarding your suggestion: For now, Option 1 or 2 is the most practical approach. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm using vllm to batch-process quite a lot of inputs. Currently
LLM(...).generate(...)throws when it encounters some text-input which causes too-many-input-tokens after tokenization.Is it possible to configure vllm to gracefully return this error in
model_outputsand still process as usual all other inputs?Alternatively, it might be good to allow specifying some "mitigation strategies": keep only first
self.model_config.max_model_lentokens or keep only lastself.model_config.max_model_lentokens.I'm providing text input to
.generate(...), so to be able to filter out bad requests I would need to invoke the tokenization logic prior to sending the input to the model - this is quite cumbersome and error-proneThanks!
All reactions