arXiv:2609.04071cs.CVSep 2026

Manuscript Offprint

arXiv:2609.04071

TAP-Path: Task-Adaptive Structural and Token Pruning for Efficient and Trustworthy Pathology Foundation Models

Mehedi Hasan, Ashfak Yeafi, Md Khairul Islam

Abstract

Pathology foundation models have substantially improved transferable representation learning for histopathology, but recent gains increasingly rely on encoders with hundreds of millions of parameters and high inference cost. This creates a practical mismatch between representational scale and task-specific deployment, especially when a downstream application requires only a subset of the pretrained hierarchy. We propose TAP-Path, a task-adaptive compression framework that directly restructures a pretrained Virchow2 encoder rather than distilling it into a separate student. TAP-Path combines validation-driven transformer-block selection, physical removal of redundant blocks, input-adaptive patch-token pruning, multi-depth feature recovery, and a lightweight gated task head. The final model retains 24 of 32 transformer blocks and 70% of patch tokens after the pruning point, reducing encoder parameters by 24.96% (631.24M to 473.70M) and analytical encoder compute by 35.20% (340.13G to 220.40G FLOPs). Across three task-head optimization seeds, TAP-Path achieved 87.98±0.067%87.98 \pm 0.067\% test accuracy, 81.26±0.49%81.26 \pm 0.49\% balanced accuracy, and 82.38±0.48%82.38 \pm 0.48\% macro-F1 on a 32-class histopathology benchmark, slightly exceeding full Virchow2 (86.89% accuracy) and UNI2-h (87.67%) while using fewer deployed parameters and substantially less analytical compute. Beyond predictive performance, we evaluate calibration, probabilistic quality, failure detection, rare-class behavior, and selective prediction. TAP-Path obtained a Brier score of 0.1800±0.00050.1800 \pm 0.0005 and failure-detection AUROC of 0.9047±0.00600.9047 \pm 0.0060. A validation-only rare-aware objective increased rare-class balanced accuracy in a secondary operating analysis, providing a complementary operating point that characterizes the trade-off between overall accuracy and minority-class sensitivity. Frozen external evaluation on 433 CPTAC samples yielded 91.22±0.83%91.22 \pm 0.83\% accuracy and 91.10±0.81%91.10 \pm 0.81\% balanced accuracy. These results indicate that task-adaptive structural and token sparsification can move large pathology foundation models toward a more favorable accuracy–efficiency operating point while preserving measurable reliability characteristics under internal and external evaluation.

Keywords: Computational pathology; pathology foundation models; structural pruning; token pruning; trustworthy AI;

model efficiency.

1 Introduction

Digital pathology has moved rapidly from task-specific convolutional pipelines toward large pretrained vision and vision-language foundation models. Models such as UNI, CONCH, Virchow, Prov-GigaPath, CHIEF, Hibou, GPFM, and PathOrchestra have demonstrated that large-scale self-supervised, weakly supervised, or multimodal pretraining can produce reusable histopathology representations across cancer classification, biomarker prediction, retrieval, prognosis, and other downstream tasks [1, 2, 3, 4, 5, 6, 7, 8]. The emerging consensus, however, is not that a single foundation model is uniformly superior. Independent benchmarking has shown substantial task dependence, cohort dependence, sensitivity to adaptation strategy, and variation under external evaluation [9, 10, 11, 12]. This makes deployment efficiency and reliability increasingly important alongside raw predictive performance.

The computational cost of contemporary pathology foundation models is particularly relevant. From a systems perspective, this mismatch is amplified at whole-slide scale. A tissue-rich WSI may generate thousands to tens of thousands of candidate tiles at diagnostic magnification, and the encoder is invoked repeatedly before slide-level aggregation or downstream decision logic. A reduction of one third in per-patch transformer compute therefore compounds across the entire WSI rather than saving only a single forward pass. This observation motivates task-specific restructuring of the patch encoder itself, rather than limiting efficiency analysis to the number of trainable downstream parameters. Virchow2 uses a ViT-H/14-scale encoder with approximately 632M parameters [3], while other leading models are similarly large. Whole-slide applications amplify this burden because a single slide may generate hundreds or thousands of patches. Even when a large encoder is frozen, its stored parameters and forward-pass operations remain present at inference. Parameter-efficient fine-tuning therefore reduces optimization cost but does not necessarily reduce the resident encoder or patch-level inference burden. Recent medical-image studies have increasingly recognized lightweight design as a distinct problem from parameter-efficient adaptation [13, 14, 15]. In computational pathology, SUDA explicitly targets this problem by distilling heavy foundation models into lightweight students [16]. Distillation can be highly effective, but it changes the model family, requires a teacher–student transfer procedure, and may need to be repeated for new tasks or domains. This leaves an important complementary question: how much of an already pretrained large pathology encoder is actually necessary for a specific downstream task?

