# tf.compat.v1.get_variable_scope

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/variable_scope.py#L1469-L1499) |

Returns the current variable scope.

    tf.compat.v1.get_variable_scope()

<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.

Although it is a legacy [`compat.v1`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/compat/v1) api,
[`tf.compat.v1.get_variable`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/compat/v1/get_variable) is compatible with eager
execution and [`tf.function`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/function)

However, to maintain variable-scope based variable reuse
you will need to combine it with
`tf.compat.v1.keras.utils.track_tf1_style_variables`. (Though
it will behave as if reuse is always set to [`tf.compat.v1.AUTO_REUSE`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/compat/v1#AUTO_REUSE).)

See the
[migration guide](https://www.tensorflow.org/guide/migrate/model_mapping)
for more info.

The TF2 equivalent, if you are just trying to track
variable name prefixes and not control `get_variable`-based variable reuse,
would be to use [`tf.name_scope`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/name_scope) and capture the output of opening the
scope (which represents the current name prefix).

For example:

    x = tf.name_scope('foo') as current_scope:
      ...

<br />

<br />

## Description