Image-Text-to-Text
Transformers
Safetensors
English
nanbeige_vlm
vlm
nanbeige
siglip
conversational
custom_code
Instructions to use SkyAsl/Nanbeige4.1-VLM-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SkyAsl/Nanbeige4.1-VLM-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="SkyAsl/Nanbeige4.1-VLM-Base", 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 NanbeigeVLM model = NanbeigeVLM.from_pretrained("SkyAsl/Nanbeige4.1-VLM-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use SkyAsl/Nanbeige4.1-VLM-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SkyAsl/Nanbeige4.1-VLM-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SkyAsl/Nanbeige4.1-VLM-Base", "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/SkyAsl/Nanbeige4.1-VLM-Base
- SGLang
How to use SkyAsl/Nanbeige4.1-VLM-Base 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 "SkyAsl/Nanbeige4.1-VLM-Base" \ --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": "SkyAsl/Nanbeige4.1-VLM-Base", "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 "SkyAsl/Nanbeige4.1-VLM-Base" \ --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": "SkyAsl/Nanbeige4.1-VLM-Base", "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 SkyAsl/Nanbeige4.1-VLM-Base with Docker Model Runner:
docker model run hf.co/SkyAsl/Nanbeige4.1-VLM-Base
Upload modeling_nanbeige_vlm.py with huggingface_hub
Browse files- modeling_nanbeige_vlm.py +3 -1
modeling_nanbeige_vlm.py
CHANGED
|
@@ -82,7 +82,7 @@ class NanbeigeVLMModel(PreTrainedModel):
|
|
| 82 |
|
| 83 |
# ── Vision tower (frozen at Stage 1) ──────────────────────────────
|
| 84 |
self.vision_tower = SiglipVisionModel.from_pretrained(
|
| 85 |
-
config.vision_model_id, torch_dtype=torch.bfloat16
|
| 86 |
)
|
| 87 |
self.vision_tower.requires_grad_(False)
|
| 88 |
vision_hidden_size = self.vision_tower.config.hidden_size
|
|
@@ -94,12 +94,14 @@ class NanbeigeVLMModel(PreTrainedModel):
|
|
| 94 |
trust_remote_code=True,
|
| 95 |
torch_dtype=torch.bfloat16,
|
| 96 |
attn_implementation="flash_attention_2",
|
|
|
|
| 97 |
)
|
| 98 |
except (ImportError, ValueError):
|
| 99 |
self.language_model = AutoModelForCausalLM.from_pretrained(
|
| 100 |
config.llm_model_id,
|
| 101 |
trust_remote_code=True,
|
| 102 |
torch_dtype=torch.bfloat16,
|
|
|
|
| 103 |
)
|
| 104 |
self.language_model.requires_grad_(False)
|
| 105 |
llm_hidden_size = self.language_model.config.hidden_size
|
|
|
|
| 82 |
|
| 83 |
# ── Vision tower (frozen at Stage 1) ──────────────────────────────
|
| 84 |
self.vision_tower = SiglipVisionModel.from_pretrained(
|
| 85 |
+
config.vision_model_id, torch_dtype=torch.bfloat16, device_map=None
|
| 86 |
)
|
| 87 |
self.vision_tower.requires_grad_(False)
|
| 88 |
vision_hidden_size = self.vision_tower.config.hidden_size
|
|
|
|
| 94 |
trust_remote_code=True,
|
| 95 |
torch_dtype=torch.bfloat16,
|
| 96 |
attn_implementation="flash_attention_2",
|
| 97 |
+
device_map=None
|
| 98 |
)
|
| 99 |
except (ImportError, ValueError):
|
| 100 |
self.language_model = AutoModelForCausalLM.from_pretrained(
|
| 101 |
config.llm_model_id,
|
| 102 |
trust_remote_code=True,
|
| 103 |
torch_dtype=torch.bfloat16,
|
| 104 |
+
device_map=None
|
| 105 |
)
|
| 106 |
self.language_model.requires_grad_(False)
|
| 107 |
llm_hidden_size = self.language_model.config.hidden_size
|