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.
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′, ConTt→It′) and intra-modal (ConIt→It′, ConTt→Tt′) structure between environments Et and Et′, 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′ and the class texts of Et′, as in standard MCM. The secondary term computes the similarity between the same test image and the class texts of a previous environment Et. 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).
2. Related Work
Continual learning. Continual learning mitigates catastrophic forgetting through regularization (Kirkpatrick et al., 2017; Zenke et al., 2017; Aljundi et al., 2018), gradient constraints (Lopez-Paz and Ranzato, 2017; Farajtabar et al., 2020; Saha et al., 2021), and replay (Rebuffi et al., 2017; Rolnick et al., 2019); see Wang et al. (2024) for a survey. For VLMs, prompt-based methods (Wang et al., 2022a,b; Zhou et al., 2022a,b) and adapters (Gao et al., 2025) adapt CLIP while keeping the backbone frozen, and ZSCL (Zheng et al., 2023) preserves zero-shot transfer by reference-model interpolation. These methods target classification accuracy and do not address the rejection of unknown inputs.
OOD detection. Post-hoc detectors use the maximum softmax probability (Hendrycks and Gimpel, 2017), temperature scaling with input perturbation (Liang et al., 2018), Mahalanobis distance (Lee et al., 2018), or free energy (Liu et al., 2020), refined by activation rectification (Sun et al., 2021) and sparsification (Sun and Li, 2022). Training-time methods use auxiliary outliers (Hendrycks et al., 2019) or contrastive representations (Tack et al., 2020), and open-world recognition couples rejection with the discovery of new classes (Bendale and Boult, 2015; Joseph et al., 2021; Vaze et al., 2022). With VLMs, MCM (Ming et al., 2022) matches an image against class text prototypes, CLIPN (Wang et al., 2023) learns explicit rejections, and zero-shot variants (Fort et al., 2021; Esmaeilpour et al., 2022) need no task-specific training; near-OOD inputs remain markedly harder than far-OOD ones (Fort et al., 2021). SCONE (Bai et al., 2023) uses unlabeled wild data, and Temp-SCONE (Naiknaware and Sekeh, 2024) and T-QPM (Naiknaware and Sekeh, 2025) extend it to temporal shift. All of these detectors score an environment using only its own classes.
Theory of OOD detection. Prior theory characterizes when OOD detection is learnable (Fang et al., 2022) and analyzes detection with pretrained VLMs through an information-theoretic lens (Peng et al., 2026), while the modality gap of contrastive VLMs limits cross-modal cosine similarities (Liang et al., 2022). None of these analyses tracks how detection changes across a sequence of environments or how the classes of a previous environment can be used. We provide a contribution-theoretic account of both, with bounds that rest on Cantelli's one-sided inequality (Cantelli, 1928).
3. Preliminaries
Dynamic Vision-Language Data. Data arrives from a sequence of environments E:={E1,…,ET}. At each time step t, the model encounters Dt={xt,i,yt,i}i=1nt from environment Et. In environment Et, the data consist of both vision and language modality samples Dt={It,Tt}, where It={It,i,yt,i}i=1nt and Tt={Tt,i}i=1nt.
Text Pattern Construction: If the ID images are not accompanied with captions, we construct text patterns using the text encoder of the frozen VLM. At time step t, for each class ytid∈
{1,…,Ct}, we employ prompt ensembling over P templates to obtain robust text representations. Let {pct(1),…,pct(P)} denote the set of prompts for class ct in environment Et. The class text embedding is computed as:
where ϕT denotes the frozen CLIP text encoder and normalization is the ℓ2-norm. Collecting all ID class embeddings yields the ID text bank Ttid=[Tt,1,…,Tt,Ct]⊤∈RCt×d, where d is the embedding dimension. Each image It,iid is paired with a text from the ID text bank. Ttid is recomputed at each time step as new class labels arrive.
If the images are already paired with captions, then Ttid=[Tt,1,…,Tt,nt]∈Rnt×d.
Feature Representations: CLIP contains an image encoder f(⋅) and a text encoder g(⋅), designed to extract features from images and text descriptions respectively. Given the pair (image, text) (It,i,Tt,i), the image can be encoded in zt,i=f(It,i)∈Rd×1 and the text can be encoded in ut,i=g(Tt,i)∈Rd×1.
OOD Detection: At inference, at each time step t, the model receives a new environment Et with unlabeled data Dtid and Dtood. The model predicts the label of Dtid and rejects the out-of-distribution (OOD) examples Dtood. Note that Dtid={Itid,Ttid} and Dtood={Itood,Ttood} are collections of image-text pairs. At each time step t, the model encounters multi-modal data drawn from a non-stationary distribution
where Ptid denotes the in-distribution (ID) distribution and Ptood denotes the semantic OOD distribution that should be rejected. The detector must simultaneously: i) maintain classification performance on ID samples, and ii) reduce the false-positive rate (FPR) and increase the area under the receiver operating characteristic (AUROC) on semantic OOD samples.
Classification Loss. When no OOD data is present, the regularized loss in (6) reduces to the classification loss, which combines a cross-entropy term
where ut,cid is the text embedding for class label c in ID dataset and τ is the temperature parameter. The CLIP loss is a sum of two cross entropy losses. The first cross entropy term is the image-to-text loss, which is minimized when the text embedding corresponding to an image has a high dot product with that image. The second term inverts this relationship to form a text-to-image loss.
Combining two losses (3) and (4), we have loss function (5) with weight λt.
L(θt)=LCE(θt)+λtLCLIP(θt).(5)
Loss Function with OOD Detection Regularization. At each time step t, the parameters θt are learned from ID data (xid,y)∼Ptid and OOD data xood∼Ptood with semantic shift:
where L is the classification loss in (5), which combines the cross-entropy loss LCE and the CLIP loss LCLIP, and Lreg is the OOD detection regularization term depending on the detector used, which generally encourages high uncertainty on Ptood.
For both losses (5) and (6), the parameters are obtained as
θt∗=argθtminL(θt)orargθtminLood(θt).
In Section 4, the balance-factor results for the classification objective use the loss in (5), while the results on OOD detection use the regularized loss in (6) together with the detector introduced below.
Cross-Environment OOD Model and Detector. Writing PsI for the marginal law of the images of Es, we adopt the cross-environment OOD model in which the OOD images of Et are images of the other environments,
Ptood=s=t∑wt,sPsI,wt,s≥0,s=t∑wt,s=1,(7)
so that the semantic shifts produced by the continual partition serve as OOD data. To detect OOD data, we use a ranking function gθ:X↦R with parameter θ and threshold λ:
Dθ(x)={IDOODifgθ(x)≥λ,ifgθ(x)<λ.(8)
The threshold λ is typically chosen so that a high fraction of ID data is correctly classified. Write ut,c:=ut,cid,c∈{1,…,Ct}, for the class text prototypes of Et. The cosine form of the maximum concept matching (MCM) score (Ming et al., 2022) of an image x against Et is
St(x)=τ1c∈{1,…,Ct}maxcos(ut,c,f(x)),(9)
which is high for in-distribution and low for OOD images.
Definition 3.1 (Generalized and maximal cross-modal contribution) For any ordered pair of environments (t,s), not necessarily with t<s, let
and define the in-distribution alignment of Et as mt:=ConTt→Itmax.
When s=t′>t and the text embedding in Definition 4.2 is read as a class prototype of Et drawn uniformly, ConTt→Is coincides with ConTt→It′; Definition 3.1 removes the ordering restriction and adds the max-aggregated version used by the detector.
Table 1: Notation. Symbols that appear only inside a single assumption, algorithm, or proof are defined there. The symbol λ denotes both the CLIP loss weight in (5) (λt=λ) and the detection threshold in (8). The meaning is fixed by context.
Symbol
Meaning
Defined in
Environments and data
Et,t=1,…,T
environment at step t (with t<t′)
Sec. 3
Dt,nt,Ct
data, sample size, and classes of Et
Sec. 3
It,Tt
images and texts of Et
Sec. 3
Ptid,Ptood
ID and OOD data distributions
(2)
PsI,wt,s
image law of Es; OOD mixture weight
(7)
Encoders and losses
f,g
image and text encoders
Sec. 3
zt,i,ut,i
image and text embeddings
Sec. 3
ut,c
text prototype of class c in Et
(3)
τ
temperature
(3)
LCE,LCLIP
cross-entropy and CLIP losses
(3), (4)
L(θt),λt
classification loss and its CLIP weight
(5)
Lood,Lreg,λood
regularized loss; regularizer; weight
(6)
Contributions and balance factor
ConIt→It′, ConIt→It′
intra-modal contributions
Def. 4.1
ConIt→It′, ConIt→It′
cross-modal contributions
Def. 4.2
ConEt→Et′, α
environment contribution; threshold
Def. 4.3
ConTt→Ismax,mt
maximal contribution; ID alignment
Def. 3.1
Pt→t′, Pt→t′(i)
balance factor; per-sample version
Def. 4.4
St,yiid
intra-environment alignment score
(17)
FPRt→t′, FPRt′, nt′ood
FPRs of the two MCM scores; OOD count
(18)
FPRt→t′, β
smoothed FPR; sharpness
(19)
OOD detection
Dθ,gθ,λ
detector; ranking function; threshold
(8)
si(It′test),si(It→t′test)
cosine with class text i of Et′ and of Et
(23)
SMCM(Ittest)
intra-environment MCM score
(22)
SMCM(It→t′test)
cross-environment MCM score
(23)
At→t′∗
environment alignment factor
(24)
St(x),ℓ
cosine MCM score; threshold ℓ=τλ
(9)
TPRt,FPRt,AUROCt
rates for ID Et vs. OOD Es
(28)
γt,s,νt,s,η
score gap; spread; soft/hard margin
(30)
δt
true-class misalignment
(33)
Uk,S(k),ρk,s
pooled prototypes, score; pollution
(35), (36)
4. Theory
We analyze in continual VLMs over a sequence of environments E:={E1,E2,…,ET} how the intra-modality and cross-modality contributions govern the transfer between environments and the detection of OOD examples. We state the intra- and cross-modal contribution measurements in our analysis.
Definition 4.1 (Intra-Modal Contribution) The image Itid from environment Et with class Ct, σI-contributes in feature representation of images Itid in environment Et′ if and only if
Similarly the text Ttid from environment Et with class Ct, σT-contributes in feature representation of text Ttid in environment Et′ if and only if
Definition 4.2 (Cross-Environment Cross-Modal Contribution) The image Itid from environment Et with class Ct, σIT-contributes in feature representation of text Ttid in environment Et′ if and only if
In both Def. 4.1 and 4.2, cos(⋅,⋅) is cosine similarity and 0≤σI,σT,σIT,σTI≤1.
Definition 4.3 Two environments Et and Et′ are aligned if and only if ConEt→Et′:=ConIt→It′+ConTt→Tt′>α for a threshold α, with the intra-modal contributions of Def. 4.1.
4.1. Cross-modality contribution balance factor bridges the gap between environments
We next show how controlling the balance of cross-modality contributions affects the transition between environments. We mainly seek to investigate the central question: How modal contribution balance factor controls intra- and cross-modal contribution between environments?
Definition 4.4 (Cross-Modal Contribution Balance Factor) We define contribution balance factor (CBF) from Et to Et′ by Pt→t′∈{0,1}d which is optimized by
We define the cross-modal CBF from Et to sample (xt′,i,yt′,i) as Pt→t′(i).
The assumptions below play distinct roles: Assumptions 4.5 and 4.6 focus on the normalized components of LCE and LCLIP, assuming that their gradient drift is sufficiently large, whereas Assumption 4.7 bounds the overall gradient magnitude of the loss function.
Assumption 4.5 (Sufficient class-normalized gradient drift) We assume that the cross-modal CBF is sufficiently effective in average over all labels:
Assumption 4.7 (Slow gradient) The magnitude of the gradient of loss changes slowly i.e. ∥∇θL(θt)∥2=O(1/ξ), which implies 1/∥∇θL(θt)∥2=Ω(ξ).
Theorem 4.8 (Optimal CBF via intra-environment alignment scores) Under Assumptions 4.5-4.7, the optimal Pt→t′∗ for the classification loss L(θt′) in (5) is alternatively achieved by
Remark. Note that the scores in (17) differ from the cross-modal contributions defined in Def. 4.2, even though both are based on dot products. Intra-environment alignment captures relationships within a single environment and does not aggregate information across environments. In contrast, our cross-modal contribution scores bridge vision and language embeddings across evolving environments, facilitating the transfer of cross-modal information to subsequent learning stages.
In the regularized loss Lood in (6), we take the regularization term Extood∼Ptood[Lreg(fθt(xtood))] to be the false-positive rate of the cross-environment MCM detector, defined as
where β controls the sharpness and σ is sigmoid function.
Assumption 4.9 (FPR Slow gradient) The magnitude of the gradient of FPR changes slowly i.e. ∥∇θFPRt→t′∥2=O(1/ξt→t′), which implies 1/∥∇θFPRt→t′∥2=Ω(ξt→t′).
Theorem 4.10 (Optimal CBF for the smoothed FPR) Under Assumption 4.9, the optimal Pt→t′∗ for OOD detection regularization i.e. FPR (OOD loss) is given by
where, for the i-th OOD image, sj,t′ and sj,t→t′ are the similarities sj(Ii,t′ood) and sj(Ii,t→t′ood) in (23), pj,t′ and pj,t→t′ are the corresponding softmax probabilities, k is the class attaining the maximum in (23), and Cσ,k, ρ^max,t→t′, and ξt→t′ are constants.
Algorithm 1 combines the two balance factors of Theorems 4.8 and 4.10 into one training procedure and uses the cross-environment MCM score of Definition 4.12 at test time. Both objectives Stid[Pt→t′(i)] and Δt→t′[Pt→t′(i)] are linear in the binary mask, since ∥P⊙v∥2=∑jPjvj2; under a budget of b retained coordinates, each per-sample maximization therefore keeps the b coordinates with the largest weights. The secondary text bank of the previous environment is used only through the alignment factor At→t′∗, which adds its concept matches when Et and Et′ are aligned and subtracts them otherwise.
4.2. Environment-Aware Zero-Shot OOD Detection
We assume that the CLIP (or VLM) has been trained in each environment using (5) or (6) and the training image and text representations are stored for contribution computations.
Cross-Modal Contribution and MCM Score
Definition 4.11 (Intra-Environment MCM Score Ming et al. (2022))
Algorithm 1 Contribution-balanced continual training and environment-aware OOD detection
3: t←t′−1; compute ConIt→It′, ConTt→Tt′ from stored representations (Def. 4.1)
4: ConEt→Et′←ConIt→It′+ConTt→Tt′
5: At→t′∗←+ConEt→Et′ if ConEt→Et′>α, and −ConEt→Et′ otherwise (24)
6: end if
7: repeat
8: P(i)←argmax∥P∥0=bStid[P] for each ID sample i (Theorem 4.8)
9: Pid←nt′1∑i=1nt′P(i)
10: G←Pid⊙∇θL(θt′) (5)
11: if t′>1 then
12: P(i)←argmax∥P∥0=bΔt→t′[P] for each OOD sample i (Theorem 4.10)
13: Pood←nt′ood1∑i=1nt′oodP(i)
14: G←G+λoodPood⊙∇θFPRt→t′(τ,λ) (19)
15: end if
16: θ←θ−ηlrG
17: until convergence on Dt′
18: store the training image and text representations of Et′
19: end for
20: Detection at step t′: for a test image It′test, set zt′←f(It′test)
21: si(It′test)←cos(zt′,ut′,i) for i=1,…,C (primary term)
22: si(It→t′test)←cos(zt′,ut,i) for i=1,…,C (secondary term)
23: return ID if SMCM(It→t′test)≥λ and OOD otherwise (23)
At timestep t, for a given task with label set Yin={y1,y2,...,yC}, and a collection of concept vectors T(ti),i∈{1,2,...,C}, where ti is the text prompt “this is a photo of a --label--” for a label yi. At time step t, for any test image Ittest, the MCM score is defined by
where τ is the temperature and si is the cosine similarity between the image embedding zt=f(Ittest) and the text embedding ut,i:=g(Tttrain(ti)). Recall the OOD detector Dθ in (8) and replace gθ with SMCM to compute MCM-based OOD detector.
We define cross-environment MCM score under the setup that ID inputs are accompanied by text descriptions (label captions for ID data) as follows:
Definition 4.12
(Cross-Environment MCM Score) Consider two environments Et and Et′, t<t′ with label sets Yin,t={yt,1,yt,2,...,yt,C} and Yin,t′={yt′,1,yt′,2,...,yt′,C} and collection of concepts vectors
Tt,i,Tt′,i,for i=1,…,C. Without loss of generality we assume that both environments have the same class size. At time step t′, for any test image input It′test, the cross-environment MCM score is defined as
where si(It′test) is the cosine similarity between test image encoder zt′=f(It′test) and train text encoder in Et′ut′,i:=g(Tt′train(ti)). si(It→t′test) is the cosine similarity between test image encoder zt′=f(It′test) in Et′ and train text encoder in Etut,i:=g(Tttrain(ti)). The environment alignment factor At→t′∗ is determined by intra-modal contribution in Def. 4.1:
where ConEt→Et′ and alignment are as in Definition 4.3.
Remark: The similarity score si(It→t′test) in (23), is the cross-modal contribution in Def. 4.2 in the presence of a test image when image encoder f and text encoder g are trained on training image in environment t′ and text in environment t, respectively.
Assumption 4.13 (Positive Environment Transition) We assume that the two environments Et and Et′, t<t′ have a positive transition if the softmax normalizer of the secondary term is at least that of the primary term, i.e.
j=1∑Cesj(It′test)/τ≤j=1∑Cesj(It→t′test)/τ.
Assumption 4.14 (Optimal Class Connections) Define y^t→t′:=argmaxi∈[C]si(It→t′test) to be largest cross-environment cosine similarities for an OOD input I. And y^t′:=argmaxi∈[C]si(It′test) to be the largest intra-environment cosine similarities for an OOD input I. Then ∃δ≥0 and ∃M≥0.
where ConEt→Et′=2−σI−σT (Def. 4.3) and κ is an upper bound for sy^t→t′(It′test).
Theorem 4.15 (Cross-environment contribution improves FPR.) Consider a pre-trained CLIP-like model. If the OOD distribution PIt′testood of test images in Et′ satisfies Assumptions 4.13 and 4.14, then
Not all OOD inputs are equally difficult to reject: images from an environment whose content is close to the ID environment are hard, whereas semantically distant ones are soft. We make this precise with Definition 3.1. Throughout, the detector Dθ in (8) uses gθ=St in (9) with threshold λ, and ℓ:=τλ∈(−1,1) is the threshold in cosine units. For an ID environment Et and an OOD environment Es, s=t, let X∼PtI and X′∼PsI be independent and define
Let γt,s:=τ(E[St(X)]−E[St(X′)]) be the score gap, vtid:=Var(τSt(X)) and vt,sood:=Var(τSt(X′)), and νt,s:=vtid+vt,sood≤2 the score spread. Proofs of the results in this subsection are given in Appendix A.4.
Lemma 4.16 (Detector moments are contributions) For any s=t, τE[St(X)]=mt and τE[St(X′)]=ConTt→Ismax≥ConTt→Is; hence
Definition 4.17 (Hard and soft OOD) Let η>0. An environment Es is η-soft OOD for Et if γt,s≥η, and η-hard OOD if γt,s≤η; it is strictly hard if γt,s<0. By Lemma 4.16, ConTt→Is≥mt−η suffices for η-hardness.
Theorem 4.18 (Soft OOD is provably separable) If Es is η-soft OOD for Et, then AUROCt(s)≥η2/(η2+νt,s)≥η2/(η2+2), and at the threshold ℓ=mt−η/2,
Theorem 4.19 (Hard OOD cannot be reliably rejected) If Es is η-hard OOD for Et, then the certificate of Theorem 4.18 is at most η2/(η2+νt,s), and for every threshold with ℓ<mt−η,
FPRt(s;λ)≥1−ℓmt−η−ℓ,TPRt(λ)≥1−ℓmt−ℓ,(32)
so the guaranteed acceptance rates of ID and hard OOD images differ by at most η/(1−ℓ). If Es is strictly hard, then AUROCt(s)≤νt,s/(νt,s+(ConTt→Ismax−mt)2).
Theorems 4.18 and 4.19 split OOD environments by the single number (30): for soft OOD, a threshold inside the gap certifies a high TPR and a low FPR simultaneously, whereas for hard OOD any threshold that retains the ID data also accepts OOD data at nearly the same guaranteed rate. Hardness is induced by intra-modal alignment. Let
δt:=1−E(x,y)∼Ptid[cos(ut,y,f(x))](33)
be the true-class misalignment of Et; for ℓ2-normalized embeddings, δt=1−τE[St,yiid] with St,yiid in (17).
Proposition 4.20 (Intra-modal alignment induces hardness) If (x,y)∼Ptid and x′∼PsI are coupled so that E[cos(f(x),f(x′))]=ConIt→Is=1−σI (Definition 4.1), then
ConTt→Ismax≥1−(δt+σI)2.(34)
Corollary 4.21 (Aligned environments are hard OOD) If ConIt→Is≥1−σˉ and 1−(δt+σˉ)2≥mt−η, then Es is η-hard OOD for Et and (32) applies.
Corollary 4.21 explains the sign of At→t′∗ in (24): images of an aligned environment behave as near-ID under St, so their concept matches are added rather than subtracted. Because pre-trained CLIP separates image and text embeddings (Liang et al., 2022), δt is large before adaptation, and (34) becomes informative as adaptation reduces the true-class misalignment.
4.4. Cascaded OOD Detection Failure
In continual deployment, detection cascades over the environments seen so far. Environments arrive in an order π=(π1,…,πT), and after step k the detector uses the pooled prototype set and score
At step k, images of Eπk are ID and images of a past environment Eπs, s<k, are OOD. With X∼PπkI and X′∼PπsI independent, FPR(k)(s;λ), AUROC(k)(s), γs(k), and νs(k)≤2 are defined as in (28)–(29) with S(k) in place of St. Let
be the pollution level of Eπs and the mean pooled ID score. Proofs are given in Appendix A.5.
Proposition 4.22 (Monotone prototype pollution) For every image x, step k, and threshold λ: S(k)(x)≤S(k+1)(x); FPR(k)(s;λ)≤FPR(k+1)(s;λ) for every past environment s<k; and τEx∼PπsI[S(k)(x)]≥ρk,s for every s≤k.
Environment-Dependent Failure. Once an environment’s prototypes enter the pool, its images score at least its own alignment, so failure is a property of each past environment.
Theorem 4.23 (Environment-dependent failure of cascaded detection) For every past environment s<k, γs(k)≤Mk−ρk,s. If ρk,s>Mk, then AUROC(k)(s)≤νs(k)/(νs(k)+(ρk,s−Mk)2). For every threshold with ℓ=τλ<ρk,s and every later step k′≥k,
FPR(k′)(s;λ)≥1−ℓρk,s−ℓ≥1−ℓmπs−ℓ.(37)
Corollary 4.24 (Which environments fail) Let s<k and ℓ<mπs. Every past environment is falsely accepted at rate at least (mπs−ℓ)/(1−ℓ) at every later step, so better-learned environments fail more. Moreover, by Proposition 4.20, ρk,s≥maxj≤k,j=s[1−(δπj+σI(πj,πs))2] with 1−σI(πj,πs)=ConIπj→Iπs, so past environments that are image-aligned with any seen environment satisfy (37) with a large ρk,s.
Cascaded failure is therefore a property of the environments and their order rather than of the detector: it concentrates on well-learned or aligned past environments and, at a fixed threshold, can only worsen over time. Uniform pooling is the source of the failure, which motivates scores such as (23) that weight other environments by their alignment instead of pooling them.
5. Conclusion
We studied out-of-distribution detection for vision–language models that encounter a sequence of environments. Our analysis rests on pairwise contribution scores. These scores are cosine expectations between the image and text features of two environments. We showed that they govern when detection succeeds or fails.
First, we proposed a cross-environment MCM score. The score adds the concept matches of a previous environment when the two environments are aligned. It subtracts them when the environments are not aligned. Under the assumptions of Theorem 4.15, this score does not increase the false-positive rate of the standard MCM detector. A contribution balance factor applied to the gradients of the classification loss and of a smoothed false-positive rate gives the training procedure in Algorithm 1.
Second, we showed that the score gap of an MCM detector equals the self-contribution of the ID environment minus its cross-modal contribution into the OOD environment. This gap separates soft OOD environments from hard ones. For a soft OOD environment, a threshold inside the gap certifies a high true-positive rate, a low false-positive rate, and an AUROC lower bound. A hard OOD environment cannot be reliably rejected by any threshold that retains the in-distribution data. Intra-modal alignment between two environments provably makes one hard OOD for the other.
Third, we studied cascaded detection, in which the prototypes of all seen environments are pooled. At a fixed threshold, the false-positive rate on every past environment can only grow over time. Failure concentrates on environments that were learned well or that are aligned with other seen environments.
Our guarantees rely on assumptions about the transition between environments, the class-matching margin of OOD inputs, and the magnitude of the loss gradient. We do not verify these assumptions here. The separability bounds are distribution-free and therefore conservative. Tighter bounds under sub-Gaussian score tails, an analysis that combines more than one previous environment, and an empirical evaluation of Algorithm 1 are natural next steps.
Acknowledgments
This work has been partially supported by NSF CAREER CCF-2451457. The findings are those of the authors only and do not represent any position of these funding bodies.
References
R. Aljundi, F. Babiloni, M. Elhoseiny, M. Rohrbach, and T. Tuytelaars. Memory aware synapses: Learning what (not) to forget. In Proc. ECCV, 2018.
H. Bai, Z. Ming, and Y. Li. Feed two birds with one scone: Exploiting wild data for both out-of-distribution generalization and detection. In Proc. ICML, 2023.
A. Bendale and T. Boult. Towards open world recognition. In Proc. CVPR, 2015.
F. P. Cantelli. Sui confini della probabilità. In Atti del Congresso Internazionale dei Matematici, Bologna, 3–10 Settembre 1928, volume 6, pages 47–59, 1928.
S. Esmaeilpour, B. Liu, E. Robertson, and L. Shu. Zero-shot out-of-distribution detection based on the pre-trained model clip. In Proc. AAAI, 2022.
Z. Fang, Y. Li, J. Lu, J. Dong, B. Han, and F. Liu. Is out-of-distribution detection learnable? In Proc. NeurIPS, 2022.
M. Farajtabar, N. Azizan, A. Mott, and A. Li. Orthogonal gradient descent for continual learning. In Proc. AISTATS, 2020.
S. Fort, J. Ren, and B. Lakshminarayanan. Exploring the limits of out-of-distribution detection. In Proc. NeurIPS, 2021.
D. Hendrycks and K. Gimpel. A baseline for detecting misclassified and out-of-distribution examples in neural networks. In Proc. ICLR, 2017.
D. Hendrycks, M. Mazeika, and T. Dietterich. Deep anomaly detection with outlier exposure. In Proc. ICLR, 2019.
K. J. Joseph, S. Khan, F. S. Khan, and V. Balasubramanian. Towards open world object detection. In Proc. CVPR, 2021.
J. Kirkpatrick, R. Pascanu, N. Rabinowitz, J. Veness, G. Desjardins, A. A. Rusu, K. Milan, J. Quan, T. Ramalho, A. Grabska-Barwinska, D. Hassabis, C. Clopath, D. Kumaran, and R. Hadsell. Overcoming catastrophic forgetting in neural networks. PNAS, 114(13):3521–3526, 2017.
K. Lee, K. Lee, H. Lee, and J. Shin. A simple unified framework for detecting out-of-distribution samples and adversarial attacks. In Proc. NeurIPS, 2018.
S. Liang, Y. Li, and R. Srikant. Enhancing the reliability of out-of-distribution image detection in neural networks. In Proc. ICLR, 2018.
W. Liang, Y. Zhang, Y. Kwon, S. Yeung, and J. Zou. Mind the gap: Understanding the modality gap in multi-modal contrastive representation learning. In Proc. NeurIPS, 2022.
W. Liu, X. Wang, J. Owens, and Y. Li. Energy-based out-of-distribution detection. In Proc. NeurIPS, 2020.
D. Lopez-Paz and M. Ranzato. Gradient episodic memory for continual learning. In Proc. NeurIPS, 2017.
Yifei Ming, Ziyang Cai, Jiuxiang Gu, Yiyou Sun, Wei Li, and Yixuan Li. Delving into out-of-distribution detection with vision-language representations. Advances in neural information processing systems, 35:35087–35102, 2022.
A. Naiknaware and S. Y. Sekeh. Temp-scone: A novel out-of-distribution detection and domain generalization framework for wild data with temporal shift, 2024. arXiv:2512.04571.
A. Naiknaware and S. Y. Sekeh. T-qpm: Enabling temporal out-of-distribution detection and domain generalization for vision-language models in open-world, 2025. arXiv:2603.18481.
Bo Peng, Jie Lu, Guangquan Zhang, and Zhen Fang. An information-theoretical framework for understanding out-of-distribution detection with pretrained vision-language models. Advances in Neural Information Processing Systems, 38:1930–1957, 2026.
A. Radford, J. W. Kim, C. Hallacy, A. Ramesh, G. Goh, S. Agarwal, G. Sastry, A. Askell, P. Mishkin, J. Clark, G. Krueger, and I. Sutskever. Learning transferable visual models from natural language supervision. In Proc. ICML, 2021.
S.-A. Rebuffi, A. Kolesnikov, G. Sperl, and C. H. Lampert. icarl: Incremental classifier and representation learning. In Proc. CVPR, 2017.
D. Rolnick, A. Ahuja, J. Schwarz, T. Lillicrap, and G. Wayne. Experience replay for continual learning. In Proc. NeurIPS, 2019.
G. Saha, I. Garg, and K. Roy. Gradient projection memory for continual learning. In Proc. ICLR, 2021.
Y. Sun and Y. Li. Dice: Leveraging sparsification for out-of-distribution detection. In Proc. ECCV, 2022.
Y. Sun, C. Guo, and Y. Li. React: Out-of-distribution detection with rectified activations. In Proc. NeurIPS, 2021.
J. Tack, S. Mo, J. Jeong, and J. Shin. Csi: Novelty detection via contrastive learning on distributionally shifted instances. In Proc. NeurIPS, 2020.
S. Vaze, K. Han, A. Vedaldi, and A. Zisserman. Generalized category discovery. In Proc. CVPR, 2022.
H. Wang, Y. Li, H. Yao, and X. Li. Clipn for zero-shot out-of-distribution detection: Teaching clip to say no. In Proc. ICCV, 2023.
Liyuan Wang, Xingxing Zhang, Hang Su, and Jun Zhu. A comprehensive survey of continual learning: Theory, method and application. IEEE transactions on pattern analysis and machine intelligence, 46(8):5362–5383, 2024.
Z. Wang, Z. Zhang, C.-Y. Lee, H. Zhang, R. Sun, X. Ren, G. Su, V. Perot, J. Dy, and T. Pfister. Learning to prompt for continual learning. In Proc. CVPR, 2022a.
Z. Wang, Z. Zhang, H. Zhang, C.-Y. Lee, R. Sun, X. Ren, G. Su, V. Perot, J. Dy, and T. Pfister. Dualprompt: Complementary prompting for rehearsal-free continual learning. In Proc. ECCV, 2022b.
F. Zenke, B. Poole, and S. Ganguli. Continual learning through synaptic intelligence. In Proc. ICML, 2017.
Z. Zheng, M. Ma, K. Wang, Z. Qin, X. Yue, and Y. You. Preventing zero-shot transfer degradation in continual learning of vision-language models. In Proc. ICCV, 2023.
K. Zhou, J. Yang, C. C. Loy, and Z. Liu. Learning to prompt for vision-language models. IJCV, 130(9):2337–2348, 2022a.
Kaiyang Zhou, Jingkang Yang, Chen Change Loy, and Ziwei Liu. Conditional prompt learning for vision-language models. In Proc. CVPR, pages 16816–16825, 2022b.
Appendix A. Proofs
A.1. Proof of Theorem 4.8
Proof Recall the total loss function L(θt) for Et in (5) and take gradient w.r.t parameter θ
∇θL(θt)=∇θLCE(θt)+λt∇θLCLIP(θt).(38)
Next step is to apply CBF from Et to Et′, i.e. Pt→t′⊙∇θL(θt′) from Def. 4.4 in both sides of (38).
where Ω(ξt′)=λΩ(ξˉt′)+Ω(ξt′). Note that Ω(ξt′) has the same dimension as ∇θL(θt′). Taking L2-norm from LHS and RHS of (44) and using ∥a∥2=∥−a∥2, leads to
where ρ^max,t→t′ is maximum remainder and Cσ,k=CσCk.
A.3. Proof of Theorem 4.15
For two environments Et, Et′ ( t<t′) with label sets Yin,t={yt,1,yt,2,...,yt,C} and Yin,t′={yt′,1,yt′,2,...,yt′,C} and collection of concepts vectors Tt,i, Tt′,i, for i=1,…,C. Without loss of generality we assume that both environments have the same class size. We define the cross-environment maximum concept matching (MCM) score
where si(It′test) is the cosine similarity between test image encoder zt′=f(It′test) and trained text encoder in Et′ut′,i:=g(Tt′train(ti)). si(It→t′test) is the cosine similarity between test image encoder zt′=f(It′test) in Et′ and train text encoder in Etut,i:=g(Tttrain(ti)). The environment alignment factor At→t′∗ is determined by intra-modal contribution in Def. 4.1:
Proof Let z:=1{yt′∈Yin,t′} and PIt′testood:PIt′test∣z=0 (i.e the marginal distribution of It′ conditioned on z=0) denotes the out-of-distribution for image It′. By definition, the false positive rate FPR(τ,λ) is computed as
where y^t→t′:=argmaxi∈[C]si(It→t′test) is largest cross-environment cosine similarities for an OOD input I. And y^t′:=argmaxi∈[C]si(It′test) is the largest intra-environment cosine similarities for an OOD input I. Note that y^t′ and y^t→t′ are different classes.
The inequality in (60) is based on Assumption 4.13. Note that because of Et and Et′ are aligned therefore At→t′∗ is positive. By inequality eu≥1+u, we have,
where λ′=(1−Cλ1)τ. Recalling Definition 4.1 and the environment alignment factor (57), we have At→t′∗=2−σI−σT. Under Assumption 4.14 (b), ∃M≥0 such that
where y^t′:=argmaxi∈[C]si(It′test). The Ineq. (67) holds true because the normalized term ∑j=1Cesj(It′test)/τ is bounded. This concludes that
FPRt→t′(τ,λ)≤FPRt′(τ,λt′),λt′:=M′τ(λ′−δ).
A.4. Proofs for Section 4: hard and soft OOD
Throughout we use Cantelli's one-sided inequality (Cantelli, 1928): for a random variable W with mean μ and variance v, and any a>0, Pr[W−μ≤−a]≤v/(v+a2) and Pr[W−μ≥a]≤v/(v+a2). We also use the following bound for variables bounded above: if W≤1 has mean μ and ℓ<1, then μ≤ℓPr[W<ℓ]+Pr[W≥ℓ]=ℓ+(1−ℓ)Pr[W≥ℓ], so
Pr[W≥ℓ]≥1−ℓμ−ℓ.(68)
Proof of Lemma 4.16 By (9), τSt(x)=maxccos(ut,c,f(x)); taking expectations under PtI and PsI gives mt and ConTt→Ismax by Definition 3.1. A maximum over the classes dominates their uniform average pointwise, which gives ConTt→Ismax≥ConTt→Is.
Proof of Theorem 4.18 Let D=τ(St(X)−St(X′)). By independence, E[D]=γt,s≥η>0 and Var(D)=νt,s, so Cantelli gives Pr[D≤0]≤νt,s/(νt,s+γt,s2) and AUROCt(s)≥Pr[D>0]≥γt,s2/(γt,s2+νt,s). Since g↦g2/(g2+ν) is non-decreasing on g>0, this is at least η2/(η2+νt,s), and νt,s≤2 gives the last inequality. For the rates, τSt(X) has mean mt and variance vtid, so 1−TPRt(λ)=Pr[τSt(X)<mt−η/2]≤vtid/(vtid+η2/4). The variable τSt(X′) has mean μ′≤mt−η, so FPRt(s;λ)≤Pr[τSt(X′)−μ′≥η/2]≤vt,sood/(vt,sood+η2/4). The outer bounds use vtid,vt,sood≤1.
Proof of Theorem 4.19 The first claim follows from Definition 4.17 and the monotonicity of g↦g2/(g2+ν). For (32), apply (68) to W=τSt(X′), whose mean is ConTt→Ismax≥mt−η, and to W=τSt(X), whose mean is mt (Lemma 4.16); note that St≥λ if and only if τSt≥ℓ. If Es is strictly hard, then with D as above E[D]=γt,s<0, so AUROCt(s)≤Pr[D≥0]=Pr[D−γt,s≥∣γt,s∣]≤νt,s/(νt,s+γt,s2) by Cantelli, and ∣γt,s∣=ConTt→Ismax−mt by (30).
Proof of Proposition 4.20 Let a,b,c be the unit vectors along ut,y, f(x), and f(x′). For unit vectors ∥a−b∥2=2(1−cos(a,b)), so the triangle inequality ∥a−c∥≤∥a−b∥+∥b−c∥ gives, pointwise,
1−cos(a,c)≤(1−cos(a,b)+1−cos(b,c))2.
Expanding the square, taking expectations, and applying the Cauchy–Schwarz inequality E[UV]≤E[U]E[V] to the cross term yields E[1−cos(a,c)]≤(δt+σI)2. Finally, maxc′cos(ut,c′,f(x′))≥cos(ut,y,f(x′)) pointwise and x′ has marginal law PsI, so ConTt→Ismax≥E[cos(a,c)].
Proof of Corollary 4.21 Here σI≤σˉ, and the right-hand side of (34) is non-increasing in σI; combine with Definition 4.17.
A.5. Proofs for Section 4: cascaded detection
Proof of Proposition 4.22 Since Uk⊆Uk+1 and a maximum over a larger set is no smaller, S(k)(x)≤S(k+1)(x); hence {S(k)(X′)≥λ}⊆{S(k+1)(X′)≥λ}, which gives the monotonicity of the false-positive rate. For each j≤k, Uk contains the prototypes of Eπj, so τS(k)(x)≥maxccos(uπj,c,f(x)) pointwise; taking Ex∼PπsI gives ConTπj→Iπsmax, and j=s gives mπs.
Proof of Theorem 4.23 By Proposition 4.22, τE[S(k)(X′)]≥ρk,s, so γs(k)=Mk−τE[S(k)(X′)]≤Mk−ρk,s; moreover Mk≤1 since τS(k)≤1, and Mk≥mπk since Uk contains the prototypes of Eπk. If ρk,s>Mk, then γs(k)<0 with ∣γs(k)∣≥ρk,s−Mk, and the Cantelli argument in the proof of Theorem 4.19, applied to D=τ(S(k)(X)−S(k)(X′)), gives the AUROC bound. Finally, (68) applied to W=τS(k)(X′), whose mean is at least ρk,s, gives (37) at step k; Proposition 4.22 extends it to every k′≥k, and ρk,s≥mπs.
Proof of Corollary 4.24 The first claim is the second inequality in (37). The second follows from ρk,s≥ConTπj→Iπsmax for each j=s and (34) applied to the pair (πj,πs).