Experiments / model_loader.py
credent007's picture
change to old setup
f26ff7c verified
raw
history blame
1.42 kB
import torch
from transformers import AutoProcessor, AutoModelForVision2Seq
MODEL_NAME = "Qwen/Qwen2.5-VL-7B-Instruct"
device = "cuda" if torch.cuda.is_available() else "cpu"
print("Loading processor...")
processor = AutoProcessor.from_pretrained(
MODEL_NAME,
trust_remote_code=True,
use_fast=True) # use_fast to avoid warnings in logs
print("Loading model...")
model = AutoModelForVision2Seq.from_pretrained(
MODEL_NAME,
trust_remote_code=True,
torch_dtype=torch.float16,
device_map="auto"
)
print("Model loaded successfully")
# import torch
# from transformers import AutoProcessor, AutoModelForVision2Seq
# MODEL_NAME = "Qwen/Qwen2.5-VL-7B-Instruct"
# model = None
# processor = None
# device = "cuda" if torch.cuda.is_available() else "cpu"
# def get_model():
# global model, processor, device
# if model is None or processor is None:
# print("Loading processor...")
# processor = AutoProcessor.from_pretrained(
# MODEL_NAME,
# trust_remote_code=True,
# use_fast=True
# )
# print("Loading model...")
# model = AutoModelForVision2Seq.from_pretrained(
# MODEL_NAME,
# trust_remote_code=True,
# torch_dtype=torch.float16,
# device_map="auto"
# )
# print("Model loaded successfully")
# return model, processor, device