mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Here's the command I used to invoke autopep8 (in parallel!): git ls-files | grep '\.py$' | xargs -n1 -P`nproc` autopep8 -i Several rules are ignored in setup.cfg. The goal is to let autopep8 handle everything which it can handle safely, and to disable any rules which are tricky or controversial to address. We may want to come back and re-enable some of these rules later, but I'm trying to make this patch as safe as possible. Also configures flake8 to match pep8's behavior. Also configures TravisCI to check the whole project for lint.
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import torch
|
|
from .Module import Module
|
|
from .utils import clear
|
|
|
|
|
|
class RReLU(Module):
|
|
|
|
def __init__(self, lower=1. / 8, upper=1. / 3, inplace=False):
|
|
super(RReLU, self).__init__()
|
|
self.lower = lower
|
|
self.upper = upper
|
|
self.inplace = inplace
|
|
|
|
assert self.lower <= self.upper and self.lower >= 0 and self.upper >= 0
|
|
self.noise = torch.Tensor()
|
|
self.train = True
|
|
|
|
def updateOutput(self, input):
|
|
self._backend.RReLU_updateOutput(
|
|
self._backend.library_state,
|
|
input,
|
|
self.output,
|
|
self.noise,
|
|
self.lower,
|
|
self.upper,
|
|
self.train,
|
|
self.inplace,
|
|
torch.default_generator if not input.is_cuda else 0
|
|
)
|
|
return self.output
|
|
|
|
def updateGradInput(self, input, gradOutput):
|
|
self._backend.RReLU_updateGradInput(
|
|
self._backend.library_state,
|
|
input,
|
|
gradOutput,
|
|
self.gradInput,
|
|
self.noise,
|
|
self.lower,
|
|
self.upper,
|
|
self.train,
|
|
self.inplace
|
|
)
|
|
return self.gradInput
|
|
|
|
def __repr__(self):
|
|
return super(RReLU, self).__repr__() + '({:.4f}, {:.4f})'.format(self.lower, self.upper)
|
|
|
|
def clearState(self):
|
|
clear(self, 'noise')
|
|
return super(RReLU, self).clearState()
|