Image-Text-to-Text
Transformers
Safetensors
multilingual
sa2va_chat
feature-extraction
Sa2VA
custom_code
conversational
Instructions to use ByteDance/Sa2VA-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ByteDance/Sa2VA-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ByteDance/Sa2VA-8B", 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("ByteDance/Sa2VA-8B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use ByteDance/Sa2VA-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ByteDance/Sa2VA-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ByteDance/Sa2VA-8B", "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/ByteDance/Sa2VA-8B
- SGLang
How to use ByteDance/Sa2VA-8B 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 "ByteDance/Sa2VA-8B" \ --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": "ByteDance/Sa2VA-8B", "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 "ByteDance/Sa2VA-8B" \ --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": "ByteDance/Sa2VA-8B", "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 ByteDance/Sa2VA-8B with Docker Model Runner:
docker model run hf.co/ByteDance/Sa2VA-8B
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -32,7 +32,7 @@ We built the Sa2VA series based on Qwen2-VL and InternVL2/2.5. In the following
|
|
| 32 |
|
| 33 |
| Model Name | Base MLLM | Language Part | HF Link |
|
| 34 |
|:----------:|:-----------------------------------------------------------------:|:-----------------------------------------------------------------------------:|:----------------------------------------------------:|
|
| 35 |
-
| Sa2VA-1B | [InternVL2.
|
| 36 |
| Sa2VA-4B | [InternVL2.5-4B](https://huggingface.co/OpenGVLab/InternVL2_5-4B) | [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) | [🤗 link](https://huggingface.co/ByteDance/Sa2VA-4B) |
|
| 37 |
| Sa2VA-8B | [InternVL2.5-8B](https://huggingface.co/OpenGVLab/InternVL2_5-8B) | [internlm2_5-7b-chat](https://huggingface.co/internlm/internlm2_5-7b-chat) | [🤗 link](https://huggingface.co/ByteDance/Sa2VA-8B) |
|
| 38 |
|
|
@@ -67,7 +67,7 @@ tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast
|
|
| 67 |
|
| 68 |
# for image chat
|
| 69 |
image_path = "/PATH/TO/IMAGE"
|
| 70 |
-
text_prompts = "
|
| 71 |
image = Image.open(image_path).convert('RGB')
|
| 72 |
input_dict = {
|
| 73 |
'image': image,
|
|
@@ -81,7 +81,7 @@ answer = return_dict["prediction"] # the text format answer
|
|
| 81 |
|
| 82 |
# for image chat with segmentation output
|
| 83 |
image_path = "/PATH/TO/IMAGE"
|
| 84 |
-
text_prompts = "
|
| 85 |
image = Image.open(image_path).convert('RGB')
|
| 86 |
input_dict = {
|
| 87 |
'image': image,
|
|
@@ -97,7 +97,7 @@ masks = return_dict['prediction_masks'] # segmentation masks, list(np.array(1,
|
|
| 97 |
# for chat with visual prompt (mask format) input
|
| 98 |
mask_prompts = np.load('/PATH/TO/pred_masks.npy') # np.array(n_prompts, h, w)
|
| 99 |
image_path = "/PATH/TO/IMAGE"
|
| 100 |
-
text_prompts = "
|
| 101 |
image = Image.open(image_path).convert('RGB')
|
| 102 |
input_dict = {
|
| 103 |
'image': image,
|
|
@@ -116,7 +116,7 @@ images_paths = [os.path.join(video_folder, image_path) for image_name in images_
|
|
| 116 |
if len(images_paths) > 5: # uniformly sample 5 frames
|
| 117 |
step = (len(images_paths) - 1) // (5 - 1)
|
| 118 |
images_paths = [images_paths[0]] + images_paths[1:-1][::step][1:] + [images_paths[-1]]
|
| 119 |
-
text_prompts = "
|
| 120 |
input_dict = {
|
| 121 |
'video': images_paths,
|
| 122 |
'text': text_prompts,
|
|
@@ -132,7 +132,7 @@ answer = return_dict["prediction"] # the text format answer
|
|
| 132 |
video_folder = "/PATH/TO/VIDEO_FOLDER"
|
| 133 |
images_paths = os.listdir(video_folder)
|
| 134 |
images_paths = [os.path.join(video_folder, image_path) for image_name in images_paths]
|
| 135 |
-
text_prompts = "
|
| 136 |
input_dict = {
|
| 137 |
'video': images_paths,
|
| 138 |
'text': text_prompts,
|
|
|
|
| 32 |
|
| 33 |
| Model Name | Base MLLM | Language Part | HF Link |
|
| 34 |
|:----------:|:-----------------------------------------------------------------:|:-----------------------------------------------------------------------------:|:----------------------------------------------------:|
|
| 35 |
+
| Sa2VA-1B | [InternVL2.0-1B](https://huggingface.co/OpenGVLab/InternVL2-1B) | [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) | [🤗 link](https://huggingface.co/ByteDance/Sa2VA-1B) |
|
| 36 |
| Sa2VA-4B | [InternVL2.5-4B](https://huggingface.co/OpenGVLab/InternVL2_5-4B) | [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) | [🤗 link](https://huggingface.co/ByteDance/Sa2VA-4B) |
|
| 37 |
| Sa2VA-8B | [InternVL2.5-8B](https://huggingface.co/OpenGVLab/InternVL2_5-8B) | [internlm2_5-7b-chat](https://huggingface.co/internlm/internlm2_5-7b-chat) | [🤗 link](https://huggingface.co/ByteDance/Sa2VA-8B) |
|
| 38 |
|
|
|
|
| 67 |
|
| 68 |
# for image chat
|
| 69 |
image_path = "/PATH/TO/IMAGE"
|
| 70 |
+
text_prompts = "<image>\nPlease describe the image."
|
| 71 |
image = Image.open(image_path).convert('RGB')
|
| 72 |
input_dict = {
|
| 73 |
'image': image,
|
|
|
|
| 81 |
|
| 82 |
# for image chat with segmentation output
|
| 83 |
image_path = "/PATH/TO/IMAGE"
|
| 84 |
+
text_prompts = "<image>\nCould you please give me a brief description of the image? Please respond with interleaved segmentation masks for the corresponding parts of the answer."
|
| 85 |
image = Image.open(image_path).convert('RGB')
|
| 86 |
input_dict = {
|
| 87 |
'image': image,
|
|
|
|
| 97 |
# for chat with visual prompt (mask format) input
|
| 98 |
mask_prompts = np.load('/PATH/TO/pred_masks.npy') # np.array(n_prompts, h, w)
|
| 99 |
image_path = "/PATH/TO/IMAGE"
|
| 100 |
+
text_prompts = "<image>\nCan you provide me with a detailed description of the region in the picture marked by region1."
|
| 101 |
image = Image.open(image_path).convert('RGB')
|
| 102 |
input_dict = {
|
| 103 |
'image': image,
|
|
|
|
| 116 |
if len(images_paths) > 5: # uniformly sample 5 frames
|
| 117 |
step = (len(images_paths) - 1) // (5 - 1)
|
| 118 |
images_paths = [images_paths[0]] + images_paths[1:-1][::step][1:] + [images_paths[-1]]
|
| 119 |
+
text_prompts = "<image>\nPlease describe the video."
|
| 120 |
input_dict = {
|
| 121 |
'video': images_paths,
|
| 122 |
'text': text_prompts,
|
|
|
|
| 132 |
video_folder = "/PATH/TO/VIDEO_FOLDER"
|
| 133 |
images_paths = os.listdir(video_folder)
|
| 134 |
images_paths = [os.path.join(video_folder, image_path) for image_name in images_paths]
|
| 135 |
+
text_prompts = "<image>\nPlease segment the person."
|
| 136 |
input_dict = {
|
| 137 |
'video': images_paths,
|
| 138 |
'text': text_prompts,
|