parameters: (to_annotate)
return_statement: return keras.models.clone_model(
        to_annotate, input_tensors=None, clone_function=_add_quant_wrapper)
docstring: Annotate a `tf.keras` model to be quantized.
  
    This function does not actually quantize the model. It merely specifies
    that the model needs to be quantized. `quantize_apply` can then be used
    to quantize the model.
  
    This function is intended to be used in conjunction with the
    `quantize_annotate_layer` API. Otherwise, it is simpler to use
    `quantize_model`.
  
    Annotate a model while overriding the default behavior for a layer:
  
    ```python
    quantize_config = MyDenseQuantizeConfig()
  
    model = quantize_annotate_model(
      keras.Sequential([
        layers.Dense(10, activation='relu', input_shape=(100,)),
        quantize_annotate_layer(
            layers.Dense(2, activation='sigmoid'),
            quantize_config=quantize_config)
      ]))
  
    # The first Dense layer gets quantized with the default behavior,
    # but the second layer uses `MyDenseQuantizeConfig` for quantization.
    quantized_model = quantize_apply(model)
    ```
  
    Note that this function removes the optimizer from the original model.
  
    Args:
      to_annotate: `tf.keras` model which needs to be quantized.
  
    Returns:
      New tf.keras model with each layer in the model wrapped with
      `QuantizeAnnotate`. The new model preserves weights from the original
      model.
docstring_summary: Annotate a `tf.keras` model to be quantized.
docstring_tokens: Annotate a tf . keras model to be quantized .
function: def quantize_annotate_model(to_annotate):
    """Annotate a `tf.keras` model to be quantized.
  
    This function does not actually quantize the model. It merely specifies
    that the model needs to be quantized. `quantize_apply` can then be used
    to quantize the model.
  
    This function is intended to be used in conjunction with the
    `quantize_annotate_layer` API. Otherwise, it is simpler to use
    `quantize_model`.
  
    Annotate a model while overriding the default behavior for a layer:
  
    ```python
    quantize_config = MyDenseQuantizeConfig()
  
    model = quantize_annotate_model(
      keras.Sequential([
        layers.Dense(10, activation='relu', input_shape=(100,)),
        quantize_annotate_layer(
            layers.Dense(2, activation='sigmoid'),
            quantize_config=quantize_config)
      ]))
  
    # The first Dense layer gets quantized with the default behavior,
    # but the second layer uses `MyDenseQuantizeConfig` for quantization.
    quantized_model = quantize_apply(model)
    ```
  
    Note that this function removes the optimizer from the original model.
  
    Args:
      to_annotate: `tf.keras` model which needs to be quantized.
  
    Returns:
      New tf.keras model with each layer in the model wrapped with
      `QuantizeAnnotate`. The new model preserves weights from the original
      model.
    """
    if to_annotate is None:
      raise ValueError('`to_annotate` cannot be None')
  
    if not isinstance(to_annotate, keras.Model):
      raise ValueError(
          '`to_annotate` can only be a `tf.keras.Model` instance. Use '
          'the `quantize_annotate_layer` API to handle individual layers. '
          'You passed an instance of type: {input}.'.format(
              input=to_annotate.__class__.__name__))
  
    if not isinstance(to_annotate, keras.Sequential) \
        and not to_annotate._is_graph_network:  # pylint: disable=protected-access
      raise ValueError(
          '`to_annotate` can only either be a tf.keras Sequential or '
          'Functional model.')
  
    def _add_quant_wrapper(layer):
      """Add annotation wrapper."""
      # Already annotated layer. No need to wrap.
      if isinstance(layer, quantize_annotate_mod.QuantizeAnnotate):
        return layer
  
      if isinstance(layer, tf.keras.Model):
        raise ValueError(
            'Quantizing a tf.keras Model inside another tf.keras Model is not supported.'
        )
  
      return quantize_annotate_mod.QuantizeAnnotate(layer)
  
    return keras.models.clone_model(
        to_annotate, input_tensors=None, clone_function=_add_quant_wrapper)
function_tokens: def quantize_annotate_model ( to_annotate ) : if to_annotate is None : raise ValueError ( '`to_annotate` cannot be None' ) if not isinstance ( to_annotate , keras . Model ) : raise ValueError ( '`to_annotate` can only be a `tf.keras.Model` instance. Use ' 'the `quantize_annotate_layer` API to handle individual layers. ' 'You passed an instance of type: {input}.' . format ( input = to_annotate . __class__ . __name__ ) ) if not isinstance ( to_annotate , keras . Sequential ) and not to_annotate . _is_graph_network : # pylint: disable=protected-access raise ValueError ( '`to_annotate` can only either be a tf.keras Sequential or ' 'Functional model.' ) def _add_quant_wrapper ( layer ) : """Add annotation wrapper.""" # Already annotated layer. No need to wrap. if isinstance ( layer , quantize_annotate_mod . QuantizeAnnotate ) : return layer if isinstance ( layer , tf . keras . Model ) : raise ValueError ( 'Quantizing a tf.keras Model inside another tf.keras Model is not supported.' ) return quantize_annotate_mod . QuantizeAnnotate ( layer ) return keras . models . clone_model ( to_annotate , input_tensors = None , clone_function = _add_quant_wrapper )