Skip to main content

histotuner

Linux And O2 Install

PyPI does not allow published package metadata to hard-code direct CPU wheel URLs for PyTorch, so histotuner cannot enforce a CPU-only Linux PyTorch build at package metadata level. The clean pattern is to install the PyTorch flavor you want first, then install histotuner without re-resolving dependencies.

Recommended default CPU install on Linux:

pip install torch==2.11.0 torchvision==0.26.0 --index-url https://download.pytorch.org/whl/cpu
pip install --no-deps histotuner

upload to O2

python upload_melanoma_to_o2.py \
  --csv "test.csv" \
  --destination /n/scratch/users/a/ajn16/melanoma_uploads \
  --offset 0 \
  --report-csv upload_report.csv \
  --dry-run

Run full pipeline in O2 (new)

The O2 runners, submitters and template configs ship with the package as histotuner.o2, so nothing needs uploading. Each job runs a copy of the runner staged from the installed package, and imports histotuner from the job's conda env(s), so install the same histotuner version in every env a job activates.

Every job reads its config from <output-dir>/scripts/template_config.yaml, and reads it when the job starts. Run the submit command once without --submit, edit that file, then rerun with --submit: without --template-config the edited file is kept, so the change applies to every job (including queued jobs that have not started). Passing --template-config replaces it.

histotuner-o2-full-pipeline \
  --image-root /n/scratch/users/a/ajn16/melanoma_cohort \
  --output-dir /n/scratch/users/a/ajn16/full_pipeline_jobs \
  --template-config /n/scratch/users/a/ajn16/embedder.yaml \
  --conda-env-embed histotuner_embed \
  --conda-env-analysis histotuner \
  --cpus 16 \
  --time 0-06:00 \
  --partition gpu_quad \
  --gres gpu:l40s:1 \
  --mem 128G \
  --overwrite-existing-tables \
  --continue-on-error \
  --run-mode api \
  --submit \
  --limit 20

Recommended HMS O2 / Linux GPU install for CUDA 12.8:

conda create -n histotuner python=3.13 -y
conda activate histotuner
conda config --env --set channel_priority strict

conda install -c rapidsai -c conda-forge -c nvidia -c nodefaults \
  "cuda-version=12.8" "cuda-bindings>=12.8,<13" "cuda-python>=12.8,<13" \
  "cuda-core>=0.3,<0.4" "cuda-nvrtc=12.*" "cuda-nvrtc-dev=12.*" \
  "cuda-cudart=12.*" "cuda-cudart-dev=12.*" \
  cupy cuml=26.06 cudf=26.06 cugraph=26.06 rmm pylibraft timm transformers \
  numpy scipy=1.16.2 scikit-learn numba umap-learn \
  anndata dask geopandas leidenalg matplotlib pandas pillow psutil pyqt pyyaml \
  python-igraph shapely spatialdata tifffile tqdm zarr \
  -y

  

pip install histotuner --no-deps --upgrade

python -m pip install torch==2.11.0 torchvision==0.26.0 --index-url https://download.pytorch.org/whl/cu128

pip install spatialdata==0.8.0

python -c "import torch; print('GPU Available:', torch.cuda.is_available())"


# multi embeder
module load gcc/14.2.0
conda activate histotuner-embed
# --template-config defaults to the he_embedder.example_multimodel.yaml shipped with histotuner
python -m histotuner.o2.run_batch_he_embedder_multimodel \
  --image-folder embed/

histotuner-o2-batch-embed \
  --image-root /path/on/o2/embed \
  --output-dir /path/on/o2/embed_jobs \
  --time 0-10:00 \
  --mem 256G \
  --submit

# multi embedder on MGB Nucleus: same flags as histotuner-o2-batch-embed, but
# requests --partition gpu-l40s with --nodes/--gpus instead of --gres, and
# activates conda via `module load miniforge3`. Drop --submit to only write the
# Slurm scripts; drop --limit to submit every image.
histotuner-nucleus-batch-embed \
  --image-root /path/to/project/images \
  --output-dir /path/to/project/embeddings_test \
  --template-config /path/to/my_config.yaml \
  --time 0-03:00 \
  --limit 2 \
  --submit


# run cell_sep scoring / melanocyte DBSCAN (O2 or Nucleus)

# one Slurm job per .zarr; drop --submit to only write the scripts
histotuner-melanocyte-dbscan \
  --image-root /n/scratch/users/a/ajn16/test \
  --output-dir /n/scratch/users/a/ajn16/test/jobs_reader_check \
  --hpc o2 \
  --limit 1 \
  --submit

