Skip to content

Commit

Permalink
[Misc] Validate grammar and fail early
Browse files Browse the repository at this point in the history
  • Loading branch information
comaniac committed Dec 11, 2024
1 parent 72ff3a9 commit e1fb91e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions vllm/model_executor/guided_decoding/xgrammar_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def from_guided_params(cls,
f"Conversion error: {str(e)}") from e
else:
grammar_str = guided_params.grammar

# Validate the grammar and raise ValueError here if it is invalid.
# This is to avoid exceptions in model execution, which will crash
# the engine worker process.
try:
xgr.Grammar.from_ebnf(grammar_str)
except RuntimeError as err:
raise ValueError(str(err)) from err

return cls(grammar_str=grammar_str,
vocab_size=model_config.hf_text_config.vocab_size,
encoded_vocab=encoded_vocab,
Expand Down
9 changes: 4 additions & 5 deletions vllm/model_executor/models/llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ def _get_dummy_mm_kwargs(
image_processor = hf_processor.image_processor # type: ignore
hf_inputs = image_processor.preprocess(data['image'],
return_tensors="pt")
is_pixtral = isinstance(hf_processor, PixtralProcessor)
if 'is_pixtral' not in hf_inputs:
hf_inputs['is_pixtral'] = isinstance(hf_processor,
PixtralProcessor)

return MultiModalKwargs(
**hf_inputs,
is_pixtral=torch.tensor(is_pixtral),
)
return MultiModalKwargs(**hf_inputs)


class LlavaLikeConfig(Protocol):
Expand Down

0 comments on commit e1fb91e

Please sign in to comment.