MCPcopy Create free account
hub / github.com/pytorch/pytorch / operator_add

Function operator_add

test/dynamo/test_python_autograd.py:147–164  ·  view source on GitHub ↗
(self: Variable, rhs: Variable)

Source from the content-addressed store, hash-verified

145
146
147def operator_add(self: Variable, rhs: Variable) -> Variable:
148 # Add follows a similar pattern to Mul, but it doesn't end up
149 # capturing any variables.
150 r = Variable(self.value + rhs.value)
151 # print(f'{r.name} = {self.name} + {rhs.name}')
152
153 def propagate(dL_doutputs: List[Variable]):
154 (dL_dr,) = dL_doutputs
155 dr_dself = 1.0
156 dr_drhs = 1.0
157 dL_dself = dL_dr * dr_dself
158 dL_drhs = dL_dr * dr_drhs
159 return [dL_dself, dL_drhs]
160
161 gradient_tape.append(
162 TapeEntry(inputs=[self.name, rhs.name], outputs=[r.name], propagate=propagate)
163 )
164 return r
165
166
167def operator_sum(self: Variable, name: Optional[str]) -> "Variable":

Callers 1

__add__Method · 0.85

Calls 3

TapeEntryClass · 0.85
VariableClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…