# MGB Nucleus: L40S by default (partition gpu-l40s, --gpus=1)
histotuner-melanocyte-dbscan --image-root /path/to/project/images --hpc nucleus --submit

# run locally
histotuner-melanocyte-dbscan "C:\Users\aj\Downloads\test" `
  --recursive `
  --continue-on-error `
  --summary-json "C:\Users\aj\Downloads\test\melanocyte_dbscan_summary.json"


  # sort by slrum status
  histotuner-o2-sort-by-status \
  --manifest /path/to/jobs/submission_manifest.csv \
  --source-root /path/to/sample/root \
  --report-csv job_status_folder_sort_report.csv \
  --dry-run

# remove tables
python -m histotuner.delete_tables --image-folder "C:\Users\aj\Downloads\test" --tables hoptimus1_tokens,uni2h_tokens 

python - <<'PY'
mods = ["histotuner", "spatialdata", "anndata", "zarr", "cupy", "cuml", "cudf", "cugraph", "umap", "torch"]
for m in mods:
    try:
        mod = __import__(m)
        print(m, "OK", getattr(mod, "__version__", "unknown"))
    except Exception as e:
        print(m, "FAIL", type(e).__name__, e)

import cupy, torch, histotuner as ht
print("cupy devices:", cupy.cuda.runtime.getDeviceCount())
print("torch cuda:", torch.cuda.is_available(), torch.cuda.device_count())
print(ht.umap_backend_status())
PY

To use a different GPU PyTorch build, replace the PyTorch index, for example cu126 or cu128, before installing histotuner --no-deps.

If you do use a plain pip install histotuner, the exact PyTorch wheel flavor chosen on Linux depends on pip resolution and the available package indexes in that environment.

GPU UMAP and Clustering on Linux

histotuner installs CPU UMAP support through umap-learn. GPU UMAP is optional because it depends on the local CUDA driver/toolkit stack and should be installed separately from the package dependencies in pyproject.toml.

GPU UMAP uses RAPIDS cuML when both cuml and cupy are available in the active Python environment and a CUDA-capable NVIDIA GPU is visible.

The same optional GPU stack is also used by native clustering:

  • ht.umap(...)
  • ht.leiden(...)
  • ht.dbscan(...)
  • histotuner-leiden
  • histotuner-dbscan

Check the active environment from Python:

import histotuner as ht

ht.umap_backend_status()

Expected GPU-ready output has gpu_available: True, with both gpu_cuml and gpu_cupy set to True.

Recommended install path on Linux is to create a RAPIDS-compatible environment with the official RAPIDS install selector:

https://docs.rapids.ai/install/

To request an interactive O2 GPU session for testing:

srun --pty -p gpu_quad --gres=gpu:l40s:1 -c 8 --mem=64G --time=0-03:00 /bin/bash

Inside the allocation, activate the same environment used by batch jobs and verify both the Slurm GPU allocation and the Python RAPIDS stack:

module purge
module load gcc/14.2.0
source "$HOME/miniconda3/etc/profile.d/conda.sh"
conda activate histotuner
nvidia-smi
python - <<'PY'
import histotuner as ht
print(ht.umap_backend_status())
PY

If nvidia-smi sees a GPU but ht.umap_backend_status() reports gpu_cupy=False, gpu_cuml=False, or gpu_device_count=0, the conda environment is not GPU-ready. Inspect the CUDA/RAPIDS stack:

conda list | egrep 'cuda-bindings|cuda-python|cuda-core|cuda-cudart|cuda-version|cuml|cudf|cupy'
python -m pip show cuda-bindings cuda-python cuda-core

A common failure is a pip-installed CUDA 13 cuda-bindings package mixed with conda CUDA 12/RAPIDS packages, for example cuda-bindings 13.x with cuda-python 12.9 and RAPIDS cuda12. Fix it by removing the pip binding and reinstalling CUDA bindings from conda:

python -m pip uninstall -y cuda-bindings
conda install -c conda-forge -c nvidia \
  "cuda-bindings>=12.9,<13" "cuda-python=12.9.*" \
  --force-reinstall

Then re-test:

python - <<'PY'
import cupy
print("cupy devices", cupy.cuda.runtime.getDeviceCount())
import cuml
print("cuml", cuml.__version__)
import histotuner as ht
print(ht.umap_backend_status())
PY

Keep CUDA/RAPIDS packages conda-managed in this environment; avoid installing cuda-* packages with pip after RAPIDS is installed.

For pip-based RAPIDS installs, choose wheels matching the installed CUDA major version and use the RAPIDS selector for the exact command:

https://docs.rapids.ai/install/

Then run UMAP with:

ht.umap(
    sdata=zarr_path,
    tableKeys=["mstar_tokens", "virchow2_tokens"],
    sample_n=25000,
    prefer_gpu="auto",  # uses GPU if RAPIDS is available, otherwise CPU
)

To require GPU and fail loudly if RAPIDS is not available:

ht.umap(
    sdata=zarr_path,
    tableKeys=["mstar_tokens", "virchow2_tokens"],
    sample_n=25000,
    prefer_gpu="gpu",
)

Native clustering uses the same prefer_gpu switch:

ht.leiden(
    sdata=zarr_path,
    tableKeys="tokens",
    obsm_key="X_umap",
    prefer_gpu="auto",
    target_col="leiden",
)
ht.dbscan(
    sdata=zarr_path,
    tableKeys="tokens",
    obsm_key="X_umap",
    prefer_gpu="gpu",
    target_col="dbscan",
)

CLI examples:

histotuner-leiden /path/to/sample.zarr \
  --tables tokens \
  --obsm-key X_umap \
  --prefer-gpu auto \
  --target-col leiden
histotuner-dbscan /path/to/sample.zarr \
  --tables tokens \
  --obsm-key X_umap \
  --prefer-gpu gpu \
  --target-col dbscan

Notes:

  • RAPIDS requires Linux or WSL2; native Windows Python environments generally cannot install/use cuML, cuGraph, or cuDF directly.
  • GPU UMAP uses cuml plus cupy.
  • GPU Leiden uses cudf, cugraph, cuml, and cupy.
  • GPU DBSCAN uses cuml plus cupy.
  • CUDA package suffixes must match the CUDA toolkit/driver stack in the environment. If installation fails, generate a fresh command from the RAPIDS selector for the specific Linux, Python, CUDA, and RAPIDS versions.

Supported token-extraction backends

histotuner can append multiple model-specific token tables into the same SpatialData Zarr while keeping shared geometry layers model-agnostic.

Currently supported token extractors:

  • hf-hub:bioptimus/H-optimus-1
  • hf-hub:MahmoodLab/UNI2-h
  • hf-hub:paige-ai/Virchow2
  • hf-hub:Wangyh/mSTAR
  • hf-hub:prov-gigapath/prov-gigapath
  • owkin/phikon-v2
  • MahmoodLab/conchv1_5
  • WenchuanZhang/Patho-CLIP-L
  • majiabo/GPFM
  • kaiko-ai/vitl14
  • xiangjx/musk

Token-grid semantics

All currently supported models export a unified 14x14 token grid so token tables can be compared directly across models.

  • phikon-v2 exports a native 14x14 patch-token grid.
  • hf-hub:bioptimus/H-optimus-1, hf-hub:Wangyh/mSTAR, and hf-hub:prov-gigapath/prov-gigapath export native 14x14 grids.
  • hf-hub:MahmoodLab/UNI2-h and hf-hub:paige-ai/Virchow2 have native 16x16 patch-token grids after special tokens are stripped, and histotuner adaptively average-pools them to 14x14.
  • conchv1_5 is special:
    • the native vision encoder runs at 448x448 with patch16
    • that produces a native 28x28 patch-token grid
    • histotuner average-pools each non-overlapping 2x2 token neighborhood to export a compatibility 14x14 token grid
  • Patho-CLIP-L is also special:
    • the native CLIP-L/14 vision encoder produces a 24x24 patch-token grid at 336x336 input resolution
    • histotuner adaptively average-pools that native 24x24 grid to export a compatibility 14x14 token grid
  • GPFM is also special:
    • the native DINOv2 ViT-L/14 encoder produces a 16x16 patch-token grid at 224x224 input resolution
    • histotuner adaptively average-pools that native 16x16 grid to export a compatibility 14x14 token grid
  • kaiko-ai/vitl14 is also special:
    • the native Kaiko ViT-L/14 encoder produces a 16x16 patch-token grid at 224x224 input resolution
    • histotuner uses the Kaiko preprocessing defaults (mean=std=0.5) and adaptively average-pools that native 16x16 grid to export a compatibility 14x14 token grid
  • xiangjx/musk is also special:
    • the native MUSK patch16 vision encoder produces a 24x24 patch-token grid at 384x384 input resolution
    • histotuner uses the MUSK preprocessing defaults (mean=std=0.5) and adaptively average-pools that native 24x24 grid to export a compatibility 14x14 token grid
    • MUSK is gated on Hugging Face and requires the optional official musk package

That pooling choice is deliberate so downstream single-cell workflows can consume every supported model through the same 14x14 token layout. For the pooled models, this is a compatibility semantic rather than the model's native tokenization:

  • UNI2-h and Virchow2: pooled from native 16x16
  • conchv1_5: pooled from native 28x28
  • Patho-CLIP-L: pooled from native 24x24
  • GPFM: pooled from native 16x16
  • kaiko-ai/vitl14: pooled from native 16x16
  • xiangjx/musk: pooled from native 24x24

Not yet supported for token extraction

  • none from the current requested set

O2 batch job generation

To generate one embedder.yaml and one embed_cluster.sh per sample folder on O2:

python generate_o2_jobs.py \
  --root-dir /n/scratch/users/a/ajn16/histotuner/full \
  --template-yaml embedder.yaml \
  --template-shell embed_cluster.sh \
  --output-dir /n/scratch/users/a/ajn16/histotuner/generated_jobs

  python generate_o2_jobs.py \
  --root-dir /n/scratch/users/a/ajn16/histotuner/heonly \
  --template-yaml embedder_HEonly.yaml \
  --template-shell embed_cluster_HEonly.sh \
  --output-dir /n/scratch/users/a/ajn16/histotuner/generated_jobs

To preview the sbatch submissions for the generated job scripts:

python submit_generated_jobs.py \
  --generated-dir /n/scratch/users/a/ajn16/histotuner/generated_jobs \
  --dry-run

Melanocyte UMAP/DBSCAN token pipeline

histotuner-melanocyte-dbscan (Python: ht.melanocyteDbscan) finds SpatialData .zarr stores under a folder, maps tokens to cells, computes a global UMAP for native token tables, maps broad phenotype labels onto token tables, computes a second melanocyte-only UMAP, computes cell-type separability from phenotype_broad, and runs DBSCAN on X_umap_melanocytes for tokens where phenotype_broad == "Melanocytes". It then generates thumbnail PDFs for dbscan_melanocytes_umap using an HE image auto-detected beside each .zarr, and saves UMAP plots for each token table/model:

  • X_umap/phenotype_broad.png, excluding -1 and 0
  • X_umap_melanocytes/phenotype_broad.png, subset to Melanocytes
  • X_umap_melanocytes/dbscan_melanocytes_umap.png, excluding -1 and nan

The folder may also be a single .zarr. Run a local dry-run first:

histotuner-melanocyte-dbscan "C:\Users\aj\Downloads\test" --recursive --dry-run

Run the local pipeline and write a summary:

histotuner-melanocyte-dbscan "C:\Users\aj\Downloads\test" `
  --recursive `
  --continue-on-error `
  --summary-json "C:\Users\aj\Downloads\test\melanocyte_dbscan_summary.json"

