# 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 `/workspace` so 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.md` and stop cleanly. ## Hard rules 1. Never `pip install torch` or anything that replaces NGC torch (breaks TransformerEngine). Use `--no-deps`/constraints. 2. Never merge LoRA into FP8 weights. `--merge_lora false`; merge only against BF16. 3. 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-linear` and never attach LoRA to shared/dense FFNs. 4. Cap training seq len at 4K (8K max after memory proven). 5. Do not modify text tokenizer/vocab. Images enter as continuous embeddings at `` placeholder in template/encoding layer. 6. (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 1. Install ms-swift[megatron] + Megatron-Core dev per swift DeepSeek-V4 best-practices doc. Pin commits in `/workspace/ENV.md`. 2. Run official text-only V4-Flash SFT example (tiny dataset, LoRA). Success = loss decreases ~50 steps, no NaNs, checkpoint saves/reloads. 3. 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_precision` too slow: validate 5 prompts swift-infer vs reference; require near-identical. - Store on network volume; record sizes in ENV.md. ## Phase 3 — Vision graft 1. Study ms-swift MLLM registration (Qwen-VL, DeepSeek-VL2); mirror pattern. 2. Register: SigLIP2-so400m (frozen) + 2-layer MLP projector (GELU) + V4-Flash. `` placeholder expansion count == projected patch count. 3. Unit gate: one image+text sample → loss computes, grads ONLY to projector, generation runs. 4. 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 1. Save adapters; merge against BF16 only; mcore→HF (`--to_hf true`). 2. Copy ORIGINAL config.json over exported one, adjust `expert_dtype` (transformers-saved config is vLLM-incompatible). 3. Document: DSpark/speculative decoding not adapted for images — disable for multimodal inference. 4. 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 into `docs/publication_state.json`; regenerates the research paper and technical-report result blocks; and copies all five publication artifacts into the release's hash-bound `documentation/` directory. The launcher then starts the detached `phase6-final-hf-backup` session, which resumably uploads the complete merged directory to `ConwayResearch/dsv4-flash-0731-vision`. Do not stop the pod until `/workspace/evals/final_release_hf_backup.json` exists with `status: 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.log` and `/workspace/evals/final_release_hf_backup.status.json`. The authoritative Phase-6 state moves through `VERIFYING_FINAL_RELEASE_BACKUP` and `VERIFYING_GOAL_COMPLETION`. It reaches `FINAL_RELEASE_COMPLETE` only after `verify_goal_completion.py` rechecks 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.json` and `/workspace/evals/GOAL_COMPLETION.json` are 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 either `VERIFYING_*` state resumes or supervises the detached finalizer; a `FAILED` state is resumed only when it identifies the final backup/goal audit and the verified local release manifest exists. 5. Start and try the completed vision model: ```bash 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.json ``` The 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`; set `FINAL_VISION_RUN_TRIAL=0` only 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: ```bash 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: ```bash 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.