# tf.compat.v1.placeholder_with_default

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/array_ops.py#L3175-L3224) |

A placeholder op that passes through `input` when its output is not fed.

    tf.compat.v1.placeholder_with_default(
        input, shape, name=None
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

This API is strongly discouraged for use with eager execution and
[`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function). The primary use of this API is for testing computation wrapped
within a [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function) where the input tensors might not have statically known
fully-defined shapes. The same can be achieved by creating a
[concrete function](https://www.tensorflow.org/guide/function#obtaining_concrete_functions)
from the [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function) with a [`tf.TensorSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TensorSpec) input which has partially
defined shapes. For example, the code

    @tf.function
    def f():
      x = tf.compat.v1.placeholder_with_default(
          tf.constant([[1., 2., 3.], [4., 5., 6.]]), [None, 3])
      y = tf.constant([[1.],[2.], [3.]])
      z = tf.matmul(x, y)
      assert z.shape[0] == None
      assert z.shape[1] == 1

    f()

can easily be replaced by

    @tf.function
    def f(x):
      y = tf.constant([[1.],[2.], [3.]])
      z = tf.matmul(x, y)
      assert z.shape[0] == None
      assert z.shape[1] == 1

    g = f.get_concrete_function(tf.TensorSpec([None, 3]))

You can learn more about [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function) at [Better
performance with tf.function](https://www.tensorflow.org/guide/function).

<br />

<br />

## Description

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input` | A `Tensor`. The default value to produce when output is not fed. |
| `shape` | A [`tf.TensorShape`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TensorShape) or list of `int`s. The (possibly partial) shape of the tensor. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor`. Has the same type as `input`. ||

<br />