import tensorflow as tf

        assert var.name == var_name_n_prune_ratio[0], \
          'unmatched variable names: %s vs. %s' % (var.name, var_name_n_prune_ratio[0])
        prune_ratio = self.__calc_prune_ratio_dyn(var_name_n_prune_ratio[1])

        # create a mask and non-masked backup for each variable
        name = var.name.replace(':0', '_mask')
        mask = tf.get_variable(name, initializer=tf.ones(var.shape), trainable=False)
        name = var.name.replace(':0', '_var_bkup')
        var_bkup = tf.get_variable(name, initializer=var.initialized_value(), trainable=False)

        # create update operations
        var_bkup_update_op = var_bkup.assign(tf.where(mask > 0.5, var, var_bkup))
        with tf.control_dependencies([var_bkup_update_op]):
          mask_thres = tf.contrib.distributions.percentile(tf.abs(var_bkup), prune_ratio * 100)
          mask_update_op = mask.assign(tf.cast(tf.abs(var_bkup) > mask_thres, tf.float32))
        with tf.control_dependencies([mask_update_op]):
          prune_op = var.assign(var_bkup * mask)

        # record pruning masks & operations
        masks += [mask]
        prune_ops += [prune_op]

    return masks, tf.group(prune_ops)

  def __calc_prune_ratio_dyn(self, prune_ratio_fnl):
    """Calculate the dynamic pruning ratio.
    Args:
    * prune_ratio_fnl: final pruning ratio
    Returns:
    * prune_ratio_dyn: dynamic pruning ratio
