Official implementation of the D3M algorithm for provable post-deployment deterioration monitoring. D3M:
- Flags deteriorating shifts in the unsupervised deployment data distribution
- Resists flagging non-deteriorating shifts, unlike classical OOD detection leveraging distances and/or metrics between data distributions.
-
Train: A feature extractor (
$FE_\theta$ ) and a Variational Bayesian Last Layer ($VBLL_\theta$ ) are trained to model a posterior predictive distribution (PPD) over class logits. -
Calibrate: Disagreement statistics are computed by bootstrapping held-out in-distribution (ID) datasets, sampling from the learned posteriors, and comparing sampled predictions to the base model’s outputs to collect a set of maximum disagreement rates
$\Phi$ . For illustrative purposes, agreements and disagreements between$\hat{y}^{(3)}$ and$\bar{y}$ are colored green and orange, respectively. -
Deploy: At deployment, D3M monitors the model on incoming unlabeled data by computing the maximum disagreement rate
$\tilde{\phi}$ and flags a deteriorating shift if$\tilde{\phi} \geq \text{Quantile}_{1-\alpha}(\Phi)$ .
Importantly, upon the completion of Calibrate, no training data is required at deployment, an important advantage over competitive baselines requiring computations of certain statistics on the training set at deployment time.
First, cd into the working directory:
cd d3m/
In this example, we use anaconda3. Create a new d3m environment:
conda create -n d3m python=3.11
conda activate d3m
pip install -r requirements.txt
This repository uses Hydra (hydra-core on PyPI) in order to streamline hyperparameter loading. Best hyperparameter presets are provided in d3m/experiments/configs/. In the paper, the test size d3m.data_sample_size in our configuration, available to all experiments.
The Camelyon17 dataset and CIFAR-10 dataset will be automatically installed the first time experiments/run.py is run using their corresponding configs. To install the UCI Heart Disease preprocessed dataset as well as the CIFAR-10.1 dataset, run:
chmod +x install_datasets.sh
./install_datasets.sh
Warning: the Camelyon17 dataset takes a long time to download and process.
All experiments are run as follows. For example, to run the UCI Heart Disease with d3m environment and run:
python experiments/run.py --config-name=uci_best d3m.data_sample_size=100
Optional arguments:
-
wandb_enabled: enabled by default, setting it to False disables live-logging withwandb. Will require logging in with awandbaccount. -
self_log: enabled by default, setting it to False,run.pywill not write results intoresults/<name_of_dataset>_<d3m.data_sample_size>.csv. -
seed: set to$57$ by default.
For a given dataset, run experiments/run.py with the same configuration and the same d3m.data_sample_size, incrementing the seed by self_log. We recommend doing 20-50 runs at low
In short, training a D3MMonitor consists of a three steps.
- Train the base model of the monitor on I.D. training data
- With a held-out set of I.D. validation data, train the distribution of I.D. disagreement rates (Phi) of the monitor
- Deploy the base model and monitor by periodically running
d3m_teston batches of unsupervised deployment data
When d3m_test returns True, the monitor recognizes that the base model may severely underperform on the unsupervised deployment data. This is the cue for ML practitioners to inspect the problem further and consider further measures such as adapting and retraining.
For a full tutorial on how to deploy d3m to monitor a downstream task, consider running the guidebook tutorials/classification.ipynb where we train a D3MBayesianMonitor to monitor an induced deteriorating shift on the UCI Heart Disease dataset.
