code: def _downscale2d(x, factor=2, gain=1):
      assert x.shape.ndims == 4 and all(
          dim.value is not None for dim in x.shape[1:]
      )
      assert isinstance(factor, int) and factor >= 1
  
      # 2x2, float32 => downscale using _blur2d().
      if factor == 2 and x.dtype == tf.float32:
          f = [np.sqrt(gain) / factor] * factor
          return _blur2d(x, f=f, normalize=False, stride=factor)
  
      # Apply gain.
      if gain != 1:
          x *= gain
  
      # No-op => early exit.
      if factor == 1:
          return x
  
      # Large factor => downscale using tf.nn.avg_pool().
      # NOTE: Requires tf_config['graph_options.place_pruned_graph']=True to work.
      ksize = [1, 1, factor, factor]
      return tf.nn.avg_pool(
          x,
          ksize=ksize,
          strides=ksize,
          padding="VALID",
          data_format="NCHW",
      )
  
imports: import numpy
  import tensorflow
  import dnnlib
  import dnnlib.tflib
label_desc: Use image node_id 3 for calling a global function with example usage: _downscale2d(x, factor, gain) and returns: tf, _blur2d, x