Image-Text-to-Text
Transformers
Safetensors
dsv4_vl
text-generation
deepseek-v4
multimodal
vision-language
siglip2
lora
custom_code
Instructions to use LoyalAI/dsv4-flash-0731-vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LoyalAI/dsv4-flash-0731-vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LoyalAI/dsv4-flash-0731-vision", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("LoyalAI/dsv4-flash-0731-vision", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LoyalAI/dsv4-flash-0731-vision with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LoyalAI/dsv4-flash-0731-vision" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LoyalAI/dsv4-flash-0731-vision", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/LoyalAI/dsv4-flash-0731-vision
- SGLang
How to use LoyalAI/dsv4-flash-0731-vision 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 "LoyalAI/dsv4-flash-0731-vision" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LoyalAI/dsv4-flash-0731-vision", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "LoyalAI/dsv4-flash-0731-vision" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LoyalAI/dsv4-flash-0731-vision", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use LoyalAI/dsv4-flash-0731-vision with Docker Model Runner:
docker model run hf.co/LoyalAI/dsv4-flash-0731-vision
File size: 5,368 Bytes
1d7c7c4 | 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #!/usr/bin/env python3
"""Compare exact-source and vision-adapted text evaluations."""
from __future__ import annotations
import argparse
import hashlib
import json
import os
from pathlib import Path
from typing import Any
FORMAT = "dsv4vl-text-regression-v1"
BASE_FORMAT = "dsv4vl-text-baseline-v1"
ADAPTED_FORMAT = "dsv4vl-text-adapted-v1"
BASE_MODEL = "deepseek-ai/DeepSeek-V4-Flash-0731"
ADAPTED_MODEL = "deepseek-ai/DeepSeek-V4-Flash-0731-vision-adapted-bf16"
BASE_GENERATION_MODEL = "deepseek-v4-flash-0731-base"
ADAPTED_GENERATION_MODEL = "deepseek-v4-flash-0731-vision-adapted-bf16"
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def comparison(name: str, before: float, after: float, tolerance: float) -> dict[str, Any]:
change = after - before
return {
"name": name,
"before": before,
"after": after,
"change": change,
"maximum_allowed_drop": tolerance,
"pass": change >= -tolerance - 1e-12,
}
def compare(base: dict[str, Any], adapted: dict[str, Any]) -> dict[str, Any]:
if (
base.get("format") != BASE_FORMAT
or base.get("model_id") != BASE_MODEL
or base.get("generation_model") != BASE_GENERATION_MODEL
):
raise ValueError("base text report is not the exact pinned 0731 baseline")
if (
adapted.get("format") != ADAPTED_FORMAT
or adapted.get("model_id") != ADAPTED_MODEL
or adapted.get("generation_model") != ADAPTED_GENERATION_MODEL
):
raise ValueError("adapted text report has unexpected format/model provenance")
base_manifest = base.get("artifacts", {}).get("eval_manifest", {}).get("sha256")
adapted_manifest = adapted.get("artifacts", {}).get("eval_manifest", {}).get(
"sha256"
)
if not base_manifest or base_manifest != adapted_manifest:
raise ValueError("base/adapted text reports use different eval manifests")
b, a = base["metrics"], adapted["metrics"]
checks = [
comparison(
"long_context_accuracy",
float(b["long_context"]["accuracy"]),
float(a["long_context"]["accuracy"]),
max(0.03, 1 / int(b["long_context"]["total"])),
),
comparison(
"humaneval_base_pass_at_1",
float(b["humaneval_plus"]["base_pass_at_1"]),
float(a["humaneval_plus"]["base_pass_at_1"]),
0.03,
),
comparison(
"humaneval_plus_pass_at_1",
float(b["humaneval_plus"]["plus_pass_at_1"]),
float(a["humaneval_plus"]["plus_pass_at_1"]),
0.03,
),
comparison(
"terminal_bench_mean_reward",
float(b["terminal_bench"]["mean_reward"]),
float(a["terminal_bench"]["mean_reward"]),
max(0.03, 1 / int(b["terminal_bench"]["tasks"])),
),
]
return {
"format": FORMAT,
"status": "PASS" if all(item["pass"] for item in checks) else "FAIL",
"base_model": base["model_id"],
"adapted_model": adapted["model_id"],
"policy": "maximum 3 percentage-point drop, relaxed only to one-sample resolution",
"checks": checks,
}
def markdown(report: dict[str, Any]) -> str:
rows = [
"# DSV4-VL text regression",
"",
f"Status: **{report['status']}**",
"",
"| Metric | Base | Adapted | Change | Allowed drop | Pass |",
"|---|---:|---:|---:|---:|:---:|",
]
for item in report["checks"]:
rows.append(
f"| {item['name']} | {item['before']:.4f} | {item['after']:.4f} | "
f"{item['change']:+.4f} | {item['maximum_allowed_drop']:.4f} | "
f"{'yes' if item['pass'] else 'no'} |"
)
return "\n".join(rows) + "\n"
def atomic_write(path: Path, content: str) -> None:
if path.exists():
raise FileExistsError(f"refusing to replace text-regression artifact: {path}")
path.parent.mkdir(parents=True, exist_ok=True)
temporary = path.with_suffix(path.suffix + f".tmp-{os.getpid()}")
temporary.write_text(content)
os.replace(temporary, path)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--base", type=Path, required=True)
parser.add_argument("--adapted", type=Path, required=True)
parser.add_argument("--output-json", type=Path, required=True)
parser.add_argument("--output-md", type=Path, required=True)
args = parser.parse_args()
if args.output_json.exists() or args.output_md.exists():
raise FileExistsError("refusing to replace existing text-regression outputs")
report = compare(json.loads(args.base.read_text()), json.loads(args.adapted.read_text()))
report["reports"] = {
"base": {"path": str(args.base.resolve()), "sha256": sha256(args.base)},
"adapted": {"path": str(args.adapted.resolve()), "sha256": sha256(args.adapted)},
}
atomic_write(args.output_json, json.dumps(report, indent=2) + "\n")
atomic_write(args.output_md, markdown(report))
print(json.dumps(report, indent=2))
if report["status"] != "PASS":
raise SystemExit(2)
if __name__ == "__main__":
main()
|