Carving Deployable Models from Medical Foundation Models, Selected on Unseen Hospitals

Hospitals increasingly have access to large models pre-trained on medical images, such as pathology and chest X-ray foundation models. A foundation model here means a big network trained without labels on millions of domain images, so that its features can be reused across many tasks. The machines that actually run inference in a clinic, though, are often ordinary laptops or lab workstations with no GPU. Deployed models also tend to lose accuracy once they leave the site where they were validated. This note proposes cutting a small, fast sub-model out of a domain foundation model. The cut decides how many layers to keep, where to place small trainable adapters, how many image patches to read, and at what numeric precision to run. The key choice is how the winning cut is picked. It is selected for its accuracy on hospitals it never trained on, under a hard latency and memory budget, and not for its accuracy on a pooled validation split.

The bet is that the second choice matters more than it looks. Architecture search, meaning automated search over network configurations, has always ranked candidates on held-out data drawn from the training distribution. Clinical deployment, by contrast, is defined by distribution shift. If the configurations that win on pooled validation are systematically the ones that fit site-specific quirks, then automating architecture choice makes the "retrospective-to-prospective" drop worse. Choosing by worst unseen site would then give small models that hold up better. If the two rankings agree, search can safely ignore shift, and that would also be worth knowing. Either way the study answers a question that current medical architecture search does not ask.

Core Claim

Within the space of sub-models carved from one domain-pretrained backbone, two orderings may disagree substantially. One is the order by in-distribution validation accuracy. The other is the order by worst-site accuracy on held-out hospitals. If they disagree, then selecting by leave-one-site-out performance under a fixed CPU latency budget gives deployable models that beat (a) the best pooled-validation pick from the same search space, (b) off-the-shelf small backbones with uniform adapters, and (c) a large frozen foundation model that does not meet the budget. The gain must also survive per-site threshold recalibration. The claim is about the selection rule and the search space jointly. The search algorithm itself is deliberately standard.

Position Relative to Prior Work

Three papers motivate the gap. MedNNS builds a weight-sharing supernet over medical datasets. It learns a joint embedding of datasets and architectures that retrieves a sub-network and initialization for a new task, reporting a 1.7% average accuracy gain on MedMNIST. It works on 28×28 images, ranks candidates by in-distribution accuracy, ignores hardware, and struggled on unusual textures such as kidney cortex microscopy. EGNAS searches compact graph-network prediction heads on a frozen DINOv2 backbone and runs them on a GPU-less clinical laptop. It reports 2.1× less head memory than an MLP head and 78% IoU in a live brain tumor case, but it never touches the backbone and never selects for cross-site robustness. eWSI shows that low-rank adapters (LoRA, small trainable weight updates added to frozen layers) plus sparse patch sampling and a multiple-instance aggregator can match in-domain baselines on whole slides. Its architecture is fixed by hand, and it notes that sparse sampling shifts calibration and inflates false positives. We reuse eWSI's training recipe as the inner loop and make its fixed choices (adapter placement, rank, patch budget) searchable. We add depth truncation and precision on top.

Two papers constrain the design. StainNet shows that pathology representations do not cross stain boundaries: non-H&E pre-training helps IHC tasks but not H&E tasks. So the backbone family must match the task domain, and we do not try to search across stain domains. DEPLOYR documents the live-deployment drop, for example a white-blood-cell predictor falling from 0.76 AUROC retrospectively to 0.69 prospectively. That result supplies the evaluation philosophy: held-out-site performance is the honest proxy we can afford for a silent trial.

Two papers supply methods. Single-Path NAS observed that a 3×3 kernel is the inner core of a 5×5 kernel, which makes the smaller choice a nested subset of the larger one. Our search space has the same nesting: a depth-k truncation is a prefix of the full transformer, and a rank-r adapter can be a slice of a rank-2r adapter. So one shared-weight supernet covers it at low cost. Optimizing the Implementation of Clinical Predictive Models to Minimize National Costs shows that thresholds tuned per subgroup capture large utility over a single uniform threshold. We adopt that as a mandatory post-processing step for every method, so architecture gains are not confused with threshold gains.

Research Program

