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

add basic support for internvl2-4b #11718

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

MeouSker77
Copy link
Contributor

@MeouSker77 MeouSker77 commented Aug 6, 2024

Description

add basic support for internvl2-4b

1. Why the change?

2. User API changes

test with transformers 4.38.0

A simple example:

pip install lmdeploy timm
import time
import torch

model_path = 'InternVL2-4B'

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_cod=True)

from ipex_llm.transformers import AutoModelForCausalLM
# use "sym_int8" for better output, use "sym_int4" for better speed
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True,
                                             load_in_low_bit="sym_int8", modules_to_not_convert=["vision_model"])
model = model.half().eval()
model = model.to('xpu')

from lmdeploy.vl import load_image
from transformers import CLIPImageProcessor
image_processor = CLIPImageProcessor.from_pretrained(model_path)
# image = load_image('https://github.com/raw/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
image = load_image("tiger.jpeg")
pixel_values = image_processor(images=[image], return_tensors='pt').pixel_values
pixel_values = pixel_values.to('xpu')

generation_config = {
    "max_new_tokens": 32,
    "do_sample": False,
}

question = "<image>What's in the picture?"

with torch.inference_mode():
    for i in range(5):
        st = time.time()
        response = model.chat(
            tokenizer=tokenizer,
            pixel_values=pixel_values,
            question=question,
            generation_config=generation_config,
            history=[]
        )
        et = time.time()
        print(response)
        print(et - st)

see this for more examples and usage

for now, lmdeploy usage is not supported

3. Summary of the change

4. How to test?

  • N/A
  • Unit test: Please manually trigger the PR Validation here by inputting the PR number (e.g., 1234). And paste your action link here once it has been successfully finished.
  • Application test
  • Document test
  • ...

@MeouSker77
Copy link
Contributor Author

@MeouSker77 MeouSker77 merged commit f44b732 into intel-analytics:main Aug 6, 2024
1 check passed
@MeouSker77 MeouSker77 deleted the support-internvl2-4b branch August 6, 2024 05:36
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