Skip to content

Commit 01c37e2

Browse files
committed
update
1 parent a3fd2e3 commit 01c37e2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lmdeploy/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ def __init__(self, model_path: str = '', **kwargs):
748748
if hasattr(self.tokenizer, 'eot_token') and self.tokenizer.eot_token is not None:
749749
self.stop_words.append(self.tokenizer.eot_token)
750750
cfg = PretrainedConfig.from_pretrained(model_path, trust_remote_code=True)
751-
if cfg.architectures[0] == 'GptOssForCausalLM':
751+
self.is_gpt_oss = getattr(cfg, 'architectures', [''])[0] == 'GptOssForCausalLM'
752+
if self.is_gpt_oss:
752753
self.stop_words.append('<|call|>')
753754
except Exception as e:
754755
raise ValueError(f'Try apply_chat_template failed: {e}')
@@ -790,6 +791,9 @@ def messages2prompt(self, messages, sequence_start=True, **kwargs):
790791

791792
if messages[-1]['role'] == 'assistant' and len(self.assistant_end) > 0:
792793
prompt = prompt[:-len(self.assistant_end)] # prefix of response to let the model complete the response
794+
if self.is_gpt_oss and not kwargs.get('tools'):
795+
# for gpt-oss model, remove this seems more conducive to instruction following.
796+
prompt = prompt.replace('commentary, ', '', 1)
793797
return prompt
794798

795799
def _role_instruction(self, role):

lmdeploy/serve/async_engine.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,6 @@ async def _get_prompt_input(self,
633633
raise ValueError(
634634
f'You are using base template to handle chat task. Please specify a `--chat-template` name chosen from `lmdeploy list` if you want to use OpenAI messages input.' # noqa
635635
)
636-
if self.arch == 'GptOssForCausalLM' and (tools is None or len(tools) == 0):
637-
# for gpt-oss model, remove this seems more conducive to instruction following.
638-
prompt = prompt.replace('commentary, ', '', 1)
639636
input_ids = self.tokenizer.encode(prompt, add_bos=sequence_start)
640637
return {'prompt': prompt, 'input_ids': input_ids}
641638

0 commit comments

Comments
 (0)