Open rexainn opened 4 months ago
@rexainn 麻烦把推理代码也贴一下,我们看看问题
@rexainn 麻烦把推理代码也贴一下,我们看看问题
以下是我的推理代码:
import torch, auto_gptq
from modelscope import snapshot_download, AutoModel, AutoTokenizer
from auto_gptq.modeling._base import BaseGPTQForCausalLM
import json
heatmap = []
results = []
top = 5
result_file = "/DATA/DATA1/renxiaoyu/202403_mllm/results/asd/internlm-xcomposer_" + str(top) + ".json"
with open('/DATA/DATA1/renxiaoyu/202403_mllm/data/heatmap_asd_list.txt', 'r', encoding='utf-8') as f:
for ann in f.readlines():
ann = ann.strip('\n') #去除文本中的换行符
heatmap.append(ann)
auto_gptq.modeling._base.SUPPORTED_MODELS = ["internlm"]
torch.set_grad_enabled(False)
class InternLMXComposer2QForCausalLM(BaseGPTQForCausalLM):
layers_block_name = "model.layers"
outside_layer_modules = [
'vit', 'vision_proj', 'model.tok_embeddings', 'model.norm', 'output',
]
inside_layer_modules = [
["attention.wqkv.linear"],
["attention.wo.linear"],
["feed_forward.w1.linear", "feed_forward.w3.linear"],
["feed_forward.w2.linear"],
]
# init model and tokenizer
model_dir = snapshot_download('Shanghai_AI_Laboratory/internlm-xcomposer2-vl-7b-4bit')
model = InternLMXComposer2QForCausalLM.from_quantized(model_dir, trust_remote_code=True, device="cuda:0").eval()
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
text = '<ImageHere> You are a classifier, and the two classes are autistic and normal. Based on this saliency map, which is generated through real eyemovements, you should judge whether the gaze there is more like an autistic person or more like a normal person. The output format is like a dict:{class: autistic or normal, reasons: why}.'
with torch.cuda.amp.autocast():
for idx in range(top):
image = heatmap[idx]
response, _ = model.chat(tokenizer, query=text, image=image, history=[], do_sample=False)
print(response)
bug: