-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adversary as pl.LightningModule
#103
Conversation
|
||
on_run_end() | ||
""" | ||
class Adversary(pl.LightningModule): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would inherit from LitModular
. Then we can create pre-defined sequences for training.
I tried to run adversarial training on 2 GPUs but failed. Then hiding perturber parameters accidentally resolved the issue. python -m mart \
experiment=CIFAR10_CNN_Adv \
trainer=ddp \
trainer.devices=2 \
model.optimizer.lr=0.2 \
trainer.max_steps=2925 \
datamodule.ims_per_batch=256 File "/home/weilinxu/coder/MART/.venv/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 807, in <listcomp>
for param_name, param in module.named_parameters(recurse=False)
File "/home/weilinxu/coder/MART/mart/attack/perturber.py", line 83, in named_parameters
raise MisconfigurationException("You need to call configure_perturbation before fit.")
pytorch_lightning.utilities.exceptions.MisconfigurationException: You need to call configure_perturbation before fit. |
@@ -0,0 +1,2 @@ | |||
attack_in_eval_mode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we make an accurate name for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go away in #141.
* Fix progress bar display. * Enable progress bar for adversary. * Switch on/off progress bar for adversary in the callback config. * Make a default progress bar for adversary that can be turned off in FGSM. * Display progress bars of adversary in multi-rank. * Display gain instead of loss. * Make process_position configurable and avoid touching the internal variable. * Make renaming metrics configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this PR do?
Right now we treat adversaries as special things with their own loops and callbacks, when really we should just treat them like LightningModules. Doing so means that we can just use a Trainer to fit its parameters. This PR attempts to make that so.
As of dcf7599, there is a bug in adversarial training.Depends upon #146 and #147.
Type of change
Please check all relevant options.
Testing
Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.
pytest
python -m mart experiment=CIFAR10_CNN_Adv trainer=gpu
achieves 71% accuracy.python -m mart experiment=CIFAR10_CNN_Adv trainer=ddp datamodule.world_size=2 trainer.devices=2
achieves 71% accuracy.Before submitting
pre-commit run -a
command without errorsDid you have fun?
Make sure you had fun coding 🙃