The pipeline is a thin wrapper around histotuner package APIs. It uses native histotuner readers and writers directly and does not monkey-patch SpatialData, AnnData, UMAP, DBSCAN, or plotting internals. Runtime errors should be fixed in the package rather than patched inside this wrapper.

It uses native histotuner token-table selection. By default, tokenCellMapper and phenotypeCellMapper auto-detect token tables, while UMAP and DBSCAN use the native tokens selector. Melanocyte DBSCAN uses --dbscan-min-samples 100 by default. Pass --no-thumbnail-pdfs to skip PDF generation, or --thumbnail-image-path /path/to/image.ome.tiff to provide an explicit image for a single-sample run. Pass --no-umap-plots to skip the saved UMAP plots. The pipeline runs ht.repairSpatialDataTableRegistry(...) before any per-zarr step, after global UMAP writes, after melanocyte UMAP writes, and after DBSCAN writes so on-disk tables are re-registered before downstream plotting/PDF steps. The repair function detects Zarr v2 stores, writes Zarr v3 metadata with zarr.metadata.migrate_v3.migrate_v2_to_v3(...), and then applies the Zarr v3 table registry repair. Existing Zarr v3 stores skip migration and go straight to the v3 repair path. Cell-type separability is enabled by default with the batch-notebook defaults: phenotype_broad, max_tokens_per_cell_type=10000, max_comparison_tokens_per_cell_type=10000, initial_sample_size=200, bootstrap_repeats=100, target_relative_ci_width=0.05, and distance_metric="cosine". Per-sample output is written to <sample>/<sample>_cell_type_separability.csv. Pass --no-cell-type-separability to skip this step.

