File size: 6,123 Bytes
fb4bb78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Handoff: human-factory training data (functional windows)

For the session picking this up on the M1 Mac. Everything persistent is in
two places:

- **Code:** branch `blueprint-corpus`, PR [#501](https://github.com/beyarkay/factorion/pull/501), head `0596291`. All tests pass.
- **Data:** HF dataset [`beyarkay/factorio-blueprints`](https://huggingface.co/datasets/beyarkay/factorio-blueprints). It's public; the write token is the user's.

Nothing from the old cloud container is needed.

## What exists

| Where | What |
|---|---|
| `corpus/convert.py` | `edit` turns a save region's 30×30 interior into a working 32×32 factory: sources and sinks where flows leave it, of the item the save saw on the belt. `paste` rebuilds a window from its edits. `functional` is the SFT stream (random turn and mirror). |
| `corpus/windows.py` | The precompute: one `windows/<save>.parquet` per input file. It resumes, skipping files already written, and keeps only windows that deliver anything. Columns: `crafted`, `delivered`. |
| `sft.py` | `--windows-frac F` mixes F of functional windows into every batch. `val/human/thput@N` is the generation eval on the windows of the 5% of saves held out (`convert.held_out(save, 20)`). |
| `ci/` | `/ci sft` takes `--windows-frac`, `--corpus-frac` and `--lr`. |
| HF `designs/` | Every design (unchanged). Windows join to it on `layout_hash`. |
| HF `windows/` | Precomputed windows of 164 of ~1,425 lane-labelled save files. |
| HF `raw_lanes/` | One `*.jsonl.gz` per save: scraped-style records with each region's `string`, `unbuildable` and `lanes` (`[x, y, line, "item,…"]`, line 1 = left lane). 1,425 files. |
| HF `scripts/saves/` | `relabel.py` (the re-export: download → check → extract with belt contents → delete, one save at a time), plus `fetch_saves.py` and `save_meta.py`. `relabel_state/` holds the candidate lists (`relabel_part_00..02`, 2,083 saves in total) and the done lists (`relabel_done_0..2.jsonl`, 1,447 done). |
| HF `scripts/flow_debug/` | Scratch scripts for renders and A/B checks. `render_ported.py` renders 12 random windows; `ab.py` compares two builder versions on the same views; `dump.py` dumps one window with its surroundings. They use the prototype `functional.py` only for its `sample()`. |

## Jobs to resume

**1. Window precompute** over all of `raw_lanes/`. About 30 ms per window, ~18 windows per region. Use every core:

```bash
uv sync && uv run maturin develop --release --manifest-path factorion_rs/Cargo.toml
huggingface-cli download beyarkay/factorio-blueprints --repo-type dataset --include "raw_lanes/*" "windows/*" --local-dir hf
uv run python -m corpus.windows hf/raw_lanes/*.jsonl.gz --out hf --procs $(sysctl -n hw.ncpu)
# then upload hf/windows to the dataset's windows/ (corpus.windows --repo, or HfApi.upload_folder)
```

Expect roughly 240k windows with machine output, from ~1,400 saves.

**2. Lane re-export** of the remaining ~640 saves (optional; the ~1,400 done are enough for the sweep).

- It needs Factorio, and the free headless server is Linux x64 only. On the Mac, either:
  - point `corpus/extract_saves.py`'s `FACTORIO` / `FACTORIO_EXPERIMENTAL` at the macOS app binary (full game with Space Age; untested), or
  - run the Linux headless server in Docker (`--platform linux/amd64`).
- Run three pipelines on ports 27300/27310/27320, each reading one candidate part on stdin:

  ```bash
  python relabel.py <dl_dir> <out_dir> relabel_done_i.jsonl <port> < relabel_part_0i
  ```

  Each save's records are written atomically to their own file, and the done list makes it resumable.

## Results so far

Two 1M-sample SFT runs, one seed each, at the same commit:

| Run | `val/thput@8` | `val/trial_thput@8` | Human eval |
|---|---|---|---|
| [25% windows `i2t3fu8g`](https://wandb.ai/beyarkay/factorion/runs/i2t3fu8g) | 0.223 | 0.010 | 0.86 |
| [Baseline `41ciydxe`](https://wandb.ai/beyarkay/factorion/runs/41ciydxe) | 0.373 | 0.079 | 1.41 (scored offline) |

- The windows run is worse even at equal synthetic samples.
- The human eval doesn't measure what we want. Only 17% of held-out windows have machine output; the rest are belt routing. And 16% of each window's sinks get nothing in the human build, so a model that feeds them beats the human score.

## Decided

**Next experiment:** a human share × LR sweep at 5M samples, human data mixed into every batch (not phased).
- Proposed grid: share {0, 0.25, 0.5} × LR {5e-4, 1e-3, 1.5e-3 (default), 3e-3}, 12 runs, ~55 GPU-hours on an A4000.
- **Don't launch until the user approves the details.**

**Before the sweep:**
1. Finish the precompute (job 1). Today's 26.6k machine windows would be seen ~47–94 times each at 25–50% human.
2. Train only on windows with machine output (`crafted > 0`).
3. Fix the human eval: hold out only machine windows, and keep only the sinks of items those machines make, so feeding raw items to sinks earns nothing.

## Known issues

- **Loops:** any cycle in the flow graph makes the engine score the whole factory 0 (`throughput.rs::calc_throughput`). That loses belt balancers and platform loops, about 4% of windows; they're filtered out today. There's a separate task, "Make the throughput engine handle belt loops".
- **Labels:** a source carries one item, so a lane the save saw empty (e.g. starved steel) leaves its machines unfed. Example: low-density-structure rows.
- **Space platforms** with no poles come out unpowered. Unverified whether platforms need poles in the game.
- **Marker clutter:** some windows have 50–150 markers (inserter grids into masked entities).
- **CPU smoke tests:** `sft.py` refuses CPU unless `CI=1`. A script that starts DataLoader workers needs an `if __name__ == "__main__":` guard.

## The user's standing preferences for this work

- After each builder change, render 12 *randomly sampled* windows (not filtered on success) for spot-checks. They have a low bar for checking against the real game.
- No GPU runs without approval; keep runs short while bugs remain.
- Per `CLAUDE.md`: small commits, minimal diffs, end-to-end tests, and the full checklist before pushing.