Skip to content
Merged
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
14 changes: 12 additions & 2 deletions tests/unit_tests/mocks/mock_hf_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

def make_mock_model_and_tokenizer():
"""Returns a tuple of HF AutoModelForCausalLM and AutoTokenizer."""
import torch

torch.set_num_threads(1)

from transformers import AutoModelForCausalLM, AutoTokenizer

# Can regenerate the sample pipe with this:
Expand All @@ -15,9 +19,15 @@ def make_mock_model_and_tokenizer():
os.path.abspath(os.path.normpath(os.path.dirname(__file__))), "tiny-random-gpt2"
)

model = AutoModelForCausalLM.from_pretrained(savedir, local_files_only=True)
model = AutoModelForCausalLM.from_pretrained(
savedir,
local_files_only=True,
)

tokenizer = AutoTokenizer.from_pretrained(savedir, local_files_only=True)
tokenizer = AutoTokenizer.from_pretrained(
savedir,
local_files_only=True,
)

return model, tokenizer

Expand Down