prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Keras model in federated_learning_for_image_classification.ipynb throws warning
  **Describe the bug**
  Keras Sequential Model in [federated_learning_for_image_classification.ipynb](https://github.com/tensorflow/federated/blob/master/docs/tutorials/federated_learning_for_image_classification.ipynb) throws warning.
  The model in the notebook is
  ```python
  def create_keras_model():
    return tf.keras.models.Sequential([
        tf.keras.layers.Input(shape=(784,)),
        tf.keras.layers.Dense(10, kernel_initializer='zeros'),
        tf.keras.layers.Softmax(),
    ])
  ```
  Warning thrown:
  ```python
  WARNING:tensorflow:Please add `keras.layers.InputLayer` instead of `keras.Input` to Sequential model. `keras.Input` is intended to be used by Functional model.
  <tensorflow.python.keras.engine.sequential.Sequential at 0x7f66178a46d0>
  ```
  
  Easily fixed using the correct layer type:
  ```python
  def create_keras_model():
    return tf.keras.models.Sequential([
        tf.keras.layers.InputLayer(input_shape=(784,)),
        tf.keras.layers.Dense(10, kernel_initializer='zeros'),
        tf.keras.layers.Softmax(),
    ])
  ```
  
  [colab](https://colab.research.google.com/drive/1LFgBiu9xUa-k92IW24fiSX_kVp7lb0SB?usp=sharing) notebook that reproduces the bug.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `tensorflow_federated/python/examples/remote_execution/remote_executor_example.py`
  Content:
  ```
  1 # Copyright 2018, The TensorFlow Federated Authors.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #      http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 """Example showing how to run a multi-machine simulation.
  15 
  16 In order to run this example, you must have a running instance of the
  17 Executor Service, either locally or on Kubernetes.
  18 
  19 The model trains EMNIST for a small number of rounds, but uses a RemoteExecutor
  20 to distribute the work to the ExecutorService.
  21 """
  22 
  23 import collections
  24 import warnings
  25 
  26 from absl import app
  27 from absl import flags
  28 import grpc
  29 import numpy as np
  30 import tensorflow as tf
  31 import tensorflow_federated as tff
  32 
  33 FLAGS = flags.FLAGS
  34 
  35 flags.DEFINE_string('host', None, 'The host to connect to.')
  36 flags.mark_flag_as_required('host')
  37 flags.DEFINE_string('port', '8000', 'The port to connect to.')
  38 flags.DEFINE_integer('n_clients', 10, 'Number of clients.')
  39 flags.DEFINE_integer('n_rounds', 3, 'Number of rounds.')
  40 
  41 
  42 def preprocess(dataset):
  43 
  44   def element_fn(element):
  45     return collections.OrderedDict([
  46         ('x', tf.reshape(element['pixels'], [-1])),
  47         ('y', tf.reshape(element['label'], [1])),
  48     ])
  49 
  50   return dataset.repeat(NUM_EPOCHS).map(element_fn).batch(BATCH_SIZE)
  51 
  52 
  53 def make_federated_data(client_data, client_ids):
  54   return [
  55       preprocess(client_data.create_tf_dataset_for_client(x))
  56       for x in client_ids
  57   ]
  58 
  59 
  60 NUM_EPOCHS = 10
  61 BATCH_SIZE = 20
  62 
  63 
  64 def make_remote_executor(inferred_cardinalities):
  65   """Make remote executor."""
  66 
  67   def create_worker_stack(ex):
  68     ex = tff.framework.ThreadDelegatingExecutor(ex)
  69     return tff.framework.ReferenceResolvingExecutor(ex)
  70 
  71   client_ex = []
  72   num_clients = inferred_cardinalities.get(tff.CLIENTS, None)
  73   if num_clients:
  74     print('Inferred that there are {} clients'.format(num_clients))
  75   else:
  76     print('No CLIENTS placement provided')
  77 
  78   for _ in range(num_clients or 0):
  79     channel = grpc.insecure_channel('{}:{}'.format(FLAGS.host, FLAGS.port))
  80     remote_ex = tff.framework.RemoteExecutor(channel)
  81     worker_stack = create_worker_stack(remote_ex)
  82     client_ex.append(worker_stack)
  83 
  84   federating_strategy_factory = tff.framework.FederatedResolvingStrategy.factory(
  85       {
  86           tff.SERVER: create_worker_stack(tff.framework.EagerTFExecutor()),
  87           tff.CLIENTS: client_ex,
  88       })
  89   unplaced_ex = create_worker_stack(tff.framework.EagerTFExecutor())
  90   federating_ex = tff.framework.FederatingExecutor(federating_strategy_factory,
  91                                                    unplaced_ex)
  92   return tff.framework.ReferenceResolvingExecutor(federating_ex)
  93 
  94 
  95 def main(argv):
  96   if len(argv) > 1:
  97     raise app.UsageError('Too many command-line arguments.')
  98 
  99   warnings.simplefilter('ignore')
  100 
  101   np.random.seed(0)
  102 
  103   emnist_train, _ = tff.simulation.datasets.emnist.load_data()
  104 
  105   sample_clients = emnist_train.client_ids[0:FLAGS.n_clients]
  106 
  107   federated_train_data = make_federated_data(emnist_train, sample_clients)
  108 
  109   example_dataset = emnist_train.create_tf_dataset_for_client(
  110       emnist_train.client_ids[0])
  111 
  112   preprocessed_example_dataset = preprocess(example_dataset)
  113   input_spec = preprocessed_example_dataset.element_spec
  114 
  115   def model_fn():
  116     model = tf.keras.models.Sequential([
  117         tf.keras.layers.Input(shape=(784,)),
  118         tf.keras.layers.Dense(10, kernel_initializer='zeros'),
  119         tf.keras.layers.Softmax(),
  120     ])
  121     return tff.learning.from_keras_model(
  122         model,
  123         input_spec=input_spec,
  124         loss=tf.keras.losses.SparseCategoricalCrossentropy(),
  125         metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])
  126 
  127   iterative_process = tff.learning.build_federated_averaging_process(
  128       model_fn,
  129       client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02))
  130 
  131   factory = tff.framework.ResourceManagingExecutorFactory(make_remote_executor)
  132   context = tff.framework.ExecutionContext(factory)
  133   tff.framework.set_default_context(context)
  134 
  135   state = iterative_process.initialize()
  136 
  137   state, metrics = iterative_process.next(state, federated_train_data)
  138   print('round  1, metrics={}'.format(metrics))
  139 
  140   for round_num in range(2, FLAGS.n_rounds + 1):
  141     state, metrics = iterative_process.next(state, federated_train_data)
  142     print('round {:2d}, metrics={}'.format(round_num, metrics))
  143 
  144 
  145 if __name__ == '__main__':
  146   app.run(main)
  147
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py b/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py
  --- a/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py
  +++ b/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py
  @@ -114,7 +114,7 @@
   
     def model_fn():
       model = tf.keras.models.Sequential([
  -        tf.keras.layers.Input(shape=(784,)),
  +        tf.keras.layers.InputLayer(input_shape=(784,)),
           tf.keras.layers.Dense(10, kernel_initializer='zeros'),
           tf.keras.layers.Softmax(),
       ])
  
verification_info: {"golden_diff": "diff --git a/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py b/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py\n--- a/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py\n+++ b/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py\n@@ -114,7 +114,7 @@\n \n   def model_fn():\n     model = tf.keras.models.Sequential([\n-        tf.keras.layers.Input(shape=(784,)),\n+        tf.keras.layers.InputLayer(input_shape=(784,)),\n         tf.keras.layers.Dense(10, kernel_initializer='zeros'),\n         tf.keras.layers.Softmax(),\n     ])\n", "issue": "Keras model in federated_learning_for_image_classification.ipynb throws warning\n**Describe the bug**\r\nKeras Sequential Model in [federated_learning_for_image_classification.ipynb](https://github.com/tensorflow/federated/blob/master/docs/tutorials/federated_learning_for_image_classification.ipynb) throws warning.\r\nThe model in the notebook is\r\n```python\r\ndef create_keras_model():\r\n  return tf.keras.models.Sequential([\r\n      tf.keras.layers.Input(shape=(784,)),\r\n      tf.keras.layers.Dense(10, kernel_initializer='zeros'),\r\n      tf.keras.layers.Softmax(),\r\n  ])\r\n```\r\nWarning thrown:\r\n```python\r\nWARNING:tensorflow:Please add `keras.layers.InputLayer` instead of `keras.Input` to Sequential model. `keras.Input` is intended to be used by Functional model.\r\n<tensorflow.python.keras.engine.sequential.Sequential at 0x7f66178a46d0>\r\n```\r\n\r\nEasily fixed using the correct layer type:\r\n```python\r\ndef create_keras_model():\r\n  return tf.keras.models.Sequential([\r\n      tf.keras.layers.InputLayer(input_shape=(784,)),\r\n      tf.keras.layers.Dense(10, kernel_initializer='zeros'),\r\n      tf.keras.layers.Softmax(),\r\n  ])\r\n```\r\n\r\n[colab](https://colab.research.google.com/drive/1LFgBiu9xUa-k92IW24fiSX_kVp7lb0SB?usp=sharing) notebook that reproduces the bug.\r\n\n", "before_files": [{"content": "# Copyright 2018, The TensorFlow Federated Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Example showing how to run a multi-machine simulation.\n\nIn order to run this example, you must have a running instance of the\nExecutor Service, either locally or on Kubernetes.\n\nThe model trains EMNIST for a small number of rounds, but uses a RemoteExecutor\nto distribute the work to the ExecutorService.\n\"\"\"\n\nimport collections\nimport warnings\n\nfrom absl import app\nfrom absl import flags\nimport grpc\nimport numpy as np\nimport tensorflow as tf\nimport tensorflow_federated as tff\n\nFLAGS = flags.FLAGS\n\nflags.DEFINE_string('host', None, 'The host to connect to.')\nflags.mark_flag_as_required('host')\nflags.DEFINE_string('port', '8000', 'The port to connect to.')\nflags.DEFINE_integer('n_clients', 10, 'Number of clients.')\nflags.DEFINE_integer('n_rounds', 3, 'Number of rounds.')\n\n\ndef preprocess(dataset):\n\n  def element_fn(element):\n    return collections.OrderedDict([\n        ('x', tf.reshape(element['pixels'], [-1])),\n        ('y', tf.reshape(element['label'], [1])),\n    ])\n\n  return dataset.repeat(NUM_EPOCHS).map(element_fn).batch(BATCH_SIZE)\n\n\ndef make_federated_data(client_data, client_ids):\n  return [\n      preprocess(client_data.create_tf_dataset_for_client(x))\n      for x in client_ids\n  ]\n\n\nNUM_EPOCHS = 10\nBATCH_SIZE = 20\n\n\ndef make_remote_executor(inferred_cardinalities):\n  \"\"\"Make remote executor.\"\"\"\n\n  def create_worker_stack(ex):\n    ex = tff.framework.ThreadDelegatingExecutor(ex)\n    return tff.framework.ReferenceResolvingExecutor(ex)\n\n  client_ex = []\n  num_clients = inferred_cardinalities.get(tff.CLIENTS, None)\n  if num_clients:\n    print('Inferred that there are {} clients'.format(num_clients))\n  else:\n    print('No CLIENTS placement provided')\n\n  for _ in range(num_clients or 0):\n    channel = grpc.insecure_channel('{}:{}'.format(FLAGS.host, FLAGS.port))\n    remote_ex = tff.framework.RemoteExecutor(channel)\n    worker_stack = create_worker_stack(remote_ex)\n    client_ex.append(worker_stack)\n\n  federating_strategy_factory = tff.framework.FederatedResolvingStrategy.factory(\n      {\n          tff.SERVER: create_worker_stack(tff.framework.EagerTFExecutor()),\n          tff.CLIENTS: client_ex,\n      })\n  unplaced_ex = create_worker_stack(tff.framework.EagerTFExecutor())\n  federating_ex = tff.framework.FederatingExecutor(federating_strategy_factory,\n                                                   unplaced_ex)\n  return tff.framework.ReferenceResolvingExecutor(federating_ex)\n\n\ndef main(argv):\n  if len(argv) > 1:\n    raise app.UsageError('Too many command-line arguments.')\n\n  warnings.simplefilter('ignore')\n\n  np.random.seed(0)\n\n  emnist_train, _ = tff.simulation.datasets.emnist.load_data()\n\n  sample_clients = emnist_train.client_ids[0:FLAGS.n_clients]\n\n  federated_train_data = make_federated_data(emnist_train, sample_clients)\n\n  example_dataset = emnist_train.create_tf_dataset_for_client(\n      emnist_train.client_ids[0])\n\n  preprocessed_example_dataset = preprocess(example_dataset)\n  input_spec = preprocessed_example_dataset.element_spec\n\n  def model_fn():\n    model = tf.keras.models.Sequential([\n        tf.keras.layers.Input(shape=(784,)),\n        tf.keras.layers.Dense(10, kernel_initializer='zeros'),\n        tf.keras.layers.Softmax(),\n    ])\n    return tff.learning.from_keras_model(\n        model,\n        input_spec=input_spec,\n        loss=tf.keras.losses.SparseCategoricalCrossentropy(),\n        metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])\n\n  iterative_process = tff.learning.build_federated_averaging_process(\n      model_fn,\n      client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02))\n\n  factory = tff.framework.ResourceManagingExecutorFactory(make_remote_executor)\n  context = tff.framework.ExecutionContext(factory)\n  tff.framework.set_default_context(context)\n\n  state = iterative_process.initialize()\n\n  state, metrics = iterative_process.next(state, federated_train_data)\n  print('round  1, metrics={}'.format(metrics))\n\n  for round_num in range(2, FLAGS.n_rounds + 1):\n    state, metrics = iterative_process.next(state, federated_train_data)\n    print('round {:2d}, metrics={}'.format(round_num, metrics))\n\n\nif __name__ == '__main__':\n  app.run(main)\n", "path": "tensorflow_federated/python/examples/remote_execution/remote_executor_example.py"}], "after_files": [{"content": "# Copyright 2018, The TensorFlow Federated Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Example showing how to run a multi-machine simulation.\n\nIn order to run this example, you must have a running instance of the\nExecutor Service, either locally or on Kubernetes.\n\nThe model trains EMNIST for a small number of rounds, but uses a RemoteExecutor\nto distribute the work to the ExecutorService.\n\"\"\"\n\nimport collections\nimport warnings\n\nfrom absl import app\nfrom absl import flags\nimport grpc\nimport numpy as np\nimport tensorflow as tf\nimport tensorflow_federated as tff\n\nFLAGS = flags.FLAGS\n\nflags.DEFINE_string('host', None, 'The host to connect to.')\nflags.mark_flag_as_required('host')\nflags.DEFINE_string('port', '8000', 'The port to connect to.')\nflags.DEFINE_integer('n_clients', 10, 'Number of clients.')\nflags.DEFINE_integer('n_rounds', 3, 'Number of rounds.')\n\n\ndef preprocess(dataset):\n\n  def element_fn(element):\n    return collections.OrderedDict([\n        ('x', tf.reshape(element['pixels'], [-1])),\n        ('y', tf.reshape(element['label'], [1])),\n    ])\n\n  return dataset.repeat(NUM_EPOCHS).map(element_fn).batch(BATCH_SIZE)\n\n\ndef make_federated_data(client_data, client_ids):\n  return [\n      preprocess(client_data.create_tf_dataset_for_client(x))\n      for x in client_ids\n  ]\n\n\nNUM_EPOCHS = 10\nBATCH_SIZE = 20\n\n\ndef make_remote_executor(inferred_cardinalities):\n  \"\"\"Make remote executor.\"\"\"\n\n  def create_worker_stack(ex):\n    ex = tff.framework.ThreadDelegatingExecutor(ex)\n    return tff.framework.ReferenceResolvingExecutor(ex)\n\n  client_ex = []\n  num_clients = inferred_cardinalities.get(tff.CLIENTS, None)\n  if num_clients:\n    print('Inferred that there are {} clients'.format(num_clients))\n  else:\n    print('No CLIENTS placement provided')\n\n  for _ in range(num_clients or 0):\n    channel = grpc.insecure_channel('{}:{}'.format(FLAGS.host, FLAGS.port))\n    remote_ex = tff.framework.RemoteExecutor(channel)\n    worker_stack = create_worker_stack(remote_ex)\n    client_ex.append(worker_stack)\n\n  federating_strategy_factory = tff.framework.FederatedResolvingStrategy.factory(\n      {\n          tff.SERVER: create_worker_stack(tff.framework.EagerTFExecutor()),\n          tff.CLIENTS: client_ex,\n      })\n  unplaced_ex = create_worker_stack(tff.framework.EagerTFExecutor())\n  federating_ex = tff.framework.FederatingExecutor(federating_strategy_factory,\n                                                   unplaced_ex)\n  return tff.framework.ReferenceResolvingExecutor(federating_ex)\n\n\ndef main(argv):\n  if len(argv) > 1:\n    raise app.UsageError('Too many command-line arguments.')\n\n  warnings.simplefilter('ignore')\n\n  np.random.seed(0)\n\n  emnist_train, _ = tff.simulation.datasets.emnist.load_data()\n\n  sample_clients = emnist_train.client_ids[0:FLAGS.n_clients]\n\n  federated_train_data = make_federated_data(emnist_train, sample_clients)\n\n  example_dataset = emnist_train.create_tf_dataset_for_client(\n      emnist_train.client_ids[0])\n\n  preprocessed_example_dataset = preprocess(example_dataset)\n  input_spec = preprocessed_example_dataset.element_spec\n\n  def model_fn():\n    model = tf.keras.models.Sequential([\n        tf.keras.layers.InputLayer(input_shape=(784,)),\n        tf.keras.layers.Dense(10, kernel_initializer='zeros'),\n        tf.keras.layers.Softmax(),\n    ])\n    return tff.learning.from_keras_model(\n        model,\n        input_spec=input_spec,\n        loss=tf.keras.losses.SparseCategoricalCrossentropy(),\n        metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])\n\n  iterative_process = tff.learning.build_federated_averaging_process(\n      model_fn,\n      client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02))\n\n  factory = tff.framework.ResourceManagingExecutorFactory(make_remote_executor)\n  context = tff.framework.ExecutionContext(factory)\n  tff.framework.set_default_context(context)\n\n  state = iterative_process.initialize()\n\n  state, metrics = iterative_process.next(state, federated_train_data)\n  print('round  1, metrics={}'.format(metrics))\n\n  for round_num in range(2, FLAGS.n_rounds + 1):\n    state, metrics = iterative_process.next(state, federated_train_data)\n    print('round {:2d}, metrics={}'.format(round_num, metrics))\n\n\nif __name__ == '__main__':\n  app.run(main)\n", "path": "tensorflow_federated/python/examples/remote_execution/remote_executor_example.py"}]}