Skip to content

Commit

Permalink
fix internvl-4b (modelscope#3178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintao-Huang authored Feb 19, 2025
1 parent 7989581 commit 12ec92f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions swift/llm/infer/infer_engine/pt_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ def _infer(
except Exception as e:
error_list.append((i, e))
continue
if len(batched_inputs) == 0:
if request_config.stream:

def _gen_wrapper():
yield self._add_error_list([], error_list)

return _gen_wrapper()
else:
return self._add_error_list([], error_list)
template_inputs = [inputs.pop('template_inputs') for inputs in batched_inputs]
inputs = to_device(template.data_collator(batched_inputs), self.model.device)
template.debug_logger(inputs) # debug
Expand Down
8 changes: 4 additions & 4 deletions swift/llm/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ def _swift_encode(self, inputs: StdTemplateInputs):
res_context_types: List[ContextType] = []
sep_token = None
if template_meta.auto_add_bos:
all_tokens = self.tokenizer.encode('0')
single_zero = self.tokenizer.encode('0', add_special_tokens=False)
assert len(single_zero) == 1
idx = all_tokens.index(single_zero[0])
all_tokens = self.tokenizer.encode('a')
single_token = self.tokenizer.encode('a', add_special_tokens=False)
assert len(single_token) == 1
idx = all_tokens.index(single_token[0])
bos_token = all_tokens[:idx]
sep_token = all_tokens[idx + 1:]
if bos_token:
Expand Down

0 comments on commit 12ec92f

Please sign in to comment.