code: def create_ema_and_scales_fn(
      target_ema_mode,
      start_ema,
      scale_mode,
      start_scales,
      end_scales,
      total_steps,
      distill_steps_per_iter,
  ):
      def ema_and_scales_fn(step):
          if target_ema_mode == "fixed" and scale_mode == "fixed":
              target_ema = start_ema
              scales = start_scales
          elif (
              target_ema_mode == "fixed" and scale_mode == "progressive"
          ):
              target_ema = start_ema
              scales = np.ceil(
                  np.sqrt(
                      (step / total_steps)
                      * ((end_scales + 1) ** 2 - start_scales**2)
                      + start_scales**2
                  )
                  - 1
              ).astype(np.int32)
              scales = np.maximum(scales, 1)
              scales = scales + 1
  
          elif (
              target_ema_mode == "adaptive"
              and scale_mode == "progressive"
          ):
              scales = np.ceil(
                  np.sqrt(
                      (step / total_steps)
                      * ((end_scales + 1) ** 2 - start_scales**2)
                      + start_scales**2
                  )
                  - 1
              ).astype(np.int32)
              scales = np.maximum(scales, 1)
              c = -np.log(start_ema) * start_scales
              target_ema = np.exp(-c / scales)
              scales = scales + 1
          elif target_ema_mode == "fixed" and scale_mode == "progdist":
              distill_stage = step // distill_steps_per_iter
              scales = start_scales // (2**distill_stage)
              scales = np.maximum(scales, 2)
  
              sub_stage = np.maximum(
                  step
                  - distill_steps_per_iter
                  * (np.log2(start_scales) - 1),
                  0,
              )
              sub_stage = sub_stage // (distill_steps_per_iter * 2)
              sub_scales = 2 // (2**sub_stage)
              sub_scales = np.maximum(sub_scales, 1)
  
              scales = np.where(scales == 2, sub_scales, scales)
  
              target_ema = 1.0
          else:
              raise NotImplementedError
  
          return float(target_ema), int(scales)
  
      return ema_and_scales_fn
  
file_path: consistency_models/cm/script_util.py
imports: import argparse
  from .karras_diffusion import KarrasDenoiser
  from .unet import UNetModel
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: create_ema_and_scales_fn(target_ema_mode, start_ema, scale_mode, start_scales, end_scales, total_steps, distill_steps_per_iter) and returns: ema_and_scales_fn, float,  int