czczup commited on
Commit
c53152d
·
verified ·
1 Parent(s): 1421f4a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +252 -3
README.md CHANGED
@@ -7,7 +7,7 @@ pipeline_tag: image-text-to-text
7
 
8
  [\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[🆕 Blog\]](https://internvl.github.io/blog/) [\[📜 InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[📜 InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
9
 
10
- [\[🗨️ Chat Demo\]](https://internvl.opengvlab.com/) [\[🤗 HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[🚀 Quick Start\]](#quick-start) [\[📖 中文解读\]](https://zhuanlan.zhihu.com/p/675877376)
11
 
12
  ## Introduction
13
 
@@ -315,7 +315,132 @@ print(f'Assistant: {response}')
315
 
316
  ### LMDeploy
317
 
318
- > Warning: This model is not yet supported by LMDeploy.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
  ## License
321
 
@@ -410,7 +535,131 @@ InternVL 2.0 是一个多模态大语言模型系列,包含各种规模的模
410
 
411
  ### LMDeploy
412
 
413
- > 注意:此模型尚未被 LMDeploy 支持。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
  ## 开源许可证
416
 
 
7
 
8
  [\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[🆕 Blog\]](https://internvl.github.io/blog/) [\[📜 InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[📜 InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
9
 
10
+ [\[🗨️ Chat Demo\]](https://internvl.opengvlab.com/) [\[🤗 HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[🚀 Quick Start\]](#quick-start) [\[📖 中文解读\]](https://zhuanlan.zhihu.com/p/706547971) \[🌟 [魔搭社区](https://modelscope.cn/organization/OpenGVLab) | [教程](https://mp.weixin.qq.com/s/OUaVLkxlk1zhFb1cvMCFjg) \]
11
 
12
  ## Introduction
13
 
 
315
 
316
  ### LMDeploy
317
 
318
+ LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
319
+
320
+ ```sh
321
+ pip install lmdeploy
322
+ ```
323
+
324
+ LMDeploy abstracts the complex inference process of multi-modal Vision-Language Models (VLM) into an easy-to-use pipeline, similar to the Large Language Model (LLM) inference pipeline.
325
+
326
+ #### A 'Hello, world' example
327
+
328
+ ```python
329
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig
330
+ from lmdeploy.vl import load_image
331
+
332
+ model = 'OpenGVLab/InternVL2-4B'
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-phi3')
336
+ chat_template_config.meta_instruction = system_prompt
337
+ pipe = pipeline(model, chat_template_config=chat_template_config,
338
+ backend_config=PytorchEngineConfig(session_len=8192))
339
+ response = pipe(('describe this image', image))
340
+ print(response.text)
341
+ ```
342
+
343
+ If `ImportError` occurs while executing this case, please install the required dependency packages as prompted.
344
+
345
+ #### Multi-images inference
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, PytorchEngineConfig, ChatTemplateConfig
351
+ from lmdeploy.vl import load_image
352
+ from lmdeploy.vl.constants import IMAGE_TOKEN
353
+
354
+ model = 'OpenGVLab/InternVL2-4B'
355
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
356
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
357
+ chat_template_config.meta_instruction = system_prompt
358
+ pipe = pipeline(model, chat_template_config=chat_template_config,
359
+ backend_config=PytorchEngineConfig(session_len=8192))
360
+
361
+ image_urls=[
362
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg',
363
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg'
364
+ ]
365
+
366
+ images = [load_image(img_url) for img_url in image_urls]
367
+ # Numbering images improves multi-image conversations
368
+ response = pipe((f'Image-1: {IMAGE_TOKEN}\nImage-2: {IMAGE_TOKEN}\ndescribe these two images', images))
369
+ print(response.text)
370
+ ```
371
+
372
+ #### Batch prompts inference
373
+
374
+ Conducting inference with batch prompts is quite straightforward; just place them within a list structure:
375
+
376
+ ```python
377
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig
378
+ from lmdeploy.vl import load_image
379
+
380
+ model = 'OpenGVLab/InternVL2-4B'
381
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
382
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
383
+ chat_template_config.meta_instruction = system_prompt
384
+ pipe = pipeline(model, chat_template_config=chat_template_config,
385
+ backend_config=PytorchEngineConfig(session_len=8192))
386
+
387
+ image_urls=[
388
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg",
389
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg"
390
+ ]
391
+ prompts = [('describe this image', load_image(img_url)) for img_url in image_urls]
392
+ response = pipe(prompts)
393
+ print(response)
394
+ ```
395
+
396
+ #### Multi-turn conversation
397
+
398
+ There are two ways to do the multi-turn conversations with the pipeline. One is to construct messages according to the format of OpenAI and use above introduced method, the other is to use the `pipeline.chat` interface.
399
+
400
+ ```python
401
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig, GenerationConfig
402
+ from lmdeploy.vl import load_image
403
+
404
+ model = 'OpenGVLab/InternVL2-4B'
405
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
406
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
407
+ chat_template_config.meta_instruction = system_prompt
408
+ pipe = pipeline(model, chat_template_config=chat_template_config,
409
+ backend_config=PytorchEngineConfig(session_len=8192))
410
+
411
+ image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')
412
+ gen_config = GenerationConfig(top_k=40, top_p=0.8, temperature=0.8)
413
+ sess = pipe.chat(('describe this image', image), gen_config=gen_config)
414
+ print(sess.response.text)
415
+ sess = pipe.chat('What is the woman doing?', session=sess, gen_config=gen_config)
416
+ print(sess.response.text)
417
+ ```
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-4B --backend pytorch --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
 
 
535
 
536
  ### LMDeploy
537
 
538
+ LMDeploy 是由 MMRazor 和 MMDeploy 团队开发的用于压缩、部署和服务大语言模型(LLM)的工具包。
539
+
540
+ ```sh
541
+ pip install lmdeploy
542
+ ```
543
+
544
+ LMDeploy 将多模态视觉-语言模型(VLM)的复杂推理过程抽象为一个易于使用的管道,类似于大语言模型(LLM)的推理管道。
545
+
546
+ #### 一个“你好,世界”示例
547
+
548
+ ```python
549
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig
550
+ from lmdeploy.vl import load_image
551
+
552
+ model = 'OpenGVLab/InternVL2-4B'
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-phi3')
556
+ chat_template_config.meta_instruction = system_prompt
557
+ pipe = pipeline(model, chat_template_config=chat_template_config,
558
+ backend_config=PytorchEngineConfig(session_len=8192))
559
+ response = pipe(('describe this image', image))
560
+ print(response.text)
561
+ ```
562
+
563
+ 如果在执行此示例时出现 `ImportError`,请按照提示安装所需的依赖包。
564
+
565
+ #### 多图像推理
566
+
567
+ 在处理多张图像时,可以将它们全部放入一个列表中。请注意,多张图像会导致输入 token 数量增加,因此通常需要增加上下文窗口的大小。
568
+
569
+ ```python
570
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig
571
+ from lmdeploy.vl import load_image
572
+ from lmdeploy.vl.constants import IMAGE_TOKEN
573
+
574
+ model = 'OpenGVLab/InternVL2-4B'
575
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
576
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
577
+ chat_template_config.meta_instruction = system_prompt
578
+ pipe = pipeline(model, chat_template_config=chat_template_config,
579
+ backend_config=PytorchEngineConfig(session_len=8192))
580
+
581
+ image_urls=[
582
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg',
583
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg'
584
+ ]
585
+
586
+ images = [load_image(img_url) for img_url in image_urls]
587
+ response = pipe((f'Image-1: {IMAGE_TOKEN}\nImage-2: {IMAGE_TOKEN}\ndescribe these two images', images))
588
+ print(response.text)
589
+ ```
590
+
591
+ #### 批量Prompt推理
592
+
593
+ 使用批量Prompt进行推理非常简单;只需将它们放在一个列表结构中:
594
+
595
+ ```python
596
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig
597
+ from lmdeploy.vl import load_image
598
+
599
+ model = 'OpenGVLab/InternVL2-4B'
600
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
601
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
602
+ chat_template_config.meta_instruction = system_prompt
603
+ pipe = pipeline(model, chat_template_config=chat_template_config,
604
+ backend_config=PytorchEngineConfig(session_len=8192))
605
+
606
+ image_urls=[
607
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg",
608
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg"
609
+ ]
610
+ prompts = [('describe this image', load_image(img_url)) for img_url in image_urls]
611
+ response = pipe(prompts)
612
+ print(response)
613
+ ```
614
+
615
+ #### 多轮对话
616
+
617
+ 使用管道进行多轮对话有两种方法。一种是根据 OpenAI 的格式构建消息并使用上述方法,另一种是使用 `pipeline.chat` 接口。
618
+
619
+ ```python
620
+ from lmdeploy import pipeline, PytorchEngineConfig, ChatTemplateConfig, GenerationConfig
621
+ from lmdeploy.vl import load_image
622
+
623
+ model = 'OpenGVLab/InternVL2-4B'
624
+ system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
625
+ chat_template_config = ChatTemplateConfig('internvl-phi3')
626
+ chat_template_config.meta_instruction = system_prompt
627
+ pipe = pipeline(model, chat_template_config=chat_template_config,
628
+ backend_config=PytorchEngineConfig(session_len=8192))
629
+
630
+ image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')
631
+ gen_config = GenerationConfig(top_k=40, top_p=0.8, temperature=0.8)
632
+ sess = pipe.chat(('describe this image', image), gen_config=gen_config)
633
+ print(sess.response.text)
634
+ sess = pipe.chat('What is the woman doing?', session=sess, gen_config=gen_config)
635
+ print(sess.response.text)
636
+ ```
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
+ ```
649
+
650
+ LMDeploy 的 `api_server` 使模型能够通过一个命令轻松打包成服务。提供的 RESTful API 与 OpenAI 的接口兼容。以下是服务启动的示例:
651
+
652
+ ```shell
653
+ lmdeploy serve api_server OpenGVLab/InternVL2-4B --backend pytorch --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