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/phase1_install.sh from LoyalAI/dsv4-flash-0731-vision: direct link, hf CLI and curl.
- Browser
- Download file 4.63 kB
-
https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/scripts/phase1_install.sh
- Command line
-
hf download hf://LoyalAI/dsv4-flash-0731-vision/source/repository/scripts/phase1_install.sh
-
curl -L -o phase1_install.sh https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/scripts/phase1_install.sh
4.63 kB
| # Phase 1a: install ms-swift (Megatron backend) on the pod WITHOUT touching NGC torch. | |
| # Source: swift.readthedocs.io/en/latest/BestPractices/deepseek-v4.html (fetched 2026-08-03) | |
| set -euo pipefail | |
| WS=${WS:-/workspace} | |
| SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) | |
| if [[ -f "$WS/env.sh" ]]; then | |
| # shellcheck disable=SC1090 | |
| source "$WS/env.sh" | |
| fi | |
| if [[ -n "${DSV4VL_VENV:-}" ]]; then | |
| test -x "$DSV4VL_VENV/bin/python" || { | |
| echo "Missing requested persistent venv: $DSV4VL_VENV" >&2 | |
| exit 2 | |
| } | |
| # shellcheck disable=SC1090 | |
| source "$DSV4VL_VENV/bin/activate" | |
| fi | |
| # Guard: record torch before, verify unchanged after (hard rule 1). | |
| TORCH_BEFORE=$(python -c "import torch; print(torch.__version__)") | |
| # Constraint file pins torch so no dependency can replace it. | |
| python - <<'EOF' | |
| import torch, pathlib | |
| pathlib.Path("/tmp/constraints.txt").write_text(f"torch=={torch.__version__}\n") | |
| EOF | |
| export PIP_CONSTRAINT=/tmp/constraints.txt | |
| # Megatron commit fd1121b8 requires the NVRx 0.6 async-checkpoint API. NGC | |
| # 25.06 bundles 0.4.0, whose namespace package also lacks __version__. | |
| pip install "nvidia-resiliency-ext==0.6.0" | |
| # NGC 25.06 ships safetensors 0.5.3, which cannot deserialize the | |
| # DeepSeek-V4 FP4-scale dtype (F8_E8M0). 0.8.0 opens all 48 source shards. | |
| pip install "safetensors==0.8.0" | |
| # Transformers 5.12's pre-quantized DSV4 attention dispatches through the | |
| # public kernels-community/finegrained-fp8 implementation. Pin inside the | |
| # release's declared >=0.12,<0.13 range and prohibit dependency resolution so | |
| # this optional runtime cannot replace the NGC torch stack. | |
| # Install the Hub client first: Python packaging enumerates every installed | |
| # entry point while Megatron builds its metadata, which imports `kernels` and | |
| # therefore its optional Hub module even before ms-swift installs Transformers. | |
| pip install "huggingface_hub==1.26.0" | |
| pip install --no-deps "kernels==0.12.3" | |
| # Megatron-LM dev branch — tested commit from the swift best-practices doc. | |
| MEGATRON_COMMIT=fd1121b8ff7e3a4f83a28d35aed172d7bc0260e1 | |
| MCORE_BRIDGE_COMMIT=1f0b2c4ead2d607e9c90af64070a67597cd0f360 | |
| MS_SWIFT_COMMIT=49efcbfe59e480d4fa9a8bdecdb76c743d0af37d | |
| pip install "git+https://github.com/NVIDIA/Megatron-LM.git@${MEGATRON_COMMIT}" | |
| pip install "git+https://github.com/modelscope/mcore-bridge.git@${MCORE_BRIDGE_COMMIT}" | |
| pip install "ms-swift[megatron] @ git+https://github.com/modelscope/ms-swift.git@${MS_SWIFT_COMMIT}" | |
| # ms-swift's broad dataset requirement currently selects PyArrow 25, which | |
| # conflicts with the NGC 25.06 cuDF stack. Reveal the image's PyArrow 19.0.1 | |
| # again and restore the exact data versions used to build/verify the Stage-2 | |
| # mix. These pins satisfy ms-swift's declared datasets>=3,<4.8.5 range. | |
| pip uninstall -y pyarrow | |
| pip install --no-deps --force-reinstall -r "$SCRIPT_DIR/../requirements-stage2-data.txt" | |
| pip install "packaging==24.2" | |
| python "$SCRIPT_DIR/verify_stage2_data_runtime.py" | |
| # DeepSeek-V4 compressed/heavily-compressed attention rotates the DSA indexer | |
| # activations with this CUDA kernel. Build only Hopper (H100/H200 = SM90) and | |
| # reuse the pinned NGC Torch instead of creating a build-isolation environment. | |
| MAX_JOBS=16 TORCH_CUDA_ARCH_LIST=9.0 \ | |
| pip install --no-build-isolation \ | |
| "git+https://github.com/Dao-AILab/fast-hadamard-transform.git@1cc807efbd6cc001df359822d60bf6052dd66859" | |
| # Apply idempotent compatibility fixes for NGC TE, PEFT/TorchAO discovery, and | |
| # the fail-closed attention-only trainable audit. | |
| python "$SCRIPT_DIR/patch_runtime_compat.py" | |
| TORCH_AFTER=$(python -c "import torch; print(torch.__version__)") | |
| if [ "$TORCH_BEFORE" != "$TORCH_AFTER" ]; then | |
| echo "FATAL: torch changed ($TORCH_BEFORE -> $TORCH_AFTER) — NGC/TE stack broken. Rebuild container." >&2 | |
| exit 1 | |
| fi | |
| python - <<'PY' | |
| import importlib.metadata | |
| import megatron.core | |
| import swift | |
| import transformer_engine | |
| assert importlib.metadata.version("kernels") == "0.12.3" | |
| assert importlib.metadata.version("packaging") == "24.2" | |
| print("TE/mcore/swift/kernels import OK") | |
| PY | |
| python "$SCRIPT_DIR/verify_stage2_training_runtime.py" | |
| pip check | |
| # Record environment for reproducibility. | |
| { | |
| echo "## ENV ($(date -u +%F))" | |
| echo "torch: $TORCH_AFTER" | |
| echo "Megatron-LM: $MEGATRON_COMMIT" | |
| echo "mcore-bridge: $MCORE_BRIDGE_COMMIT" | |
| echo "ms-swift: $MS_SWIFT_COMMIT" | |
| echo "venv: $(python -c 'import sys; print(sys.prefix)')" | |
| pip freeze | grep -iE 'ms-swift|mcore-bridge|megatron|transformer.engine|flash|kernels' || true | |
| nvidia-smi --query-gpu=name,memory.total --format=csv | |
| } >> "$WS/ENV.md" | |
| echo "Install OK. ENV recorded in $WS/ENV.md" | |