MCPcopy Index your code
hub / github.com/pytorch/pytorch / test_gradient

Method test_gradient

caffe2/python/python_op_test.py:171–187  ·  view source on GitHub ↗
(self, x, in_place, gc, dc)

Source from the content-addressed store, hash-verified

169 @given(x=hu.tensor(), in_place=st.booleans(), **hu.gcs)
170 @settings(deadline=10000)
171 def test_gradient(self, x, in_place, gc, dc):
172 def f(inputs, outputs):
173 outputs[0].reshape(inputs[0].shape)
174 outputs[0].data[...] = inputs[0].data * 2
175
176 def grad_f(inputs, outputs):
177 # Ordering is [inputs, outputs, grad_outputs]
178 grad_output = inputs[2]
179
180 grad_input = outputs[0]
181 grad_input.reshape(grad_output.shape)
182 grad_input.data[...] = grad_output.data * 2
183
184 op = CreatePythonOperator(
185 f, ["x"], ["x" if in_place else "y"], grad_f=grad_f)
186 self.assertGradientChecks(gc, op, [x], 0, [0])
187 self.assertDeviceChecks(dc, op, [x], [0])
188
189 @given(inputs=hu.tensors(n=2), **hu.gcs)
190 @settings(deadline=10000)

Callers

nothing calls this directly

Calls 3

CreatePythonOperatorFunction · 0.90
assertGradientChecksMethod · 0.80
assertDeviceChecksMethod · 0.80

Tested by

no test coverage detected