Brigalow-QLD-v1 / scripts /RUN_STATEWIDE.md
srg's picture
Brigalow v1 (1.0.0)
4a3ac26 verified
|
Raw History Blame Contribute Delete
6.01 kB

Statewide run on a rented GPU box

One statewide map year = 250 Sentinel-2 tiles, about 1.5 h on one RTX 4090 / 5090 for one setting (fp32), about 0.5 TB read from Earth Search. Tested on Ubuntu containers from the pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime image with 24 GB GPUs and 250 GB disk.

Choosing machines

  • Use boxes on different physical hosts if you rent several; check the host-to-GPU bandwidth and the real CPU count (cat /sys/fs/cgroup/cpu.max, not nproc).
  • GPU memory: an idle worker holds 2 GiB, an active one ~6.4 GiB. On a 24 GB card use --workers 7 --threads 8 --torch-threads 1 --gpu-slots 1 (21 GB peak; 10 workers ran out of memory).
  • Host RAM: size --workers so that workers x peak RSS (up to ~7 GB with three settings) stays ~15 % under the box RAM.

Run everything from the control machine, in the repository root. Set the box address once:

export BOX="root@<box address>"; export BOXP=<port>
alias bx='ssh -p $BOXP $BOX'

1. Code and setup

rsync -a -e "ssh -p $BOXP" --exclude .git --exclude results --exclude __pycache__ ./ $BOX:/root/clearing-qld/
bx 'cd /root/clearing-qld && bash scripts/statewide_setup.sh 2>&1 | tail -4'      # ends with "setup ok"
bx 'cat /sys/fs/cgroup/cpu.max /sys/fs/cgroup/memory.max'                          # real CPU and RAM limits

2. Queensland layers to /data/tern

Either copy a local TERN folder (fastest; include the pre-combined cvmsre_qld_2026_afma2.tif for label year 2026, otherwise the monthly 2026 files are merged per tile at ~55 s per tile), or download with your TERN key, passed over ssh stdin only (never in a file, shell history or log):

printf '%s\n' "$TERN_API_KEY" | \
  bx 'read -r K; mkdir -p /data/tern; cd /root/clearing-qld; TERN_API_KEY="$K" PYTHONPATH=src setsid nohup python -m brigalow.statewide_tern /data/tern --procs 8 > /data/tern_dl.log 2>&1 < /dev/null & unset K; echo started'
until bx 'grep -q "TERN root complete" /data/tern_dl.log'; do sleep 60; done; bx 'tail -1 /data/tern_dl.log; du -sh /data/tern'

About 9 GB in ~25 min with --procs 8; rerunning resumes.

3. Model

rsync -a -e "ssh -p $BOXP" weights/brigalow/ $BOX:/data/model/          # model.json + member0..4.pt (+ .onnx)
bx 'cd /root/clearing-qld && PYTHONPATH=src python -m brigalow.infer verify /data/model'     # must print VERIFY PASSED

The release inference settings come from model.json: 256 px crops, stride 128, Hann weighting, horizontal-flip test-time augmentation, fp32. For faster forward runs you may set "precision": "bf16" in the inference entry of a copy of model.json on the box (2.6x faster on an RTX 4090; max probability difference 2.2e-4, 99.997 % of stored values identical on the reference crops). Keep the published model.json at fp32.

4. Run one label year

Y=2025
bx "cd /root/clearing-qld && PYTHONPATH=src setsid nohup python -m brigalow.statewide run --label-year $Y \
   --ckpt /data/model --tern-root /data/tern --setting standard \
   --workers 7 --threads 8 --torch-threads 1 --gpu-slots 1 --out /data/run > /data/run_$Y.log 2>&1 < /dev/null & echo started"
  • Settings: --setting standard,immediate,s2only reads imagery and masks once and runs the network once per setting on the same features: prob/<Y>/<tile>.tif = the first setting, prob_immediate/<Y>/ and prob_s2only/<Y>/ the others. A tile counts as done only when all its settings exist. Do not add settings to a half-finished --out.
  • LightGBM baselines on the 124 fixed blocks (results/baselines/tree_blocks.parquet): add --gbt standard=weights/gbt/gbt_standard.txt,immediate=weights/gbt/gbt_immediate.txt,s2only=weights/gbt/gbt_s2only.txt; each is applied to the baseline features (features.compute_basic) of the same reads and written to /data/run/gbt_prob/<setting>/<Y>/<tile>.tif (uint8 p*250, 255 outside the blocks).
  • Mask vintages: woody extent and cropping three years old, fire scars before and inside the window (the released maps' setting). The newest TERN woody extent is 2023, so the woody lag is never less than Y - 2023.
  • Resume: rerun the same command. A tile is finished only when both <tile>.tif and <tile>.json exist (the .json is written last, atomically). Claims left by dead workers are released at start; transient read errors are retried (3 tries per tile, then a second pass at the end of each worker's list). Use --tile-list to finish missing tiles.
  • Killing the driver terminates its workers (PR_SET_PDEATHSIG covers SIGKILL too). Kill by PID; never pkill -f a pattern that also appears in your own ssh command line.
  • Swath edges: where the lowest-cloud dates cover only part of a tile, extra dates fill pixels that would otherwise have no clear view ("gap fill"; at most 4 clear dates per pixel; interior pixels untouched).
  • Coverage after each year (target: every tile >= 99.5 % of owned land pixels valid): bx "python -c 'import json;print(json.load(open(\"/data/run/progress_$Y.json\"))[\"coverage\"])'"; rerun only low tiles with --redo-below 0.995. A few Cape York / Torres Strait tiles stay below 99.5 % in cloudy years.
  • Rare edge cases handled in statewide.py: 60 m SCL assets are resampled to the 20 m blocks; STAC items missing a required band asset are skipped before date selection.

5. Progress

bx "cat /data/run/progress_$Y.json"          # tiles_done / tiles_total, tiles_per_hour, rx_gb, eta_h, coverage
bx "grep -c '\"ok\": false' /data/run/tiles_$Y.jsonl; tail -2 /data/run_$Y.log"

6. Copy finished tiles to storage

Copy finished tiles off the box incrementally (so a box going offline loses little work), e.g.

rsync -a -e "ssh -p $BOXP" --include='*/' --include='*.tif' --include='*.json' --include='*.jsonl' --exclude='*' $BOX:/data/run/ ./run_statewide/

When the year is done, check there are 250 tifs per year and shut the box down. Then build the release files with scripts/make_release_maps.py.