arXiv:2610.27211cs.LGOct 2026

Manuscript Offprint

arXiv:2610.27211

A Theoretical Analysis of Environment-Aware Out-of-Distribution Detection for Vision-Language Models

Salimeh Sekeh, Mary Wisell

Abstract

Continual vision–language models (VLMs) encounter a stream of environments and, at deployment, must also reject inputs that do not belong to the environment at hand. In this setting, the class information learned in earlier environments is a resource for out-of-distribution (OOD) detection, yet existing detectors score each environment in isolation, and it remains theoretically unclear when the previous environments help or hurt. We develop a contribution-theoretic analysis of environment-aware OOD detection built on pairwise cosine expectations, called contribution scores, that measure how the image and text features of one environment align with those of another. We propose a cross-environment maximum-concept-matching (MCM) score with two terms: a primary term that matches the test image of the current environment against the class texts of the current environment, and a secondary term that matches the same image against the class texts of a previous environment, weighted by the intra-modal alignment between the two environments. We prove that, under a positive environment transition and a bounded class-matching margin for OOD inputs, this score attains a false-positive rate no larger than that of the standard MCM detector at an adjusted threshold, so the secondary term strengthens detection when the environments are strongly connected. We then show that the score gap of an MCM detector between two environments equals the self-contribution of the in-distribution environment minus its cross-modal contribution into the OOD environment, which separates soft OOD environments, provably detectable with explicit AUROC, true-positive, and false-positive guarantees, from hard OOD environments, for which any threshold that retains the in-distribution data also accepts OOD inputs at nearly the same guaranteed rate. For cascaded detection, in which the text prototypes of all seen environments are pooled, the false-positive rate on every past environment is non-decreasing in time, and we characterize when detection provably fails. A contribution balance factor applied to the gradients of the classification loss and of a smoothed false-positive rate completes the framework.

Keywords: Out-of-distribution detection, continual learning, vision–language models, cross-modal alignment, hard OOD examples, AUROC bounds

1. Introduction

Large vision-language models (VLMs) such as CLIP (Radford et al., 2021) are increasingly deployed in open, changing environments. They are adapted to new environments by sequential fine-tuning, which trades plasticity for stability: representations acquired for a new environment overwrite those learned for earlier ones, causing catastrophic forgetting (Kirkpatrick et al., 2017; Wang et al., 2024). At the same time, a deployed model must recognize what it does not know. At every step it receives a mixture of in-distribution (ID) data and semantically novel out-of-distribution (OOD) data, and it must classify the former while rejecting the latter (Hendrycks and Gimpel, 2017; Bendale and Boult, 2015).

VLMs make this possible without task-specific training: a test image can be scored against the text descriptions of the current classes, as in maximum concept matching (MCM) (Ming et al.,

2022). Existing detectors, however, treat every environment in isolation, and existing continual methods, such as prompt tuning (Wang et al., 2022a,b), adapters (Gao et al., 2025), and weight interpolation (Zheng et al., 2023), are designed to limit forgetting rather than to detect novel inputs. When environments arrive continuously, the class information of the previous environments is already available and can sharpen detection in the current one. Two questions follow: when should a detector use the previous environments, and why does detection that works for one environment fail once several environments have been learned?

We answer both questions with modality-specific contribution scores: pairwise cosine expectations that measure how the image and text features of one environment align with those of another. Four scores capture cross-modal (ConIt→Tt′(Con_{\mathcal{I}_t \to \mathcal{T}_t'}, ConTt→It′Con_{\mathcal{T}_t \to \mathcal{I}_t'}) and intra-modal (ConIt→It′(Con_{\mathcal{I}_t \to \mathcal{I}_t'}, ConTt→Tt′Con_{\mathcal{T}_t \to \mathcal{T}_t'}) structure between environments Et\mathcal{E}_t and Et′\mathcal{E}_{t'}, and each is computable from stored training representations.

Our analysis tells a two-part story. The first part concerns how to use the previous environment. We propose a cross-environment MCM score with two terms (Algorithm 1). The primary term computes the similarity between a test image of the current environment Et′\mathcal{E}_{t'} and the class texts of Et′\mathcal{E}_{t'}, as in standard MCM. The secondary term computes the similarity between the same test image and the class texts of a previous environment Et\mathcal{E}_{t}. The secondary term is added when the two environments are aligned, that is, when their intra-modal contributions are high, and subtracted otherwise. We prove that, under a positive environment transition and a bounded class-matching margin for OOD inputs, the cross-environment score attains a false-positive rate no larger than that of the standard MCM detector at an adjusted threshold, so the secondary term enhances OOD detection when there is a strong connection between environments. The second part explains when detection succeeds or fails. The score gap of an MCM detector between two environments is exactly the self-contribution of the ID environment minus its cross-contribution into the OOD environment. This gap classifies OOD environments as soft, for which a threshold inside the gap certifies a high true-positive rate and a low false-positive rate together with an AUROC lower bound, or hard, for which any threshold that retains the ID data accepts OOD data at nearly the same guaranteed rate; strong intra-modal image alignment between two environments provably induces hardness. When the prototypes of all seen environments are pooled, detection can fail on earlier environments. Underlying both parts is a Contribution Balance Factor (CBF), a mask applied to the gradients of the classification loss and of a smoothed false-positive rate that controls how the contributions of one environment transfer to the next across environments and modalities.

Our contributions are as follows:

• A contribution-theoretic view of continual OOD detection. We show that the moments of an MCM detector are cross-modal contributions, so the separation between two environments reduces to a single computable quantity, the score gap (Definition 3.1, Lemma 4.16).

• Detection that reuses the previous environment. We introduce a cross-environment MCM score whose secondary term is weighted by the alignment between environments, and we prove that it does not increase the false-positive rate of standard MCM (Theorem 4.15). We also characterize the optimal contribution balance factor for the classification loss and for a smoothed false-positive rate (Theorems 4.8 and 4.10), and combine both in a training and detection procedure (Algorithm 1).

• A hard versus soft dichotomy for OOD environments. Soft OOD environments admit explicit AUROC, true-positive, and false-positive guarantees, while hard ones cannot be rejected by any threshold that retains the in-distribution data (Theorems 4.18 and 4.19). Intra-modal alignment between environments provably induces hardness (Proposition 4.20, Corollary 4.21).

• A failure mode of cascaded detection. Pooling the prototypes of all seen environments makes the false-positive rate on every past environment non-decreasing in time, and failure concentrates on environments that were learned well or that are aligned with others (Proposition 4.22, Theorem 4.23, Corollary 4.24).

References (36)