cellmap_flow.models.hf_catalog

The models on the Hugging Face Hub that cellmap-flow serves, for the dashboard’s picker.

Those of the organizations in HUGGING_FACE_ORGS that cellmap-flow can serve: cellmap-models exports (a metadata.json at the root), and models trained with mia-train whose config.json cellmap_models can serve (resolve.servable_mia_config), which are served as type mia (LISTED_TYPE); any other repo is left out.

list_huggingface_models answers from a cache file under ~/.cellmap_flow once it holds every organization’s listing, so opening the dashboard does not query the Hub each time; refresh_huggingface_models rebuilds it; cached_huggingface_models reads the cache alone, for a list that must not wait on the Hub. Each organization is listed on its own, and the cache says which it holds the listing of (LISTED_ORGS): one not listed yet, or whose listing failed, is asked for again by the next listing, the others answered from the cache. Each model is keyed by its repo id, with the metadata.json it publishes and, beside its fields, what every model list shows of a model without downloading it (FACTS): its weight formats, how it can be finetuned, the size of its largest weights file, and the copy of it that runs in the browser, if it has one. Those are read from the repo’s file list and the sizes of its weights (one listing of the organization’s repos with their file names, then one request of sizes per repo), and from the manifests of cellmap/onnx-web-models, when the cache is built, and kept in it: a page’s poll never asks the Hub for them. A mia-train model has no metadata.json; its config.json is read instead, once per such repo when the cache is built, with its model card for its description, and how it can be finetuned is read from those same downloads (_mia_plan).

Attributes

HUGGING_FACE_ORGS

HF_CACHE_DIR

HF_CACHE_FILE

LISTED_ORGS

WEB_MODELS_REPO

FORMATS

WEIGHT_ENDINGS

FACTS

LISTED_TYPE

MIA_DESCRIPTION

MIA_NOTE

Functions

listed_entry(repo, metadata, name) → Dict[str, Any]

The model entry of repo as the list has it (metadata, its

weight_facts(sizes) → Dict[str, Any]

formats, finetune_modes and size_mb of a model whose

folder_facts(folder) → Dict[str, Any]

FACTS of a cellmap_models export's folder (the Local Catalog's

facts_of(metadata) → Dict[str, Any]

The FACTS a listed model's entry has (a cache written before they

repo_facts(repo[, revision]) → Dict[str, Any]

FACTS of one repo, for a model added by reference that the listing

list_huggingface_models([orgs]) → Dict[str, Any]

List available Hugging Face models, using cache if available.

cached_huggingface_models() → Optional[Dict[str, Any]]

The models as the last fetch cached them, or None when nothing is

refresh_huggingface_models([orgs]) → Dict[str, Any]

Force refresh the Hugging Face models cache.

Module Contents

cellmap_flow.models.hf_catalog.HUGGING_FACE_ORGS = ('cellmap', 'ai-hhmi')
cellmap_flow.models.hf_catalog.HF_CACHE_DIR
cellmap_flow.models.hf_catalog.HF_CACHE_FILE
cellmap_flow.models.hf_catalog.LISTED_ORGS = 'listed_orgs'
cellmap_flow.models.hf_catalog.WEB_MODELS_REPO = 'cellmap/onnx-web-models'
cellmap_flow.models.hf_catalog.FORMATS = (('.ts', 'TorchScript'), ('.pt2', 'torch.export'), ('.onnx', 'ONNX'))
cellmap_flow.models.hf_catalog.WEIGHT_ENDINGS = ('.ts', '.pt2', '.onnx', '.onnx.data', '.pt', '.pth', '.safetensors', '.ckpt')
cellmap_flow.models.hf_catalog.FACTS = ('formats', 'finetune_modes', 'size_mb', 'browser_copy', 'variants', 'last_modified')
cellmap_flow.models.hf_catalog.LISTED_TYPE = 'cellmap_flow_type'
cellmap_flow.models.hf_catalog.MIA_DESCRIPTION = "Trained with mia-train; converted into a cellmap-models export on its first start, on its...
cellmap_flow.models.hf_catalog.MIA_NOTE = '(trained with mia-train; runs on a GPU server only, converted on its first start)'
cellmap_flow.models.hf_catalog.listed_entry(repo: str, metadata: Dict[str, Any] | None, name: str) → Dict[str, Any]

The model entry of repo as the list has it (metadata, its entry; None when the list has none): huggingface, or the type it is listed as (LISTED_TYPE). The Models tab’s Submit and the ranking’s candidates build each listed model from it.

cellmap_flow.models.hf_catalog.weight_facts(sizes: Dict[str, int | None]) → Dict[str, Any]

formats, finetune_modes and size_mb of a model whose top-level files are sizes (each name’s size in bytes, None when not known).

finetune_modes is the training form’s for the model (export_finetune_modes).

cellmap_flow.models.hf_catalog.folder_facts(folder: str) → Dict[str, Any]

FACTS of a cellmap_models export’s folder (the Local Catalog’s models, models.yaml), from its files’ names and sizes as a repo’s are read, loading nothing; a browser cannot read a folder of the cluster’s, so none has a browser copy. Empty when the folder cannot be listed.

cellmap_flow.models.hf_catalog.facts_of(metadata: Dict[str, Any]) → Dict[str, Any]

The FACTS a listed model’s entry has (a cache written before they were listed has none).

cellmap_flow.models.hf_catalog.repo_facts(repo: str, revision: str | None = None) → Dict[str, Any]

FACTS of one repo, for a model added by reference that the listing does not have (another owner’s, as David’s finetuned exports): from its files, and its browser copy only when it holds one in a folder of its own, cellmap/onnx-web-models having copies of cellmap’s models alone, which the listing has. Raises what listing its files raises.

cellmap_flow.models.hf_catalog.list_huggingface_models(orgs=HUGGING_FACE_ORGS) → Dict[str, Any]

List available Hugging Face models, using cache if available.

The organizations whose listing the cache does not hold (every one before a first listing; one whose listing failed, _fetch_huggingface_models) are fetched, and the others answered from the cache.

Parameters:

orgs – the Hugging Face organizations to list (HUGGING_FACE_ORGS by default)

Returns:

A dict mapping model IDs to their metadata

cellmap_flow.models.hf_catalog.cached_huggingface_models() → Dict[str, Any] | None

The models as the last fetch cached them, or None when nothing is cached (or the cache cannot be read), without asking the Hub: the Finetune tab’s ranking lists them so (routes/finetune/rank_routes.py), and its Refresh is the Models tab’s, refresh_huggingface_models.

cellmap_flow.models.hf_catalog.refresh_huggingface_models(orgs=HUGGING_FACE_ORGS) → Dict[str, Any]

Force refresh the Hugging Face models cache.