The search space is built on a domain-pretrained vision transformer. A configuration $a$ specifies five things: the exit depth (which transformer block feeds the head), the set of blocks receiving LoRA and their ranks, the number of patches $M$ sampled per slide or the input resolution for radiographs, the aggregator or head type (attention pooling, eWSI's LinMax, or a linear head), and weight precision (fp16 or int8). On a 12-block ViT-Base this gives on the order of $10^{6}$–$10^{8}$ configurations. That is far too many to train one by one, but the nesting makes them shareable.

We train one supernet per domain. Each step samples a configuration, using the common trick of always including the largest and smallest configurations in each batch. Training data are grouped by acquisition site. Selection solves

$$a^\star = \arg\max_{a}\; \min_{s \in \mathcal{S}_{\text{held}}} U_s(a) \quad \text{subject to} \quad T(a) \le L,\; R(a) \le B.$$

Here $\mathcal{S}_{\text{held}}$ is the set of validation sites excluded from supernet training in a given fold. $U_s(a)$ is sensitivity at 90% specificity on site $s$, measured after the threshold is recalibrated using a small labeled sample from that site. $T(a)$ and $R(a)$ are the measured CPU latency and peak RAM on a reference laptop, and $L$, $B$ are the budgets. We use the worst site, not the mean site, because a deployment fails at its weakest hospital. Selection uses evolutionary or random search over the supernet, with latency taken from a lookup table profiled on the target CPU.

Weight sharing can scramble rankings, so we validate the supernet before trusting it. About 40 configurations, spread across the latency range, are retrained standalone with the eWSI recipe. We then report Kendall rank correlation between supernet scores and standalone scores. If that correlation is poor, we fall back to a surrogate predictor trained on standalone runs.

The central analysis comes from the same 40 standalone configurations. We compute the rank correlation between pooled-validation scores and worst-held-out-site scores. We also characterize which axes drive any disagreement. One possibility is that deeper exits and higher adapter ranks overfit site staining. Another is that larger patch budgets help robustness.

Proposed Experiments

Histopathology is the primary domain. The tasks are Camelyon16 metastasis detection, TCGA NSCLC and BRCA subtyping with splits grouped by tissue source site, and BRACS three-way lesion classification. The backbones are an ImageNet ViT and the in-domain Hist-SSL encoder used by eWSI. Chest radiography is the second domain. Models train on CheXpert and are tested on MIMIC-CXR as an unseen institution, for pleural effusion, edema and cardiomegaly. The file reports no cross-dataset CheXpert-to-MIMIC number, so all results there are new measurements. The deployment target follows the EGNAS setting: a GPU-less laptop with a fixed RAM budget, here an 8 GB budget and a per-slide latency cap set at the speed of a ViT-Small with $M=512$ patches. All metrics are reported both before and after per-site recalibration, alongside expected calibration error at the operating point.

Baselines

The naive reference point is the full frozen domain foundation model with an attention-pooling head and no compute budget. It shows how much accuracy the budget costs and whether any carved model gets close.

The strongest existing method is eWSI with the Hist-SSL encoder, which reports 98.5% AUC on Camelyon16. We rerun it with its published configuration under our site-grouped splits, so its numbers are comparable. We report it twice: unconstrained, and with its backbone swapped to ViT-Small so that it fits the budget. Beating it means matching its pooled AUC within one point while exceeding its worst-held-out-site sensitivity at 90% specificity, at no more than the budget latency. For radiographs, the reference is the CheXpert DenseNet121, reported at 0.97 AUC for pleural effusion and 0.94 for edema on the CheXpert test set. We retrain it and evaluate it on MIMIC-CXR.

The best hand-designed in-budget model is a ViT-Small domain backbone (Hist-SSL-Small, or StainNet-Small for IHC tasks) with uniform LoRA on every block. Practitioners would reach for this first.

Two baselines target the method directly. The first is EGNAS-style head-only search on a frozen backbone, which tests whether searching the backbone carve matters at all. The second is random search in our space with standalone training at matched GPU-hours, which tests whether weight sharing earns its keep.

The ablation that isolates the key ingredient is identical search, space and budget, with selection by pooled validation instead of worst held-out site. Every method gets the same training data, the same per-site recalibration sample and the same hyperparameter-tuning budget in GPU-hours.

Why not just…?

Why not just use an off-the-shelf small domain backbone with uniform LoRA? This is the most likely real threat. If ViT-Small with uniform adapters lands within noise of the searched carve on worst-site sensitivity at equal latency, the search adds nothing and we will say so. The EGNAS memory and runtime gains over MLP heads suggest that structure inside the budget matters. Still, those gains were in the head, not the backbone, so this comparison is the first one we run.

Why not just distill the foundation model into a small student? Distillation makes the student mimic the teacher's outputs on the training distribution, and that includes any site-specific shortcuts the teacher has learned. We include a distilled ViT-Small trained on the same sites as an extra in-budget baseline. If distillation matches the carve on held-out sites, the cheaper route wins.

Why not just recalibrate thresholds per site, as in the sepsis cost study? Per-subgroup threshold optimization yields large gains, and much of the deployment drop may be a calibration shift rather than lost ranking ability. That is why every method is recalibrated before comparison. Recalibration fixes the operating point but cannot restore lost AUROC, so the claim survives only if the carved model has better ranking on unseen sites. Reporting metrics before and after recalibration shows how much of the gap each fix closes.

Why not just do leave-one-site-out hyperparameter tuning of a fixed architecture? That is the ablation in disguise, with a smaller space. Tuning learning rate and LoRA rank of a fixed ViT-Small by held-out site is run as an additional baseline. If it captures most of the gain, the lesson is "select by unseen site," not "search architectures," and that becomes the headline.

Decisive Checks

The idea stands or falls on three measurements. First, across the 40 standalone configurations, the rank correlation between pooled-validation and worst-held-out-site scores should be clearly below that between two pooled-validation seeds. If the two orderings agree, selection rule does not matter, and the proposal reduces to ordinary budgeted search. Second, after per-site recalibration, the worst-site-selected carve should beat both the pooled-selected carve and uniform-LoRA ViT-Small on worst-site sensitivity at 90% specificity, consistently across at least two of the TCGA, Camelyon16 and CheXpert-to-MIMIC settings, at equal measured CPU latency. Third, supernet-to-standalone rank correlation must be high enough that the selected configuration is also the best one after standalone retraining. Otherwise the cheap search is not trustworthy and the surrogate fallback is required.