Download code/recipes/data_efficient.sh from aziz9788/OvisOCR3-Arabic-workdir: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/datasets/aziz9788/OvisOCR3-Arabic-workdir/resolve/main/code/recipes/data_efficient.sh
- Command line
-
hf download hf://datasets/aziz9788/OvisOCR3-Arabic-workdir/code/recipes/data_efficient.sh
-
curl -L -o data_efficient.sh https://huggingface.co/datasets/aziz9788/OvisOCR3-Arabic-workdir/resolve/main/code/recipes/data_efficient.sh
2.75 kB
| # Data-efficient fine-tuning pipeline (Linux). See docs/finetuning_recipes.md for the evidence behind each stage. | |
| # sieve -> balance -> sft -> hard -> selfplay -> grpo -> eval (alpha sweep) | |
| # Prerequisite: canonical data from `python -m common.data_prep --sources configs/sources.yaml --formats hf`. | |
| # Usage: | |
| # MODEL=data/models/OvisOCR3 bash recipes/data_efficient.sh | |
| # STAGES="selfplay grpo eval" bash recipes/data_efficient.sh # only some stages (they reuse earlier outputs) | |
| # Settings below fit an 8 GB GPU (LoRA, fp32 on pre-Ampere cards, <= 0.59 MP images, short sequences). | |
| source "$(dirname "$0")/../common/env.sh" | |
| MODEL=${MODEL:-$MODELS/OvisOCR3} | |
| STAGES=${STAGES:-"sieve balance sft hard selfplay grpo eval"} | |
| NAME=$(basename "$MODEL") | |
| DATA=$PREPARED/canonical | |
| SEL=$PREPARED/selected | |
| OUT=$RUNS/recipe-$NAME | |
| SMALL=(--max-pixels 589824 --gradient-checkpointing) | |
| PROMPT=() | |
| [[ -f "$MODEL/prompts/document_markdown.txt" ]] && PROMPT=(--prompt-file "$MODEL/prompts/document_markdown.txt") | |
| has() { [[ " $STAGES " == *" $1 "* ]]; } | |
| mkdir -p "$SEL" "$OUT" | |
| has sieve && $PY -m common.select_data sieve --input "$DATA/train.jsonl" --out "$SEL/clean.jsonl" | |
| has balance && $PY -m common.select_data balance --input "$SEL/clean.jsonl" --per-source 20000 --out "$SEL/balanced.jsonl" | |
| if has sft; then | |
| $PY -m common.vlm_sft --model "$MODEL" "${PROMPT[@]}" --train "$SEL/balanced.jsonl" --output "$OUT/sft" \ | |
| --lora 16 --lr 1e-4 --epochs 2 --grad-accum 8 --max-length 2048 "${SMALL[@]}" | |
| fi | |
| if has hard; then | |
| $PY -m common.vlm_infer --model "$MODEL" --adapter "$OUT/sft" "${PROMPT[@]}" --input "$SEL/balanced.jsonl" \ | |
| --max-pixels 589824 --out "$OUT/train_preds.jsonl" | |
| $PY -m common.select_data hard --input "$SEL/balanced.jsonl" --preds "$OUT/train_preds.jsonl" --keep 0.3 --out "$SEL/hard.jsonl" | |
| fi | |
| if has selfplay; then | |
| $PY -m common.selfplay --model "$MODEL" --adapter "$OUT/sft" "${PROMPT[@]}" --train "$SEL/hard.jsonl" --output "$OUT/selfplay" \ | |
| --rounds 3 --max-new 1024 "${SMALL[@]}" | |
| fi | |
| if has grpo; then | |
| $PY -m common.select_data entropy --input "$SEL/hard.jsonl" --model "$MODEL" --adapter "$OUT/selfplay/round3" \ | |
| "${PROMPT[@]}" --keep 0.5 --max-pixels 589824 --out "$SEL/grpo.jsonl" | |
| $PY -m common.grpo --model "$MODEL" --adapter "$OUT/selfplay/round3" "${PROMPT[@]}" --train "$SEL/grpo.jsonl" --output "$OUT/grpo" \ | |
| --group 4 --kl 0.02 --max-new 1024 "${SMALL[@]}" | |
| fi | |
| if has eval; then | |
| for SCALE in 1.0 0.8 0.6; do | |
| $PY -m common.vlm_infer --model "$MODEL" --adapter "$OUT/grpo/final" --adapter-scale "$SCALE" "${PROMPT[@]}" \ | |
| --input "$DATA/eval.jsonl" --max-pixels 589824 --out "$OUT/eval_scale$SCALE.jsonl" | |
| $PY -m common.score "$OUT/eval_scale$SCALE.jsonl" | |
| done | |
| fi | |