Imageomics / Imageomics/pybioclip
CLI predict reloads model on every invocation, consider persistent session
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:
-
oc.create_model_from_pretrained(...)loads ~2.5 GB of weights from the HF cache torch.compile(model.to(self.device))triggers JIT compilation overhead on first forward pass (only works on Linux OS, bypass fallback for Windows)TreeOfLifeClassifierdownloads/loadstxt_emb_species.npy(the TreeOfLife-200M text embedding table, BioCLIP 2 default) and its metadata JSON
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 servestarts a local daemon that loads the classifier oncebioclip predict image.jpgdetects the running daemon and routes the request through it; falls back to the current in-process behavior if no daemon is runningbioclip stop/bioclip statusfor lifecycle management- An idle timeout so the daemon auto-shuts down if unused
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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