Skip to content

Added cache_dir argument #2212

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

Closed
Closed
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
12 changes: 6 additions & 6 deletions tools/who_what_benchmark/whowhatbench/model_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def load_text_llamacpp_pipeline(model_dir):
return model


def load_text_hf_pipeline(model_id, device):
def load_text_hf_pipeline(model_id, device, cache_dir=None):
model_kwargs = {}

if not torch.cuda.is_available or device.lower() == "cpu":
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True, cache_dir=cache_dir)
is_gptq = False
is_awq = False
if getattr(config, "quantization_config", None):
Expand All @@ -111,11 +111,11 @@ def load_text_hf_pipeline(model_id, device):


def load_text_model(
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, use_llamacpp=False, **kwargs,
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, use_llamacpp=False, cache_dir=None, **kwargs,
):
if use_hf:
logger.info("Using HF Transformers API")
model = load_text_hf_pipeline(model_id, device)
model = load_text_hf_pipeline(model_id, device, cache_dir)
elif use_genai:
model = load_text_genai_pipeline(model_id, device, ov_config, **kwargs)
elif use_llamacpp:
Expand Down Expand Up @@ -366,7 +366,7 @@ def load_inpainting_model(


def load_model(
model_type, model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, use_llamacpp=False, **kwargs
model_type, model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, use_llamacpp=False, cache_dir=None, **kwargs
):
if model_id is None:
return None
Expand All @@ -378,7 +378,7 @@ def load_model(
ov_options = {}

if model_type == "text":
return load_text_model(model_id, device, ov_options, use_hf, use_genai, use_llamacpp, **kwargs)
return load_text_model(model_id, device, ov_options, use_hf, use_genai, use_llamacpp, cache_dir, **kwargs)
elif model_type == "text-to-image":
return load_text2image_model(
model_id, device, ov_options, use_hf, use_genai
Expand Down
8 changes: 8 additions & 0 deletions tools/who_what_benchmark/whowhatbench/wwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def parse_args():
default=42,
help="Text-to-image specific parameter that defines the seed value.",
)
parser.add_argument(
"--cache-dir",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--cache-dir is a generic name but option enabled for text hf text models only. Does it make sense to rename it to --hf-cache-dir and support other model types (text-to-image, visual-text etc)?

type=str,
default=None,
help="Path to the local (non-standard) Huggingface cache containing the model files.",
)

return parser.parse_args()

Expand Down Expand Up @@ -512,6 +518,7 @@ def main():
args.ov_config,
args.hf,
args.genai,
args.cache_dir,
**kwargs,
)
evaluator = create_evaluator(base_model, args)
Expand All @@ -536,6 +543,7 @@ def main():
args.hf,
args.genai,
args.llamacpp,
args.cache_dir,
**kwargs
)
all_metrics_per_question, all_metrics = evaluator.score(
Expand Down