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
Download schema.py from Valen-Team/Valen-4B: direct link, hf CLI and curl.
- Browser
- Download file 3.29 kB
-
https://huggingface.co/Valen-Team/Valen-4B/resolve/main/schema.py
- Command line
-
hf download hf://Valen-Team/Valen-4B/schema.py
-
curl -L -o schema.py https://huggingface.co/Valen-Team/Valen-4B/resolve/main/schema.py
3.29 kB
| """Strict JSONL contract. IDs and labels never enter the model prompt.""" | |
| import json | |
| import math | |
| from pathlib import Path | |
| def candidates(question): | |
| kind = question.get("type") | |
| if not isinstance(question.get("instructions"), str) or not question["instructions"].strip(): | |
| raise ValueError("instructions must be nonempty text") | |
| criteria = question.get("criteria") | |
| if kind == "noul": | |
| return [("true", "True / 是:满足问题中的条件。"), ("false", "False / 否:不满足问题中的条件。")] | |
| if kind == "choice": | |
| if not isinstance(criteria, dict) or not 1 <= len(criteria) <= 255: | |
| raise ValueError("Choice needs 1–255 named criteria") | |
| result = list(criteria.items()) | |
| elif kind == "score": | |
| if not isinstance(criteria, list) or not 2 <= len(criteria) <= 255: | |
| raise ValueError("Score criteria must be an ordered list of 2–255 descriptions") | |
| result = [(str(i), text) for i, text in enumerate(criteria)] | |
| else: | |
| raise ValueError(f"Unsupported question type: {kind}") | |
| if any(not isinstance(k, str) or not k or not isinstance(v, str) or not v.strip() for k, v in result): | |
| raise ValueError("Candidate names and descriptions must be nonempty strings") | |
| return result | |
| def target_distribution(target, keys): | |
| if target is None or target.get("probabilities") is None: | |
| return None | |
| probs = target["probabilities"] | |
| if not isinstance(probs, dict) or set(probs) != set(keys): | |
| raise ValueError(f"Probability keys must exactly match {keys}") | |
| values = [probs[k] for k in keys] | |
| if any(isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(v) or v < 0 for v in values): | |
| raise ValueError("Probabilities must be finite nonnegative numbers") | |
| if not math.isclose(sum(values), 1.0, abs_tol=1e-6): | |
| raise ValueError("Target probabilities must sum to 1") | |
| return values | |
| def validate_record(record, candidate_fn=candidates): | |
| request = record["request"] | |
| state = request["state"] | |
| if not isinstance(state, (str, dict)): | |
| raise ValueError("state must be text or a messages object") | |
| if not isinstance(request["questions"], dict) or not request["questions"]: | |
| raise ValueError("questions must be a nonempty mapping") | |
| targets = record.get("targets", {}) | |
| if set(targets) - set(request["questions"]): | |
| raise ValueError("Unknown target question IDs") | |
| for qid, question in request["questions"].items(): | |
| target_distribution(targets.get(qid), [k for k, _ in candidate_fn(question)]) | |
| if not record.get("group_id"): | |
| raise ValueError("group_id is required for leakage-free splits") | |
| return record | |
| def read_jsonl(path, candidate_fn=candidates): | |
| records = [] | |
| with Path(path).open(encoding="utf-8") as stream: | |
| for line_number, line in enumerate(stream, 1): | |
| if line.strip(): | |
| try: | |
| records.append(validate_record(json.loads(line), candidate_fn)) | |
| except (ValueError, KeyError, TypeError, AttributeError) as exc: | |
| raise ValueError(f"{path}:{line_number}: {exc}") from exc | |
| if not records: | |
| raise ValueError("Empty dataset") | |
| return records | |