# tf.distribute.experimental.partitioners.FixedShardsPartitioner

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/distribute/sharded_variable.py#L83-L112) |

Partitioner that allocates a fixed number of shards.

Inherits From: [`Partitioner`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/distribute/experimental/partitioners/Partitioner)

    tf.distribute.experimental.partitioners.FixedShardsPartitioner(
        num_shards
    )

#### Examples:

    # standalone usage:
    partitioner = FixedShardsPartitioner(num_shards=2)
    partitions = partitioner(tf.TensorShape([10, 3]), tf.float32)
    [2, 1]

    # use in ParameterServerStrategy
    # strategy = tf.distribute.experimental.ParameterServerStrategy(
    #   cluster_resolver=cluster_resolver, variable_partitioner=partitioner)

<br />

<br />

<br />

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

<br />

## Methods

### `__call__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/distribute/sharded_variable.py#L108-L112)

    __call__(
        shape, dtype, axis=0
    )

Partitions the given `shape` and returns the partition results.

Examples of a partitioner that allocates a fixed number of shards:

    partitioner = FixedShardsPartitioner(num_shards=2)
    partitions = partitioner(tf.TensorShape([10, 3], tf.float32), axis=0)
    print(partitions) # [2, 0]

<br />

<br />

<br />

| Args ||
|---|---|
| `shape` | a [`tf.TensorShape`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/TensorShape), the shape to partition. |
| `dtype` | a `tf.dtypes.Dtype` indicating the type of the partition value. |
| `axis` | The axis to partition along. Default: outermost axis. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A list of integers representing the number of partitions on each axis, where i-th value correponds to i-th axis. ||

<br />