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

add variable cache_dir to download models in specified directory #72

Open
wants to merge 2 commits 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
3 changes: 2 additions & 1 deletion galai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

def load_model(
name: str,
cache_dir: str,
dtype: Union[str, torch.dtype] = None,
num_gpus: int = None,
parallelize: bool = False
Expand Down Expand Up @@ -128,6 +129,6 @@ def load_model(
tensor_parallel=parallelize,
)
model._set_tokenizer(hf_model)
model._load_checkpoint(checkpoint_path=hf_model)
model._load_checkpoint(checkpoint_path=hf_model, cache_dir=cache_dir)

return model
3 changes: 2 additions & 1 deletion galai/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
self.max_input_length = 2020
self._master_port = None

def _load_checkpoint(self, checkpoint_path: str):
def _load_checkpoint(self, checkpoint_path: str, cache_dir: str):
"""
Loads the checkpoint for the model

Expand All @@ -108,6 +108,7 @@ def _load_checkpoint(self, checkpoint_path: str):

self.model = OPTForCausalLM.from_pretrained(
checkpoint_path,
cache_dir=cache_dir,
torch_dtype=self.dtype,
low_cpu_mem_usage=True,
device_map=device_map,
Expand Down