class_docstr: A class for a gather-like operations with encoding.
  
  This class provides functionality for encoding in the "many-to-one" case,
  where multiple locations hold a `Tensor` of the same shape and dtype, and one
  needs to compute their sum at a central location, while only encoded
  representations are communicated between the locations.
  
  An instance of `GatherEncoder` is capable of encoding only values of a shape
  and dtype, as specified at construction time. For example, a separate
  instance of this class should be used for encoding every `Variable` of a
  model, as opposed to a single instance being reused for each `Variable`.
  
  `GatherEncoder` exposes the state of the underlying encoder, and the user is
  responsible for keeping track of the state in case the encoding should be
  adaptive as part of an iterative process.
  
  In the following illustration of a typical pattern of usage of this class, we
  will refer to the "one" central location as `server` and the "many" locations
  as `workers`. By `user`, we denote the parts that are the responsibility of
  the user of this class -- for instance, the communication between the `server`
  and `workers` might need to happen outside of TensorFlow, depending on the
  target deployment.
  
  1.  `[server]` Use the `initial_state` method to create an initial `state`.
  2.  `[server]` Use the `get_params` method to derive `encode_params`,
      `decode_before_sum_params` and `decode_after_sum_params` for the remaining
      methods, based on the `state`.
  3.  `[user]` Make the `encode_params` available to the `workers`.
  4.  `[workers]` Use the `encode` method to get `encoded_x` and
      `state_update_tensors`.
  5.  `[user]` Make the `encoded_x` and `state_update_tensors` available to the
      `server`.
  6.  `[server]` Use the `decode_before_sum` method to partially decode all of
      the `encoded_x` values.
  7.  `[user]` Sum the partially decoded values.
  8.  `[server]` Use the `decode_after_sum` method to finish decoding the summed
      and partially decoded values.
  9.  `[user]` Aggregate the `state_update_tensors` according to aggregation
      modes declared by the `state_update_aggregation_modes` property.
  10. `[server]` Use the `update_state` method to update the `state` based on
      the existing `state` and aggregated `state_update_tensors`.
  
  NOTE Step 5 could overlap with the steps 6--9, depending on the indended
  deployment. For instnace, if communication is realized using a multi-tier
  aggregation architecture, intermediary nodes would need to access
  `decode_before_sum_params` and use the `decode_before_sum` method and sum the
  part decoded representations. These would be then summed again at the
  `server`, which would finish the decoding.
  
  NOTE The use of the `state` is optional. It is needed only when the encoding
  mechanism should adapt based on the values being encoded during an iterative
  execution.
docstr: Creates a `GatherEncoder` for encoding `tensorspec`-like values.
  
  This class should not be instantiated directly. Instead, use the
  provided `@classmethod`.
  
  Args:
    tensorspec: A `tf.TensorSpec`. The created `GatherEncoder` will be
      constrained to only encode input values compatible with `tensorspec`.
    commuting_structure: The commuting structure of the `GatherEncoder`.
    state_update_aggregation_modes: The `StageAggregationMode` values to be
      used to aggregate `state_update_tensors`
    initial_state_fn: A `tf.function`.
    get_params_fn: A `tf.function`.
    encode_fn: A `tf.function`.
    decode_before_sum_fn: A `tf.function`.
    decode_after_sum_fn: A `tf.function`.
    update_state_fn: A `tf.function`.
  
  Returns:
    A `GatherEncoder`.
docstr_tok: ["Creates","a","`","GatherEncoder","`","for","encoding","`","tensorspec","`","-like","values",".","This","class","should","not","be","instantiated","directly",".","Instead",",","use","the","provided","`","@","classmethod","`",".","Args",":","tensorspec",":","A","`","tf.TensorSpec","`",".","The","created","`","GatherEncoder","`","will","be","constrained","to","only","encode","input","values","compatible","with","`","tensorspec","`",".","commuting_structure",":","The","commuting","structure","of","the","`","GatherEncoder","`",".","state_update_aggregation_modes",":","The","`","StageAggregationMode","`","values","to","be","used","to","aggregate","`","state_update_tensors","`","initial_state_fn",":","A","`","tf.function","`",".","get_params_fn",":","A","`","tf.function","`",".","encode_fn",":","A","`","tf.function","`",".","decode_before_sum_fn",":","A","`","tf.function","`",".","decode_after_sum_fn",":","A","`","tf.function","`",".","update_state_fn",":","A","`","tf.function","`",".","Returns",":","A","`","GatherEncoder","`","."]
code: def __init__(
      self,
      tensorspec,
      commuting_structure,
      state_update_aggregation_modes,
      initial_state_fn,
      get_params_fn,
      encode_fn,
      decode_before_sum_fn,
      decode_after_sum_fn,
      update_state_fn,
  ):
      """Creates a `GatherEncoder` for encoding `tensorspec`-like values.
  
      This class should not be instantiated directly. Instead, use the
      provided `@classmethod`.
  
      Args:
        tensorspec: A `tf.TensorSpec`. The created `GatherEncoder` will be
          constrained to only encode input values compatible with `tensorspec`.
        commuting_structure: The commuting structure of the `GatherEncoder`.
        state_update_aggregation_modes: The `StageAggregationMode` values to be
          used to aggregate `state_update_tensors`
        initial_state_fn: A `tf.function`.
        get_params_fn: A `tf.function`.
        encode_fn: A `tf.function`.
        decode_before_sum_fn: A `tf.function`.
        decode_after_sum_fn: A `tf.function`.
        update_state_fn: A `tf.function`.
  
      Returns:
        A `GatherEncoder`.
      """
      self._tensorspec = tensorspec
      self._commuting_structure = commuting_structure
      self._state_update_aggregation_modes = (
          state_update_aggregation_modes
      )
  
      self._initial_state_fn = initial_state_fn
      self._get_params_fn = get_params_fn
      self._encode_fn = encode_fn
      self._decode_before_sum_fn = decode_before_sum_fn
      self._decode_after_sum_fn = decode_after_sum_fn
      self._update_state_fn = update_state_fn
  
file_path: model-optimization/tensorflow_model_optimization/python/core/internal/tensor_encoding/core/gather_encoder.py
imports: import collections
  import tensorflow
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import core_encoder
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.utils import py_utils
label_desc: Use image node_id 1 to create a new GatherEncoder object  with example: obj = GatherEncoder(tensorspec, commuting_structure, state_update_aggregation_modes, initial_state_fn, get_params_fn, encode_fn, decode_before_sum_fn, decode_after_sum_fn, update_state_fn)