Zero-Training Hidden-State Monitoring for Robustness in Vision, Language, and Generative Models
Project description
DeepDrift
DeepDrift is a runtime neural network monitoring library based on analyzing the rate of change of hidden states (Semantic Velocity). It requires no additional training, calibrates only on normal data, and introduces <1.5% computational overhead.
Installation
# Install from source
git clone https://github.com/Eutonics/DeepDrift.git
cd DeepDrift
pip install .
# Or via pip (after publication)
# pip install deepdrift
Quick Start (ViT OOD)
from deepdrift import DeepDriftMonitor
from torchvision.models import vit_b_16
import torch
model = vit_b_16(pretrained=True)
monitor = DeepDriftMonitor(
model,
layer_names=['encoder.layers.5', 'encoder.layers.11'],
pooling='cls'
)
x = torch.randn(1, 3, 224, 224)
_ = model(x)
velocities = monitor.get_spatial_velocity()
print(f"Peak velocity: {max(velocities):.4f}")
Use Cases
1. OOD Detection in Vision Transformers
Use DeepDriftVision for automatic calibration and Out-of-Distribution
detection.
Dataset Metric AUC (DeepDrift)
CIFAR-100 (In) - - SVHN (OOD) Peak Velocity 0.982 LSUN (OOD) Peak Velocity 0.975
from deepdrift import DeepDriftVision
monitor = DeepDriftVision(model)
monitor.fit(train_dataloader)
diagnosis = monitor.predict(test_batch)
if diagnosis.is_anomaly:
print("OOD detected!")
2. Predicting RL Agent Collapse
from deepdrift.rl import DeepDriftRL
monitor = DeepDriftRL(agent.policy, threshold=0.15)
for obs in episode:
diag = monitor.step(obs)
if diag.is_anomaly:
print(f"Warning: High instability detected! Velocity: {diag.peak_velocity}")
3. Hallucination Detection in LLMs
from deepdrift import DeepDriftGuard
guard = DeepDriftGuard(llm_model)
for token in generation_loop:
diag = guard(token)
if diag.is_anomaly:
print("Possible hallucination detected.")
4. Early Memorization Detection in Diffusion Models
See experiments/diffusion_memorization.py.
API Reference
DeepDriftMonitor
__init__(model, layer_names, pooling, n_channels, ...)get_spatial_velocity()get_temporal_velocity()calibrate(dataloader)
DeepDriftVision / DeepDriftGuard
Specialized wrappers with simplified API.
Reproducing Experiments
git clone https://github.com/Eutonics/DeepDrift
cd DeepDrift
bash scripts/reproduce_all.sh
Citation
@article{evtushenko2026deepdrift,
title={DeepDrift: Zero-Training Hidden-State Monitoring for Robustness in Vision, Language, and Generative Models},
author={Alexey Evtushenko},
year={2026},
journal={arXiv preprint},
url={https://github.com/Eutonics/DeepDrift}
}
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepdrift-1.1.2.tar.gz.
File metadata
- Download URL: deepdrift-1.1.2.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c85f3bce8587d6597c80d60ab431c344ebc9a2f280a334798d7f897f4f15c72
|
|
| MD5 |
6a18ba9290370a6769c5eb8b3c9aa948
|
|
| BLAKE2b-256 |
6c0e1b6f216d8b7902b9f670e8cd96988aca25fc82d26b291473b48844fd3be1
|
File details
Details for the file deepdrift-1.1.2-py3-none-any.whl.
File metadata
- Download URL: deepdrift-1.1.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c434969572496e407a35a5a1db42df20a8fc4721eaae9cde3e4c2bca83965d
|
|
| MD5 |
31ec71f0844853d6cf9ba139c1513129
|
|
| BLAKE2b-256 |
e92c807c9331721c4c6e3489d0aa24c460d45b2a15dea495fcb0c81a40c0e033
|