---
title: TorchElasticEnvironment
description: Environment for fault-tolerant and elastic training with torchelastic
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.plugins.environments.TorchElasticEnvironment
---
# TorchElasticEnvironment {#torchelasticenvironment}

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

Bases: [`ClusterEnvironment`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.plugins.environments.ClusterEnvironment.md#lightning.pytorch.plugins.environments.ClusterEnvironment "lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment")

Environment for fault-tolerant and elastic training with [torchelastic](https://pytorch.org/elastic/)

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

Returns `True` if the current process was launched using the torchelastic command.

Return type:

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

#### `global_rank()` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)")

#### `local_rank()` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)")

#### `node_rank()` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)")

#### `validate_settings(num_devices, num_nodes)` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)")

#### `world_size()` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)")

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

Whether the environment creates the subprocesses or not.

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

The main address through which all processes connect and communicate.

#### `property main_port: int` {#lightning.pytorch.plugins.environments.TorchElasticEnvironment.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)
