llava : Allow locally downloaded models for QwenVL (#10833)

* Allow locally downloaded models for QwenVL

* Define model_path

* rm trailing space

---------

Co-authored-by: Xuan Son Nguyen <thichthat@gmail.com>
This commit is contained in:
Bartowski 2024-12-15 15:43:25 -05:00 committed by GitHub
parent a0974156f3
commit 4ddd199f6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -88,6 +88,8 @@ def main(args):
else: else:
raise ValueError() raise ValueError()
local_model = False
model_path = ""
model_name = args.model_name model_name = args.model_name
print("model_name: ", model_name) print("model_name: ", model_name)
qwen2vl = Qwen2VLForConditionalGeneration.from_pretrained( qwen2vl = Qwen2VLForConditionalGeneration.from_pretrained(
@ -97,8 +99,10 @@ def main(args):
vcfg = cfg.vision_config vcfg = cfg.vision_config
if os.path.isdir(model_name): if os.path.isdir(model_name):
local_model = True
if model_name.endswith(os.sep): if model_name.endswith(os.sep):
model_name = model_name[:-1] model_name = model_name[:-1]
model_path = model_name
model_name = os.path.basename(model_name) model_name = os.path.basename(model_name)
fname_out = f"{model_name.replace('/', '-').lower()}-vision.gguf" fname_out = f"{model_name.replace('/', '-').lower()}-vision.gguf"
@ -139,6 +143,9 @@ def main(args):
it will be hardcoded in the `clip_image_build_graph` from `clip.cpp`. it will be hardcoded in the `clip_image_build_graph` from `clip.cpp`.
""" """
if local_model:
processor: Qwen2VLProcessor = AutoProcessor.from_pretrained(model_path)
else:
processor: Qwen2VLProcessor = AutoProcessor.from_pretrained(model_name) processor: Qwen2VLProcessor = AutoProcessor.from_pretrained(model_name)
fout.add_array("clip.vision.image_mean", processor.image_processor.image_mean) # type: ignore[reportAttributeAccessIssue] fout.add_array("clip.vision.image_mean", processor.image_processor.image_mean) # type: ignore[reportAttributeAccessIssue]
fout.add_array("clip.vision.image_std", processor.image_processor.image_std) # type: ignore[reportAttributeAccessIssue] fout.add_array("clip.vision.image_std", processor.image_processor.image_std) # type: ignore[reportAttributeAccessIssue]