Change the eos-token argument for mlx_lm.generate (#1176)

This commit is contained in:
Angelos Katharopoulos
2025-01-05 22:26:05 -08:00
committed by GitHub
parent c4833a2f55
commit 25ec2d8c44
2 changed files with 17 additions and 4 deletions

View File

@@ -266,6 +266,18 @@ class TokenizerWrapper:
else {tokenizer.eos_token_id}
)
def add_eos_token(self, token: str):
token_id = None
try:
token_id = int(token)
except ValueError:
token_id = self._tokenizer.convert_tokens_to_ids(token)
if token_id is None:
raise ValueError(f"'{token}' is not a token for this tokenizer")
self._eos_token_ids.add(token_id)
def __getattr__(self, attr):
if attr == "detokenizer":
return self._detokenizer