Skip to content

fix(drift): make ABCD usable without PyTorch, and default to PCA - #384

Merged
hmgomes merged 1 commit into
adaptive-machine-learning:mainfrom
hmgomes:fix/abcd-torch-gating
Aug 7, 2026
Merged

fix(drift): make ABCD usable without PyTorch, and default to PCA#384
hmgomes merged 1 commit into
adaptive-machine-learning:mainfrom
hmgomes:fix/abcd-torch-gating

Conversation

@hmgomes

@hmgomes hmgomes commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

ABCD reconstructs instances with one of three encoder-decoder models, but only the autoencoder needs PyTorch. PCAModel and KernelPCAModel use scikit-learn, which is a core dependency. All three shared a module whose top-level import torch.nn put the whole detector behind the torch gate, so a default install lost CapyMOA's only multivariate drift detector even for configurations that never touch PyTorch.

AutoEncoder moves to its own module. It subclasses nn.Module, so the import cannot be deferred into a method; a separate file is what lets abcd.py load it lazily and only when model_id="ae" is requested. Asking for that model without the extra raises an error naming the model rather than the detector:

OptionalDependencyError: PyTorch is required for ABCD's autoencoder model (model_id='ae').
Install it with: pip install capymoa[torch]

The default changes from "ae" to "pca", so a plain ABCD() works in a default install. That alters which model an existing caller gets and belongs in the release notes. On the univariate stream in the drift detection notebook the two behave identically (1 detection, 2 warnings, first at 1011), so its stored output is unchanged.

Verified in a real torch-free virtualenv, not only with the sys.meta_path simulation: ABCD imports, stays in __all__, and pca/kpca/default all run with torch never entering sys.modules.

Closes the follow-up left open by #370, which supplies capymoa._optional and OptionalDependencyError.

ABCD reconstructs instances with one of three encoder-decoder models. Only
the autoencoder needs PyTorch; PCAModel and KernelPCAModel use scikit-learn,
which is a core dependency. All three lived in feature_extraction.py, whose
module-level `import torch.nn` forced the whole detector behind the torch
gate, so `pip install capymoa` lost the only multivariate drift detector even
for configurations that never touch PyTorch.

Move AutoEncoder to its own module. It subclasses nn.Module, so the import
cannot be deferred into a method; a separate file is what lets abcd.py load it
lazily, and only when model_id="ae" is actually requested. Asking for that
model without the extra now raises OptionalDependencyError naming the model
rather than the detector, since the other two remain available.

Switch the default from "ae" to "pca" so a plain ABCD() works in a default
install. This changes the model an existing caller gets from the default, and
belongs in the release notes; on the univariate stream in the drift detection
notebook both models behave identically, so its stored output is unchanged.

Also give the unknown-model_id branch a message instead of a bare ValueError.
@hmgomes
hmgomes force-pushed the fix/abcd-torch-gating branch from 79d4749 to 467943d Compare August 7, 2026 10:54
@hmgomes
hmgomes merged commit 476d2d7 into adaptive-machine-learning:main Aug 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant