czczup commited on
Commit
19371f1
1 Parent(s): d1769b9

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +77 -23
  2. config.json +1 -1
  3. conversation.py +7 -4
README.md CHANGED
@@ -330,7 +330,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
330
  from lmdeploy.vl import load_image
331
 
332
  model = 'OpenGVLab/InternVL2-2B'
333
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
334
  image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
335
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
336
  chat_template_config.meta_instruction = system_prompt
@@ -346,13 +346,15 @@ If `ImportError` occurs while executing this case, please install the required d
346
 
347
  When dealing with multiple images, you can put them all in one list. Keep in mind that multiple images will lead to a higher number of input tokens, and as a result, the size of the context window typically needs to be increased.
348
 
 
 
349
  ```python
350
  from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
351
  from lmdeploy.vl import load_image
352
  from lmdeploy.vl.constants import IMAGE_TOKEN
353
 
354
  model = 'OpenGVLab/InternVL2-2B'
355
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
356
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
357
  chat_template_config.meta_instruction = system_prompt
358
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -378,7 +380,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
378
  from lmdeploy.vl import load_image
379
 
380
  model = 'OpenGVLab/InternVL2-2B'
381
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
382
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
383
  chat_template_config.meta_instruction = system_prompt
384
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -402,7 +404,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig, Genera
402
  from lmdeploy.vl import load_image
403
 
404
  model = 'OpenGVLab/InternVL2-2B'
405
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
406
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
407
  chat_template_config.meta_instruction = system_prompt
408
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -418,29 +420,55 @@ print(sess.response.text)
418
 
419
  #### Service
420
 
421
- For lmdeploy v0.5.0, please configure the chat template config first. Create the following JSON file `chat_template.json`.
422
 
423
  ```json
424
  {
425
- "model_name":"internlm2",
426
- "meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。",
427
  "stop_words":["<|im_start|>", "<|im_end|>"]
428
  }
429
  ```
430
 
431
- LMDeploy's `api_server` enables models to be easily packed into services with a single command. The provided RESTful APIs are compatible with OpenAI's interfaces. Below are an example of service startup:
432
 
433
  ```shell
434
- lmdeploy serve api_server OpenGVLab/InternVL2-2B --backend turbomind --chat-template chat_template.json
435
  ```
436
 
437
- The default port of `api_server` is `23333`. After the server is launched, you can communicate with server on terminal through `api_client`:
438
 
439
  ```shell
440
- lmdeploy serve api_client http://0.0.0.0:23333
441
  ```
442
 
443
- You can overview and try out `api_server` APIs online by swagger UI at `http://0.0.0.0:23333`, or you can also read the API specification from [here](https://github.com/InternLM/lmdeploy/blob/main/docs/en/serving/restful_api.md).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
  ## License
446
 
@@ -550,7 +578,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
550
  from lmdeploy.vl import load_image
551
 
552
  model = 'OpenGVLab/InternVL2-2B'
553
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
554
  image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
555
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
556
  chat_template_config.meta_instruction = system_prompt
@@ -572,7 +600,7 @@ from lmdeploy.vl import load_image
572
  from lmdeploy.vl.constants import IMAGE_TOKEN
573
 
574
  model = 'OpenGVLab/InternVL2-2B'
575
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
576
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
577
  chat_template_config.meta_instruction = system_prompt
578
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -597,7 +625,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
597
  from lmdeploy.vl import load_image
598
 
599
  model = 'OpenGVLab/InternVL2-2B'
600
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
601
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
602
  chat_template_config.meta_instruction = system_prompt
603
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -621,7 +649,7 @@ from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig, Genera
621
  from lmdeploy.vl import load_image
622
 
623
  model = 'OpenGVLab/InternVL2-2B'
624
- system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
625
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
626
  chat_template_config.meta_instruction = system_prompt
