class_docstr: `Sequential` groups a linear stack of layers into a `tf.keras.Model`.
  
  `Sequential` provides training and inference features on this model.
  
  Examples:
  
  >>> # Optionally, the first layer can receive an `input_shape` argument:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8, input_shape=(16,)))
  >>> # Afterwards, we do automatic shape inference:
  >>> model.add(tf.keras.layers.Dense(4))
  
  >>> # This is identical to the following:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.Input(shape=(16,)))
  >>> model.add(tf.keras.layers.Dense(8))
  
  >>> # Note that you can also omit the `input_shape` argument.
  >>> # In that case the model doesn't have any weights until the first call
  >>> # to a training/evaluation method (since it isn't yet built):
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> # model.weights not created yet
  
  >>> # Whereas if you specify the input shape, the model gets built
  >>> # continuously as you are adding layers:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8, input_shape=(16,)))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> len(model.weights)
  4
  
  >>> # When using the delayed-build pattern (no input shape specified), you can
  >>> # choose to manually build your model by calling
  >>> # `build(batch_input_shape)`:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> model.build((None, 16))
  >>> len(model.weights)
  4
  
  ```python
  # Note that when using the delayed-build pattern (no input shape specified),
  # the model gets built the first time you call `fit`, `eval`, or `predict`,
  # or the first time you call the model on some input data.
  model = tf.keras.Sequential()
  model.add(tf.keras.layers.Dense(8))
  model.add(tf.keras.layers.Dense(1))
  model.compile(optimizer='sgd', loss='mse')
  # This builds the model for the first time:
  model.fit(x, y, batch_size=32, epochs=10)
  ```
class_docstr_tok: ["`","Sequential","`","groups","a","linear","stack","of","layers","into","a","`","tf.keras.Model","`",".","`","Sequential","`","provides","training","and","inference","features","on","this","model",".","Examples",":",">",">",">","#","Optionally",",","the","first","layer","can","receive","an","`","input_shape","`","argument",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",",","input_shape=","(","16",",",")",")",")",">",">",">","#","Afterwards",",","we","do","automatic","shape","inference",":",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","#","This","is","identical","to","the","following",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.Input","(","shape=","(","16",",",")",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","#","Note","that","you","can","also","omit","the","`","input_shape","`","argument",".",">",">",">","#","In","that","case","the","model","does","n't","have","any","weights","until","the","first","call",">",">",">","#","to","a","training\/evaluation","method","(","since","it","is","n't","yet","built",")",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","#","model.weights","not","created","yet",">",">",">","#","Whereas","if","you","specify","the","input","shape",",","the","model","gets","built",">",">",">","#","continuously","as","you","are","adding","layers",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",",","input_shape=","(","16",",",")",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","len","(","model.weights",")","4",">",">",">","#","When","using","the","delayed-build","pattern","(","no","input","shape","specified",")",",","you","can",">",">",">","#","choose","to","manually","build","your","model","by","calling",">",">",">","#","`","build","(","batch_input_shape",")","`",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","model.build","(","(","None",",","16",")",")",">",">",">","len","(","model.weights",")","4","``","`","python","#","Note","that","when","using","the","delayed-build","pattern","(","no","input","shape","specified",")",",","#","the","model","gets","built","the","first","time","you","call","`","fit","`",",","`","eval","`",",","or","`","predict","`",",","#","or","the","first","time","you","call","the","model","on","some","input","data",".","model","=","tf.keras.Sequential","(",")","model.add","(","tf.keras.layers.Dense","(","8",")",")","model.add","(","tf.keras.layers.Dense","(","1",")",")","model.compile","(","optimizer='sgd","'",",","loss='mse","'",")","#","This","builds","the","model","for","the","first","time",":","model.fit","(","x",",","y",",","batch_size=32",",","epochs=10",")","``","`"]
docstr: Adds a layer instance on top of the layer stack.
  
  Args:
      layer: layer instance.
  
  Raises:
      TypeError: If `layer` is not a layer instance.
      ValueError: In case the `layer` argument does not
          know its input shape.
      ValueError: In case the `layer` argument has
          multiple output tensors, or is already connected
          somewhere else (forbidden in `Sequential` models).
