Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Run this model with HF Jobs
Run OpenGVLab/InternVL2-2B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/OpenGVLab/InternVL2-2B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/OpenGVLab/InternVL2-2B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/OpenGVLab/InternVL2-2B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/OpenGVLab/InternVL2-2B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use OpenGVLab/InternVL2-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-2B", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL2-2B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenGVLab/InternVL2-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/OpenGVLab/InternVL2-2B
- SGLang
How to use OpenGVLab/InternVL2-2B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "OpenGVLab/InternVL2-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "OpenGVLab/InternVL2-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use OpenGVLab/InternVL2-2B with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-2B
Upload folder using huggingface_hub
Browse files295 unmodified lines296297298299300301302303304305306307308309310311312313314315316317295 unmodified linespip install lmdeploy```You can run batch inference locally with the following python code:```pythonfrom lmdeploy.vl import load_imagefrom lmdeploy import ChatTemplateConfig, pipelinemodel = 'OpenGVLab/InternVL2-2B'system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')chat_template_config = ChatTemplateConfig('internlm2-chat')chat_template_config.meta_instruction = system_promptpipe = pipeline(model, chat_template_config=chat_template_config)response = pipe(('describe this image', image))print(response)```## LicenseThis project is released under the MIT license, while InternLM is licensed under the Apache-2.0 license.295 unmodified lines296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394295 unmodified linespip install lmdeploy```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.#### A 'Hello, world' example```pythonfrom lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfigfrom lmdeploy.vl import load_imagemodel = 'OpenGVLab/InternVL2-2B'system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')chat_template_config = ChatTemplateConfig('internlm2-chat')chat_template_config.meta_instruction = system_promptpipe = pipeline(model, chat_template_config=chat_template_config,backend_config=TurbomindEngineConfig(session_len=8192))response = pipe(('describe this image', image))print(response)```If `ImportError` occurs while executing this case, please install the required dependency packages as prompted.#### Multi-images inferenceWhen 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.```pythonfrom lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfigfrom lmdeploy.vl import load_imagemodel = 'OpenGVLab/InternVL2-2B'system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'chat_template_config = ChatTemplateConfig('internlm2-chat')chat_template_config.meta_instruction = system_promptpipe = pipeline(model, chat_template_config=chat_template_config,backend_config=TurbomindEngineConfig(session_len=8192))image_urls=['https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg','https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg']images = [load_image(img_url) for img_url in image_urls]response = pipe(('describe these images', images))print(response)```#### Batch prompts inferenceConducting inference with batch prompts is quite straightforward; just place them within a list structure:```pythonfrom lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfigfrom lmdeploy.vl import load_imagemodel = 'OpenGVLab/InternVL2-2B'system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'chat_template_config = ChatTemplateConfig('internlm2-chat')chat_template_config.meta_instruction = system_promptpipe = pipeline(model, chat_template_config=chat_template_config,backend_config=TurbomindEngineConfig(session_len=8192))image_urls=["https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg","https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg"]prompts = [('describe this image', load_image(img_url)) for img_url in image_urls]response = pipe(prompts)print(response)```#### Multi-turn conversationThere 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.```pythonfrom lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfigfrom lmdeploy.vl import load_imagemodel = 'OpenGVLab/InternVL2-2B'system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'chat_template_config = ChatTemplateConfig('internlm2-chat')chat_template_config.meta_instruction = system_promptpipe = pipeline(model, chat_template_config=chat_template_config,backend_config=TurbomindEngineConfig(session_len=8192))image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')gen_config = GenerationConfig(top_k=40, top_p=0.8, temperature=0.8)sess = pipe.chat(('describe this image', image), gen_config=gen_config)print(sess.response.text)sess = pipe.chat('What is the woman doing?', session=sess, gen_config=gen_config)print(sess.response.text)```## LicenseThis project is released under the MIT license, while InternLM is licensed under the Apache-2.0 license.
README.md+80-3