627
  pipe = pipeline(model, chat_template_config=chat_template_config,
@@ -637,12 +665,12 @@ print(sess.response.text)
637
 
638
  #### API部署
639
 
640
- 对于 lmdeploy v0.5.0,请先配置聊天模板配置文件。创建如下的 JSON 文件 `chat_template.json`。
641
 
642
  ```json
643
  {
644
- "model_name":"internlm2",
645
- "meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。",
646
  "stop_words":["<|im_start|>", "<|im_end|>"]
647
  }
648
  ```
@@ -650,16 +678,42 @@ print(sess.response.text)
650
  LMDeploy 的 `api_server` 使模型能够通过一个命令轻松打包成服务。提供的 RESTful API 与 OpenAI 的接口兼容。以下是服务启动的示例:
651
 
652
  ```shell
653
- lmdeploy serve api_server OpenGVLab/InternVL2-2B --backend turbomind --chat-template chat_template.json
654
  ```
655
 
656
- `api_server` 的默认端口是 `23333`。服务器启动后,你可以通过 `api_client` 在终端与服务器通信:
657
 
658
  ```shell
659
- lmdeploy serve api_client http://0.0.0.0:23333
660
  ```
661
 
662
- 你可以通过 `http://0.0.0.0:23333` 的 swagger UI 在线查看和试用 `api_server` 的 API,也可以从 [这里](https://github.com/InternLM/lmdeploy/blob/main/docs/en/serving/restful_api.md) 阅读 API 规范。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
663
 
664
  ## 开源许可证
665
 
 
330
  from lmdeploy.vl import load_image
331
 
332
  model = 'OpenGVLab/InternVL2-2B'
333
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
334
  image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
335
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
336
  chat_template_config.meta_instruction = system_prompt
 
346
 
347
  When dealing with multiple images, you can put them all in one list. Keep in mind that multiple images will lead to a higher number of input tokens, and as a result, the size of the context window typically needs to be increased.
348
 
349
+ > Warning: Due to the scarcity of multi-image conversation data, the performance on multi-image tasks may be unstable, and it may require multiple attempts to achieve satisfactory results.
350
+
351
  ```python
352
  from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
353
  from lmdeploy.vl import load_image
354
  from lmdeploy.vl.constants import IMAGE_TOKEN
355
 
356
  model = 'OpenGVLab/InternVL2-2B'
357
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
358
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
359
  chat_template_config.meta_instruction = system_prompt
360
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
380
  from lmdeploy.vl import load_image
381
 
382
  model = 'OpenGVLab/InternVL2-2B'
383
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
384
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
385
  chat_template_config.meta_instruction = system_prompt
386
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
404
  from lmdeploy.vl import load_image
405
 
406
  model = 'OpenGVLab/InternVL2-2B'
407
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
408
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
409
  chat_template_config.meta_instruction = system_prompt
410
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
420
 
421
  #### Service
422
 
423
+ To deploy InternVL2, please configure the chat template config first. Create the following JSON file `chat_template.json`.
424
 
425
  ```json
426
  {
427
+ "model_name":"internvl-internlm2",
428
+ "meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。",
429
  "stop_words":["<|im_start|>", "<|im_end|>"]
430
  }
431
  ```
432
 
433
+ LMDeploy's `api_server` enables models to be easily packed into services with a single command. The provided RESTful APIs are compatible with OpenAI's interfaces. Below are an example of service startup.
434
 
435
  ```shell
436
+ lmdeploy serve api_server OpenGVLab/InternVL2-2B --model-name InternVL2-2B --backend turbomind --server-port 23333 --chat-template chat_template.json
437
  ```
438
 
439
+ To use the OpenAI-style interface, you need to install OpenAI:
440
 
441
  ```shell
442
+ pip install openai
443
  ```
444
 
445
+ Then, use the code below to make the API call:
446
+
447
+ ```python
448
+ from openai import OpenAI
449
+
450
+ client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
451
+ model_name = client.models.list().data[0].id
452
+ response = client.chat.completions.create(
453
+ model="InternVL2-2B",
454
+ messages=[{
455
+ 'role':
456
+ 'user',
457
+ 'content': [{
458
+ 'type': 'text',
459
+ 'text': 'describe this image',
460
+ }, {
461
+ 'type': 'image_url',
462
+ 'image_url': {
463
+ 'url':
464
+ 'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
465
+ },
466
+ }],
467
+ }],
468
+ temperature=0.8,
469
+ top_p=0.8)
470
+ print(response)
471
+ ```
472
 
473
  ## License
474
 
 
578
  from lmdeploy.vl import load_image
579
 
580
  model = 'OpenGVLab/InternVL2-2B'
581
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
582
  image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
583
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
584
  chat_template_config.meta_instruction = system_prompt
 
600
  from lmdeploy.vl.constants import IMAGE_TOKEN
601
 
602
  model = 'OpenGVLab/InternVL2-2B'
603
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
604
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
605
  chat_template_config.meta_instruction = system_prompt
606
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
625
  from lmdeploy.vl import load_image
626
 
627
  model = 'OpenGVLab/InternVL2-2B'
628
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
629
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
630
  chat_template_config.meta_instruction = system_prompt
631
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
649
  from lmdeploy.vl import load_image
650
 
651
  model = 'OpenGVLab/InternVL2-2B'
652
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
653
  chat_template_config = ChatTemplateConfig('internvl-internlm2')
654
  chat_template_config.meta_instruction = system_prompt
655
  pipe = pipeline(model, chat_template_config=chat_template_config,
 
665
 
666
  #### API部署
667
 
668
+ 为了部署InternVL2,请先配置聊天模板配置文件。创建如下的 JSON 文件 `chat_template.json`。
669
 
670
  ```json
671
  {
672
+ "model_name":"internvl-internlm2",
673
+ "meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。",
674
  "stop_words":["<|im_start|>", "<|im_end|>"]
675
  }
676
  ```
 
678
  LMDeploy 的 `api_server` 使模型能够通过一个命令轻松打包成服务。提供的 RESTful API 与 OpenAI 的接口兼容。以下是服务启动的示例:
679
 
680
  ```shell
681
+ lmdeploy serve api_server OpenGVLab/InternVL2-2B --model-name InternVL2-2B --backend turbomind --server-port 23333 --chat-template chat_template.json
682
  ```
683
 
684
+ 为了使用OpenAI风格的API接口,您需要安装OpenAI:
685
 
686
  ```shell
687
+ pip install openai
688
  ```
689
 
690
+ 然后,使用下面的代码进行API调用:
691
+
692
+ ```python
693
+ from openai import OpenAI
694
+
695
+ client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
696
+ model_name = client.models.list().data[0].id
697
+ response = client.chat.completions.create(
698
+ model="InternVL2-2B",
699
+ messages=[{
700
+ 'role':
701
+ 'user',
702
+ 'content': [{
703
+ 'type': 'text',
704
+ 'text': 'describe this image',
705
+ }, {
706
+ 'type': 'image_url',
707
+ 'image_url': {
708
+ 'url':
709
+ 'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
710
+ },
711
+ }],
712
+ }],
713
+ temperature=0.8,
714
+ top_p=0.8)
715
+ print(response)
716
+ ```
717
 
718
  ## 开源许可证
719
 
config.json CHANGED
@@ -91,7 +91,7 @@
91
  "tie_word_embeddings": false,
92
  "tokenizer_class": null,
93
  "top_k": 50,
94
- "top_p": null,
95
  "torch_dtype": "bfloat16",
96
  "torchscript": false,
97
  "transformers_version": "4.37.2",
 
91
  "tie_word_embeddings": false,
92
  "tokenizer_class": null,
93
  "top_k": 50,
94
+ "top_p": 1.0,
95
  "torch_dtype": "bfloat16",
96
  "torchscript": false,
97
  "transformers_version": "4.37.2",
conversation.py CHANGED
@@ -330,13 +330,16 @@ def get_conv_template(name: str) -> Conversation:
330
  return conv_templates[name].copy()
331
 
332
 
333
- # Note that for inference, using the Hermes-2 and internlm2-chat templates is equivalent.
 
 
 
334
  register_conv_template(
335
  Conversation(
336
  name='Hermes-2',
337
  system_template='<|im_start|>system\n{system_message}',
338
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
339
- # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
340
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
341
  roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
342
  sep_style=SeparatorStyle.MPT,
@@ -357,7 +360,7 @@ register_conv_template(
357
  name='internlm2-chat',
358
  system_template='<|im_start|>system\n{system_message}',
359
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
360
- # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
361
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
362
  roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
363
  sep_style=SeparatorStyle.MPT,
@@ -376,7 +379,7 @@ register_conv_template(
376
  name='phi3-chat',
377
  system_template='<|system|>\n{system_message}',
378
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
379
- # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
380
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
381
  roles=('<|user|>\n', '<|assistant|>\n'),
382
  sep_style=SeparatorStyle.MPT,
 
330
  return conv_templates[name].copy()
331
 
332
 
333
+ # Both Hermes-2 and internlm2-chat are chatml-format conversation templates. The difference
334
+ # is that during training, the preprocessing function for the Hermes-2 template doesn't add
335
+ # <s> at the beginning of the tokenized sequence, while the internlm2-chat template does.
336
+ # Therefore, they are completely equivalent during inference.
337
  register_conv_template(
338
  Conversation(
339
  name='Hermes-2',
340
  system_template='<|im_start|>system\n{system_message}',
341
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
342
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。',
343
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
344
  roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
345
  sep_style=SeparatorStyle.MPT,
 
360
  name='internlm2-chat',
361
  system_template='<|im_start|>system\n{system_message}',
362
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
363
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。',
364
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
365
  roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
366
  sep_style=SeparatorStyle.MPT,
 
379
  name='phi3-chat',
380
  system_template='<|system|>\n{system_message}',
381
  # note: The new system prompt was not used here to avoid changes in benchmark performance.
382
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。',
383
  system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
384
  roles=('<|user|>\n', '<|assistant|>\n'),
385
  sep_style=SeparatorStyle.MPT,