Melanocyte DBSCAN jobs on O2 or Nucleus

Add --hpc o2 or --hpc nucleus and the same command writes one Slurm job per .zarr (found recursively) instead of running locally; add --submit to sbatch them. Python: ht.submitMelanocyteDbscanJobs(root, hpc="o2", submit=True).

HMS O2 (--hpc o2) MGB Nucleus (--hpc nucleus)
GPU (--gpu) l40s default; any O2 type, e.g. a100 l40s
GPU request --gres=gpu:<gpu>:<n> on gpu_quad --gpus=<n> on gpu-l40s (max 8 h)
CPU only (--gpu none) partition short partition normal
Environment module load gcc/14.2.0, ~/miniconda3 conda module load miniforge3, conda shell.bash hook

Jobs activate the conda env that is active when you run the command (activate the env with histotuner first; base is refused unless passed explicitly). Defaults for both: 16 CPUs, 128G, 0-06:00. Override with --partition --gres --gpu-count --cpus --mem --time --conda-env --conda-sh --module-load --setup-script --mail-user --mail-type. Personal settings can live in ~/.histotuner/hpc.yaml (or --hpc-config), keyed by cluster:

o2:
  mail_user: you@example.org
  setup_script: ~/softwares/hf_o2_setup.sh
nucleus:
  mail_user: you@example.org

