# Phase B: build SFT set, QLoRA train, convert adapter to GGUF, eval tuned model on MATH-500 $ErrorActionPreference="Continue" $py="..\.venv\Scripts\python.exe"; $env:PYTHONUNBUFFERED=1 $base=& $py -c "from huggingface_hub import snapshot_download;print(snapshot_download('Qwen/Qwen3-8B',allow_patterns=['*.json','*.safetensors','*.txt']))" "B start $(Get-Date)" & $py build_sft.py & $py train.py 1.0 2>&1 | Out-File -Encoding utf8 logs\train_stdout.log if (-not (Test-Path out\lora_adapter\adapter_model.safetensors)) { "train failed at 1536, retry 1024 $(Get-Date)"; $env:E20_MAXLEN="1024" & $py train.py 1.0 2>&1 | Out-File -Encoding utf8 logs\train_stdout_1024.log } if (-not (Test-Path out\lora_adapter\adapter_model.safetensors)) { "TRAIN_FAILED $(Get-Date)"; exit 1 } "B train done $(Get-Date)" & $py llama-py\convert_lora_to_gguf.py --base $base --outtype f16 --outfile out\e20_lora.gguf out\lora_adapter $srv=Start-Process C:\AGI\llama.cpp\llama-server.exe -ArgumentList "--port 8096 -m C:\AGI\gguf\q3_8b\Qwen3-8B-Q4_K_M.gguf --lora out\e20_lora.gguf -ngl 99 -c 32768 -np 8 -fa on -ctk q8_0 -ctv q8_0 -t 8" -PassThru -WindowStyle Hidden -RedirectStandardError logs\srvB.err -RedirectStandardOutput logs\srvB.out do { Start-Sleep 3; try { $ok=(Invoke-RestMethod http://127.0.0.1:8096/health).status -eq "ok" } catch { $ok=$false } } until ($ok -or $srv.HasExited) & $py gen.py --items data/math500.jsonl --out out/tuned_math500.jsonl Stop-Process -Id $srv.Id -Force & $py grade.py out/base_math500.jsonl; & $py grade.py out/tuned_math500.jsonl "PHASEB_DONE $(Get-Date)" & $py analyze.py