Virtual-Human-CHC
This repository contains the vhmodels package. Its goal is to unify access to multiple deep learning models developed at Helmholtz Munich.
Core concept
Each model lives in its own directory with its implementation, metadata, and
runtime dependencies. vhmodels executes it in either a per-model Conda
environment or an Apptainer container. Apptainer images use Ubuntu 24.04 and a
uv-managed Python environment at /opt/venv.
Metadata and resource locations are declared in model.json +
manifests/<variant>.json, validated against a Pydantic schema and resolved
by vhmodels.models.registry.Registry; see docs/manifest.md.
Installation
git clone https://github.com/HelmholtzAI-Consultants-Munich/vhmodels.git
cd vhmodels
pip install -e ".[cli]"
For Conda execution, install Miniforge. For
Apptainer execution, install Apptainer on Linux/HPC or Lima on macOS
(brew install lima); vhmodels manages the Lima VM automatically. You do not
need to install uv on the host.
CLI usage
List available models
vh-checker list
Create a Conda environment
vh-checker create-env <model_name>
Example:
vh-checker create-env dinobloom
Create an Apptainer image
vh-checker create-apptainer-image <model_name>
By default this creates vhmodels-<model_name>.sif in the current directory. Run a model from that image with e.g.:
import vhmodels
model = vhmodels.load_model(
project="dinobloom", model="s", runtime="apptainer"
)
Pass image_path="/path/to/image.sif" to load_model when the image is stored
elsewhere. The CLI equivalent is
vh-checker run ... --runtime apptainer --image-path /path/to/image.sif.
Set APPTAINER_NV=1 when running directly on an NVIDIA Linux/HPC host to expose
its GPU to the container. The Lima path on macOS is CPU-only.
Example scripts
The repository-level test.py runs the Nicheformer example, matching
the default MODEL in hpc-job-submit/config.json. The example inference
scripts for the other models are under examples/. All of them can
be used as INFERENCE_SCRIPT in the
HPC job submission guide.
Model lifetime
Both Conda- and Apptainer-backed models start one worker lazily on their first
embed() call. The model is loaded once in that worker and reused by later
calls on the same model object. Conda uses a local process; Apptainer uses a
background instance. Call model.close() when finished, or use the model as a
context manager; remaining workers are also stopped when Python exits normally.
Abrupt termination may leave an Apptainer instance behind; inspect with
apptainer instance list and stop it with apptainer instance stop <name>.
Apptainer bind mounts are fixed when the instance starts, so set
APPTAINER_BINDPATH before the first embed() when inputs live outside
Apptainer's default host mounts. Rebuild images created with an older version of
vhmodels, since the persistent worker is installed by the image template.
with vhmodels.load_model(
project="dinobloom", model="s"
) as model:
first = model.embed(input="first.bmp")
second = model.embed(input="second.bmp") # reuses the loaded model
Quick start
First create the corresponding Conda environment or Apptainer image. The
examples below use the default Conda runtime; pass runtime="apptainer" to use
an image.
DinoBloom
import vhmodels
model = vhmodels.load_model(project='dinobloom', model='s')
results = model.embed(input='example_data/DinoBloom/001.bmp')
print(results)
H-Optimus-0
H-Optimus-0 is a gated Hugging Face model. Accept its access conditions on the
model page, then authenticate
with hf auth login or set HF_TOKEN before the model worker starts.
import vhmodels
with vhmodels.load_model(project="hoptimus0") as model:
results = model.embed(input="example_data/H-Optimus-0/TUM-AACHEHDV.tif")
print(results) # one 1,536-dimensional embedding for this tile
Inputs must be 224 x 224 H&E tiles extracted at 0.5 microns per pixel. The
integration accepts one tile, a list of tiles, or a directory of tiles; it does
not tile or aggregate whole-slide images. The example TIFF's dimensions and
RGB decoding are checked by the worker, but its physical scale is not encoded
in a way this integration can verify.
Hyformer
import vhmodels