Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions opacus/utils/adaptive_clipping/adaptive_clipping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ def __init__(
self.clipbound_learning_rate = clipbound_learning_rate
self.initial_noise_multiplier = initial_noise_multiplier

def __call__(self, input, target) -> DPTensorFastGradientAdaptiveClipping:
def __call__(self, *args, **kwargs) -> DPTensorFastGradientAdaptiveClipping:
"""
Redefining the forward function to compute per-sample loss and wrap it in DPTensorFastGradientAdaptiveClipping
"""

loss_per_sample = self.criterion(
input,
target,
*args,
**kwargs,
)
return DPTensorFastGradientAdaptiveClipping(
self.module,
Expand Down
4 changes: 2 additions & 2 deletions opacus/utils/fast_gradient_clipping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def __init__(
self.loss_reduction = loss_reduction
self.criterion.reduction = "none"

def __call__(self, input, target, shape=None) -> DPTensorFastGradientClipping:
def __call__(self, *args, shape=None, **kwargs) -> DPTensorFastGradientClipping:
"""
Redefining the forward function to compute per-sample loss and wrap it in DPTensorFastGradientClipping
"""

loss_per_sample = self.criterion(input, target)
loss_per_sample = self.criterion(*args, **kwargs)

if shape is not None and loss_per_sample.shape[0] == shape[0] * shape[1]:
# Note that the privacy unit for generative NLP tasks is per sequence.
Expand Down
Loading