wilsonHuggingFace commited on
Commit
c105666
·
verified ·
1 Parent(s): 9146dd5

Update IXC2-4KHD.py

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