Skip to content

About

Code for "A Multi-Task Generative Pathology Model for Unified Tumor Profiling"

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

PathoVerse

A Multi-Task Generative Pathology Model for Unified Tumor Profiling

Model weights on Hugging Face PathoVerse-Atlas on Hugging Face

PathoVerse uses natural-language queries to predict tumor morphology, molecular biomarkers, biological programs and clinical outcomes from H&E whole-slide images (WSIs). It supports categorical questions, continuous-valued predictions and survival risk estimation within a single model.

PathoVerse model architecture

Quick start

Create a conda environment and install the dependencies:

git clone https://github.com/MAGIC-AI4Med/PathoVerse.git
cd PathoVerse

conda create -n pathoverse python=3.11 -y
conda activate pathoverse

# CUDA 12.6 example; skip if PyTorch >= 2.8 is installed
pip install torch==2.8.0 --index-url https://download.pytorch.org/whl/cu126

# Install PathoVerse with tested dependencies
pip install -e . -r requirements.txt

# Download weights and run the example
hf download nanozyme/PathoVerse --local-dir weights/PathoVerse
python test.py --config configs/test.yaml

The first run loads the Qwen3.5-9B backbone. The included example queries demonstrate categorical, continuous and survival predictions using precomputed slide features from a TCGA-LGG slide (case TCGA-HT-7884; source slide). No feature extraction is needed. Results are written to runs/prediction/predictions.json.

The example features are provided for academic research under the source data and encoder terms, including those of TITAN and PRISM.

Run the following commands from the repository root.

Slide feature extraction

PathoVerse uses KEEP patch embeddings and four slide embeddings. Install TRIDENT in a separate environment and configure the encoders listed below. The study used TRIDENT v0.3.0.

Encoder Input at zero overlap Output TRIDENT directory
KEEP 20×, 256 × 256 px N × 768 patches 20x_256px_0px_overlap/features_keep
TITAN CONCHv1.5, 20×, 512 × 512 px 768 per slide 20x_512px_0px_overlap/slide_features_titan
PRISM Virchow, 20×, 224 × 224 px 1280 per slide 20x_224px_0px_overlap/slide_features_prism
Prov-GigaPath GigaPath, 20×, 256 × 256 px 768 per slide 20x_256px_0px_overlap/slide_features_gigapath
CHIEF CTransPath, 10×, 256 × 256 px 768 per slide 10x_256px_0px_overlap/slide_features_chief

Run the following in the TRIDENT environment. The last argument selects the GPU.

bash scripts/extract_features.sh /path/to/TRIDENT /path/to/wsis /path/to/features 0

Each output directory contains one HDF5 file per slide with the same stem as the source image.

  • KEEP requires features of shape (N, 768) and matching coords of shape (N, 2), ordered as level-0 (x, y) coordinates. Store the level-0 patch stride in coords.attrs["patch_size_level0"].
  • Each slide file contains a features vector of shape (D,) or (1, D). Keep slide_features_titan, slide_features_prism, slide_features_gigapath and slide_features_chief in the respective paths so the loader can identify the encoder.

Query records

Each record pairs one slide with a question. Supply a JSON array or a JSONL file, with feature paths relative to the working directory. Adapt the example queries or use the records from PathoVerse-Atlas.

Field Value
id, project Unique query ID and cohort or cancer project
category mcqa::<target>, regression::<target> or survival::<endpoint>
route_family Adapter for the query, listed below
image List containing the KEEP patch file
wsi_features TITAN, PRISM, Prov-GigaPath and CHIEF slide files
conversations A human query with an <image> placeholder, followed by a gpt answer field
regression_targets, survival_targets Reference targets for training and evaluation, or null for prediction

PathoVerse uses six task-family routes:

Query Route
Morphology, diagnosis, grade or stage morphology_clinicopathology
Molecular biomarker molecular_biomarker
RNA program transcriptomic_program
Protein program protein_program
Immune or stromal target immune_microenvironment
Survival or other outcome outcome

For prediction, leave the categorical answer empty and use <REG> or <SRV> for numeric tasks. Include measured clinical context in the question when appropriate.

For example, an unlabeled tumor-grade query using the included features is:

{
  "id": "tumor_grade::test::540::main_DX",
  "project": "TCGA-LGG",
  "category": "mcqa::tumor_grade",
  "route_family": "morphology_clinicopathology",
  "image": ["examples/features/features_keep.h5"],
  "wsi_features": [
    "examples/features/slide_features_chief.h5",
    "examples/features/slide_features_gigapath.h5",
    "examples/features/slide_features_titan.h5",
    "examples/features/slide_features_prism.h5"
  ],
  "conversations": [
    {
      "from": "human",
      "value": "<QUESTION>\nWhat is the tumor grade?\n<CHOICES>\nA) G1\nB) G2\nC) G3\nD) G4\n<image>"
    },
    {
      "from": "gpt",
      "value": ""
    }
  ],
  "regression_targets": null,
  "survival_targets": null
}

For labeled data, supply the categorical answer (e.g. B) G2), a numeric regression target, or a survival target on the training time scale. An example survival target is:

{
  "time": 2.5,
  "event": 1,
  "bins": {
    "target_y": [0, 0, 1, 0, 0, 0],
    "at_risk_mask": [1, 1, 1, 0, 0, 0]
  }
}

Inference and evaluation

Use configs/test.yaml for prediction and labeled evaluation. Edit the config or override paths on the command line. Multi-GPU inference and training use FSDP by default.

# Multi-GPU inference
CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 test.py --config configs/test.yaml

# Evaluate your own labeled records using the released model
python test.py --data data/test.json --output runs/evaluation

# Evaluate a fine-tuned checkpoint
python test.py --checkpoint runs/finetune/step_00000500/model \
    --data data/test.json --output runs/evaluation

Predictions are saved to predictions.json, the resolved configuration to resolved_config.json, and evaluation metrics to metrics.json when reference labels are available.

Task Prediction fields
Categorical prediction_text and mcqa_choice_logits
Continuous regression_prediction on the training target scale
Survival survival_prediction with six interval hazards, survival probabilities and risk_score (sum of hazards; higher indicates greater risk)

Evaluation metrics:

Task Metrics
Categorical Accuracy for all tasks, weighted F1 and balanced accuracy for binary tasks or shared label spaces, and binary AUROC from available choice logits
Continuous RMSE, MAE, R², Pearson and Spearman correlations
Survival C-index within each endpoint and project, with a sample-weighted endpoint summary

Reference answers are excluded from inference prompts, and metrics are computed only for labeled records. Invalid categorical answers count as incorrect. See the evaluation code for metric definitions.

Fine-tuning

Set data.path in configs/train.yaml to your labeled records. For PathoVerse-Atlas, use data/PathoVerse-Atlas/qa/tcga/train.json and place features at the paths in the records.

CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 train.py --config configs/train.yaml

For one GPU, use python train.py with the same config. To train newly initialized PathoVerse modules, use configs/train_from_scratch.yaml instead.

The training configs also document trainable modes, checkpoint resume and sampling settings.

License and acknowledgments

PathoVerse's original contributions are released under the MIT License. Third-party resources retain their own terms.

We thank the authors and developers of SlideChat, Qwen, KEEP, TITAN, PRISM, Prov-GigaPath, CHIEF and TRIDENT for their contributions.

About

Code for "A Multi-Task Generative Pathology Model for Unified Tumor Profiling"

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages