myownskyW7 commited on
Commit
4e6d71b
1 Parent(s): 194829f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -8
README.md CHANGED
@@ -29,14 +29,13 @@ We release InternLM-XComposer2 series in two versions:
29
  To load the InternLM-XComposer2-7B model using Transformers, use the following code:
30
  ```python
31
  import torch
32
- from PIL import image
33
  from transformers import AutoTokenizer, AutoModelForCausalLM
34
  ckpt_path = "internlm/internlm-xcomposer2-7b"
35
  tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
36
  # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
37
  model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
38
  model = model.eval()
39
- model.vit.resize_pos()
40
  img_path_list = [
41
  './panda.jpg',
42
  './bamboo.jpeg',
@@ -48,9 +47,18 @@ for img_path in img_path_list:
48
  images.append(image)
49
  image = torch.stack(images)
50
  query = '<ImageHere> <ImageHere>please write an article based on the images. Title: my favorite animal.'
51
- response, history = model.chat(tokenizer, query=query, image=image, history=[], meta_instruction='')
 
52
  print(response)
53
- # in this animal kingdom, there are many species of animals. Each animal has its own special charm and characteristics. Among them, I like pandas the most. Pandas have a big black circle on their white furry faces, so they look very cute. It's not surprising that people call them "bearcats." But do you know why they're called pandas? Because pandas only eat bamboo shoots.\n\npandas' favorite food is bamboo shoots. The color of fresh bamboo shoots is light green. There is some starch in it, which can be used to make delicious food. But because panda's stomach doesn't produce amylase, it needs to consume large amounts of bamboo shoots every day to meet its body's nutritional needs. As a result, pandas spend most of their time eating bamboo, as well as sleeping. However, pandas cannot eat any meat except bamboo shoots. When pandas are hungry, they may go into the field to look for ants or other insects to eat. In fact, when pandas really want to eat meat, they can easily get away from it.\n\nbesides their love of eating bamboo, pandas also have another interesting characteristic: they always walk backwards. This makes them look slow and lazy. Although they seem sluggish, they actually run at speeds of up to 35 km/h (21.7 mph) when they need to escape danger! So don't underestimate pandas just because they're lazy!\n\nunfortunately, due to the destruction of natural habitats by humans, there are currently less than 1,800 pandas left in the world. I hope everyone can help me save pandas and protect our environment!
 
 
 
 
 
 
 
 
54
  ```
55
 
56
  ### 通过 Transformers 加载
@@ -63,8 +71,7 @@ ckpt_path = "internlm/internlm-xcomposer2-7b"
63
  tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
64
  # `torch_dtype=torch.float16` 可以令模型以 float16 精度加载,否则 transformers 会将模型加载为 float32,导致显存不足
65
  model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
