Photo curation pipeline (2/3): Clef decision-model judge, local on M1 (mlx-community/clef-flash-4bit) #6
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Add a model-judge stage to the clock-photo curation pipeline that scores photos with Cloudflare's Clef decision model, running locally on the M1 Pro (16 GB) — not via any hosted API. This is stage 2 of 3. Companion issues: #5 (stage 1, cheap local pre-filters) and stage 3 (LAION aesthetic predictor baseline, filed separately). Work on this issue independently; do not implement the other stages.
Why
Generic aesthetic scores cannot judge "good living-room TV wallpaper" (no text/watermarks, works cover-cropped to 16:9, well exposed for a bright room, calm composition). Clef is a decision model: you send the image plus a schema of typed questions whose
instructions/criteriaare natural language, and it returns calibrated probabilities for every option in a single non-autoregressive forward pass — no text generation, no parsing. It is the open-weight (Apache-2.0) counterpart of TypeSafe's Jev, but multimodal (Jev is text-only, and closed-source).Model + how to run it (verified — follow exactly)
mlx-community/clef-flash-4biton HuggingFace — Cloudflare'sclef-flash(9B, Qwen3.5-9B base + vision encoder + custom joint schema head), MLX 4-bit. 6.2 GB download, ~7 GB peak RAM → fits the M1 Pro 16 GB. License: Apache-2.0.pip install "mlx-vlm>=0.7.4,<0.8" huggingface_hub(no torch needed), thenhf download mlx-community/clef-flash-4bit --local-dir clef-flash-4bit.clef_mlx.pyloader shipped in that repo. Clef is not a chat model:mlx_vlm.generate,mlx_lm.generate, LM Studio, and Ollama load the backbone but produce meaningless text — the custom decision head (two-stage attention routing over the schema) only runs viaclef_mlx.py, asmodel.systemone({...})/model.predict({...}), via its CLI (python clef_mlx.py predict --image photo.jpg --state ... --questions '{...}'), or as a localhost server (clef_mlx.py serve --port 8000, Jev-compatiblePOST /v1/systemone).Suggested question schema (refine as you see fit)
The natural-language semantics live in
instructions/criteria. Responses are typed answers with per-option probabilities + confidence — threshold onwallpaper=keepwith a confidence floor, or rank by ascorequestion instead.What to build
A maintainer-run script under
scripts/(style ofdiscover-clock-photos.py) that:clef_mlx.py, loops one record per call, and catches per-photo errors without aborting the batch,mv),pip install,hf download) in the script docstring and/ordocs/, plus expected runtime on the M1 Pro.Run it after the pre-filters and before
--clock-photo-probe, so Vision segmentation is never spent on rejects.Repo context (read first)
AGENTS.md— product constraints + source-control workflow: worktree under.worktrees/on afeat/…branch; commit freely;make testbefore proposing a merge; never merge/push tomainwithout explicit operator confirmation; push only when asked..wiki/_index.md+.wiki/wiki/references/task-routing.md— canonical routing; "Clock photos" section (manifest, probe, atomic-write rule, push path). (Wiki says manifest is atResources/photos/manifest.json; actual path isSources/TVDashboard/Resources/photos/manifest.json.)Sources/TVDashboard/Resources/photos/manifest.json(file/caption/credit/date/author/license/source/downloadUrl/clockY/depth); loaderSources/TVDashboard/Clock/ClockPhotoLibrary.swift.discover-clock-photos.py→fetch-clock-photos.sh→--clock-photo-probe→gen-photo-credits.py..wiki/(committed on your feature branch) for durable decisions (where the judge runs, sidecar location, schema).Decisions already made (do not re-litigate)
Acceptance criteria
make testpasses.Open questions for the planning agent
discover-clock-photos.pydeclares deps; keep the MLX env separate from any PyTorch env stage 3 might want).clef-flash-4bit/— likely gitignored; check.gitignore).Planning update — awaiting operator approval
Planning/read-only inspection is complete. No implementation, tests, inference, or calibration have begun. All recommendations below remain unapproved. This update changes no issue scope or approval status.
Proposed scope
Add a maintainer-only Clef judge under
scripts/, with model-free fixture tests and concise setup/schema documentation. Load the pinned bundledclef_mlx.pyonce in an isolated MLX environment, callpredictserially on local images, retain option probabilities, handle per-photo errors, and atomically checkpoint a sidecar. No hosted judging, app UI, manifest edits, photo deletion/quarantine, or runtime filtering. Remain independent of companion stages #5 and #7 through fixtures and a documented input contract; explicit standalone selection should support development without merged branches.Recommend separate stage-owned, gitignored outputs under worktree-local
.photo-curation/, outside bundled resources: versioned set/file/SHA256 identity, schema/config/model provenance, and pass/reject/review/error semantics. Only fresh passes advance. Commit schemas/tests/docs, not generated pool results.Material findings and risks
bake-clock-placement.pyinvokes a whole-set probe;ClockPhotoLibrary.swift::probeanalyzes every available photo. Neither consumes curation sidecars/allowlists. Merely running this judge before baking does not spare Vision work.fetch-clock-photos.shnormalizes downloaded images to sRGB JPEG, longest edge ≤1280, and can invalidate built resource copies. The worktree contains 13 seeds versus 649 manifest entries: 636 files are missing.b5adbe2c3a95200d4bf04a0727c8ec457157d5e1.predictreturns full option probabilities;systemoneboolean answers omit explicit option maps, and choice confidence is the winning probability, not independent reliability.Validation still needed: fixture coverage for upstream selection, stale hashes/provenance, threshold boundaries, malformed outputs, per-photo failures, atomic checkpoint/resume; subsequently an approved M1 pilot, hand-checked representative sample and full-pool calibration, then scheduled
make test. GUI-capable tests can activate windows and write shared caches; never relaunch/replace a running dashboard.Questions for the operator
Awaiting operator answers and explicit implementation approval.