Skip to content

feat(encoders): platform-aware default encoder for new albums#307

Open
lstein wants to merge 1 commit into
masterfrom
lstein/feature/cpu-default-encoder
Open

feat(encoders): platform-aware default encoder for new albums#307
lstein wants to merge 1 commit into
masterfrom
lstein/feature/cpu-default-encoder

Conversation

@lstein
Copy link
Copy Markdown
Owner

@lstein lstein commented Jun 7, 2026

Problem

OpenCLIP ViT-L-14 (the default encoder for new albums) is impractically slow to index and search on a CPU-only host. Testing on a Windows machine without GPU acceleration confirmed this.

Change

New albums now pick their default encoder based on the host:

Host Default encoder
CUDA available (any OS) OpenCLIP ViT-L-14 / DFN-2B (unchanged)
macOS (no CUDA) OpenCLIP ViT-L-14 / DFN-2B (unchanged — lighter path untested)
Linux / Windows, no CUDA OpenAI CLIP ViT-B/32 (lighter, much faster)

The dropdown still offers all three encoders for manual override; this only changes which one is pre-selected for a new album.

Implementation

  • encoders.pyCPU_FALLBACK_ENCODER_SPEC + default_encoder_spec() resolver. DEFAULT_ENCODER_SPEC / LEGACY_ENCODER_SPEC unchanged.
  • config.pyAlbum.encoder_spec now uses default_factory=default_encoder_spec.
  • routers/album.pyGET /default_encoder/ exposes the host-resolved default so the frontend doesn't have to guess the server's GPU/OS.
  • album-manager.js — new-album dropdown pre-selects the server default (cached fetch; falls back to the recommended option if the request fails).

Scope notes

  • Existing albums are unaffected — they keep their stored encoder_spec and would need re-indexing to switch.
  • The index_images CLI path already defaulted to the light ViT-B/32 (Embeddings.encoder_spec = LEGACY_ENCODER_SPEC), so only frontend-created albums hit the slow path. That's what this fixes.

Tests

  • test_encoders.pydefault_encoder_spec() across CUDA / macOS / CPU-Linux / CPU-Windows (monkeypatched), plus the new constant.
  • test_albums.py — the /default_encoder/ endpoint.
  • All green: backend pytest, ruff check, frontend npm run lint + format:check, Jest 349/349.

🤖 Generated with Claude Code

OpenCLIP ViT-L-14 is impractically slow to index/search on CPU-only
Linux/Windows hosts. New albums on those hosts now default to the
lightweight OpenAI CLIP ViT-B/32 instead, while CUDA hosts and macOS
(untested for the lighter path) keep the high-quality ViT-L-14 default.

- encoders.py: add CPU_FALLBACK_ENCODER_SPEC + default_encoder_spec()
  resolver (CUDA/macOS -> ViT-L-14, CPU Linux/Windows -> ViT-B/32)
- config.py: Album.encoder_spec uses default_factory=default_encoder_spec
- routers/album.py: GET /default_encoder/ exposes the host-resolved default
- album-manager.js: new-album dropdown pre-selects the server default
  (cached fetch, falls back to recommended option on failure)

Existing albums keep their stored encoder_spec; only the default for
newly created albums changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <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