MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / grad

Function grad

tensorflow/python/ops/custom_gradient.py:391–404  ·  view source on GitHub ↗

Gradient function calculation for inner function.

(dresult, variables=None)

Source from the content-addressed store, hash-verified

389 result = f(*args, **kwargs)
390
391 def grad(dresult, variables=None):
392 """Gradient function calculation for inner function."""
393 with backprop.GradientTape() as t:
394 t.watch(args)
395 if variables is not None:
396 t.watch(variables)
397 with ops.control_dependencies([dresult]):
398 result = f(*args, **kwargs)
399 kw_vars = []
400 if variables is not None:
401 kw_vars = list(variables)
402 grads = t.gradient(
403 result, list(args) + kw_vars, output_gradients=[dresult])
404 return grads[:len(args)], grads[len(args):]
405
406 return result, grad
407

Callers

nothing calls this directly

Calls 6

gradientMethod · 0.80
fFunction · 0.70
GradientTapeMethod · 0.45
watchMethod · 0.45
control_dependenciesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected