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/docs/HANDOFF.md from LoyalAI/dsv4-flash-0731-vision: direct link, hf CLI and curl.
- Browser
- Download file 10.9 kB
-
https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/docs/HANDOFF.md
- Command line
-
hf download hf://LoyalAI/dsv4-flash-0731-vision/source/repository/docs/HANDOFF.md
-
curl -L -o HANDOFF.md https://huggingface.co/LoyalAI/dsv4-flash-0731-vision/resolve/main/source/repository/docs/HANDOFF.md
Track B Handoff (verbatim copy for pod sessions)
Mission
Graft vision onto deepseek-ai/DeepSeek-V4-Flash-0731 (LLaVA-style: frozen SigLIP2 tower → trained MLP projector → V4 base) using ms-swift with the Megatron backend (Megatron-SWIFT), on a single RunPod pod, while preserving V4's text/agentic strengths. Deliverable: a merged BF16 multimodal checkpoint + LoRA adapters + eval report.
2026-08-03 amendment: the active target is one 8×H200 SXM RunPod pod
q2q1xd45kl6u6d. With 8 GPUs, use swift's official 8-GPU/EP=8 topology; rule
6 below applies only if this plan is later moved to 4 GPUs.
2026-08-06 amendment: the active pod has a 4 TB network volume and costs
$35.70/hr. Stage 2 is the approved attention-only LoRA plus projector run:
1,000,000 records, global batch 128, 4K sequence cap, and exactly 7,813
optimizer steps. STATUS.md is authoritative for its live step and audited
checkpoints.
Environment (current)
- Pod: RunPod
q2q1xd45kl6u6d, 8×H200 SXM, EP=8. - Runtime: the verified NGC 25.06-compatible training environment pinned in
/workspace/ENV.md; do not replace its Torch/TransformerEngine stack. - Container disk: 200 GB. Network volume 4 TB at
/workspaceso the source checkpoint, BF16 conversion, datasets, and final BF16 export can coexist. - Run all long jobs inside
tmux. Checkpoint every 30–60 min. - Pod $35.70/hr. Never idle. If blocked >30 min, write
/workspace/STATUS.mdand stop cleanly.
Hard rules
- Never
pip install torchor anything that replaces NGC torch (breaks TransformerEngine). Use--no-deps/constraints. - Never merge LoRA into FP8 weights.
--merge_lora false; merge only against BF16. - Freeze the MoE router and every routed/shared expert FFN. LoRA targets are
attention-only: the explicit MLA query, key/value, and output projections.
Never use
all-linearand never attach LoRA to shared/dense FFNs. - Cap training seq len at 4K (8K max after memory proven).
- Do not modify text tokenizer/vocab. Images enter as continuous embeddings at
<image>placeholder in template/encoding layer. - (4-GPU pods only) Halve parallelism from 8-GPU examples; never copy 8-GPU commands verbatim.
Phase 0 — Prep (CPU pod, before GPUs)
- Download to network volume: V4-Flash-0731 HF checkpoint (
167 GB), SigLIP2-so400m, LLaVA-Pretrain (558K), Stage-2 SFT mix. - Clone: official DeepSeek V4 repo,
encoding_dsv4. - Stage-2 mix (~1M): 80–85% multimodal (doc/chart/screenshot, GUI-agent traces, multimodal coding), 15–20% text-only (agentic/tool-use, coding, long-form reasoning — mandatory anti-forgetting).
- Prepare in ms-swift custom dataset format; validation script renders 5 random samples through the chat template.
Phase 1 — Bring-up + GO/NO-GO
- Install ms-swift[megatron] + Megatron-Core dev per swift DeepSeek-V4 best-practices doc. Pin commits in
/workspace/ENV.md. - Run official text-only V4-Flash SFT example (tiny dataset, LoRA). Success = loss decreases ~50 steps, no NaNs, checkpoint saves/reloads.
- GATE (B200 only): TE/Megatron kernel failures unfixable in ~2 h → STOP, recommend 8×H100 SXM. (Moot on H100.)
Result: passed on 8×H200. The audited 60-step attention-only LoRA run had
finite, falling loss and no router/expert trainables; checkpoint-60 saved and
reloaded successfully for a zero-LR probe. TensorBoard is served from
/workspace/outputs on port 6006.
Phase 2 — Weight conversion
swift export --to_mcore true(BF16); FP4 experts auto-upconvert. If--test_convert_precisiontoo slow: validate 5 prompts swift-infer vs reference; require near-identical.- Store on network volume; record sizes in ENV.md.
Phase 3 — Vision graft
- Study ms-swift MLLM registration (Qwen-VL, DeepSeek-VL2); mirror pattern.
- Register: SigLIP2-so400m (frozen) + 2-layer MLP projector (GELU) + V4-Flash.
<image>placeholder expansion count == projected patch count. - Unit gate: one image+text sample → loss computes, grads ONLY to projector, generation runs.
- Overfit gate: 32 pairs → near-zero loss. Fallback: Stage 1 in lighter harness (base frozen, no Megatron backprop), revisit Stage 2 integration after.
Phase 4 — Stage 1: Projector alignment
- Projector only. LLaVA-Pretrain 558K, 1 epoch, LR 1e-3 cosine, eff. batch ~256, seq ≤2K. ~1–2 days. Acceptance: coherent held-out captions, converged loss.
Phase 5 — Stage 2: Instruction tuning + preservation
- LoRA r=64, α=128 on attention only; projector LR 2e-5; LoRA LR 2e-4; router, routed experts, shared experts, and the vision tower frozen; one epoch over the exact 1M-record mix at global batch 128, 7,813 steps, seq 4K.
- Before: benchmark base on text suite (Terminal-Bench subset, HumanEval+, long-context probe) →
/workspace/EVAL_BASELINE.md. - After: rerun with adapters. GATE: <2–3% regression, else raise text-only fraction / lower rank, rerun.
- Multimodal acceptance: MMBench, TextVQA, MME — beat projector-only baseline.
- During production, every 460-step audited full state is uploaded privately and clean-downloaded at its exact revision; all 11 optimizer/RNG files plus the adapter and projector must revalidate before the restore receipt passes. The periodic monitor excludes step 7,813 because the canonical final-backup and Phase-6 restore path owns that checkpoint.
Phase 6 — Merge, export, verify
Save adapters; merge against BF16 only; mcore→HF (
--to_hf true).Copy ORIGINAL config.json over exported one, adjust
expert_dtype(transformers-saved config is vLLM-incompatible).Document: DSpark/speculative decoding not adapted for images — disable for multimodal inference.
Run
phase6_finalize_release.sh: require the verified export plus passing complete vision/text gates, then persist 10 multimodal + 10 text generations, copied reports, model card, and hash-bound release manifest under the merged model directory. Before assembly it requires the final checkpoint, merged export, vision-improvement, and text-preservation receipts; promotes their accepted values intodocs/publication_state.json; regenerates the research paper and technical-report result blocks; and copies all five publication artifacts into the release's hash-bounddocumentation/directory. The launcher then starts the detachedphase6-final-hf-backupsession, which resumably uploads the complete merged directory toConwayResearch/dsv4-flash-0731-vision. Do not stop the pod until/workspace/evals/final_release_hf_backup.jsonexists withstatus: PASS; that receipt means the exact private revision, remote inventory, file sizes, and SHA-256 values were reverified after upload. Progress and failure details are in/workspace/logs/phase6_final_hf_backup.logand/workspace/evals/final_release_hf_backup.status.json. The authoritative Phase-6 state moves throughVERIFYING_FINAL_RELEASE_BACKUPandVERIFYING_GOAL_COMPLETION. It reachesFINAL_RELEASE_COMPLETEonly afterverify_goal_completion.pyrechecks the step-7,813 recovery tree, final private Stage-2 restore, merged bundle, final vision/text/publication gates, and exact private release revision. Do not stop the pod until both/workspace/evals/final_release_hf_backup.jsonand/workspace/evals/GOAL_COMPLETION.jsonare PASS and the Phase-6 detail binds the latter's SHA-256. Re-running the external launcher at that state verifies both receipts and exits successfully without rerunning sandboxes. Re-running it during eitherVERIFYING_*state resumes or supervises the detached finalizer; aFAILEDstate is resumed only when it identifies the final backup/goal audit and the verified local release manifest exists.Start and try the completed vision model:
bash /workspace/dsv4vision/scripts/phase6_start_vision_server.sh python /workspace/dsv4vision/scripts/try_vision_model.py \ --image /workspace/example.png \ --prompt "Describe this image in detail." \ --server-status /workspace/evals/final_vision_server.status.json \ --receipt /workspace/evals/first_user_trial.jsonThe server binds only to
127.0.0.1:8001; use the SSH tunnel printed by the launcher for a local client. It refuses to start before the hash-bound goal-completion audit passes. The launcher itself runs or verifies one real held-out MMBench request by default and writes/workspace/evals/final_vision_user_trial.json; setFINAL_VISION_RUN_TRIAL=0only for a deliberate server-only restart. Reuse requires the same holdout-file SHA-256 and row index, image/prompt, decoding settings, response hash, server receipt, and goal-completion hash.From the configured Mac, the completion-gated server, exact goal/server receipts, SSH tunnel, and one local image request can be verified in one command:
scripts/try_remote_vision_model.sh /path/to/image.png \ "Describe this image in detail."This helper does not weaken the gate: before opening the tunnel it invokes the remote launcher, downloads the exact server and goal receipts, rehashes their binding, and verifies the served model inventory.
The generated-code and interactive terminal evaluations remain outside the
RunPod training environment. Once
/workspace/evals/phase6_followup_status.json reaches
WAITING_FOR_TEXT_SANDBOXES (or the vision-cost variant), run
scripts/phase6_run_external_text_evals.sh on the configured local Docker
host. It uses the dedicated SSH key/known-hosts file, content-addresses the
generated samples, runs networkless EvalPlus plus pinned Terminal-Bench through
an SSH-tunneled adapted endpoint, returns hash-checked artifacts, enforces the
text-regression gate, and finalizes the release when the vision gate is also
complete.
The local sandbox dependencies can be rechecked before that state exists:
PHASE6_EXTERNAL_PREFLIGHT_ONLY=1 bash scripts/phase6_run_external_text_evals.sh
This verifies the pinned EvalPlus image/dataset and the frozen Terminal-Bench checkout, package environment, base-image labels, and ten-task inventory. It does not require adapted generations and does not execute generated code.
Failure playbook
- Kernel/build fail on B200 → Phase 1 gate → H100 fallback.
- MoE routing instability (loss spikes, expert-load entropy collapse) → LR ÷2–5, confirm router frozen, resume last good ckpt.
- OOM → seq len ↓ → micro-batch ↓ → activation checkpointing ↑ → CPU-offload optimizer — in that order.
- Ambiguous / >$100 exploration → STOP, STATUS.md, ask user.
Budget
- Phase 1–3 ≤ 1 day, Phase 4 ≤ 2 days, Phase 5 ≤ 7 days.
- Push checkpoints to network volume (opt. private HF repo) so pod can die anytime.