diff --git a/swift/llm/template/base.py b/swift/llm/template/base.py index 676158ff83..5993dfee0c 100644 --- a/swift/llm/template/base.py +++ b/swift/llm/template/base.py @@ -1139,7 +1139,11 @@ def _swift_encode(self, inputs: StdTemplateInputs): if isinstance(stop_word, str)) # self.is_training needed because we may want to continue generation from # the current response - if (self.is_training or self.task_type != 'causal_lm') and not sep_token and not endswith_stop_words: + add_eos = inputs.extra_kwargs.get('add_eos') + if add_eos is None: + add_eos = (self.is_training + or self.task_type != 'causal_lm') and not sep_token and not endswith_stop_words + if add_eos: extra_context_list = template_meta.suffix extra_context_type = ContextType.SUFFIX elif template_meta.response_prefix: