refactor(poisoning): migrate to new attack/defense architecture#77
Open
asim29 wants to merge 1 commit intopr/4.3-evasionfrom
Open
refactor(poisoning): migrate to new attack/defense architecture#77asim29 wants to merge 1 commit intopr/4.3-evasionfrom
asim29 wants to merge 1 commit intopr/4.3-evasionfrom
Conversation
4 tasks
BadNets (attacks/badnets.py):
- Now subclasses PoisoningAttack(ABC).
- Splits attack(mode="train"|"test") into the two required ABC methods:
poison_train(dataset) and poison_test(dataset).
- poison_train keeps existing logic; poison_test keeps existing logic.
- Constructor delegates random_seed to super().__init__(random_seed).
- torch.tensor -> torch.as_tensor in train path to avoid an extra copy.
OutlierRemoval (defenses/outlier_removal.py):
- Removes pandas dependency; replaces pd.Series wrapper with direct
numpy operations on normalized_scores, train_inputs, train_targets.
- Fixes threshold direction: was keeping samples BELOW the (100-percent)
percentile (wrong); now keeps samples AT OR ABOVE the percent-th
percentile, so the lowest-scoring self.percent% are removed as intended.
- Renames self.train -> self._train_fn to avoid shadowing the built-in.
- Fixes typo: _knn_shapely -> _knn_shapley (method name).
- Honors self.criterion and self.optimizer from the base class instead of
silently creating new CrossEntropyLoss and Adam instances.
- DataLoader shuffle=False -> shuffle=True for the cleaned training set.
5b66d42 to
b1cca7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Fourth in the
refactor/risk-modulesstack. Stacked on #76 (evasion vertical).Changes
amulet/poisoning/attacks/badnets.pyPoisoningAttack(ABC)and implements the newpoison_train(dataset)/poison_test(dataset)split entry points, replacing the oldattack(mode=...)dispatch.random_seedtosuper().__init__(random_seed).amulet/poisoning/defenses/outlier_removal.pypandasdependency; filtering now uses pure NumPy.(100 - percent)percentile (wrong); now correctly keeps samples at or above thepercentpercentile.self.train→self._train_fnto avoid shadowing the built-in._knn_shapely→_knn_shapley.self.criterionandself.optimizerfrom the base class instead of creating new ones internally.examples/attack_pipelines/run_poisoning.pypoison_train/poison_testAPI.tests/integration/test_poisoning.py(new)poison_train→poison_testlifecycle, output shape, label-flip correctness, and defense coverage.Test plan
uv run pytest tests/integration/test_poisoning.py -v -m integrationuv run pre-commit run --all-files