Skip to content

Personalization data pipeline: record → R2 → relay → Modal ingest (+ base-selectability) - #2

Open
ebowwa wants to merge 5 commits into
mainfrom
feat/collect-pipeline
Open

ebowwa wants to merge 5 commits into
mainfrom
feat/collect-pipeline

Conversation

@ebowwa

@ebowwa ebowwa commented Jul 25, 2026

Copy link
Copy Markdown
Owner

A full personalization data pipeline for Open-Alterego, plus coverage planning and pretrained-base selectability. Builds on #1 (includes the same engine-install fix commit, so merging this supersedes #1 — or merge #1 first and this PR's diff shrinks to the new work).

What's in it

cloud/relay/ — Bun + Hono + bun:sqlite + R2-presign gateway. The iOS app (Phase B, not here) never holds R2 creds; it gets short-lived scoped presigned PUTs from this relay. Endpoints (bearer-auth): GET prompts (versioned), POST examples (idempotent → presigned PUT, never proxies video), POST examples/complete, GET status, GET export (what Modal reads), POST presign (batch clip GETs), POST /v1/presign (raw R2 keys, for model fetch), DELETE. SQLite metadata on the host; R2 S3 creds live only here. 16 contract tests, tsc clean.

cloud/modal/ingest.py — ingest_from_r2(speaker, …) on a light image (requests only; no torch/mediapipe/engine; no R2 creds in Modal). Reads the relay export, batch-presigns GETs on demand, streams clips to /data/<speaker>/clips, atomically writes manifest.csv (id,video,text,split), commits the volume. Idempotent + manifest_only dry-run. prepare/train are unchanged.

Coverage — cloud/relay/prompts/generate.ts now enforces coverage by construction: every viseme group has dedicated minimal-pair sentences, plus digits + hybrid assistant/general vocabulary (750 prompts). docs/data-coverage.md is the recording plan (viseme targets, 4–5 environment session matrix, session-disjoint held-out test, QC, recording schedule).

Base-selectability + eval — --pretrained-model default|lrs3-visual-only|hf:..|r2:..|path wired through Modal train/evaluate (cloud/modal/pretrained_resolver.py); lrs3-visual-only fails closed until pretraining/.../source.json is pinned. training/eval_personal.py + Modal evaluate score a checkpoint on the test split for base-vs-personalized A/B. docs/pretrained-models.md catalogs the bases + alternatives evaluated + the verdict.

