Skip to content
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
31 changes: 17 additions & 14 deletions tools/who_what_benchmark/whowhatbench/model_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def load_text_model(
use_cache=True,
device=device,
ov_config=ov_config,
**kwargs
)
except Exception:
config = AutoConfig.from_pretrained(model_id)
Expand All @@ -219,6 +220,7 @@ def load_text_model(
use_cache=True,
device=device,
ov_config=ov_config,
**kwargs
)

return model
Expand Down Expand Up @@ -270,9 +272,10 @@ def load_text2image_model(
if 'adapters' in kwargs and kwargs['adapters'] is not None:
raise ValueError("Adapters are not supported for OVPipelineForText2Image.")

model_kwargs = {"from_onnx": kwargs.get('from_onnx', False), "safety_checker": None}
try:
model = TEXT2IMAGEPipeline.from_pretrained(
model_id, device=device, ov_config=ov_config, safety_checker=None,
model_id, device=device, ov_config=ov_config, **model_kwargs
)
except ValueError:
model = TEXT2IMAGEPipeline.from_pretrained(
Expand All @@ -281,7 +284,7 @@ def load_text2image_model(
use_cache=True,
device=device,
ov_config=ov_config,
safety_checker=None,
**model_kwargs
)

return model
Expand Down Expand Up @@ -410,7 +413,7 @@ def load_image2image_genai_pipeline(model_dir, device="CPU", ov_config=None):


def load_imagetext2image_model(
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, **kwargs
):
if use_hf:
from diffusers import AutoPipelineForImage2Image
Expand All @@ -424,9 +427,10 @@ def load_imagetext2image_model(
else:
logger.info("Using Optimum API")
from optimum.intel.openvino import OVPipelineForImage2Image
model_kwargs = {"from_onnx": kwargs.get('from_onnx', False), "safety_checker": None}
try:
model = OVPipelineForImage2Image.from_pretrained(
model_id, device=device, ov_config=ov_config, safety_checker=None,
model_id, device=device, ov_config=ov_config, **model_kwargs
)
except ValueError:
model = OVPipelineForImage2Image.from_pretrained(
Expand All @@ -435,7 +439,7 @@ def load_imagetext2image_model(
use_cache=True,
device=device,
ov_config=ov_config,
safety_checker=None,
**model_kwargs
)
return model

Expand All @@ -455,7 +459,7 @@ def load_inpainting_genai_pipeline(model_dir, device="CPU", ov_config=None):


def load_inpainting_model(
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False
model_id, device="CPU", ov_config=None, use_hf=False, use_genai=False, **kwargs
):
if use_hf:
from diffusers import AutoPipelineForInpainting
Expand All @@ -469,9 +473,10 @@ def load_inpainting_model(
else:
logger.info("Using Optimum API")
from optimum.intel.openvino import OVPipelineForInpainting
model_kwargs = {"from_onnx": kwargs.get('from_onnx', False), "safety_checker": None}
try:
model = OVPipelineForInpainting.from_pretrained(
model_id, device=device, ov_config=ov_config, safety_checker=None,
model_id, device=device, ov_config=ov_config, **model_kwargs
)
except ValueError as e:
logger.error("Failed to load inpaiting pipeline. Details:\n", e)
Expand All @@ -481,7 +486,7 @@ def load_inpainting_model(
use_cache=True,
device=device,
ov_config=ov_config,
safety_checker=None,
**model_kwargs
)
return model

Expand Down Expand Up @@ -530,8 +535,7 @@ def load_embedding_model(model_id, device="CPU", ov_config=None, use_hf=False, u
model = OVModelForFeatureExtraction.from_pretrained(
model_id, device=device, ov_config=ov_config, safety_checker=None,
)
except ValueError as e:
logger.error("Failed to load embedding pipeline. Details:\n", e)
except ValueError:
model = OVModelForFeatureExtraction.from_pretrained(
model_id,
trust_remote_code=True,
Expand Down Expand Up @@ -596,8 +600,7 @@ def load_reranking_model(model_id, device="CPU", ov_config=None, use_hf=False, u
model = model_cls.from_pretrained(
model_id, device=device, ov_config=ov_config, safety_checker=None,
)
except ValueError as e:
logger.error("Failed to load reranking pipeline, an attempt will be made again with updated parameters. Details:\n", e)
except ValueError:
model = model_cls.from_pretrained(
model_id,
trust_remote_code=True,
Expand Down Expand Up @@ -631,9 +634,9 @@ def load_model(
elif model_type == "visual-text":
return load_visual_text_model(model_id, device, ov_options, use_hf, use_genai, **kwargs)
elif model_type == "image-to-image":
return load_imagetext2image_model(model_id, device, ov_options, use_hf, use_genai)
return load_imagetext2image_model(model_id, device, ov_options, use_hf, use_genai, **kwargs)
elif model_type == "image-inpainting":
return load_inpainting_model(model_id, device, ov_options, use_hf, use_genai)
return load_inpainting_model(model_id, device, ov_options, use_hf, use_genai, **kwargs)
elif model_type == "text-embedding":
return load_embedding_model(model_id, device, ov_options, use_hf, use_genai, **kwargs)
elif model_type == "text-reranking":
Expand Down
10 changes: 5 additions & 5 deletions tools/who_what_benchmark/whowhatbench/wwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ def main():
kwargs["cb_config"] = read_cb_config(args.cb_config)
if args.from_onnx:
kwargs["from_onnx"] = args.from_onnx
kwargs["use_cache"] = False
if args.gguf_file:
kwargs["gguf_file"] = args.gguf_file
if args.adapters is not None:
Expand All @@ -720,10 +719,11 @@ def main():
kwargs["alphas"] = args.alphas
else:
kwargs["alphas"] = [1.0] * len(args.adapters)
kwargs["empty_adapters"] = args.empty_adapters
kwargs["embeds_pooling"] = args.embeds_pooling_type
kwargs["embeds_normalize"] = args.embeds_normalize
kwargs["embeds_padding_side"] = args.embeds_padding_side
if args.model_type == "text-embedding":
kwargs["empty_adapters"] = args.empty_adapters
kwargs["embeds_pooling"] = args.embeds_pooling_type
kwargs["embeds_normalize"] = args.embeds_normalize
kwargs["embeds_padding_side"] = args.embeds_padding_side

if args.gt_data and os.path.exists(args.gt_data):
evaluator = create_evaluator(None, args)
Expand Down
Loading