Skip to content

Commit

Permalink
Remove top-level imports of transformers and datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Nov 15, 2023
1 parent facac71 commit 1051e8c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions outlines/models/transformers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import torch
from datasets.fingerprint import Hasher
from transformers.file_utils import SPIECE_UNDERLINE

from outlines.models.tokenizer import Tokenizer

Expand Down Expand Up @@ -157,6 +155,8 @@ def decode(self, token_ids: torch.LongTensor) -> List[str]:
return text

def convert_token_to_string(self, token: str) -> str:
from transformers.file_utils import SPIECE_UNDERLINE

string = self.tokenizer.convert_tokens_to_string([token])

if self.is_llama:
Expand All @@ -172,6 +172,8 @@ def __eq__(self, other):
return NotImplemented

def __hash__(self):
from datasets.fingerprint import Hasher

return hash(Hasher.hash(self.tokenizer))


Expand Down

0 comments on commit 1051e8c

Please sign in to comment.