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

Function _get_grad_blob

caffe2/python/gradient_checker.py:20–37  ·  view source on GitHub ↗
(grad_map, input_to_check)

Source from the content-addressed store, hash-verified

18
19
20def _get_grad_blob(grad_map, input_to_check):
21 grad_blob = grad_map[input_to_check]
22
23 if isinstance(grad_blob, core.BlobReference):
24 return workspace.blobs[grad_blob]
25
26 # If grad_blob is not a single blob, it should be a gradient slice.
27 # To make it comparable with the estimiated gradient which is dense,
28 # we need to first convert grad_blob to dense gradient.
29 assert isinstance(grad_blob, core.GradientSlice)
30 dense_grad = 'tmp_dense_grad'
31 sparse_to_dense_op = core.CreateOperator(
32 'SparseToDense',
33 [grad_blob.indices, grad_blob.values, input_to_check],
34 dense_grad,
35 )
36 workspace.RunOperatorOnce(sparse_to_dense_op)
37 return workspace.blobs[dense_grad]
38
39
40def _get_grad(net, outputs, outputs_with_grad, input_values, inputs_with_grads):

Callers 1

_get_gradFunction · 0.85

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…