class_docstr: Model for predicting autofills given context.
class_docstr_tok: ["Model","for","predicting","autofills","given","context","."]
docstr: Adds output saved from earlier layer to x if at residual period.
docstr_tok: ["Adds","output","saved","from","earlier","layer","to","x","if","at","residual","period","."]
code: def apply_residual(self, x, is_first, is_last):
      """Adds output saved from earlier layer to x if at residual period."""
      if not self.hparams.use_residual:
          return x
      if self.output_for_residual is None:
          return x
      if self.output_for_residual.get_shape()[-1] != x.get_shape()[-1]:
          # shape mismatch; e.g. change in number of filters
          self.residual_reset()
          return x
      if self.residual_counter % self.residual_period == 0:
          if not is_first and not is_last:
              x += self.output_for_residual
      return x
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  from magenta.models.coconet import lib_hparams
  from magenta.models.coconet import lib_tfutil
  import tensorflow.compat.v1
label_desc: Use image node_id 19 for calling the CoconetGraph obj's underlying member method code with example usage: obj.apply_residual(x, is_first, is_last) and returns: x, x, x, x