code: def downscale2d(x, factor=2):
      with tf.variable_scope("Downscale2D"):
  
          @tf.custom_gradient
          def func(x):
              y = _downscale2d(x, factor)
  
              @tf.custom_gradient
              def grad(dy):
                  dx = _upscale2d(dy, factor, gain=1 / factor**2)
                  return dx, lambda ddx: _downscale2d(ddx, factor)
  
              return y, grad
  
          return func(x)
  
imports: import numpy
  import tensorflow
  import dnnlib
  import dnnlib.tflib
label_desc: Use image node_id 6 for calling a global function with example usage: downscale2d(x, factor) and returns: func, y,  grad, dx,  function