Pipeline options (e.g. --dbscan-min-samples 150 --no-thumbnail-pdfs) are passed on to every job. The submitter copies the pipeline script into <output-dir>/scripts/melanocyte_dbscan.py and every job runs that staged copy, so upgrading histotuner does not change jobs that were already generated. Pass --pipeline-script to stage a different copy.

Generate one Slurm script per .zarr without submitting:

histotuner-melanocyte-dbscan \
  --image-root /n/scratch/users/a/ajn16/he_embed \
  --output-dir /n/scratch/users/a/ajn16/melanocyte_dbscan_jobs \
  --hpc o2

Submit a single test job:

histotuner-melanocyte-dbscan \
  --image-root /n/scratch/users/a/ajn16/he_embed \
  --output-dir /n/scratch/users/a/ajn16/melanocyte_dbscan_jobs_test \
  --hpc o2 \
  --limit 1 \
  --submit

Submit all jobs on Nucleus with a smaller resource request:

histotuner-melanocyte-dbscan \
  --image-root /path/to/project/images \
  --output-dir /path/to/project/melanocyte_dbscan_jobs \
  --hpc nucleus \
  --cpus 8 \
  --mem 64G \
  --time 0-03:00 \
  --submit

Without --output-dir, jobs go to <image-root>/melanocyte_dbscan_jobs. That folder holds the Slurm scripts, logs (<sample>/run.<jobid>.out), per-job summary JSON files, and submission_manifest.csv. The main analysis outputs are written beside each sample .zarr, and each .zarr is updated in place. After submitting, the job log should include:

[pipeline] Version: melanocyte_dbscan_package_v2_2026_11_20

If it does not, the job is using an old staged script. Regenerate the jobs; already submitted Slurm jobs will not change retroactively.

The previous standalone scripts are kept, unmaintained, in o2/archive/melanocyte_dbscan/.

Metadata

Release files for histotuner 0.4.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for histotuner 0.4.14
File Size Uploaded Provenance Actions
histotuner-0.4.14.tar.gz 289.3 kB Without provenance Details for histotuner-0.4.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for histotuner 0.4.14
File Interpreter ABI Platform Actions
histotuner-0.4.14-py3-none-any.whl Python 3 none any Details for histotuner-0.4.14-py3-none-any.whl

Total release size: 610.8 kB

Release files / histotuner-0.4.14.tar.gz

Download URL histotuner-0.4.14.tar.gz
Size 289.3 kB
Tags Source
SHA-256 checksum
How to use checksums
77f7a56ebff137c19b4510f85af3336bca6fa0047be7554f46f99b809508a169
BLAKE2b-256 checksum
How to use checksums
3ffc617057d80068dea2b63ab1c84814f8087aba8d88f0f7e256a0fed9f1680e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / histotuner-0.4.14-py3-none-any.whl

Download URL histotuner-0.4.14-py3-none-any.whl
Size 321.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a05e5d44b27ef0627185008041efcbe3bceba4f5ff0e482d225be73e816cb651
BLAKE2b-256 checksum
How to use checksums
11bc31ca15b2d069f8ab4b3ab049a069eccc17e5a07aa95bd196b979fe2d9a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for histotuner 0.4.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.14 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page