Skip to content

Commit

Permalink
Fall back to base template if there is no chat_template in tokenizer_…
Browse files Browse the repository at this point in the history
…config.json (#1294)
  • Loading branch information
AllentDan authored Mar 15, 2024
1 parent 3a13188 commit 2da44bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lmdeploy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,11 @@ def best_match_model(query: str) -> Optional[str]:
for name, model in MODELS.module_dict.items():
if model.match(query):
return model.match(query)
try:
from transformers import AutoTokenizer
tokenizer_config = AutoTokenizer.from_pretrained(
query, trust_remote_code=True)
if tokenizer_config.chat_template is None:
return 'base'
except Exception as e:
assert type(e) == OSError
3 changes: 3 additions & 0 deletions tests/test_lmdeploy/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@pytest.mark.parametrize(
'model_path_and_name',
[('internlm/internlm-chat-7b', ['internlm']),
('internlm/internlm2-1_8b', ['base']),
('models--internlm--internlm-chat-7b/snapshots/1234567', ['internlm']),
('Qwen/Qwen-7B-Chat', ['qwen']),
('codellama/CodeLlama-7b-hf', ['codellama']),
Expand All @@ -19,6 +20,8 @@
('tiiuae/falcon-7b', ['falcon']), ('workspace', [None])])
@pytest.mark.parametrize('suffix', ['', '-w4', '-4bit', '-16bit'])
def test_best_match_model(model_path_and_name, suffix):
if model_path_and_name[0] == 'internlm/internlm2-1_8b' and suffix:
return # internlm/internlm2-1_8b-suffix will got None
deduced_name = best_match_model(model_path_and_name[0] + suffix)
if deduced_name is not None:
assert deduced_name in model_path_and_name[
Expand Down

0 comments on commit 2da44bf

Please sign in to comment.