Skip to content

Commit 2073a29

Browse files
authored
Fix issue with encodings for together models. (#483)
1 parent f6fee3a commit 2073a29

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lighteval/models/litellm_model.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,18 @@ def greedy_until(
255255
def tokenizer(self):
256256
return self._tokenizer
257257

258+
def _encode(self, text: str):
259+
enc = encode(model=self.model, text=text)
260+
if hasattr(enc, "ids"):
261+
return enc.ids
262+
return enc
263+
258264
def tok_encode(self, text: str | list[str]):
259265
if isinstance(text, list):
260-
toks = [encode(model=self.model, text=t["content"]) for t in text]
266+
toks = [self._encode(t["content"]) for t in text]
261267
toks = [tok for tok in toks if tok]
262268
return toks
263-
return encode(model=self.model, text=text)
269+
return self._encode(text)
264270

265271
@property
266272
def add_special_tokens(self) -> bool:

0 commit comments

Comments
 (0)