Returns the gradient of x and y given the gradient of x * y.
(op, grad)
| 1671 | |
| 1672 | @ops.RegisterGradient("BatchMatMul") |
| 1673 | def _BatchMatMul(op, grad): |
| 1674 | """Returns the gradient of x and y given the gradient of x * y.""" |
| 1675 | x = op.inputs[0] |
| 1676 | y = op.inputs[1] |
| 1677 | adj_x = op.get_attr("adj_x") |
| 1678 | adj_y = op.get_attr("adj_y") |
| 1679 | |
| 1680 | if not adj_x: |
| 1681 | if not adj_y: |
| 1682 | grad_x = math_ops.matmul(grad, y, adjoint_a=False, adjoint_b=True) |
| 1683 | grad_y = math_ops.matmul(x, grad, adjoint_a=True, adjoint_b=False) |
| 1684 | else: |
| 1685 | grad_x = math_ops.matmul(grad, y, adjoint_a=False, adjoint_b=False) |
| 1686 | grad_y = math_ops.matmul(grad, x, adjoint_a=True, adjoint_b=False) |
| 1687 | else: |
| 1688 | if not adj_y: |
| 1689 | grad_x = math_ops.matmul(y, grad, adjoint_a=False, adjoint_b=True) |
| 1690 | grad_y = math_ops.matmul(x, grad, adjoint_a=False, adjoint_b=False) |
| 1691 | else: |
| 1692 | grad_x = math_ops.matmul(y, grad, adjoint_a=True, adjoint_b=True) |
| 1693 | grad_y = math_ops.matmul(grad, x, adjoint_a=True, adjoint_b=True) |
| 1694 | |
| 1695 | return grad_x, grad_y |
| 1696 | |
| 1697 | |
| 1698 | @ops.RegisterGradient("BatchMatMulV2") |