Spaces:
Running
on
Zero
Running
on
Zero
File size: 5,693 Bytes
b2682d8 76cfa14 b2682d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
import os
import sys
import torch
from openai import OpenAI
from transformers import (
LlavaNextProcessor, LlavaNextForConditionalGeneration,
Qwen2VLForConditionalGeneration, Qwen2VLProcessor
)
## init device
device = "cpu"
torch_dtype = torch.float16
vlms_list = [
# {
# "type": "llava-next",
# "name": "llava-v1.6-mistral-7b-hf",
# "local_path": "models/vlms/llava-v1.6-mistral-7b-hf",
# "processor": LlavaNextProcessor.from_pretrained(
# "models/vlms/llava-v1.6-mistral-7b-hf"
# ) if os.path.exists("models/vlms/llava-v1.6-mistral-7b-hf") else LlavaNextProcessor.from_pretrained(
# "llava-hf/llava-v1.6-mistral-7b-hf"
# ),
# "model": LlavaNextForConditionalGeneration.from_pretrained(
# "models/vlms/llava-v1.6-mistral-7b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu") if os.path.exists("models/vlms/llava-v1.6-mistral-7b-hf") else
# LlavaNextForConditionalGeneration.from_pretrained(
# "llava-hf/llava-v1.6-mistral-7b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu"),
# },
# {
# "type": "llava-next",
# "name": "llama3-llava-next-8b-hf (Preload)",
# "local_path": "models/vlms/llama3-llava-next-8b-hf",
# "processor": LlavaNextProcessor.from_pretrained(
# "models/vlms/llama3-llava-next-8b-hf"
# ) if os.path.exists("models/vlms/llama3-llava-next-8b-hf") else LlavaNextProcessor.from_pretrained(
# "llava-hf/llama3-llava-next-8b-hf"
# ),
# "model": LlavaNextForConditionalGeneration.from_pretrained(
# "models/vlms/llama3-llava-next-8b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu") if os.path.exists("models/vlms/llama3-llava-next-8b-hf") else
# LlavaNextForConditionalGeneration.from_pretrained(
# "llava-hf/llama3-llava-next-8b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu"),
# },
# {
# "type": "llava-next",
# "name": "llava-v1.6-vicuna-13b-hf",
# "local_path": "models/vlms/llava-v1.6-vicuna-13b-hf",
# "processor": LlavaNextProcessor.from_pretrained(
# "models/vlms/llava-v1.6-vicuna-13b-hf"
# ) if os.path.exists("models/vlms/llava-v1.6-vicuna-13b-hf") else LlavaNextProcessor.from_pretrained(
# "llava-hf/llava-v1.6-vicuna-13b-hf"
# ),
# "model": LlavaNextForConditionalGeneration.from_pretrained(
# "models/vlms/llava-v1.6-vicuna-13b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu") if os.path.exists("models/vlms/llava-v1.6-vicuna-13b-hf") else
# LlavaNextForConditionalGeneration.from_pretrained(
# "llava-hf/llava-v1.6-vicuna-13b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu"),
# },
# {
# "type": "llava-next",
# "name": "llava-v1.6-34b-hf",
# "local_path": "models/vlms/llava-v1.6-34b-hf",
# "processor": LlavaNextProcessor.from_pretrained(
# "models/vlms/llava-v1.6-34b-hf"
# ) if os.path.exists("models/vlms/llava-v1.6-34b-hf") else LlavaNextProcessor.from_pretrained(
# "llava-hf/llava-v1.6-34b-hf"
# ),
# "model": LlavaNextForConditionalGeneration.from_pretrained(
# "models/vlms/llava-v1.6-34b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu") if os.path.exists("models/vlms/llava-v1.6-34b-hf") else
# LlavaNextForConditionalGeneration.from_pretrained(
# "llava-hf/llava-v1.6-34b-hf", torch_dtype=torch_dtype, device_map=device
# ).to("cpu"),
# },
# {
# "type": "qwen2-vl",
# "name": "Qwen2-VL-2B-Instruct",
# "local_path": "models/vlms/Qwen2-VL-2B-Instruct",
# "processor": Qwen2VLProcessor.from_pretrained(
# "models/vlms/Qwen2-VL-2B-Instruct"
# ) if os.path.exists("models/vlms/Qwen2-VL-2B-Instruct") else Qwen2VLProcessor.from_pretrained(
# "Qwen/Qwen2-VL-2B-Instruct"
# ),
# "model": Qwen2VLForConditionalGeneration.from_pretrained(
# "models/vlms/Qwen2-VL-2B-Instruct", torch_dtype=torch_dtype, device_map=device
# ).to("cpu") if os.path.exists("models/vlms/Qwen2-VL-2B-Instruct") else
# Qwen2VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2-VL-2B-Instruct", torch_dtype=torch_dtype, device_map=device
# ).to("cpu"),
# },
{
"type": "qwen2-vl",
"name": "Qwen2-VL-7B-Instruct (Default)",
"local_path": "models/vlms/Qwen2-VL-7B-Instruct",
"processor": Qwen2VLProcessor.from_pretrained(
"models/vlms/Qwen2-VL-7B-Instruct"
) if os.path.exists("models/vlms/Qwen2-VL-7B-Instruct") else Qwen2VLProcessor.from_pretrained(
"Qwen/Qwen2-VL-7B-Instruct"
),
"model": Qwen2VLForConditionalGeneration.from_pretrained(
"models/vlms/Qwen2-VL-7B-Instruct", torch_dtype=torch_dtype, device_map=device
).to("cpu") if os.path.exists("models/vlms/Qwen2-VL-7B-Instruct") else
Qwen2VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2-VL-7B-Instruct", torch_dtype=torch_dtype, device_map=device
).to("cpu"),
},
{
"type": "openai",
"name": "GPT4-o (Highly Recommended)",
"local_path": "",
"processor": "",
"model": ""
},
]
vlms_template = {k["name"]: (k["type"], k["local_path"], k["processor"], k["model"]) for k in vlms_list} |