Download code/recipes/data_efficient.ps1 from aziz9788/OvisOCR3-Arabic-workdir: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/datasets/aziz9788/OvisOCR3-Arabic-workdir/resolve/main/code/recipes/data_efficient.ps1
- Command line
-
hf download hf://datasets/aziz9788/OvisOCR3-Arabic-workdir/code/recipes/data_efficient.ps1
-
curl -L -o data_efficient.ps1 https://huggingface.co/datasets/aziz9788/OvisOCR3-Arabic-workdir/resolve/main/code/recipes/data_efficient.ps1
3.17 kB
| # Data-efficient fine-tuning pipeline (Windows). 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: | |
| # $env:MODEL = "data/models/OvisOCR3"; powershell -ExecutionPolicy Bypass -File recipes\data_efficient.ps1 | |
| # $env:STAGES = "selfplay grpo eval" to run 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). | |
| . (Join-Path $PSScriptRoot "..\common\env.ps1") | |
| $model = if ($env:MODEL) { $env:MODEL } else { "$MODELS/OvisOCR3" } | |
| $stages = if ($env:STAGES) { $env:STAGES -split "\s+" } else { @("sieve", "balance", "sft", "hard", "selfplay", "grpo", "eval") } | |
| $name = Split-Path $model -Leaf | |
| $data = "$PREPARED/canonical" | |
| $sel = "$PREPARED/selected" | |
| $out = "$RUNS/recipe-$name" | |
| $small = @("--max-pixels", "589824", "--gradient-checkpointing") | |
| $promptArgs = @() | |
| if (Test-Path "$model/prompts/document_markdown.txt") { $promptArgs = @("--prompt-file", "$model/prompts/document_markdown.txt") } | |
| New-Item -ItemType Directory -Force $sel, $out | Out-Null | |
| if ($stages -contains "sieve") { Invoke-Step $PY -m common.select_data sieve --input "$data/train.jsonl" --out "$sel/clean.jsonl" } | |
| if ($stages -contains "balance") { Invoke-Step $PY -m common.select_data balance --input "$sel/clean.jsonl" --per-source 20000 --out "$sel/balanced.jsonl" } | |
| if ($stages -contains "sft") { | |
| Invoke-Step $PY -m common.vlm_sft --model $model @promptArgs --train "$sel/balanced.jsonl" --output "$out/sft" ` | |
| --lora 16 --lr 1e-4 --epochs 2 --grad-accum 8 --max-length 2048 @small | |
| } | |
| if ($stages -contains "hard") { | |
| Invoke-Step $PY -m common.vlm_infer --model $model --adapter "$out/sft" @promptArgs --input "$sel/balanced.jsonl" ` | |
| --max-pixels 589824 --out "$out/train_preds.jsonl" | |
| Invoke-Step $PY -m common.select_data hard --input "$sel/balanced.jsonl" --preds "$out/train_preds.jsonl" --keep 0.3 --out "$sel/hard.jsonl" | |
| } | |
| if ($stages -contains "selfplay") { | |
| Invoke-Step $PY -m common.selfplay --model $model --adapter "$out/sft" @promptArgs --train "$sel/hard.jsonl" --output "$out/selfplay" ` | |
| --rounds 3 --max-new 1024 @small | |
| } | |
| if ($stages -contains "grpo") { | |
| Invoke-Step $PY -m common.select_data entropy --input "$sel/hard.jsonl" --model $model --adapter "$out/selfplay/round3" ` | |
| @promptArgs --keep 0.5 --max-pixels 589824 --out "$sel/grpo.jsonl" | |
| Invoke-Step $PY -m common.grpo --model $model --adapter "$out/selfplay/round3" @promptArgs --train "$sel/grpo.jsonl" --output "$out/grpo" ` | |
| --group 4 --kl 0.02 --max-new 1024 @small | |
| } | |
| if ($stages -contains "eval") { | |
| foreach ($scale in "1.0", "0.8", "0.6") { | |
| Invoke-Step $PY -m common.vlm_infer --model $model --adapter "$out/grpo/final" --adapter-scale $scale @promptArgs ` | |
| --input "$data/eval.jsonl" --max-pixels 589824 --out "$out/eval_scale$scale.jsonl" | |
| Invoke-Step $PY -m common.score "$out/eval_scale$scale.jsonl" | |
| } | |
| } | |