Stop gradient option for padding #68879
Labels
enhancement
Not as big of a feature, but technically not a bug. Should be easy to fix
module: autograd
Related to torch.autograd, and the autograd engine in general
module: nn
Related to torch.nn
needs research
We need to decide whether or not this merits inclusion, based on research world
Stale
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
馃殌 Feature
I'd like to propose an option to disable the gradient computation through padding pixels. Such that all source pixels get the same "weight". I propose an boolean option
detach_padding
that by default is set toFalse
for backwards compatibility, but if set to true, the replicated pixels in the padding should not be considered in the gradient computation. This concerns all functions and modules that contain a padding option liketorch.nn.functional.pad, torch.nn.ReflectionPad1d, torch.nn.ReplicationPad2d, torch.nn.Conv3d
etc.Motivation
Currently if we use padding options that reuse values from within the image, some pixels get considered multiple times in the gradient computation. This causes edge artifacts and is especially inconvenient with the
circular
options. If we use thecircular
padding mode we usually want toroidal topology (a.k.a. wallpaper tiling) where we just consider one patch of a repeating pattern. In that case we definitely don't want certain pixels to be considered different from the rest. But if we observe what the gradient looks like we see that this is not the case, the gradient computation also goes through the replicated pixels:I'd expect the gradient to be all ones, but this is not the case:
I claim that this behaviour is also not really wanted for the other padding modes, as it can cause artifacts at the edges of the images.
Pitch
Add an option to disable gradient through padding pixels in the various padding functions and modules.
cc @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @lezcano @Varal7 @mruberry @jbschlosser @walterddr @kshitij12345
The text was updated successfully, but these errors were encountered: