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.
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
import torch
|
|
from .Container import Container
|
|
|
|
|
|
class ParallelTable(Container):
|
|
|
|
def __init__(self, ):
|
|
super(ParallelTable, self).__init__()
|
|
self.modules = []
|
|
self.output = []
|
|
self.gradInput = []
|
|
|
|
def updateOutput(self, input):
|
|
for i in range(len(self.modules)):
|
|
tmp = self.modules[i].updateOutput(input[i])
|
|
if len(self.output) <= i:
|
|
self.output.append(tmp)
|
|
else:
|
|
self.output[i] = tmp
|
|
|
|
return self.output
|
|
|
|
def updateGradInput(self, input, gradOutput):
|
|
for i, module in enumerate(self.modules):
|
|
tmp = module.updateGradInput(input[i], gradOutput[i])
|
|
if len(self.gradInput) <= i:
|
|
self.gradInput.append(tmp)
|
|
else:
|
|
self.gradInput[i] = tmp
|
|
|
|
return self.gradInput
|
|
|
|
def accGradParameters(self, input, gradOutput, scale=1):
|
|
for i, module in enumerate(self.modules):
|
|
module.accGradParameters(input[i], gradOutput[i], scale)
|
|
|
|
def accUpdateGradParameters(self, input, gradOutput, lr=1):
|
|
for i, module in enumerate(self.modules):
|
|
module.accUpdateGradParameters(input[i], gradOutput[i], lr)
|
|
|
|
def __repr__(self):
|
|
tab = ' '
|
|
line = '\n'
|
|
next = ' |`-> '
|
|
ext = ' | '
|
|
extlast = ' '
|
|
last = ' ... -> '
|
|
res = torch.typename(self)
|
|
res = res + ' {' + line + tab + 'input'
|
|
for i in range(len(self.modules)):
|
|
if i == len(self.modules) - 1:
|
|
res = res + line + tab + next + '(' + str(i) + '): ' + \
|
|
str(self.modules[i]).replace(line, line + tab + extlast)
|
|
else:
|
|
res = res + line + tab + next + '(' + str(i) + '): ' + \
|
|
str(self.modules[i]).replace(line, line + tab + ext)
|
|
|
|
res = res + line + tab + last + 'output'
|
|
res = res + line + '}'
|
|
return res
|