# tf.contrib.tpu.keras_to_tpu_model

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/tpu/python/tpu/keras_support.py#L2184-L2259) |

Copy `model` along with weights to the TPU. (deprecated)

    tf.contrib.tpu.keras_to_tpu_model(
        model, strategy=None
    )

> [!WARNING]
> **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed after 2019-02-20. Instructions for updating: Switch to tf.contrib.distribute.TPUStrategy. <https://www.tensorflow.org/api_docs/python/tf/contrib/distribute/DistributionStrategy>

Returns a TPU model.

#### Usage:

    a = Input(shape=(32,))
    b = Dense(32)(a)
    model = Model(inputs=a, outputs=b)

    # If `num_cores_per_host` is greater than one, batch parallelism will be used
    # to run on multiple TPU cores.
    strategy = keras_support.TPUDistributionStrategy(tpu_cluster_resolver)
    model = keras_support.tpu_model(model, strategy)
    model.compile(
        optimizer=tf.compat.v1.train.GradientDescentOptimizer(learning_rate=1.0),
        ...)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `model` | A [`tf.keras.Model`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/Model) instance. |
| `strategy` | `TPUDistributionStrategy`. The strategy to use for replicating model across multiple TPU cores. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A new `KerasTPUModel` instance. ||

<br />