MCPcopy
hub / github.com/XPixelGroup/DiffBIR / eval_model

Function eval_model

llava/eval/run_llava.py:50–128  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

48
49
50def eval_model(args):
51 # Model
52 disable_torch_init()
53
54 model_name = get_model_name_from_path(args.model_path)
55 tokenizer, model, image_processor, context_len = load_pretrained_model(
56 args.model_path, args.model_base, model_name
57 )
58
59 qs = args.query
60 image_token_se = DEFAULT_IM_START_TOKEN + DEFAULT_IMAGE_TOKEN + DEFAULT_IM_END_TOKEN
61 if IMAGE_PLACEHOLDER in qs:
62 if model.config.mm_use_im_start_end:
63 qs = re.sub(IMAGE_PLACEHOLDER, image_token_se, qs)
64 else:
65 qs = re.sub(IMAGE_PLACEHOLDER, DEFAULT_IMAGE_TOKEN, qs)
66 else:
67 if model.config.mm_use_im_start_end:
68 qs = image_token_se + "\n" + qs
69 else:
70 qs = DEFAULT_IMAGE_TOKEN + "\n" + qs
71
72 if "llama-2" in model_name.lower():
73 conv_mode = "llava_llama_2"
74 elif "mistral" in model_name.lower():
75 conv_mode = "mistral_instruct"
76 elif "v1.6-34b" in model_name.lower():
77 conv_mode = "chatml_direct"
78 elif "v1" in model_name.lower():
79 conv_mode = "llava_v1"
80 elif "mpt" in model_name.lower():
81 conv_mode = "mpt"
82 else:
83 conv_mode = "llava_v0"
84
85 if args.conv_mode is not None and conv_mode != args.conv_mode:
86 print(
87 "[WARNING] the auto inferred conversation mode is {}, while `--conv-mode` is {}, using {}".format(
88 conv_mode, args.conv_mode, args.conv_mode
89 )
90 )
91 else:
92 args.conv_mode = conv_mode
93
94 conv = conv_templates[args.conv_mode].copy()
95 conv.append_message(conv.roles[0], qs)
96 conv.append_message(conv.roles[1], None)
97 prompt = conv.get_prompt()
98
99 image_files = image_parser(args)
100 images = load_images(image_files)
101 image_sizes = [x.size for x in images]
102 images_tensor = process_images(
103 images,
104 image_processor,
105 model.config
106 ).to(model.device, dtype=torch.float16)
107

Callers 1

run_llava.pyFile · 0.70

Calls 11

disable_torch_initFunction · 0.90
get_model_name_from_pathFunction · 0.90
load_pretrained_modelFunction · 0.90
process_imagesFunction · 0.90
tokenizer_image_tokenFunction · 0.90
image_parserFunction · 0.85
load_imagesFunction · 0.85
copyMethod · 0.80
append_messageMethod · 0.80
get_promptMethod · 0.80
generateMethod · 0.45

Tested by

no test coverage detected