File size: 6,815 Bytes
f440cbd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | # 06 β Runbook: bringing a fresh box back
The container root is an **overlay filesystem**. `/home/marimo` does **not** survive a relaunch; it
has been wiped at least three times. Everything in `dragonlimited/dragon-state` does survive. This
page is the operational procedure, corrected and with the two traps that actually bite.
Workspace convention: **`/home/marimo/dragon_fsds`** is the workspace root.
## 0. Before anything: the token
```bash
export HF_TOKEN_BOOT=<token> # restore_state.py and sync_state.py require THIS name
export HF_TOKEN=<token> # some tooling reads this one
```
Put it in the **environment**, never in a notebook cell and never in a tracked file β the
notebooks are published to public repositories. *Reading* needs no token: the model repos are public.
## 1. Get the ops scripts
They live in `dragon-harness/ops/`. Flatten them into the workspace (`ops/*.py` β workspace root,
`ops/*.json` β workspace root).
## 2. Restore the state
```bash
python restore_state.py # pulls dragon-state:state/** -> /home/marimo/dragon_fsds
python check_resume.py # 60/61 manifest items should read "yes"
```
Measured on 2026-11-21: **61 files, 0 failures, 7.2 GB, ~2 minutes.**
> **Trap 1 β the mapping.** A restore pass that matches on a single `/` silently skips every flat
> `state/<file>` entry. The mapping that works: `state/**` β workspace, `ops/*.py` β workspace
> flattened, `workplan/done/<n>` β `workplan_done/<n>`, `workplan/logs/<n>.log` β `workplan_<n>.log`.
>
> **Trap 2 β the manifest.** `sync_state.py` reads `state_manifest.json` **at import**, so the sync
> service cannot start without it. It *is* published now; `ops/state_manifest.json.example` is the
> reconstruction if it is ever missing again.
## 3. Verify the restore β do not trust it
```bash
python run_harness.py
# expect: 6,802 items | 6,791 hit | 99.8% | agreement 6,802
```
If that number moves, **the data moved, not the harness**. This is the single best check that the
restore is good, because it touches the facts database, the eval items and the whole scoring path.
The harness also needs the eval data, which is **not** in `dragon-state` β pull it from the public
eval repo into `data/`:
```bash
for f in dragon-finance-eval.jsonl dragon-finance-eval-largecap.jsonl verification.json \
corpus_overlap_accessions.txt; do
curl -sL -o data/$f \
"https://huggingface.co/datasets/dragonlimited/Dragon-Finance-Eval/raw/main/data/$f"
done
```
## 4. Recover the programs that only exist in a notebook payload
Seven ops scripts (`checkpoint_sync.py`, `test_resume.py`, `publish_plan.py`, `build_provenance.py`,
`sign_bundle.py`, `push_provenance.py`, `backup_notebook.py`) were never published as files. They are
carried inside the live model notebook's payload. If the file at `state/notebook.py` does not carry
them, recover the payload-bearing revision from git history:
```bash
GIT_TERMINAL_PROMPT=0 git clone --filter=blob:none --no-checkout --single-branch \
https://huggingface.co/dragonlimited/dragon-state ds-git
cd ds-git
for b in $(git rev-list --objects --all -- state/notebook.py | awk '{print $1}'); do
echo "$(git cat-file -s $b) $b"; done | sort -rn | head # find ~204,133 bytes
git cat-file blob <sha> > ../notebook-payload.py
```
Then decode: the payload is a dict `name -> (sha256, base64(zlib(source)))`. **Verify every sha256**
against `state/notebook_snapshot.json`'s `programs_carried` β on 2026-11-21 all 23 verified.
## 5. Restart the state sync
```bash
python sync_state.py --watch --every 300 &
```
This is what makes the night survivable. Without it, nothing written after the restore leaves the box.
## 6. Continue training
**The correct trainer is `train_sft_v4.py`.** (`RESTORE.md` says `train_fixed.py` β that is the older
trainer, see `07-CORRECTIONS.md` Β§7.)
The trainer resumes from **`{DRAGON_OUT}/resume.pt`** if it exists, restoring the LoRA weights, the
optimizer state, the step counter and the patience state β that is the difference between continuing
and restarting.
```bash
export DRAGON_TRACES=/home/marimo/dragon_fsds/tool_traces_all.jsonl # sha256 ef90f212...
export DRAGON_OUT=/home/marimo/dragon_fsds/dragon-lora-v8 # a NEW directory
export DRAGON_LOG=/home/marimo/dragon_fsds/sft_v8_log.txt
export DRAGON_MAX_STEPS=1500 DRAGON_EVAL_EVERY=150 DRAGON_PATIENCE=3
python train_sft_v4.py
```
Two things to do first, and both were learned the hard way:
1. **Never continue in a run directory that is already published.** `train_sft_v4.py` writes
`adapter_best.pt` into `DRAGON_OUT`, so resuming inside `dragon-lora-v7/` would overwrite the
adapter that `runs/verdict-v7/` and the model card both cite. Seed a new directory instead:
```bash
mkdir -p dragon-lora-v8 && cd dragon-lora-v8
for f in resume.pt adapter_best.pt adapter_last.pt RUN_STATE.json; do
hf download dragonlimited/dragon-state runs/dragon-lora-v7/$f --repo-type model --local-dir .
done
```
2. **Drop the scheduler state when you resume.** v7's cosine ran `T_max=900` and finished at
`last_epoch=900`, so a restored scheduler sits at its minimum and the continuation would not learn:
```python
import torch; ck = torch.load("resume.pt", map_location="cpu")
ck.pop("sched", None) # keep weights, optimizer, step, patience
torch.save(ck, "resume.pt")
```
Declare it wherever the resulting numbers are reported: the LR schedule is a new cycle, so a
resumed run is not a strict continuation of the old one in every respect.
## 7. Do not start these
* `run_workplan.py` β **no retry cap**: a job whose script is missing is re-admitted every tick.
* `keeper.py` β its service list still includes `cpu_lane.py`, which does not exist.
* More than one trainer at a time. Three GPU jobs were considered safe in the old plan because each is
bandwidth-bound at low occupancy (~15 GB each, 98 GB card) β but only one **trainer**.
* **Nothing on the corpus side.** Its notebook's standing rule says the model work is driven from
elsewhere and the corpus must not be started on its behalf, and a corpus publish round must not be
joined to a model run.
## 8. Publishing back
`checkpoint_sync.py` pushes `resume.pt`, `adapter_best.pt`, `adapter_last.pt` and `RUN_STATE.json` to
`dragon-state:runs/<run>/`, verifies by re-downloading, and skips unchanged files.
```bash
python checkpoint_sync.py --push /home/marimo/dragon_fsds/dragon-lora-v8
python checkpoint_sync.py --status # local vs Hub, per run, with the step each records
```
**Cap the commits.** The account allows ~128 repository commits per hour and a full sync pass costs
one per changed file. Pace writes; do not loop a full push every minute.
|