code: def test_stop_gradient():
      x = C.sequence.input_variable(
          shape=(2,), sequence_axis=C.Axis("B"), needs_gradient=True
      )
      y = C.sequence.input_variable(
          shape=(2,), sequence_axis=C.Axis("B"), needs_gradient=True
      )
      z = C.element_times(x, y)
      w = z + C.stop_gradient(z)
      a = np.reshape(np.float32([0.25, 0.5, 0.1, 1]), (1, 2, 2))
      b = np.reshape(np.float32([-1.25, 1.5, 0.1, -1]), (1, 2, 2))
      bwd, fwd = w.forward({x: a, y: b}, [w.output], set([w.output]))
      value = list(fwd.values())[0]
      expected = np.multiply(a, b) * 2
      assert np.allclose(value, expected)
      grad = w.backward(
          bwd, {w.output: np.ones_like(value)}, set([x, y])
      )
      assert np.allclose(grad[x], b)
      assert np.allclose(grad[y], a)
  
      # test stop_gradient with function as input whose arguments should have no gradients (zeros reading)
      w = C.stop_gradient(z)
      bwd, fwd = w.forward({x: a, y: b}, [w.output], set([w.output]))
      value = list(fwd.values())[0]
      expected = np.multiply(a, b)
      assert np.allclose(value, expected)
      grad = w.backward(
          bwd, {w.output: np.ones_like(value)}, set([x, y])
      )
      # there should be no gradients backward to x and y
      assert np.allclose(grad[x], np.zeros_like(b))
      assert np.allclose(grad[y], np.zeros_like(a))
  
file_path: CNTK/bindings/python/cntk/ops/tests/stop_gradient_test.py
imports: import numpy
  import cntk
  from .ops_test_utils import AA, PRECISION_TO_TYPE, precision
  from cntk.internal import sanitize_dtype_cntk
  import pytest
  from .non_diff_test import Matrices
label_desc: Use image node_id 1 for calling a global function with example usage: test_stop_gradient() without return types