8000 Adding a model path parameter · Issue #16 · NL-BioImaging/biomero · GitHub
[go: up one dir, main page]

Skip to content

Adding a model path parameter #16

Open

Description

@maartenpaul

Several Biaflows containers are making use of AI models for segmentation. Instead of including the models into the Docker image, it is more convenient to store models permanently outside the container inside a folder on the HPC. This would also make it possible to store different (fine-tuned) models other than the default model loaded by the particular AI tool.

Proposal

  • Create an additional parameter in slurm-config.ini named slurm_aimodels_path . In the example slurm-config.ini slurm_aimodels_path=my-scratch/models . There is already a parameter "slurm_model_paths" so I would suggest to use aimodels .

  • At

    sbatch_env = {
    "DATA_PATH": f"\"{self.slurm_data_path}/{input_data}\"",
    "IMAGE_PATH": f"\"{self.slurm_images_path}/{model_path}\"",
    "IMAGE_VERSION": f"{workflow_version}",
    "SINGULARITY_IMAGE": f"\"{image}_{workflow_version}.sif\"",
    "SCRIPT_PATH": f"\"{self.slurm_script_path}\"",
    }

    Add "AIMODEL_PATH": f"{self.slurm_aimodels_path}",
    So we create a env variable AIMODEL_PATH and pass this to the slurm job template.

  • At the job_template.sh add a --bind parameter to singularity run
    e.g. --bind "$AIMODEL_PATH:/tmp/models"

  • For every container that wants/needs to make use of this we add a line to the DockerFile to tell the tool where to save the models. For example, microsam uses this env variable MICROSAM_CACHEDIR to indicate where to store the models. Cellpose does this similarly.

ENV MICROSAM_CACHEDIR=/tmp/models/microsam_cache

Example: https://github.com/maartenpaul/W_Segmentation-micro-sam/blob/7e9c5af7b1a6a7d3267977b2cbad8cdc724a4abc/Dockerfile#L16

  • With this implementation if no AIMODEL_PATH is set when running the container with singularity it will be saved in the /tmp folder on the HPC and likely not cleaned up, maybe this is not ideal? Use home or scratch folder instead? When running with docker it requires downloading the model again every time, unless the /tmp folder is mounted.

Activity

  1. TorecLuik commented on Jul 17, 2025

    @TorecLuik
    Collaborator

    ok this is a bit related to the Cellpose model path issue.

    TorecLuik/W_NucleiSegmentation-Cellpose#1

    the actual issue there is singularity: the models are actually built into the docker image (which you suggest not doing), but singularity by default overrides the home dir with that of the singularity user (slurm user in this case). At that point, it loses all the prebuilt containers and tries to download them from the broken endpoints.

    At this point I'm not sure who to blame or fix, but it sounds related to this issue.

    However, models are not a biomero property, unless we mean storing (custom) models in OMERO and then sending them to HPC for a specific biaflow. We can't adjust all biaflows, because we want to reuse existing biaflows from other people. So what is generic here? Also, we'd need subdirectories per biaflow right? Can't use a celllpose model for stardist.

  2. maartenpaul commented on Aug 11, 2025

    @maartenpaul
    MemberAuthor

    the actual issue there is singularity: the models are actually built into the docker image (which you suggest not doing), but singularity by default overrides the home dir with that of the singularity user (slurm user in this case). At that point, it loses all the prebuilt containers and tries to download them from the broken endpoints.

    I see you fixed the issue for the Cellpose container (TorecLuik/W_NucleiSegmentation-Cellpose#1), by changing the model storage path outside the HOME directory :) .
    Would it be an idea to always add at least one model to a defined path in the container (e.g. /opt/cellpose/models , /opt/microsam/models), which we then add to the repository and copy (like is done for CellPose).
    When people want to make use of external/custom models they need to explicitly define a AI model path for that container, which then binds that folder to the container, and uses the models in a folder at the HPC. Difficulty remains that this is only possible for the biaflows containers we maintain and where we know where the models are stored in the container, so we can overwrite by binding that folder.

    Also, we'd need subdirectories per biaflow right? Can't use a celllpose model for stardist.
    That is correct, but I guess this can be solved similarly as is done for saving the job_scripts by using subfolders based on the name of the container? Currently I did bind '/tmp/models' to the singularity container and then set the environment variable in the Dockerfile to e.g. '/tmp/models/microsam' so it is saved in a subfolder already but guess managing this via biomero is cleaner.

  3. TorecLuik commented on Jan 13, 2026

    @TorecLuik
    Collaborator

    On the backlog, in 2 separate ideas:
    26. add a way to add custom models (from biomero) to a wf (e.g. your own model to run with cellpose)
    57. add some generic model path on slurm where downloaded models can stay so they don't need to be redownloaded all the time (e.g. the cellpose downloaded pretrained models)

  4. TorecLuik commented on Jul 2, 2026

    @TorecLuik
    Collaborator
    1. add a way to add custom models (from biomero) to a wf (e.g. your own model to run with cellpose)

    Is released / will be released per v2.7/v2.8 -> (as user) attach OMERO attachments to your workflow if they are declared in descriptor (only possible via Bilayers descriptor/config.yaml - not via BiaFlows)

    So the model has to be attached to some container (project/dataset/screen/plate/image) in OMERO, perhaps as a result of running the training workflow

    1. add some generic model path on slurm where downloaded models can stay so they don't need to be redownloaded all the time (e.g. the cellpose downloaded pretrained models)

    This does not tackle a generic path where we store 'persistent' attachments of some sort. Don't know if that's needed either tbh - Slurm is supposed to be not permanent storage, while OMERO is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0