Skip to content

refactor(examples): standardize all pipelines to use load_or_train#81

Open
asim29 wants to merge 1 commit intopr/4.7-attribute-datafrom
pr/5-examples
Open

refactor(examples): standardize all pipelines to use load_or_train#81
asim29 wants to merge 1 commit intopr/4.7-attribute-datafrom
pr/5-examples

Conversation

@asim29
Copy link
Copy Markdown
Collaborator

@asim29 asim29 commented Apr 21, 2026

Context

Eighth in the refactor/risk-modules stack. Stacked on #80 (attr-inference + data-recon). Covers all runnable example pipelines that were not already updated in their respective risk-vertical PRs.

Changes

Pattern applied uniformly across all six scripts:

  • Replace manual if filename.exists(): torch.load(...) else: train(...); torch.save(...) blocks with load_or_train().
  • Fix default=torch.device(f"cuda:{0}" if ...)default="cuda:0" if ... (was passing a torch.device object as a string argparse default).
  • Expand --dataset help strings to include utkface, cifar100, mnist.

examples/defense_pipelines/run_adversarial_training.py

  • Adds post-hoc adversarial accuracy comparison: runs EvasionPGD on both the undefended and defended models and logs the delta.

examples/defense_pipelines/run_dp_sgd.py

  • Logs baseline → DP-SGD accuracy trade-off after training.

examples/get_started.py

  • Rewritten to cover the full attack lifecycle using AmuletDataset and the new APIs across all risk modules.

examples/extending_amulet/custom_metric.md / custom_risk.md

  • Minor prose and code-fence fixes.

Test plan

  • uv run python examples/get_started.py
  • uv run pre-commit run --all-files
  • CI passes on this branch

All six pipelines replace manual if-exists/torch.load/torch.save blocks
with load_or_train(), fixing the torch.device() type bug in --device
defaults and expanding --dataset help strings to include utkface.
run_adversarial_training adds post-hoc adversarial accuracy comparison.
run_dp_sgd logs the accuracy trade-off. get_started.py rewritten to
cover the full attack lifecycle with AmuletDataset and the new APIs.
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