# prov-gigapath/prov-gigapath architecture

> Architecture diagram of the GitHub repository prov-gigapath/prov-gigapath, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prov-gigapath/prov-gigapath
- Repository: https://github.com/prov-gigapath/prov-gigapath

## Overview

Prov-GigaPath is a computational pathology foundation-model toolkit. Its main inference workflow prepares whole-slide images as tiles, encodes each tile, then combines tile embeddings and coordinates into a slide representation; downstream tasks can use that representation for classification. The repository also provides cross-validation finetuning and preprocessing utilities. The README documents the workflow, while source excerpts and the SOURCE INDEX support selected implementation links; unsampled internals and some optional integrations are not expanded.

Main entry points: [`gigapath/preprocessing/data/create_tiles_dataset.py`](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/create_tiles_dataset.py) (Tile dataset creation), [`gigapath/pipeline.py`](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/pipeline.py) (Inference pipeline), [`gigapath/slide_encoder.py`](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/slide_encoder.py) (Slide encoder), [`finetune/main.py`](https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/main.py) (Finetune workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Slide preprocessing"]
  node_tile_prep["Tile dataset creation"]
  node_foreground["Foreground segmentation"]
  node_tiling["Slide tiling<br/>[tiling.py]"]
  node_tile_images["Image tiles"]
end

subgraph group_inference["Model inference"]
  node_pipeline["Inference pipeline<br/>[pipeline.py]"]
  node_tile_encoder["Tile encoder<br/>[tile_encoder.py]"]
  node_tile_embeddings["Tile embeddings"]
  node_slide_encoder["Slide encoder<br/>[slide_encoder.py]"]
  node_slide_repr["Slide representation"]
end

subgraph group_tasks["Downstream tasks"]
  node_classification["Classification head"]
  node_finetune_entry["Finetune workflow<br/>[main.py]"]
  node_slide_dataset["Slide dataset<br/>[slide_datatset.py]"]
  node_training["Training and evaluation<br/>[training.py]"]
  node_metrics["Task metrics<br/>[metrics.py]"]
end

subgraph group_internals["Model internals"]
  node_longnet["LongNet backbone<br/>[LongNet.py]"]
  node_encoder_layers["Transformer encoder<br/>[encoder.py]"]
  node_attention["Dilated attention"]
  node_moe["Expert layers<br/>[moe_layer.py]"]
  node_routing["Expert routing<br/>[routing.py]"]
end

node_pathologist(("Pathology user"))
node_slide_files["Whole-slide images"]

node_pathologist -->|"provides slides"| node_slide_files
node_slide_files -->|"preprocesses"| node_tile_prep
node_tile_prep -->|"filters foreground"| node_foreground
node_tile_prep -->|"creates tiles"| node_tiling
node_tile_prep -->|"writes tiles"| node_tile_images
node_slide_files -->|"runs inference on"| node_pipeline
node_pipeline -->|"invokes tiling"| node_tile_prep
node_pipeline -->|"loads encoder"| node_tile_encoder
node_tile_images -->|"encodes tiles"| node_tile_encoder
node_tile_encoder -->|"produces embeddings"| node_tile_embeddings
node_tile_embeddings -->|"passes embeddings and coordinates"| node_slide_encoder
node_slide_encoder -->|"produces representation"| node_slide_repr
node_slide_encoder -->|"builds backbone"| node_longnet
node_longnet -->|"constructs layers"| node_encoder_layers
node_encoder_layers -->|"uses attention"| node_attention
node_encoder_layers -->|"uses expert layers"| node_moe
node_moe -->|"routes tokens"| node_routing
node_slide_repr -->|"classifies"| node_classification
node_pathologist -->|"configures task"| node_finetune_entry
node_finetune_entry -->|"builds datasets"| node_slide_dataset
node_finetune_entry -->|"starts training"| node_training
node_training -->|"trains model"| node_classification
node_training -->|"computes metrics"| node_metrics

click node_tile_prep "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/create_tiles_dataset.py"
click node_foreground "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/foreground_segmentation.py"
click node_tiling "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/tiling.py"
click node_pipeline "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/pipeline.py"
click node_tile_encoder "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/tile_encoder.py"
click node_slide_encoder "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/slide_encoder.py"
click node_classification "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/classification_head.py"
click node_finetune_entry "https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/main.py"
click node_slide_dataset "https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/datasets/slide_datatset.py"
click node_training "https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/training.py"
click node_metrics "https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/metrics.py"
click node_longnet "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/model/LongNet.py"
click node_encoder_layers "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/architecture/encoder.py"
click node_attention "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/multihead_attention.py"
click node_moe "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/xmoe/moe_layer.py"
click node_routing "https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/xmoe/routing.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tile_prep,node_foreground,node_tiling,node_tile_images,node_pathologist toneBlue
class node_pipeline,node_tile_encoder,node_tile_embeddings,node_slide_encoder,node_slide_repr toneAmber
class node_classification,node_finetune_entry,node_slide_dataset,node_training,node_metrics toneMint
class node_longnet,node_encoder_layers,node_attention,node_moe,node_routing toneRose
class node_slide_files toneIndigo
```

## Components

### Slide preprocessing

- [Tile dataset creation](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/create_tiles_dataset.py): `gigapath/preprocessing/data/create_tiles_dataset.py`
- [Foreground segmentation](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/foreground_segmentation.py): `gigapath/preprocessing/data/foreground_segmentation.py`
- [Slide tiling](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/preprocessing/data/tiling.py): `gigapath/preprocessing/data/tiling.py`
- **Image tiles**

### Model inference

- [Inference pipeline](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/pipeline.py): `gigapath/pipeline.py`
- [Tile encoder](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/tile_encoder.py): `gigapath/tile_encoder.py`
- **Tile embeddings**
- [Slide encoder](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/slide_encoder.py): `gigapath/slide_encoder.py`
- **Slide representation**

### Downstream tasks

- [Classification head](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/classification_head.py): `gigapath/classification_head.py`
- [Finetune workflow](https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/main.py): `finetune/main.py`
- [Slide dataset](https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/datasets/slide_datatset.py): `finetune/datasets/slide_datatset.py`
- [Training and evaluation](https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/training.py): `finetune/training.py`
- [Task metrics](https://github.com/prov-gigapath/prov-gigapath/blob/main/finetune/metrics.py): `finetune/metrics.py`

### Model internals

- [LongNet backbone](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/model/LongNet.py): `gigapath/torchscale/model/LongNet.py`
- [Transformer encoder](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/architecture/encoder.py): `gigapath/torchscale/architecture/encoder.py`
- [Dilated attention](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/multihead_attention.py): `gigapath/torchscale/component/multihead_attention.py`
- [Expert layers](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/xmoe/moe_layer.py): `gigapath/torchscale/component/xmoe/moe_layer.py`
- [Expert routing](https://github.com/prov-gigapath/prov-gigapath/blob/main/gigapath/torchscale/component/xmoe/routing.py): `gigapath/torchscale/component/xmoe/routing.py`

### Other components

- **Pathology user**
- **Whole-slide images**

## Connections

- Pathology user → Whole-slide images: provides slides (evidence: `README.md`)
- Whole-slide images → Tile dataset creation: preprocesses (evidence: `README.md`)
- Tile dataset creation → Foreground segmentation: filters foreground (evidence: `gigapath/preprocessing/data/create_tiles_dataset.py`)
- Tile dataset creation → Slide tiling: creates tiles (evidence: `gigapath/preprocessing/data/create_tiles_dataset.py`)
- Tile dataset creation → Image tiles: writes tiles (evidence: `gigapath/preprocessing/data/create_tiles_dataset.py`)
- Whole-slide images → Inference pipeline: runs inference on (evidence: `README.md`)
- Inference pipeline → Tile dataset creation: invokes tiling (evidence: `gigapath/pipeline.py`)
- Inference pipeline → Tile encoder: loads encoder (evidence: `gigapath/pipeline.py`)
- Image tiles → Tile encoder: encodes tiles (evidence: `README.md`)
- Tile encoder → Tile embeddings: produces embeddings (evidence: `README.md`)
- Tile embeddings → Slide encoder: passes embeddings and coordinates (evidence: `README.md`)
- Slide encoder → Slide representation: produces representation (evidence: `README.md`)
- Slide encoder → LongNet backbone: builds backbone (evidence: `gigapath/slide_encoder.py`)
- LongNet backbone → Transformer encoder: constructs layers (evidence: `gigapath/torchscale/model/LongNet.py`)
- Transformer encoder → Dilated attention: uses attention (evidence: `gigapath/torchscale/architecture/encoder.py`)
- Transformer encoder → Expert layers: uses expert layers (evidence: `gigapath/torchscale/architecture/encoder.py`)
- Expert layers → Expert routing: routes tokens (evidence: `gigapath/torchscale/component/xmoe/routing.py`)
- Slide representation → Classification head: classifies (evidence: `gigapath/classification_head.py`)
- Pathology user → Finetune workflow: configures task (evidence: `README.md`)
- Finetune workflow → Slide dataset: builds datasets (evidence: `finetune/main.py`)
- Finetune workflow → Training and evaluation: starts training (evidence: `finetune/main.py`)
- Training and evaluation → Classification head: trains model (evidence: `finetune/training.py`)
- Training and evaluation → Task metrics: computes metrics (evidence: `finetune/training.py`)
