refactor(lib): remove legacy generator.py / coord.py / scroll module

Drop the pre-migration PyTorch inference pipeline now that the ONNX-backed
MouseModel/ScrollModel in mouse.py and scroll.py are wired up through the
public ai_mouse API.

Deleted:
  * src/ai_mouse/generator.py        (legacy torch flow ODE + post-processing)
  * src/ai_mouse/coord.py            (legacy public coord transforms,
                                      superseded by ai_mouse._coord)
  * src/ai_mouse/_scroll_legacy.py   (legacy torch scroll VAE inference)
  * scripts/build_golden_*.py        (one-shot capture scripts, no longer
                                      needed once goldens are committed)
  * tests/unit/test_generator.py     (legacy module gone)
  * tests/unit/test_scroll_generator.py (legacy module gone)
  * tests/unit/test_coord.py         (legacy module gone; ai_mouse._coord is
                                      tested by test__coord.py)
  * scripts/                         (empty, removed)

Tools migrations:
  * tools/trainer.py: import encode_trajectory from ai_mouse._coord
    instead of the deleted ai_mouse.coord
  * tools/server/routes_verify.py, tools/server/routes_scroll.py: route to
    the public ai_mouse.generate / generate_scroll. They no longer accept
    a model_dir override — the bundled ONNX is the source of truth, and a
    fresh export goes through `python -m tools.export_onnx`.
  * tools/eval/__main__.py: same migration; model_dir CLI arg retained as
    a deprecation shim but ignored.

Final src/ai_mouse/ layout (matches plan):
  __init__.py, _assets.py, _coord.py, _model_cache.py, _postprocess.py,
  errors.py, mouse.py, py.typed, scroll.py, assets/

Test suite: 188 passed (was 188 before deletion; obsolete suites cleaned
out alongside the modules they covered).
This commit is contained in:
2026-05-12 01:23:52 +08:00
parent 525e555884
commit 31fd884dfd
12 changed files with 20 additions and 1018 deletions

View File

@@ -48,8 +48,15 @@ def _load_reference_jsonl(path: Path, n_samples: int) -> list[dict]:
def _generate_n_samples(
model_dir: str, n_samples: int, seed: int = 0
) -> list[dict]:
"""Call the project's generator N times with random start/end pairs."""
from ai_mouse.generator import generate
"""Call the project's generator N times with random start/end pairs.
``model_dir`` is accepted for CLI backward compatibility but is no longer
used — generation goes through the public ai_mouse API which loads the
bundled ONNX model. Export a fresh .onnx via ``python -m tools.export_onnx``
to refresh.
"""
del model_dir # legacy arg, unused
from ai_mouse import generate
rng = random.Random(seed)
out: list[dict] = []
@@ -63,7 +70,7 @@ def _generate_n_samples(
ex = max(0, min(800, ex))
ey = max(0, min(600, ey))
try:
pts = generate(start=(sx, sy), end=(ex, ey), model_dir=model_dir)
pts = generate(start=(sx, sy), end=(ex, ey))
except Exception as exc: # noqa: BLE001
logger.warning("generate() failed at i=%d: %s", i, exc)
continue