Spaces:
Running on Zero
Running on Zero
Dimitris Codex commited on
Commit ·
94ba245
1
Parent(s): d3c5453
fix(train): use MiniCPM-V 4.6 model id and official mmproj
Browse filesCo-authored-by: Codex <chatgpt-codex-connector[bot]@users.noreply.github.com>
- RUNBOOK.md +27 -4
- scripts/convert_to_gguf.sh +18 -20
- scripts/merge_lora.py +1 -1
- train/modal_finetune.py +7 -7
RUNBOOK.md
CHANGED
|
@@ -30,16 +30,39 @@ python train/synth_reports.py --n 12 --out train/data/preview # eyeball the im
|
|
| 30 |
```
|
| 31 |
|
| 32 |
## The fine-tune → offline pipeline (run these in order)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
```bash
|
| 34 |
# 1) Fine-tune MiniCPM-V on Modal (data generated on the box; needs Modal credits).
|
| 35 |
-
# First confirm MODEL_TYPE
|
| 36 |
modal run train/modal_finetune.py --n 4000 --epochs 2
|
| 37 |
|
| 38 |
# 2) Pull adapters from the Modal volume 'blood-test-adapters', then merge.
|
| 39 |
-
python scripts/merge_lora.py --base openbmb/MiniCPM-V-
|
| 40 |
--adapters ./adapters/minicpmv-lab-lora --out ./merged-minicpmv-lab
|
| 41 |
|
| 42 |
-
# 3) Convert
|
|
|
|
|
|
|
| 43 |
LLAMA_CPP=./llama.cpp bash scripts/convert_to_gguf.sh ./merged-minicpmv-lab
|
| 44 |
|
| 45 |
# 4) Point the app at the local model and go offline.
|
|
@@ -68,7 +91,7 @@ EXTRACTOR_BACKEND=local LOCAL_MODEL_PATH=... LOCAL_MMPROJ_PATH=... \
|
|
| 68 |
|
| 69 |
## Verify-on-hardware (can't be tested in CI)
|
| 70 |
1. `train/modal_finetune.py`: confirm the ms-swift `MODEL_TYPE` for **MiniCPM-V 4.6**.
|
| 71 |
-
2. `scripts/convert_to_gguf.sh`: llama.cpp
|
| 72 |
3. `src/extraction/local_minicpmv.py`: the `LOCAL_CHAT_HANDLER` class for your llama-cpp-python build.
|
| 73 |
|
| 74 |
## Still TODO (next PRs, not this one)
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
## The fine-tune → offline pipeline (run these in order)
|
| 33 |
+
### Step 0: validate offline with the official base GGUF first
|
| 34 |
+
Before fine-tuning, prove the local backend works with OpenBMB's official base GGUF + mmproj:
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
# Install llama.cpp tooling locally.
|
| 38 |
+
brew install llama.cpp
|
| 39 |
+
|
| 40 |
+
# Download official base GGUF assets, including the official mmproj.
|
| 41 |
+
mkdir -p models
|
| 42 |
+
huggingface-cli download openbmb/MiniCPM-V-4.6-gguf --local-dir ./models
|
| 43 |
+
|
| 44 |
+
# Point LOCAL_MODEL_PATH at the downloaded base LLM GGUF, and LOCAL_MMPROJ_PATH at the
|
| 45 |
+
# downloaded mmproj GGUF. Use the exact filenames from ./models.
|
| 46 |
+
export EXTRACTOR_BACKEND=local
|
| 47 |
+
export LOCAL_MODEL_PATH=./models/<official-base-model>.gguf
|
| 48 |
+
export LOCAL_MMPROJ_PATH=./models/<official-mmproj>.gguf
|
| 49 |
+
python app.py
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
Confirm extraction works fully offline before starting the fine-tune.
|
| 53 |
+
|
| 54 |
```bash
|
| 55 |
# 1) Fine-tune MiniCPM-V on Modal (data generated on the box; needs Modal credits).
|
| 56 |
+
# First confirm MODEL_TYPE in train/modal_finetune.py against the MiniCPM-V finetune guide.
|
| 57 |
modal run train/modal_finetune.py --n 4000 --epochs 2
|
| 58 |
|
| 59 |
# 2) Pull adapters from the Modal volume 'blood-test-adapters', then merge.
|
| 60 |
+
python scripts/merge_lora.py --base openbmb/MiniCPM-V-4.6 \
|
| 61 |
--adapters ./adapters/minicpmv-lab-lora --out ./merged-minicpmv-lab
|
| 62 |
|
| 63 |
+
# 3) Convert only the merged LLM to GGUF and quantize Q4_K_M.
|
| 64 |
+
# The script downloads/reuses the official openbmb/MiniCPM-V-4.6-gguf mmproj because LoRA
|
| 65 |
+
# touches the LLM, not the vision encoder.
|
| 66 |
LLAMA_CPP=./llama.cpp bash scripts/convert_to_gguf.sh ./merged-minicpmv-lab
|
| 67 |
|
| 68 |
# 4) Point the app at the local model and go offline.
|
|
|
|
| 91 |
|
| 92 |
## Verify-on-hardware (can't be tested in CI)
|
| 93 |
1. `train/modal_finetune.py`: confirm the ms-swift `MODEL_TYPE` for **MiniCPM-V 4.6**.
|
| 94 |
+
2. `scripts/convert_to_gguf.sh`: llama.cpp `convert_hf_to_gguf.py` path and official mmproj filename for 4.6.
|
| 95 |
3. `src/extraction/local_minicpmv.py`: the `LOCAL_CHAT_HANDLER` class for your llama-cpp-python build.
|
| 96 |
|
| 97 |
## Still TODO (next PRs, not this one)
|
scripts/convert_to_gguf.sh
CHANGED
|
@@ -1,37 +1,35 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
-
# Convert the merged, fine-tuned MiniCPM-V into a quantized GGUF
|
| 3 |
-
#
|
| 4 |
# models/minicpmv-lab.Q4_K_M.gguf (LOCAL_MODEL_PATH)
|
| 5 |
# models/minicpmv-lab.mmproj.gguf (LOCAL_MMPROJ_PATH)
|
| 6 |
#
|
| 7 |
-
#
|
| 8 |
#
|
| 9 |
-
#
|
| 10 |
-
#
|
| 11 |
-
# llama.cpp version and adjust the three SCRIPT paths below. The flow is stable; the paths drift.
|
| 12 |
set -euo pipefail
|
| 13 |
|
| 14 |
MERGED="${1:-./merged-minicpmv-lab}" # merged HF model dir
|
| 15 |
LLAMA="${LLAMA_CPP:-./llama.cpp}" # path to a llama.cpp checkout
|
| 16 |
OUT="${OUT_DIR:-./models}"
|
| 17 |
-
VER="${MINICPMV_VERSION:-3}" # MiniCPM-V arch version flag; confirm for 4.6
|
| 18 |
mkdir -p "$OUT"
|
| 19 |
|
| 20 |
-
echo "==> 1/
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
echo "==> 2/
|
| 24 |
-
python "$LLAMA/
|
| 25 |
-
-m "$MERGED" \
|
| 26 |
-
--minicpmv-projector "$MERGED/minicpmv.projector" \
|
| 27 |
-
--output-dir "$OUT" \
|
| 28 |
-
--minicpmv_version "$VER"
|
| 29 |
-
mv "$OUT"/*mmproj*.gguf "$OUT/minicpmv-lab.mmproj.gguf" 2>/dev/null || true
|
| 30 |
|
| 31 |
-
echo "==> 3/
|
| 32 |
-
python "$LLAMA/convert_hf_to_gguf.py" "$MERGED/model" --outfile "$OUT/minicpmv-lab.f16.gguf"
|
| 33 |
-
|
| 34 |
-
echo "==> 4/4 Quantize to Q4_K_M"
|
| 35 |
"$LLAMA/llama-quantize" "$OUT/minicpmv-lab.f16.gguf" "$OUT/minicpmv-lab.Q4_K_M.gguf" Q4_K_M
|
| 36 |
|
| 37 |
echo
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
+
# Convert the merged, fine-tuned MiniCPM-V LLM into a quantized GGUF for llama.cpp, and
|
| 3 |
+
# download the official MiniCPM-V 4.6 mmproj. Produces the two files the offline backend loads:
|
| 4 |
# models/minicpmv-lab.Q4_K_M.gguf (LOCAL_MODEL_PATH)
|
| 5 |
# models/minicpmv-lab.mmproj.gguf (LOCAL_MMPROJ_PATH)
|
| 6 |
#
|
| 7 |
+
# LoRA touches the LLM, not the vision encoder, so the official mmproj remains valid.
|
| 8 |
#
|
| 9 |
+
# Prereqs: a merged HF model (scripts/merge_lora.py), a local llama.cpp checkout, and
|
| 10 |
+
# huggingface-cli (`pip install huggingface_hub`).
|
|
|
|
| 11 |
set -euo pipefail
|
| 12 |
|
| 13 |
MERGED="${1:-./merged-minicpmv-lab}" # merged HF model dir
|
| 14 |
LLAMA="${LLAMA_CPP:-./llama.cpp}" # path to a llama.cpp checkout
|
| 15 |
OUT="${OUT_DIR:-./models}"
|
|
|
|
| 16 |
mkdir -p "$OUT"
|
| 17 |
|
| 18 |
+
echo "==> 1/3 Download official MiniCPM-V 4.6 GGUF assets (includes mmproj)"
|
| 19 |
+
huggingface-cli download openbmb/MiniCPM-V-4.6-gguf --local-dir "$OUT"
|
| 20 |
+
MMPROJ="$(find "$OUT" -maxdepth 1 -type f -iname '*mmproj*.gguf' | head -n 1)"
|
| 21 |
+
if [[ -z "${MMPROJ:-}" ]]; then
|
| 22 |
+
echo "No mmproj GGUF found in $OUT after download" >&2
|
| 23 |
+
exit 1
|
| 24 |
+
fi
|
| 25 |
+
if [[ "$MMPROJ" != "$OUT/minicpmv-lab.mmproj.gguf" ]]; then
|
| 26 |
+
cp "$MMPROJ" "$OUT/minicpmv-lab.mmproj.gguf"
|
| 27 |
+
fi
|
| 28 |
|
| 29 |
+
echo "==> 2/3 Convert the merged LLM to GGUF (f16)"
|
| 30 |
+
python "$LLAMA/convert_hf_to_gguf.py" "$MERGED" --outfile "$OUT/minicpmv-lab.f16.gguf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
echo "==> 3/3 Quantize to Q4_K_M"
|
|
|
|
|
|
|
|
|
|
| 33 |
"$LLAMA/llama-quantize" "$OUT/minicpmv-lab.f16.gguf" "$OUT/minicpmv-lab.Q4_K_M.gguf" Q4_K_M
|
| 34 |
|
| 35 |
echo
|
scripts/merge_lora.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"""Merge the LoRA adapters into the MiniCPM-V base → a standalone HF model for GGUF conversion.
|
| 3 |
|
| 4 |
python scripts/merge_lora.py \
|
| 5 |
-
--base openbmb/MiniCPM-V-
|
| 6 |
--adapters ./adapters/minicpmv-lab-lora \
|
| 7 |
--out ./merged-minicpmv-lab
|
| 8 |
"""
|
|
|
|
| 2 |
"""Merge the LoRA adapters into the MiniCPM-V base → a standalone HF model for GGUF conversion.
|
| 3 |
|
| 4 |
python scripts/merge_lora.py \
|
| 5 |
+
--base openbmb/MiniCPM-V-4.6 \
|
| 6 |
--adapters ./adapters/minicpmv-lab-lora \
|
| 7 |
--out ./merged-minicpmv-lab
|
| 8 |
"""
|
train/modal_finetune.py
CHANGED
|
@@ -10,19 +10,19 @@ down and convert to GGUF (see scripts/convert_to_gguf.sh).
|
|
| 10 |
|
| 11 |
Running the fine-tune on Modal also satisfies the Modal prize.
|
| 12 |
|
| 13 |
-
⚠️ VERIFY-ON-FIRST-RUN: the ms-swift `--model_type` for
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
conversion, and plumbing are correct; the trainer invocation is the one thing to confirm.
|
| 17 |
"""
|
| 18 |
|
| 19 |
from __future__ import annotations
|
| 20 |
|
| 21 |
import modal
|
| 22 |
|
| 23 |
-
# TODO(verify): confirm
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
app = modal.App("blood-test-finetune")
|
| 28 |
|
|
|
|
| 10 |
|
| 11 |
Running the fine-tune on Modal also satisfies the Modal prize.
|
| 12 |
|
| 13 |
+
⚠️ VERIFY-ON-FIRST-RUN: confirm the exact ms-swift/LLaMA-Factory `--model_type` for MiniCPM-V
|
| 14 |
+
4.6 against the finetune guide at github.com/OpenBMB/MiniCPM-V before running. Trainer CLIs
|
| 15 |
+
evolve; pin the value in MODEL_TYPE below after checking the current guide.
|
|
|
|
| 16 |
"""
|
| 17 |
|
| 18 |
from __future__ import annotations
|
| 19 |
|
| 20 |
import modal
|
| 21 |
|
| 22 |
+
# TODO(verify): confirm the exact ms-swift/LLaMA-Factory model_type for MiniCPM-V 4.6
|
| 23 |
+
# against the finetune guide at github.com/OpenBMB/MiniCPM-V before running.
|
| 24 |
+
MODEL_ID = "openbmb/MiniCPM-V-4.6" # HF id of the base vision model
|
| 25 |
+
MODEL_TYPE = "minicpm-v-v2_6-chat" # placeholder until confirmed from the guide
|
| 26 |
|
| 27 |
app = modal.App("blood-test-finetune")
|
| 28 |
|