Views
No views yet
batchified training and flash-attn for acceleration. Welcome to have a try and give me some advice~
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3ckpt_path = "internlm/internlm-xcomposer2-vl-7b"
4tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
5# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
6model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
7model = model.eval()1import torch
2from transformers import AutoModel, AutoTokenizer
3
4torch.set_grad_enabled(False)
5
6# init model and tokenizer
7model = AutoModel.from_pretrained('internlm/internlm-xcomposer2-vl-7b', trust_remote_code=True).cuda().eval()
8tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2-vl-7b', trust_remote_code=True)
9
10query = '<ImageHere>Please describe this image in detail.'
11image = './image1.webp'
12with torch.cuda.amp.autocast():
13 response, _ = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False)
14print(response)
15#The image features a quote by Oscar Wilde, "Live life with no excuses, travel with no regret,"
16# set against a backdrop of a breathtaking sunset. The sky is painted in hues of pink and orange,
17# creating a serene atmosphere. Two silhouetted figures stand on a cliff, overlooking the horizon.
18# They appear to be hiking or exploring, embodying the essence of the quote.
19# The overall scene conveys a sense of adventure and freedom, encouraging viewers to embrace life without hesitation or regrets.
20