Generic vision research suggests that substantial redundancy can exist both along transformer depth and within the token sequence. Structured sparsification and token-pruning approaches reduce computation by removing blocks, tokens, or interactions that contribute little to a target task [17, 18, 19, 20, 21]. Nevertheless, pathology foundation models are not ordinary ImageNet classifiers. Histopathological discriminative evidence may occupy small tissue regions, vary across magnification and morphology, and be especially sparse for low-prevalence classes. Aggressive pruning that looks attractive from a FLOP perspective can therefore erase diagnostically useful evidence. The desired objective is not maximum compression alone, but a validated Pareto operating point that preserves task utility while reducing genuine encoder cost. The design philosophy is similar to recent efficiency-oriented vision architectures that explicitly optimize accuracy against parameters and compute [22], but here the problem is addressed by restructuring a pretrained pathology foundation model rather than designing a new backbone from scratch.

A second limitation of efficiency-only evaluation is that a compressed medical model can retain accuracy while becoming less trustworthy in ways that aggregate accuracy does not reveal. Calibration error, negative log-likelihood, Brier score, confidence-based failure detection, and selective risk quantify different aspects of whether predicted probabilities are useful for decision support [23, 24, 25]. Recent pathology work has likewise emphasized domain robustness, fairness, and vulnerability to non-biological scanner or laboratory variation [26, 27, 28]. Thus, a credible compression study in computational pathology should establish not only accuracy and compute reduction but also whether uncertainty remains informative, minority classes are characterized explicitly, and the locked model generalizes to an independent cohort.

This study addresses these gaps with TAP-Path, short for TAP-Path, a task-adaptive structural and token pruning framework for pathology foundation models. TAP-Path begins from the pretrained Virchow2 encoder and performs validation-only structural analysis to identify a task-relevant subset of transformer blocks. Unlike freezing or masking, selected blocks are physically retained in the deployed encoder while unselected blocks are removed. The structurally compressed model is then paired with input-adaptive token pruning that preserves the prefix token and retains the most task-relevant patch tokens using a combined class-token similarity and feature-magnitude score. To compensate for information loss from shortening both depth and token sequence, TAP-Path collects multi-depth features from four locations in the retained hierarchy and fuses them through a learned soft gate before classification. The model is

selected entirely on training and validation data; the internal test set and CPTAC external cohort are evaluated only after configuration locking. The final single-head model is confirmed with three random seeds and evaluated with accuracy, balanced accuracy, macro-F1, rare-class balanced accuracy, calibration, probabilistic losses, failure-detection AUROC, runtime, parameters, analytical FLOPs, and frozen external performance.

In this paper, we propose TAP-Path, a task-adaptive compression framework that restructures a pretrained pathology foundation model for efficient and reliable downstream deployment.

The main contributions of this study are summarized as follows:

  • We propose TAP-Path, a task-adaptive compression framework that identifies task-relevant transformer depth and physically reconstructs a compact, non-contiguous subnetwork from the pretrained Virchow2 hierarchy. This enables direct compression of the foundation model without training or distilling a separate student network.

  • We develop an adaptive token-pruning and multi-depth recovery strategy that reduces redundant patch-token computation while preserving complementary representations from multiple stages of the compressed hierarchy. A learned gating mechanism integrates these representations for downstream prediction.

  • We systematically investigate the computational efficiency of pathology foundation models through deployed parameter count and analytical FLOPs, together with predictive performance. The proposed design reduces Virchow2 encoder parameters by 24.96% and FLOPs by 35.20%, demonstrating that substantial computational redundancy can be removed while preserving competitive performance on the 32-class pathology task.

  • We conduct a reliability-oriented evaluation relevant to trustworthy medical AI by examining calibration, failure awareness, selective prediction, rare-class behavior, and statistical uncertainty. We further evaluate the locked model on two independent CPTAC cohorts without external adaptation or threshold tuning to assess generalization beyond the development data.

Together, these results show that task-specific structural and token redundancy can be removed from a large pathology foundation model while retaining competitive discrimination and informative uncertainty.

References (34)