Views
No views yet

1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3ckpt_path = "internlm/internlm-xcomposer2-4khd-7b"
4tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
5# Set `torch_dtype=torch.floatb16` to load model in bfloat16, otherwise it will be loaded as float32 and might cause OOM Error.
6model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.bfloat16, 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-4khd-7b', torch_dtype=torch.bfloat16, trust_remote_code=True).cuda().eval()
8tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2-4khd-7b', trust_remote_code=True)
9
10###############
11# First Round
12###############
13
14query1 = '<ImageHere>Illustrate the fine details present in the image'
15image = './example.webp'
16with torch.cuda.amp.autocast():
17 response, his = model.chat(tokenizer, query=query, image=image, hd_num=55, history=[], do_sample=False, num_beams=3)
18print(response)
19# The image is a vibrant and colorful infographic that showcases 7 graphic design trends that will dominate in 2021. The infographic is divided into 7 sections, each representing a different trend.
20# Starting from the top, the first section focuses on "Muted Color Palettes", highlighting the use of muted colors in design.
21# The second section delves into "Simple Data Visualizations", emphasizing the importance of easy-to-understand data visualizations.
22# The third section introduces "Geometric Shapes Everywhere", showcasing the use of geometric shapes in design.
23# The fourth section discusses "Flat Icons and Illustrations", explaining how flat icons and illustrations are being used in design.
24# The fifth section is dedicated to "Classic Serif Fonts", illustrating the resurgence of classic serif fonts in design.
25# The sixth section explores "Social Media Slide Decks", illustrating how slide decks are being used on social media.
26# Finally, the seventh section focuses on "Text Heavy Videos", illustrating the trend of using text-heavy videos in design.
27# Each section is filled with relevant images and text, providing a comprehensive overview of the 7 graphic design trends that will dominate in 2021.
28
29###############
30# Second Round
31###############
32query1 = 'what is the detailed explanation of the third part.'
33with torch.cuda.amp.autocast():
34 response, _ = model.chat(tokenizer, query=query1, image=image, hd_num=55, history=his, do_sample=False, num_beams=3)
35print(response)
36# The third part of the infographic is about "Geometric Shapes Everywhere". It explains that last year, designers used a lot of
37# flowing and abstract shapes in their designs. However, this year, they have been replaced with rigid, hard-edged geometric
38# shapes and patterns. The hard edges of a geometric shape create a great contrast against muted colors.
39
40
41