Skip to content

Commit

Permalink
feat: define dedicated methods for the MistralTokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
gcalmettes committed Sep 25, 2024
1 parent ef0c854 commit 4b13606
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lmformatenforcer/integrations/vllm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
try:
import torch
import vllm
from vllm.transformers_utils.tokenizer import MistralTokenizer
from transformers import PreTrainedTokenizerBase
except ImportError:
raise ImportError('vllm is not installed. Please install it with "pip install vllm"')
Expand Down Expand Up @@ -35,6 +36,8 @@ def build_vllm_token_enforcer_tokenizer_data(tokenizer: Union[vllm.LLM, PreTrain
# There are many classes that can be passed here, this logic should work on all of them.
if hasattr(tokenizer, 'get_tokenizer'):
tokenizer = tokenizer.get_tokenizer()
if isinstance(tokenizer, MistralTokenizer):
return build_token_enforcer_tokenizer_data(tokenizer)
if hasattr(tokenizer, 'tokenizer'):
tokenizer = tokenizer.tokenizer
return build_token_enforcer_tokenizer_data(tokenizer)
Expand Down

0 comments on commit 4b13606

Please sign in to comment.