Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SentenceTransformer local_files_only env var #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from typing import List

TRUST_REMOTE_CODE = os.getenv("TRUST_REMOTE_CODE", False)
ST_LOCAL_FILES_ONLY = os.getenv("ST_LOCAL_FILES_ONLY", "False").lower() in (
"true",
"1",
"t",
)


def get_allowed_tokens() -> List[str] | None:
Expand Down
7 changes: 3 additions & 4 deletions vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
T5Tokenizer,
)

from config import ST_LOCAL_FILES_ONLY


# limit transformer batch size to limit parallel inference, otherwise we run
# into memory problems
Expand Down Expand Up @@ -96,6 +98,7 @@ def __init__(
cache_folder=model_path,
device=self.get_device(),
trust_remote_code=trust_remote_code,
local_files_only=ST_LOCAL_FILES_ONLY,
)
self.model.eval() # make sure we're in inference mode, not training

Expand Down Expand Up @@ -258,7 +261,6 @@ def vectorize(self, text: str, config: VectorInputConfig):


class HFModel:

def __init__(self, cuda_support: bool, cuda_core: str, trust_remote_code: bool):
super().__init__()
self.model = None
Expand Down Expand Up @@ -331,7 +333,6 @@ def pool_sum(self, embeddings, attention_mask):


class DPRModel(HFModel):

def __init__(
self,
architecture: str,
Expand Down Expand Up @@ -364,7 +365,6 @@ def pool_embedding(self, batch_results, tokens, config: VectorInputConfig):


class T5Model(HFModel):

def __init__(self, cuda_support: bool, cuda_core: str, trust_remote_code: bool):
super().__init__(cuda_support, cuda_core)
self.model = None
Expand Down Expand Up @@ -406,7 +406,6 @@ def get_batch_results(self, tokens, text):


class ModelFactory:

@staticmethod
def model(
model_type,
Expand Down