message: Add docstrings for get/set optimizer weights.
diff: @@ -752,11 +752,65 @@ class OptimizerV2(trackable.Trackable):
  return self._weights
  def get_weights(self):
  + """Returns the current weights of the optimizer.
  +
  + The weights of an optimizer are its state (ie, variables).
  + This function returns the weight values associated with this
  + optimizer as a list of Numpy arrays. The first value is always the
  + iterations count of the optimizer, followed by the optimizer's state
  + variables in the order they were created. The returned list can in turn
  + be used to load state into similarly parameterized optimizers.
  +
  + For example, the RMSprop optimizer for this simple model returns a list of
  + three values-- the iteration count, followed by the root-mean-square value
  + of the kernel and bias of the single Dense layer:
  +
  + >>> opt = tf.keras.optimizers.RMSprop()
  + >>> m = tf.keras.models.Sequential([tf.keras.layers.Dense(10)])
  + >>> m.compile(opt, loss='mse')
  + >>> data = np.arange(100).reshape(5, 20)
  + >>> labels = np.zeros(5)
  + >>> print('Training'); results = m.fit(data, labels)
  + Training ...
  + >>> len(opt.get_weights())
  + 3
  +
  + Returns:
  + Weights values as a list of numpy arrays.
  + """
  params = self.weights
  return backend.batch_get_value(params)
  # TODO(tanzheny): Maybe share this logic with base_layer.
  def set_weights(self, weights):
  + """Sett the weights of the optimizer.
  +
  + The weights of an optimizer are its state (ie, variables).
  + This function takes the weight values associated with this
  + optimizer as a list of Numpy arrays. The first value is always the
  + iterations count of the optimizer, followed by the optimizer's state
  + variables in the order they are created. The passed values are used to set
  + the new state of the optimizer.
  +
  + For example, the RMSprop optimizer for this simple model takes a list of
  + three values-- the iteration count, followed by the root-mean-square value
  + of the kernel and bias of the single Dense layer:
  +
  + >>> opt = tf.keras.optimizers.RMSprop()
  + >>> m = tf.keras.models.Sequential([tf.keras.layers.Dense(10)])
  + >>> m.compile(opt, loss='mse')
  + >>> data = np.arange(100).reshape(5, 20)
  + >>> labels = np.zeros(5)
  + >>> print('Training'); results = m.fit(data, labels)
  + Training ...
  + >>> new_weights = [np.array(10), np.ones([20, 10]), np.zeros([10])]
  + >>> opt.set_weights(new_weights)
  + >>> opt.iterations
  + <tf.Variable 'RMSprop/iter:0' shape=() dtype=int64, numpy=10>
  +
  + Arguments:
  + weights: weight values as a list of numpy arrays.
  + """
  params = self.weights
  if len(params) != len(weights):
  raise ValueError(
  