Imageomics / Imageomics/pybioclip

CLI predict reloads model on every invocation, consider persistent session

Open
#193 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
67
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Workshop observation

During the workshop, I have two attendees noting that bioclip predict felt slow when running more than a handful of predictions (predicting one image at a time). After looking at the source, I believe this is primarily because the CLI loads the full model, applies torch.compile(), and downloads the text embedding cache on every invocation, while none of which is cached across calls.

Flagging this as a non-priority CLI UX observation rather than a bug, since the current behavior works correctly and is simple to reason about. But the model loading dominates wall time, it meaningfully affects the interactive experience.

What happens on each bioclip predict call

In src/bioclip/__main__.py, the predict command instantiates a fresh classifier every time. For TreeOfLifeClassifier, this triggers a sequence of expensive setup in src/bioclip/predict.py:

Actual prediction is fast relative to this setup, so for users running predict repeatedly the startup cost dominates.

Proposed direction

A persistent background session would eliminate the per-call cost. I'm implementing something similar for BioCLIP Image Search Lite CLI development, loading the FAISS index, model weights, duckDB in-memory in a background session. Roughly:

  • bioclip serve starts a local daemon that loads the classifier once
  • bioclip predict image.jpg detects the running daemon and routes the request through it; falls back to the current in-process behavior if no daemon is running
  • bioclip stop / bioclip status for lifecycle management
  • An idle timeout so the daemon auto-shuts down if unused

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/bioclip/main.py at the predict command, then read classifier setup in src/bioclip/predict.py, especially TreeOfLifeClassifier. Compare the current per-invocation loading of model weights, torch.compile(), and text embeddings with the proposed persistent-session flow. Done should include reusable loaded state for repeated predictions, lifecycle handling, and fallback behavior when no session is running.

Written by the indexing model from the issue text.

Assessment

Tech stack
huggingface, python, pytorch
Domain
cli, machine-learning, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.