Long-MIL: Scaling Long Contextual Multiple Instance Learning for Histopathology Whole Slide Image Analysis

Honglin Li, Yunlong Zhang, Chenglu Zhu, Jiatong Cai, Sunyi Zheng, Lin YangarXiv 2023 · DOI

Abstract

Whole Slide Image (WSI) analysis in digital pathology faces significant challenges due to the massive scale of images and the "length extrapolation" problem. Standard Multiple Instance Learning (MIL) methods often struggle with computational complexity and spatial context generalization. We present Long-MIL, a framework that scales MIL by integrating a 2D adaptation of Attention with Linear Bias (ALiBi) and Flash-Attention. Long-MIL effectively processes massive, irregularly shaped tissue slides, outperforming state-of-the-art methods in accuracy and efficiency across multiple histopathology tasks.

Introduction: The Scale and Extrapolation Problem

In digital pathology, Whole Slide Images (WSIs) are gargantuan, often exceeding 150,000 x 150,000 pixels. To analyze them, researchers use Multiple Instance Learning (MIL), which breaks the image into thousands of small patches. However, two major hurdles remain:

  1. The Extrapolation Gap: Most models use absolute position embeddings. If a model is trained on small tissue samples and then encounters a much larger or differently shaped slide in a clinical setting, it fails to understand the spatial context because it hasn't "seen" those coordinates before.
  2. Computational Complexity: Standard self-attention memory costs grow quadratically ($O(N^2)$) with the number of patches. For a WSI with 10,000+ patches, this quickly exhausts even the most powerful GPUs.
WSI patch sequence statistics and GPU memory usage complexity.

Methodology: 2D-ALiBi and Flash-Attention

Long-MIL introduces two primary innovations to bridge the extrapolation gap and manage computational load:

2D-ALiBi (Attention with Linear Bias)

Originally developed for 1D Long Language Models, the authors adapted ALiBi for 2D spatial data. Instead of adding learned position vectors, it adds a non-learned penalty to attention scores based on the Euclidean distance between patches. Because this bias is a fixed geometric function, the model can generalize to any slide size or shape at test time without needing to have seen those specific dimensions during training.

Flash-Attention Integration

To handle massive sequence lengths (often 8k to 20k patches per slide), Long-MIL utilizes Flash-Attention. Unlike "Linear Attention" approximations which can lose information, Flash-Attention provides exact self-attention with significantly reduced memory overhead and faster processing speeds by optimizing IO-awareness.

The Long-MIL pipeline featuring 2D-ALiBi for position-aware attention.

The pipeline follows a standard MIL flow: patches are encoded into features using a pretrained backbone (like DINO or ResNet), processed by the Long-MIL Transformer head, and aggregated for a final slide-level prediction.

Key Results and Performance

The model was evaluated on four major histopathology datasets: BRACS (breast carcinoma subtyping), TCGA-BRCA (ductal vs. lobular subtyping), TCGA-COADREAD, and TCGA-STAD (survival prediction).

  • Superior Accuracy: On the BRACS dataset, Long-MIL achieved an F1 score of 0.714, significantly outperforming the previous state-of-the-art, TransMIL (0.648).
  • Robustness to Scale: In TCGA-BRCA subtyping, Long-MIL reached an AUC of 0.946, surpassing all baseline MIL methods.
  • Efficiency: Flash-Attention allowed the model to process sequences of 10,000 patches while using <10GB VRAM on a standard RTX-3090 GPU, whereas vanilla attention would have crashed.
  • Survival Prediction: Long-MIL achieved the highest C-Index scores on both COADREAD (0.624) and STAD (0.589) datasets.

Conclusion and Future Work

Long-MIL proves that modeling relative spatial distance between patches significantly boosts performance and robustness. By utilizing 2D-ALiBi, the model becomes "shape-agnostic," solving the brittle nature of absolute embeddings. While survival prediction remains a challenge, future work aims to integrate multi-modal genomic data and scale to 40× magnification, which would quadruple sequence lengths and further test the limits of this scalable architecture.

Summary updated

BibTeX
@misc{li2023long,
  author = {Honglin Li and Yunlong Zhang and Chenglu Zhu and Jiatong Cai and Sunyi Zheng and Lin Yang},
  title = {{Long-MIL: Scaling Long Contextual Multiple Instance Learning for Histopathology Whole Slide Image Analysis}},
  year = {2023},
  eprint = {2311.12885},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.12885},
}
Figure