Ensembling Pruned Attention Heads For Uncertainty-Aware Efficient Transformers
Firas Gabetni, Giuseppe Curci, Andrea Pilzer, Subhankar Roy, Elisa Ricci, Gianni Franchi
TL;DR
This work tackles uncertainty quantification in transformers by addressing the high cost of Deep Ensembles. It introduces Hydra Ensembles, a framework that prunes attention heads to create diverse subnetworks and fuses them into a single transformer via grouped fully-connected layers, achieving near-single-model inference with competitive UQ performance. Across image, text, and zero-shot tasks, Hydra Ensembles delivers strong calibration and OOD detection, often surpassing training-free baselines and narrowing or matching the Deep Ensembles gap. The approach demonstrates that careful, circuit-informed head pruning can preserve or enhance uncertainty estimates while dramatically reducing computational demands, making scalable UQ feasible for large-scale language-vision models.
Abstract
Uncertainty quantification (UQ) is essential for deploying deep neural networks in safety-critical settings. Although methods like Deep Ensembles achieve strong UQ performance, their high computational and memory costs hinder scalability to large models. We introduce Hydra Ensembles, an efficient transformer-based ensemble that prunes attention heads to create diverse members and merges them via a new multi-head attention with grouped fully-connected layers. This yields a compact model with inference speed close to a single network, matching or surpassing Deep Ensembles in UQ performance without retraining from scratch. We also provide an in-depth analysis of pruning, showing that naive approaches can harm calibration, whereas Hydra Ensembles preserves robust uncertainty. Experiments on image and text classification tasks, with various architectures, show consistent gains over Deep Ensembles. Remarkably, in zero-shot classification on ImageNet-1k, our approach surpasses state of the art methods, even without requiring additional training.
