Skip to content

Commit

Permalink
Fix issue with encodings for together models. (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelNiklaus authored Jan 7, 2025
1 parent f6fee3a commit 2073a29
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lighteval/models/litellm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,18 @@ def greedy_until(
def tokenizer(self):
return self._tokenizer

def _encode(self, text: str):
enc = encode(model=self.model, text=text)
if hasattr(enc, "ids"):
return enc.ids
return enc

def tok_encode(self, text: str | list[str]):
if isinstance(text, list):
toks = [encode(model=self.model, text=t["content"]) for t in text]
toks = [self._encode(t["content"]) for t in text]
toks = [tok for tok in toks if tok]
return toks
return encode(model=self.model, text=text)
return self._encode(text)

@property
def add_special_tokens(self) -> bool:
Expand Down

0 comments on commit 2073a29

Please sign in to comment.