cuierfei commited on
Commit
b47d2e8
1 Parent(s): 9de62f3

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +53 -1
README.md CHANGED
@@ -479,7 +479,59 @@ SWIFT from ModelScope community has supported the fine-tuning (Image/Video) of I
479
 
480
  ### LMDeploy
481
 
482
- TODO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
  ### vLLM
485
 
 
479
 
480
  ### LMDeploy
481
 
482
+ #### Service
483
+
484
+ To deploy InternVL2 as an API, please configure the chat template config first. Create the following JSON file `chat_template.json`.
485
+
486
+ ```json
487
+ {
488
+ "model_name":"internvl-internlm2",
489
+ "meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。",
490
+ "stop_words":["<|im_start|>", "<|im_end|>"]
491
+ }
492
+ ```
493
+
494
+ 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:
495
+
496
+ > **⚠️ Warning**: Please make sure to install Flash Attention; otherwise, using `--tp` will cause errors.
497
+
498
+ ```shell
499
+ CUDA_VISIBLE_DEVICES=0,1,2,3 lmdeploy serve api_server OpenGVLab/InternVL2-Llama3-76B --backend turbomind --server-port 23333 --chat-template chat_template.json --tp 4
500
+ ```
501
+
502
+ To use the OpenAI-style interface, you need to install OpenAI:
503
+
504
+ ```shell
505
+ pip install openai
506
+ ```
507
+
508
+ Then, use the code below to make the API call:
509
+
510
+ ```python
511
+ from openai import OpenAI
512
+
513
+ client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
514
+ model_name = client.models.list().data[0].id
515
+ response = client.chat.completions.create(
516
+ model=model_name,
517
+ messages=[{
518
+ 'role':
519
+ 'user',
520
+ 'content': [{
521
+ 'type': 'text',
522
+ 'text': 'describe this image',
523
+ }, {
524
+ 'type': 'image_url',
525
+ 'image_url': {
526
+ 'url':
527
+ 'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
528
+ },
529
+ }],
530
+ }],
531
+ temperature=0.8,
532
+ top_p=0.8)
533
+ print(response)
534
+ ```
535
 
536
  ### vLLM
537