---
title: ClusterEnvironment
description: Specification of a cluster environment.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.plugins.environments.ClusterEnvironment
---
# ClusterEnvironment {#clusterenvironment}

### `class lightning.pytorch.plugins.environments.ClusterEnvironment` {#lightning.pytorch.plugins.environments.ClusterEnvironment}

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC "(in Python v3.15)")

Specification of a cluster environment.

#### `abstract static detect()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.detect}

Detects the environment settings corresponding to this cluster and returns `True` if they match.

Return type:

[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")

#### `abstract global_rank()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.global_rank}

The rank (index) of the currently running process across all nodes and devices.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `abstract local_rank()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.local_rank}

The rank (index) of the currently running process inside of the current node.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `abstract node_rank()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.node_rank}

The rank (index) of the node on which the current process runs.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `teardown()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.teardown}

Clean up any state set after execution finishes.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `validate_settings(num_devices, num_nodes)` {#lightning.pytorch.plugins.environments.ClusterEnvironment.validate_settings}

Validates settings configured in the script against the environment, and raises an exception if there is an inconsistency.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `abstract world_size()` {#lightning.pytorch.plugins.environments.ClusterEnvironment.world_size}

The number of processes across all devices and nodes.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `abstract property creates_processes_externally: bool` {#lightning.pytorch.plugins.environments.ClusterEnvironment.creates_processes_externally}

Whether the environment creates the subprocesses or not.

#### `abstract property main_address: str` {#lightning.pytorch.plugins.environments.ClusterEnvironment.main_address}

The main address through which all processes connect and communicate.

#### `abstract property main_port: int` {#lightning.pytorch.plugins.environments.ClusterEnvironment.main_port}

An open and configured port in the main node through which all processes communicate.

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