code: def add(self, layer):
      """Adds a layer instance on top of the layer stack.
  
      Args:
          layer: layer instance.
  
      Raises:
          TypeError: If `layer` is not a layer instance.
          ValueError: In case the `layer` argument does not
              know its input shape.
          ValueError: In case the `layer` argument has
              multiple output tensors, or is already connected
              somewhere else (forbidden in `Sequential` models).
      """
      # If we are passed a Keras tensor created by keras.Input(), we can extract
      # the input layer from its keras history and use that without any loss of
      # generality.
      if hasattr(layer, "_keras_history"):
          origin_layer = layer._keras_history[0]
          if isinstance(origin_layer, input_layer.InputLayer):
              layer = origin_layer
              logging.warning(
                  "Please add `keras.layers.InputLayer` instead of `keras.Input` to "
                  "Sequential model. `keras.Input` is intended to be used by "
                  "Functional model."
              )
  
      if isinstance(layer, module.Module):
          if not isinstance(layer, base_layer.Layer):
              layer = functional.ModuleWrapper(layer)
      else:
          raise TypeError(
              "The added layer must be "
              "an instance of class Layer. "
              "Found: " + str(layer)
          )
  
      tf_utils.assert_no_legacy_layers([layer])
      if not self._is_layer_name_unique(layer):
          raise ValueError(
              "All layers added to a Sequential model "
              'should have unique names. Name "%s" is already the name'
              " of a layer in this model. Update the `name` argument "
              "to pass a unique name." % (layer.name,)
          )
  
      self.built = False
      set_inputs = False
      self._maybe_create_attribute("_self_tracked_trackables", [])
      if not self._self_tracked_trackables:
          if isinstance(layer, input_layer.InputLayer):
              # Case where the user passes an Input or InputLayer layer via `add`.
              set_inputs = True
          else:
              (
                  batch_shape,
                  dtype,
              ) = training_utils.get_input_shape_and_dtype(layer)
              if batch_shape:
                  # Instantiate an input layer.
                  x = input_layer.Input(
                      batch_shape=batch_shape,
                      dtype=dtype,
                      name=layer.name + "_input",
                  )
                  # This will build the current layer
                  # and create the node connecting the current layer
                  # to the input layer we just created.
                  layer(x)
                  set_inputs = True
  
          if set_inputs:
              outputs = nest.flatten(layer._inbound_nodes[-1].outputs)
              if len(outputs) != 1:
                  raise ValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)
              self.outputs = outputs
              self.inputs = layer_utils.get_source_inputs(
                  self.outputs[0]
              )
              self.built = True
              self._has_explicit_input_shape = True
  
      elif self.outputs:
          # If the model is being built continuously on top of an input layer:
          # refresh its output.
          output_tensor = layer(self.outputs[0])
          if len(nest.flatten(output_tensor)) != 1:
              raise ValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)
          self.outputs = [output_tensor]
          self.built = True
  
      if set_inputs or self._graph_initialized:
          self._init_graph_network(self.inputs, self.outputs)
          self._graph_initialized = True
      else:
          self._self_tracked_trackables.append(layer)
          self._handle_deferred_layer_dependencies([layer])
  
      self._layer_call_argspecs[layer] = tf_inspect.getfullargspec(
          layer.call
      )
  
imports: import copy
  import warnings
  from tensorflow.python import tf2
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.keras import layers
  from tensorflow.python.keras.engine import base_layer
  from tensorflow.python.keras.engine import functional
  from tensorflow.python.keras.engine import input_layer
  from tensorflow.python.keras.engine import training_utils
  from tensorflow.python.keras.saving.saved_model import model_serialization
  from tensorflow.python.keras.utils import generic_utils
  from tensorflow.python.keras.utils import layer_utils
  from tensorflow.python.keras.utils import tf_inspect
  from tensorflow.python.keras.utils import tf_utils
  from tensorflow.python.module import module
  from tensorflow.python.ops.numpy_ops import np_arrays
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.trackable import base
  from tensorflow.python.util import nest
label_desc: Use image node_id 3 for calling the Sequential obj's underlying member method code with example usage: obj.add(layer) without return types