Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix EngineGenerationConfig importError of lmdeploy #1990

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

irexyc
Copy link
Contributor

@irexyc irexyc commented Sep 9, 2024

PR type

  • Bug Fix

PR information

EngineGenerationConfig is removed from lmdeploy and swift can't use inference_lmdeploy due to importError

https://github.com/InternLM/lmdeploy/pull/2375/files
InternLM/lmdeploy#2435

Experiment results

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'

# from swift.hub import HubApi
# _api = HubApi()
# _api.login('<your-sdk-token>')  # https://modelscope.cn/my/myaccesstoken

from swift.llm import (
    ModelType, get_lmdeploy_engine, get_default_template_type,
    get_template, inference_lmdeploy, inference_stream_lmdeploy
)

model_type = ModelType.internvl2_2b
model_id_or_path = None
lmdeploy_engine = get_lmdeploy_engine(model_type, model_id_or_path=model_id_or_path)
template_type = get_default_template_type(model_type)
template = get_template(template_type, lmdeploy_engine.hf_tokenizer)
lmdeploy_engine.generation_config.max_new_tokens = 256
generation_info = {}

request_list = [{'query': '<image>描述图片', 'images': ['http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png']},
                {'query': '你是谁?'},
                {'query': (
                    '<img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png</img>'
                    '<img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png</img>'
                    'What is the difference bewteen the two images?'
                )}]
resp_list = inference_lmdeploy(lmdeploy_engine, template, request_list, generation_info=generation_info)
for request, resp in zip(request_list, resp_list):
    print(f"query: {request['query']}")
    print(f"response: {resp['response']}")

query: <image>描述图片
response: 这是一幅卡通风格的插画,描绘了四只绵羊,从左到右依次排列,背景是一片绿色的草地和山峦。绵羊们表情可爱,有的头上顶着蓬松的羊毛,有的则没有。它们的四肢是黑色的,身体是白色的,耳朵是棕色的,眼睛大而圆,鼻子是棕色的。背景的天空是浅蓝色,点缀着几朵白云,整体画面给人一种宁静、和谐的感觉。
query: 你是谁?
response: 我是InternVL,是由上海人工智能实验室的通用视觉团队(OpenGVLab)和商汤科技联合开发的模型。
query: <img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png</img><img>http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png</img>What is the difference bewteen the two images?
response: The two images are of the same cartoon sheep, but there are subtle differences between them. Let's break down the differences step by step:

1. **Positioning**:
   - In the first image, the sheep is positioned slightly to the left of the center. 
   - In the second image, the sheep is positioned a bit closer to the center but slightly more to the right.

2. **Background and Surroundings**:
   - The background looks slightly blurred in the first image, giving it a soft appearance.
   - The background in the second image is more focused and sharp, giving it a clearer look.

3. **Feathers**:
   - In the second image, the sheep has feathers on its head, which adds to the sense of a natural, well-groomed look.
   - In the first image, the sheep’s head lacks feathers, giving it a more simplistic appearance.

4. **Eye Color**:
   - The eyes in the second image are lighter in color, enhancing the cheerful character of the sheep.

5. **Texture and Fur**:
   - The fur in the second image appears slightly drier or has a different color gradient compared to the first image, giving a more distinct character.

6.

@Jintao-Huang
Copy link
Collaborator

thank you very much!

@Jintao-Huang Jintao-Huang merged commit 9fb7e93 into modelscope:main Sep 10, 2024
2 checks passed
@Jintao-Huang Jintao-Huang mentioned this pull request Sep 10, 2024
1 task
tastelikefeet added a commit that referenced this pull request Sep 14, 2024
* commit '08d9ef4f04970e934ce375394205703214ede606':
  fix rlhf & zero3 (#2034)
  Fix olora and pissa saving files which will cause the second saving failed (#2032)
  fix deploy eval kill (#2029)
  update code (#2028)
  refactor rlhf (#1975)
  Florence use post_encode & template support encoder-decoder (#2019)
  Add FAQ Document (#2013)
  fix lmdeploy qwen_vl (#2009)
  Support llava1.6-llama3.1-8b-instruct (#2005)
  Fix rlhf ref model (#2003)
  compat lmdeploy==0.6 (#2001)
  fix EngineGenerationConfig importError of lmdeploy (#1990)
  Support Deepseek 2.5 (#1992)
  fix eval is_multimodal (#1995)
  fix patch (#1997)
  fix model_mapping (#1982)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants