Image-Text-to-Text
Transformers
Safetensors
valen_qwen
feature-extraction
valen
decision-making
decision-model
image-text-to-typed-output
structured-output
shared-state
qwen3.5
custom-code
conversational
custom_code
Instructions to use Valen-Team/Valen-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Valen-Team/Valen-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Valen-Team/Valen-4B", 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("Valen-Team/Valen-4B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Valen-Team/Valen-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Valen-Team/Valen-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Valen-Team/Valen-4B", "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/Valen-Team/Valen-4B
- SGLang
How to use Valen-Team/Valen-4B 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 "Valen-Team/Valen-4B" \ --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": "Valen-Team/Valen-4B", "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 "Valen-Team/Valen-4B" \ --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": "Valen-Team/Valen-4B", "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 Valen-Team/Valen-4B with Docker Model Runner:
docker model run hf.co/Valen-Team/Valen-4B
File size: 2,953 Bytes
fdf01c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | """Pad language rows and concatenate visual patches. / 文本补齐,视觉 patch 拼接。"""
import torch
from torch.nn.utils.rnn import pad_sequence
SEQUENCE_KEYS = {"input_ids", "attention_mask", "mm_token_type_ids"}
VISUAL_KEYS = {"pixel_values", "pixel_values_videos", "image_grid_thw", "video_grid_thw"}
def collate_branches(branches, pad_token_id=0):
if not branches:
raise ValueError("Cannot collate an empty branch batch")
inputs = [branch.inputs for branch in branches]
unknown = set().union(*(row.keys() for row in inputs)) - SEQUENCE_KEYS - VISUAL_KEYS
if unknown:
raise ValueError(f"Unsupported batched Qwen inputs: {sorted(unknown)}")
if any(row["input_ids"].ndim != 2 or row["input_ids"].shape[0] != 1 for row in inputs):
raise ValueError("Each compiled branch must contain one language row")
result = {}
for key in SEQUENCE_KEYS:
if key != "input_ids" and not any(key in row for row in inputs):
continue
rows = []
for row in inputs:
value = row.get(key)
if value is None:
value = (torch.ones_like(row["input_ids"]) if key == "attention_mask"
else torch.zeros_like(row["input_ids"]))
if value.shape != row["input_ids"].shape:
raise ValueError(f"{key} must match the branch input_ids shape")
rows.append(value[0])
# Right padding keeps all compiler readout positions and spans unchanged.
# 右侧补齐,候选位置和角色区间无需偏移。
result[key] = pad_sequence(rows, batch_first=True,
padding_value=pad_token_id if key == "input_ids" else 0)
if "attention_mask" not in result:
result["attention_mask"] = pad_sequence([torch.ones_like(r["input_ids"][0]) for r in inputs],
batch_first=True, padding_value=0)
for key in VISUAL_KEYS:
values = [row[key] for row in inputs if key in row]
if values:
result[key] = torch.cat(values, dim=0)
return result
def branch_batches(questions, max_tokens):
"""Limit padded tokens per backbone forward, keeping Score branch order."""
if type(max_tokens) is not int or max_tokens <= 0:
raise ValueError("microbatch_max_tokens must be a positive integer")
batch, longest = [], 0
for question_index, question in enumerate(questions):
if not question.branches:
raise ValueError("A Qwen question requires at least one branch")
for branch in question.branches:
length = branch.inputs["input_ids"].shape[1]
if batch and max(longest, length) * (len(batch) + 1) > max_tokens:
yield batch
batch, longest = [], 0
batch.append((question_index, branch))
longest = max(longest, length)
if batch:
yield batch
|