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: Encodes the provided input.
  
  Args:
    x: A `Tensor` to be encoded.
    encode_params: Parameters controlling the encoding. A tuple, matching the
      corresponding structure returned by the `get_params` method.
    name: `string`, name of the operation.
  
  Returns:
    A `(encoded_x, state_update_tensors)` tuple, where `encoded_x` is a
    dictionary of `Tensor` values representing the encoded `x`, and
    `state_update_tensors` is a tuple of `Tensor` values, which are expected
    to be aggregated according to modes provided by the
    `state_update_aggregation_modes` property, and afterwards passed to the
    `update_state` method.
  
  Raises:
    ValueError:
      If `x` does not have the expected shape or dtype, or if `encode_params`
      does not have the same structure as corresponding return value of the
      `get_params` method.
docstr_tok: ["Encodes","the","provided","input",".","Args",":","x",":","A","`","Tensor","`","to","be","encoded",".","encode_params",":","Parameters","controlling","the","encoding",".","A","tuple",",","matching","the","corresponding","structure","returned","by","the","`","get_params","`","method",".","name",":","`","string","`",",","name","of","the","operation",".","Returns",":","A","`","(","encoded_x",",","state_update_tensors",")","`","tuple",",","where","`","encoded_x","`","is","a","dictionary","of","`","Tensor","`","values","representing","the","encoded","`","x","`",",","and","`","state_update_tensors","`","is","a","tuple","of","`","Tensor","`","values",",","which","are","expected","to","be","aggregated","according","to","modes","provided","by","the","`","state_update_aggregation_modes","`","property",",","and","afterwards","passed","to","the","`","update_state","`","method",".","Raises",":","ValueError",":","If","`","x","`","does","not","have","the","expected","shape","or","dtype",",","or","if","`","encode_params","`","does","not","have","the","same","structure","as","corresponding","return","value","of","the","`","get_params","`","method","."]
code: def encode(self, x, encode_params, name=None):
      """Encodes the provided input.
  
      Args:
        x: A `Tensor` to be encoded.
        encode_params: Parameters controlling the encoding. A tuple, matching the
          corresponding structure returned by the `get_params` method.
        name: `string`, name of the operation.
  
      Returns:
        A `(encoded_x, state_update_tensors)` tuple, where `encoded_x` is a
        dictionary of `Tensor` values representing the encoded `x`, and
        `state_update_tensors` is a tuple of `Tensor` values, which are expected
        to be aggregated according to modes provided by the
        `state_update_aggregation_modes` property, and afterwards passed to the
        `update_state` method.
  
      Raises:
        ValueError:
          If `x` does not have the expected shape or dtype, or if `encode_params`
          does not have the same structure as corresponding return value of the
          `get_params` method.
      """
      values = [x] + list(encode_params)
      with tf.compat.v1.name_scope(
          name, "gather_encoder_encode", values
      ):
          x = tf.convert_to_tensor(x)
          encode_params = tf.nest.map_structure(
              tf.convert_to_tensor, encode_params
          )
          return self._encode_fn(x, encode_params)
  
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 8 for calling the GatherEncoder obj's underlying member method code with example usage: obj.encode(x, encode_params, name) and returns: self