# tf.compat.v1.fixed_size_partitioner

<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/partitioned_variables.py#L220-L272) |

Partitioner to specify a fixed number of shards along given axis.

    tf.compat.v1.fixed_size_partitioner(
        num_shards, axis=0
    )

<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 deprecated in TF2. In TF2, partitioner is no longer part of
the variable declaration via [`tf.Variable`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/Variable).
[ParameterServer Training](https://www.tensorflow.org/tutorials/distribute/parameter_server_training)
handles partitioning of variables. The corresponding TF2 partitioner class of
`fixed_size_partitioner` is
[`tf.distribute.experimental.partitioners.FixedShardsPartitioner`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/distribute/experimental/partitioners/FixedShardsPartitioner).

Check the [migration guide](https://www.tensorflow.org/guide/migrate#2_use_python_objects_to_track_variables_and_losses)
on the differences in treatment of variables and losses between TF1 and TF2.

Before:

      x = tf.compat.v1.get_variable(
        "x", shape=(2,), partitioner=tf.compat.v1.fixed_size_partitioner(2)
      )

After:

      partitioner = (
          tf.distribute.experimental.partitioners.FixedShardsPartitioner(
              num_shards=2)
      )
      strategy = tf.distribute.experimental.ParameterServerStrategy(
                     cluster_resolver=cluster_resolver,
                     variable_partitioner=partitioner)

      with strategy.scope():
        x = tf.Variable([1.0, 2.0])

<br />

<br />

## Description

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_shards` | `int`, number of shards to partition variable. |
| `axis` | `int`, axis to partition on. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A partition function usable as the `partitioner` argument to `variable_scope` and `get_variable`. ||

<br />