Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
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)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL2-2B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- 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
Delete test_long_niah.sh
Browse files- test_long_niah.sh +0 -77
test_long_niah.sh
DELETED
|
@@ -1,77 +0,0 @@
|
|
| 1 |
-
PARTITION=${PARTITION:-"Intern5"}
|
| 2 |
-
GPUS=${GPUS:-16}
|
| 3 |
-
GPUS_PER_NODE=${GPUS_PER_NODE:-8}
|
| 4 |
-
GPUS_PER_TASK=${GPUS_PER_TASK:-1}
|
| 5 |
-
QUOTA_TYPE=${QUOTA_TYPE:-"reserved"}
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
set -x
|
| 9 |
-
|
| 10 |
-
CHECKPOINT=${1}
|
| 11 |
-
|
| 12 |
-
JOB_FOLDER=$(dirname "$CHECKPOINT")
|
| 13 |
-
files=(
|
| 14 |
-
"$JOB_FOLDER/configuration_intern_vit.py"
|
| 15 |
-
"$JOB_FOLDER/configuration_internlm2.py"
|
| 16 |
-
"$JOB_FOLDER/configuration_internvl_chat.py"
|
| 17 |
-
"$JOB_FOLDER/conversation.py"
|
| 18 |
-
"$JOB_FOLDER/modeling_intern_vit.py"
|
| 19 |
-
"$JOB_FOLDER/modeling_internlm2.py"
|
| 20 |
-
"$JOB_FOLDER/modeling_internvl_chat.py"
|
| 21 |
-
"$JOB_FOLDER/tokenization_internlm2_fast.py"
|
| 22 |
-
"$JOB_FOLDER/tokenization_internlm2.py"
|
| 23 |
-
"test_long_niah.sh"
|
| 24 |
-
)
|
| 25 |
-
for file in "${files[@]}"; do
|
| 26 |
-
dest_file="$CHECKPOINT/$(basename "$file")"
|
| 27 |
-
if [ ! -f "$dest_file" ]; then
|
| 28 |
-
cp "$file" "$CHECKPOINT"
|
| 29 |
-
fi
|
| 30 |
-
done
|
| 31 |
-
ARGS=("$@")
|
| 32 |
-
|
| 33 |
-
declare -a tasks=( \
|
| 34 |
-
'retrieval-image-test-long-subset' \
|
| 35 |
-
'retrieval-image-test-long-128k' \
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
# declare -a tasks=(\
|
| 39 |
-
# 'retrieval-image-test-long-1M'\
|
| 40 |
-
# )
|
| 41 |
-
declare -a tasks=(\
|
| 42 |
-
'retrieval-image-test-long-800k' \
|
| 43 |
-
'retrieval-image-test-long-512k' \
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
model_name="internvl"
|
| 47 |
-
for STRIDE in 1; do
|
| 48 |
-
LOG_DIR=$CHECKPOINT/eval_mm_niah_ring_attn_$STRIDE
|
| 49 |
-
mkdir -p $LOG_DIR
|
| 50 |
-
|
| 51 |
-
for ((j=0; j<${#tasks[@]}; j++)); do
|
| 52 |
-
task=${tasks[j]}
|
| 53 |
-
|
| 54 |
-
echo "$(date) ${model_name}_${task}_stride_${STRIDE}"
|
| 55 |
-
|
| 56 |
-
srun -p ${PARTITION} \
|
| 57 |
-
--gres=gpu:${GPUS_PER_NODE} \
|
| 58 |
-
--ntasks=$((GPUS / GPUS_PER_TASK)) \
|
| 59 |
-
--ntasks-per-node=$((GPUS_PER_NODE / GPUS_PER_TASK)) \
|
| 60 |
-
--quotatype=${QUOTA_TYPE} \
|
| 61 |
-
--job-name="${STRIDE}${task}" \
|
| 62 |
-
-o "${LOG_DIR}/${task}_stride_${STRIDE}.log" \
|
| 63 |
-
-e "${LOG_DIR}/${task}_stride_${STRIDE}.log" \
|
| 64 |
-
--async \
|
| 65 |
-
python -u eval/mm_niah/eval_mm_niah_long.py \
|
| 66 |
-
--checkpoint $CHECKPOINT \
|
| 67 |
-
--outputs-dir $LOG_DIR \
|
| 68 |
-
--task $task \
|
| 69 |
-
--num-gpus-per-rank ${GPUS_PER_TASK} "${ARGS[@]:1}" \
|
| 70 |
-
--rope_pos_id_version 'v5' \
|
| 71 |
-
--ring_attn \
|
| 72 |
-
--rope_pos_id_stride $STRIDE \
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
sleep 0.2
|
| 76 |
-
done
|
| 77 |
-
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|