PGD Adversarial Training Loop
When To Use
Use this skill for the outer minimization step in a Madry-style robust optimization recovery. It is designed for bounded experiments where the model can generate adversarial examples with the current parameters and then update parameters on those examples.
Do not use it to claim robust training if no PGD examples are generated or no trainable parameters change.
Inputs
- Training examples and labels.
- A trainable model with parameter gradients.
- PGD attack configuration: epsilon, step size, steps, restarts, and seed.
- Optimizer configuration: learning rate and epochs.
Outputs
- Updated model parameters.
- Training trace with
loss_before,loss_after,params_before, andparams_after. - Mechanism checks for PGD generation and optimizer execution.
Workflow
- Generate PGD adversarial examples using the current model.
- Compute adversarial loss and parameter gradients.
- Apply a gradient-descent update to model weights and bias.
- Re-evaluate adversarial loss after the update.
- Save trace fields that prove parameters changed and loss was measured before and after.
Validation
Run:
python scripts/adversarial_train.py --self-test
python tests/test_adversarial_train.py
Limitations
The included script is a deterministic reduced proxy using a tiny logistic classifier. Full MNIST/CIFAR recovery requires a real deep-learning runtime and dataset.