Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions mart/attack/adversary.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def training_step(self, batch, batch_idx):
# Use CallWith to dispatch **outputs.
gain = self.gain_fn(**outputs)

# Log gain of all examples as a metric for LR scheduler to monitor, and show gain on progress bar.
self.log("gain", gain.sum(), prog_bar=True)

# objective_fn is optional, because adversaries may never reach their objective.
if self.objective_fn is not None:
found = self.objective_fn(**outputs)
Expand All @@ -131,13 +134,7 @@ def training_step(self, batch, batch_idx):
if len(gain.shape) > 0:
gain = gain[~found]

if len(gain.shape) > 0:
gain = gain.sum()

# Log gain as a metric for LR scheduler to monitor, and show gain on progress bar.
self.log("gain", gain, prog_bar=True)

return gain
return gain.sum()

def configure_gradient_clipping(
self, optimizer, gradient_clip_val=None, gradient_clip_algorithm=None
Expand Down