66
- model = model.eval()
67
- model.vit.resize_pos()
68
  img_path_list = [
69
  './panda.jpg',
70
  './bamboo.jpeg',
@@ -76,7 +83,15 @@ for img_path in img_path_list:
76
  images.append(image)
77
  image = torch.stack(images)
78
  query = '<ImageHere> <ImageHere>请根据图片写一篇作文:我最喜欢的小动物。要求:选准角度,确定立意,明确文体,自拟标题;不要套作,不得抄袭;不得泄露个人信息。'
79
- response, history = model.chat(tokenizer, query=query, image=image, history=[], meta_instruction='')
 
80
  print(response)
81
- # 我最喜欢的小动物\n说起我喜欢的动物,那可多了,有活泼可爱的小白兔、机灵的猴子、忠诚的狗……但是我最喜欢的还是可爱的大熊猫。\n大熊猫是哺乳动物中的一种,主要分布在中国四川、陕西和甘肃等地的山区。它有着大大的眼睛,圆圆的耳朵,胖乎乎的身子,最特别的是它的身体黑白相间,所以大家都叫它“黑白仔”。\n因为它的长相很呆萌,很多人都特别喜欢它,于是就有了许多关于它的玩具。在动物园里可以看到许多熊猫玩具和熊猫主题的衣服,还看到很多小朋友抱着熊猫玩偶在玩呢!\n说到熊猫吃竹子了,那可是它们的最爱,几乎每天都吃不腻。别看它长得肥肥胖胖的,其实它也很瘦啊,都是被肚子里的竹子给撑大的哦!熊猫每次吃东西的时候,都会用两只前爪抓住竹子,然后津津有味地吃起来。\n熊猫虽然看上去温顺又憨厚,但是它发起脾气来也是不客气的。如果你去逗它,惹得它生气了,它会举起它的两个爪子,往你身上挥舞着。这时候你可不能还手哦,因为它那一巴掌下去,可不是闹着玩的,会把你打得鼻青脸肿的哦!如果它觉得无聊了,也会把自己扔进竹筐里来回滚动,好像一个球一样在地上翻滚。看着就让人忍不住想去摸摸它,抱抱它。\n你们知道吗?现在我们的国宝大熊猫已经濒临灭绝了,所以现在我们要好好保护大熊猫,让他们健康快乐地成长。
 
 
 
 
 
 
 
82
  ```
 
29
  To load the InternLM-XComposer2-7B model using Transformers, use the following code:
30
  ```python
31
  import torch
32
+ from PIL import Image
33
  from transformers import AutoTokenizer, AutoModelForCausalLM
34
  ckpt_path = "internlm/internlm-xcomposer2-7b"
35
  tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
36
  # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
37
  model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
38
  model = model.eval()
 
39
  img_path_list = [
40
  './panda.jpg',
41
  './bamboo.jpeg',
 
47
  images.append(image)
48
  image = torch.stack(images)
49
  query = '<ImageHere> <ImageHere>please write an article based on the images. Title: my favorite animal.'
50
+ with torch.cuda.amp.autocast():
51
+ response, history = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False)
52
  print(response)
53
+ """"
54
+ # My favorite animal is the panda. Pandas are one of the most popular animals in the world, and for good reason. They are adorable, cuddly creatures that have captured the hearts of people all over the globe.
55
+ Pandas are native to China and can be found in the wild in a few specific regions. However, they are also very popular in captivity, with many zoos around the world housing pandas as part of their exhibits. I have been fortunate enough to see pandas up close at several different zoos, and each time it was an amazing experience.
56
+ One thing that always strikes me about pandas is how much they love to eat bamboo. In fact, pandas spend almost all of their waking hours eating bamboo. This may not seem like a lot of fun, but pandas actually enjoy munching on this tough plant. It's fascinating to watch them chew through the tough stalks and leaves, and then lick their lips in satisfaction.
57
+ Another thing that I find interesting about pandas is their black and white fur. The combination of these two colors creates a striking contrast that makes pandas instantly recognizable. In addition, the black patches on their face give them a unique expression that seems to convey both playfulness and seriousness.
58
+ Despite their popularity, pandas do face some challenges. Their habitat is being destroyed by human activities such as logging and agriculture, which has led to a decline in their population. Additionally, pandas are considered endangered due to factors such as low reproductive rates and limited genetic diversity.
59
+ However, there are efforts underway to protect pandas and their habitats. Many organizations work to raise awareness about the importance of preserving these beautiful creatures, and governments in countries where pandas live are taking steps to conserve their natural environment.
60
+ In conclusion, pandas are truly remarkable animals that deserve our admiration and protection. With their distinctive appearance, playful personalities, and love of bamboo, it's no wonder that pandas have become so beloved around the world. Let's do what we can to ensure that future generations can continue to appreciate these wonderful creatures.
61
+ """
62
  ```
63
 
64
  ### 通过 Transformers 加载
 
71
  tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
72
  # `torch_dtype=torch.float16` 可以令模型以 float16 精度加载,否则 transformers 会将模型加载为 float32,导致显存不足
73
  model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
74
+ model = model.eval()
 
75
  img_path_list = [
76
  './panda.jpg',
77
  './bamboo.jpeg',
 
83
  images.append(image)
84
  image = torch.stack(images)
85
  query = '<ImageHere> <ImageHere>请根据图片写一篇作文:我最喜欢的小动物。要求:选准角度,确定立意,明确文体,自拟标题;不要套作,不得抄袭;不得泄露个人信息。'
86
+ with torch.cuda.amp.autocast():
87
+ response, history = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False)
88
  print(response)
89
+ """
90
+ # 我最喜欢的小动物
91
+ 我喜欢许多小动物,有活泼可爱的小狗、美丽高贵的孔雀……但我最喜欢的是那一只憨态可掬的大熊猫。
92
+ 大熊猫的毛色黑白分明,身体胖乎乎的,四肢短小,走起路来摇摇晃晃,样子十分可爱。它的头又圆又大,耳朵小小的,眼睛黑黑的,像两颗闪闪发光的黑宝石。它还有一张大大的嘴巴,里面长着锋利的牙齿,看起来非常凶猛。但是,别看它长得这么凶猛,其实它很胆小,一听到一点声音就会吓得躲到树后面去。
93
+ 大熊猫是国宝,也是我们中国的象征。它们喜欢吃竹子,每天要吃30多斤的竹子,所以人们给它取了一个外号叫“食竹动物”。
94
+ 大熊猫不仅爱吃竹子,还爱睡觉。一天中,除了吃就是睡,吃饱了就睡,睡醒了再吃,真是一个名副其实的“大懒虫”。
95
+ 这就是我喜欢的动物——大熊猫,你们喜欢吗?
96
+ """
97
  ```