1313pip install ' ms-swift[llm]' -U
1414```
1515
16+ 模型链接:
17+ - deepseek-vl-1_3b-chat: [ https://www.modelscope.cn/models/deepseek-ai/deepseek-vl-1.3b-chat/summary ] ( https://www.modelscope.cn/models/deepseek-ai/deepseek-vl-1.3b-chat/summary )
18+ - deepseek-vl-7b-chat: [ https://www.modelscope.cn/models/deepseek-ai/deepseek-vl-7b-chat/summary ] ( https://www.modelscope.cn/models/deepseek-ai/deepseek-vl-7b-chat/summary )
19+
20+
1621## 推理
1722
18- 推理 [ deepseek -vl-7b-chat] ( https://www.modelscope.cn/models/deepseek-ai/deepseek-vl-7b-chat/summary ) :
23+ 推理deepseek -vl-7b-chat:
1924
2025``` shell
2126# Experimental environment: A100
@@ -29,29 +34,36 @@ CUDA_VISIBLE_DEVICES=0 swift infer --model_type deepseek-vl-1_3b-chat
29347b模型效果展示: (支持传入本地路径或URL)
3035``` python
3136"""
32- <<< 描述这种图片
33- Input a media path or URL <<< http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png
34- 这幅图片捕捉到了一只小猫咪迷人的场景,它的眼睛睁得大大的,带着好奇心。小猫的毛发是白色和灰色的混合,给它一种几乎是空灵的外观。它的耳朵尖尖的,警觉地向上指,而它的鼻子是柔和的粉红色。小猫的眼睛是醒目的蓝色,充满了天真和好奇。小猫舒适地坐在一块白色的布料上,与它的灰色和白色毛发形成了美丽的对比。背景模糊,使人们的焦点集中在小猫的脸上,突出了它特征的精细细节。这幅图片散发出一种温暖和柔软的感觉,捕捉到了小猫的纯真和魅力。
37+ <<< 你是谁?
38+ 我是一个人工智能助手,专门设计来帮助用户解答问题和提供信息。我可以帮助你了解各种主题,从语言学习到视觉识别技术。有什么我可以帮助你的吗?
39+ --------------------------------------------------
40+ <<< <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png</img><img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png</img>这两张图片有什么区别
41+ 这两张图片的主要区别在于它们描绘的动物和场景。
42+
43+ 第一张图片展示了一只小猫,它有着醒目的蓝色眼睛和灰白色的毛皮。小猫坐在一个模糊的背景前,看起来像是一张白色的床单或毯子。小猫的目光直直地对着相机,给人一种好奇和警觉的印象。
44+
45+ 第二张图片展示了一群羊站在一个绿色的田野中。羊的毛皮是白色和棕色的,它们站在一片绿色的草地上,背景中可以看到山脉。羊群看起来很平静,没有特别指向相机,这表明它们可能正在吃草或仅仅是享受田野。
46+
47+ 两张图片的背景都是模糊的,这有助于将焦点集中在动物上。然而,第一张图片中的背景更简单,只有一张白色的床单,而第二张图片中的背景更复杂,包括了绿色的田野和远处的山脉。
48+
49+ 总的来说,这两张图片捕捉了两种不同的场景:一只小猫在室内环境中,而一群羊在户外环境中。
3550--------------------------------------------------
36- <<< 图中有几只羊?
37- Input a media path or URL <<< http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png
38- 图片中有四只羊。
51+ <<< <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png</img>图中有几只羊
52+ 图中有四只羊。
3953--------------------------------------------------
40- <<< 计算结果是多少
41- Input a media path or URL <<< http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/math.png
54+ <<< <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/math.png</img>计算结果是多少
4255将1452和45304相加的结果是1452 + 45304 = 46756。
4356--------------------------------------------------
44- <<< 根据图片中的内容写首诗
45- Input a media path or URL <<< http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/poem.png
57+ <<< <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/poem.png</img>根据图片中的内容写首诗
4658星辉洒落湖面静,
47- 独舟轻摇夜风中 。
59+ 独舟轻摇夜色中 。
4860灯火摇曳伴星辰,
4961波光粼粼映山影。
5062
51- 翠竹轻拂夜色浓 ,
52- 银河倒挂水天清 。
53- 渔火点点入梦来 ,
54- 一舟一人话星辰 。
63+ 轻风拂过水面涟 ,
64+ 舟儿前行不自知 。
65+ 夜深人静思绪远 ,
66+ 孤舟独行心悠然 。
5567"""
5668```
5769
@@ -97,16 +109,14 @@ model.generation_config.max_new_tokens = 256
97109template = get_template(template_type, tokenizer)
98110seed_everything(42 )
99111
100- images = [' http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/road.png' ]
101- query = ' 距离各城市多远?'
102- response, history = inference(model, template, query, images = images)
112+ query = ' <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/road.png</img>距离各城市多远?'
113+ response, history = inference(model, template, query)
103114print (f ' query: { query} ' )
104115print (f ' response: { response} ' )
105116
106117# 流式
107118query = ' 距离最远的城市是哪?'
108- images = images * 2
109- gen = inference_stream(model, template, query, history, images = images)
119+ gen = inference_stream(model, template, query, history)
110120print_idx = 0
111121print (f ' query: { query} \n response: ' , end = ' ' )
112122for response, history in gen:
@@ -116,7 +126,7 @@ for response, history in gen:
116126print ()
117127print (f ' history: { history} ' )
118128"""
119- query: 距离各城市多远?
129+ query: <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/road.png</img> 距离各城市多远?
120130response: 这个标志显示了从当前位置到以下城市的距离:
121131
122132- 马塔(Mata):14公里
@@ -125,8 +135,8 @@ response: 这个标志显示了从当前位置到以下城市的距离:
125135
126136这些信息是根据图片中的标志提供的。
127137query: 距离最远的城市是哪?
128- response: 距离最远的那个城市是广州,根据标志所示,从当前位置到广州的距离是293公里 。
129- history: [['距离各城市多远?', '这个标志显示了从当前位置到以下城市的距离:\n\n - 马塔(Mata):14公里\n - 阳江(Yangjiang):62公里\n - 广州(Guangzhou):293公里\n\n 这些信息是根据图片中的标志提供的。'], ['距离最远的城市是哪?', '距离最远的那个城市是广州,根据标志所示,从当前位置到广州的距离是293公里 。']]
138+ response: 根据图片中的标志,距离最远的城市是广州,距离为293公里 。
139+ history: [['<img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/road.png</img> 距离各城市多远?', '这个标志显示了从当前位置到以下城市的距离:\n\n - 马塔(Mata):14公里\n - 阳江(Yangjiang):62公里\n - 广州(Guangzhou):293公里\n\n 这些信息是根据图片中的标志提供的。'], ['距离最远的城市是哪?', '根据图片中的标志,距离最远的城市是广州,距离为293公里 。']]
130140"""
131141```
132142
@@ -148,7 +158,7 @@ LoRA微调:
148158# 20GB GPU memory
149159CUDA_VISIBLE_DEVICES=0 swift sft \
150160 --model_type deepseek-vl-7b-chat \
151- --dataset coco-mini-en-2 \
161+ --dataset coco-mini-en \
152162```
153163
154164全参数微调:
@@ -157,21 +167,35 @@ CUDA_VISIBLE_DEVICES=0 swift sft \
157167# 4 * 70GB GPU memory
158168NPROC_PER_NODE=4 CUDA_VISIBLE_DEVICES=0,1,2,3 swift sft \
159169 --model_type deepseek-vl-7b-chat \
160- --dataset coco-mini-en-2 \
161- --train_dataset_sample -1 \
170+ --dataset coco-mini-en \
162171 --sft_type full \
163172 --use_flash_attn true \
164173 --deepspeed default-zero2
165174```
166175
167176[ 自定义数据集] ( ../LLM/自定义与拓展.md#-推荐命令行参数的形式 ) 支持json, jsonl样式, 以下是自定义数据集的例子:
168177
169- (支持多轮对话, 每轮对话必须包含一张图片, 支持传入本地路径或URL)
170-
171- ``` jsonl
172- {"query" : " 55555" , "response" : " 66666" , "images" : [" image_path" ]}
173- {"query" : " eeeee" , "response" : " fffff" , "history" : [], "images" : [" image_path" ]}
174- {"query" : " EEEEE" , "response" : " FFFFF" , "history" : [[" AAAAA" , " BBBBB" ], [" CCCCC" , " DDDDD" ]], "images" : [" image_path" , " image_path2" , " image_path3" ]}
178+ (支持多轮对话, 支持每轮对话含多张图片或不含图片, 支持传入本地路径或URL)
179+
180+ ``` json
181+ [
182+ {"conversations" : [
183+ {"from" : " user" , "value" : " <img>img_path</img>11111" },
184+ {"from" : " assistant" , "value" : " 22222" }
185+ ]},
186+ {"conversations" : [
187+ {"from" : " user" , "value" : " <img>img_path</img><img>img_path2</img><img>img_path3</img>aaaaa" },
188+ {"from" : " assistant" , "value" : " bbbbb" },
189+ {"from" : " user" , "value" : " <img>img_path</img>ccccc" },
190+ {"from" : " assistant" , "value" : " ddddd" }
191+ ]},
192+ {"conversations" : [
193+ {"from" : " user" , "value" : " AAAAA" },
194+ {"from" : " assistant" , "value" : " BBBBB" },
195+ {"from" : " user" , "value" : " CCCCC" },
196+ {"from" : " assistant" , "value" : " DDDDD" }
197+ ]}
198+ ]
175199```
176200
177201
0 commit comments