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
Download source/repository/scripts/compare_text_evals.py from LoyalAI/dsv4-flash-0731-vision: direct link, hf CLI and curl.
- Browser
- Download file 5.37 kB
-
https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/scripts/compare_text_evals.py
- Command line
-
hf download hf://LoyalAI/dsv4-flash-0731-vision/source/repository/scripts/compare_text_evals.py
-
curl -L -o compare_text_evals.py https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/scripts/compare_text_evals.py
5.37 kB
| #!/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() | |