Validation status (honest)

  • ✅ Relay↔R2↔ingest→volume data path: validated end-to-end against the real R2 bucket (presigned PUT HTTP 200; smoke dataset ingests with a correct manifest).
  • ✅ Relay 16/16 tests, tsc clean; python 15/15 (ingest manifest round-trips through prepare's real _load_manifest; resolver unit tests).
  • ✅ train_personal/eval_personal --help show the new flags; cloud.modal.app imports clean.
  • ⚠️ prepare/train/evaluate on real face clips, and the hf:/r2:/transfer-flag runtime with a non-default base, are code-complete but not yet run — they need (a) real personalization recordings and (b) a pinned candidate checkpoint.
  • ℹ️ The research log's verdict: same-arch base swaps are neutral-to-worse; default + good coverage + personalization remains the recommended path. The switch is there to prove that cheaply.

Security

Full-branch secret audit before push: no secrets/keys leak. No relay token, no R2 access/secret keys, no bucket name, no real R2 account id (only <account_id> placeholder), no public IP (only 127.0.0.1/0.0.0.0), no internal project names (sanitized). All credentials are runtime-injected via Doppler / Modal secrets / env. The test bearer is "test-bearer-token" (fake); "wifi password" is a prompt sentence.

🤖 Generated with Claude Code

ebowwa and others added 5 commits July 25, 2026 14:30
Server-side data path for single-speaker personalization: iPhone records
prompted clips → relay presigns R2 PUTs → Modal pulls from R2 into the
existing data volume → unchanged prepare/train. macOS/transcription/full
auth deferred.

cloud/relay (Bun + Hono + bun:sqlite + @aws-sdk R2 presigner), deployable
behind Caddy on the relay VPS:
- GET prompts (versioned), POST examples (idempotent on idempotency_key;
  returns presigned PUT; never proxies video), POST examples/complete,
- GET status, GET export (what Modal reads), POST presign (batch GETs),
  DELETE examples (R2 object + row).
- SQLite metadata on VPS; R2 S3 creds live ONLY here. Split assigned by
  session and persisted. clip_id sanitized to prepare's _safe_component rule.
- 14 contract tests pass with an injected mock presigner (no network/R2).

cloud/modal/ingest.py: ingest_from_r2 on a light image (requests only, no
torch/mediapipe/engine; no R2 creds). Reads the relay export, batch-presigns
GETs just-in-time, streams clips to /data/<speaker>/clips, atomically writes
manifest.csv (id,video,text,split), commits the volume. Idempotent + a
manifest_only dry-run. prepare/train untouched.

prompts: 300 ASCII, letters-only prompted sentences (rev 2026-07-25) + a
deterministic generator. tests/test_ingest proves the generated manifest
round-trips through prepare_dataset._load_manifest and that ingest's id
sanitizer is byte-identical to prepare_dataset._safe_component.

.gitignore: ignore *.mp4/*.mov/*.m4v/*.webm so clips never get committed.

Co-Authored-By: Claude <noreply@anthropic.com>
Validated end-to-end against the real Cloudflare R2 bucket
(visual-transcription) using the existing caringmind-relay Doppler creds:

- config: accept generic S3_* names (S3_ACCESS_KEY/S3_SECRET_KEY/
  S3_ENDPOINT/S3_REGION/S3_FORCE_PATH_STYLE) as fallbacks, since the
  account-wide R2 token already lives there under those names; rename the
  bind-address env HOSTNAME -> BIND_HOST (HOSTNAME collides with the shell
  var on the VPS).
- r2: honor forcePathStyle so presigned URLs match the existing relay's
  path-style R2 access.
- app: presign the PUT before inserting the example row, so an R2/presign
  failure no longer leaves an orphan DB row.

Verified: presigned PUT returns HTTP 200 to visual-transcription; the smoke
dataset (s01/s02/s03) ingests via cloud/modal/ingest.py into the data volume
with a correct manifest (id,video,text,split; splits train/val/test).

Co-Authored-By: Claude <noreply@anthropic.com>
The prompt generator now enforces coverage by construction instead of random
sampling, for a hybrid assistant+general deployment (~750 prompts):

- Each of 10 viseme groups (bilabial/labiodental/dental/alveolar/postalveolar/
  r-l/velar/front-vowel/back-vowel/diphthong) has dedicated minimal-pair
  contrastive sentences included before any fill — these are where lip-reading
  actually fails. All 31 digit sentences and all curated general/assistant
  sentences are guaranteed; varied verb/object/place templates fill the rest
  (~650 unique words, lengths 2-10).
- Prints a coverage report (per-group counts, length histogram, top words).
- docs/data-coverage.md: the coverage plan — viseme targets, the 4-5
  environment session matrix (place/lighting/device/background/split), silent
  mouthing, session-disjoint held-out test for honest WER, QC rules, and a
  concrete recording schedule wired to the relay + Modal ingest/prepare/train.

Regenerate: `bun cloud/relay/prompts/generate.ts --count 750 --rev <date>`
(bump --rev when the set changes; the relay serves the newest rev file).
Redeployed to the relay VPS (now serving 750).

Co-Authored-By: Claude <noreply@anthropic.com>
Wire --pretrained-model into the personalization pipeline so any base can be
A/B-tested against the default, per docs/pretrained-models.md. (The research
log predicts same-arch swaps are neutral-to-worse; this makes the test cheap.)

train (Modal):
- new params: pretrained_model (default|lrs3-visual-only|hf:..|r2:..|path),
  transfer_frontend, transfer_encoder.
- resolves the selector to a concrete checkpoint path in-container, then
  passes --pretrained-model-path + transfer flags to train_personal.py
  (unchanged except the two new optional flags). "default" stays None and
  train_personal downloads the pinned, checksum-verified Auto-AVSR base.

cloud/modal/pretrained_resolver.py: the selector->path mapping.
- default -> None; lrs3-visual-only -> reads pretraining/.../source.json and
  FAILS CLOSED with the pin procedure until revision+checksums are resolved;
- hf:repo[@rev]:file -> huggingface_hub; r2:key -> relay POST /v1/presign ->
  presigned GET; bare path -> the path. Keeps training/ free of relay/HF I/O.

evaluate (Modal) + training/eval_personal.py: score a checkpoint (a trained
run's personalized_model.pt OR the base) on the held-out test split -> WER,
for base-vs-personalized A/B (train already reports personalized test WER).

relay: POST /v1/presign (raw R2 keys) so r2: model resolution works; auth
widened to /v1/*. +2 contract tests (relay 16/16, tsc clean).

tests/test_pretrained_resolver.py: 6 tests (default/None, path existing/missing,
lrs3-unpinned-fails-closed, r2-without-creds). 15/15 python tests pass.
docs/pretrained-models.md: catalog of bases + alternatives evaluated + the
A/B recipe + the promotion gate for adding a new base.

Co-Authored-By: Claude <noreply@anthropic.com>
The relay README and config comment referenced an internal VPS/project by
name. This is a public repo, so use generic phrasing instead. No behavior
change.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant