code: def test_grad_override(self, cls_ofg):
      x, y = T.vectors("xy")
  
      def go(inps, gs):
          x, y = inps
          (g,) = gs
          return [g * y * 2, g * x * 1.5]
  
      dedz = T.vector("dedz")
      op_mul_grad = cls_ofg([x, y, dedz], go([x, y], [dedz]))
  
      op_mul = cls_ofg([x, y], [x * y], grad_overrides=go)
      op_mul2 = cls_ofg([x, y], [x * y], grad_overrides=op_mul_grad)
  
      # single override case (function or OfG instance)
      xx, yy = T.vector("xx"), T.vector("yy")
      for op in [op_mul, op_mul2]:
          zz = T.sum(op(xx, yy))
          dx, dy = T.grad(zz, [xx, yy])
          fn = function([xx, yy], [dx, dy])
          xv = np.random.rand(16).astype(config.floatX)
          yv = np.random.rand(16).astype(config.floatX)
          dxv, dyv = fn(xv, yv)
          assert np.allclose(yv * 2, dxv)
          assert np.allclose(xv * 1.5, dyv)
  
      # list override case
      def go1(inps, gs):
          x, w, b = inps
          g = gs[0]
          return g * w * 2
  
      def go2(inps, gs):
          x, w, b = inps
          g = gs[0]
          return g * x * 1.5
  
      w, b = T.vectors("wb")
      # we make the 3rd gradient default (no override)
      op_linear = cls_ofg(
          [x, w, b], [x * w + b], grad_overrides=[go1, go2, "default"]
      )
      xx, ww, bb = T.vector("xx"), T.vector("yy"), T.vector("bb")
      zz = T.sum(op_linear(xx, ww, bb))
      dx, dw, db = T.grad(zz, [xx, ww, bb])
      fn = function([xx, ww, bb], [dx, dw, db])
      xv = np.random.rand(16).astype(config.floatX)
      wv = np.random.rand(16).astype(config.floatX)
      bv = np.random.rand(16).astype(config.floatX)
      dxv, dwv, dbv = fn(xv, wv, bv)
      assert np.allclose(wv * 2, dxv)
      assert np.allclose(xv * 1.5, dwv)
      assert np.allclose(np.ones(16, dtype=config.floatX), dbv)
  
      # NullType and DisconnectedType
      op_linear2 = cls_ofg(
          [x, w, b],
          [x * w + b],
          grad_overrides=[go1, NullType()(), DisconnectedType()()],
      )
      zz2 = T.sum(op_linear2(xx, ww, bb))
      dx2, dw2, db2 = T.grad(
          zz2,
          [xx, ww, bb],
          return_disconnected="Disconnected",
          disconnected_inputs="ignore",
          null_gradients="return",
      )
      assert isinstance(dx2.type, T.TensorType)
      assert dx2.ndim == 1
      assert isinstance(dw2.type, NullType)
      assert isinstance(db2.type, DisconnectedType)
  
imports: from __future__ import absolute_import, print_function, division
  from functools import partial
  import numpy
  import theano
  from theano import config, shared
  from theano.gradient import DisconnectedType
  from theano.gof.null_type import NullType
  from theano.compile import function
  from theano import tensor
  from theano.tensor.shared_randomstreams import RandomStreams
  from theano.compile.builders import OpFromGraph
  from theano.tests import unittest_tools
label_desc: Use image node_id 7 for calling the T_OpFromGraph obj's underlying member method code with example usage: obj.test_grad_override(cls_ofg) and returns: list, unknown, unknown