---
title: SLURMEnvironment
description: Cluster environment for training on a cluster managed by SLURM.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.plugins.environments.SLURMEnvironment
---
# SLURMEnvironment {#slurmenvironment}

### `class lightning.pytorch.plugins.environments.SLURMEnvironment(auto_requeue=True, requeue_signal=None)` {#lightning.pytorch.plugins.environments.SLURMEnvironment}

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")

Cluster environment for training on a cluster managed by SLURM.

You can configure the main\_address and main\_port properties via the env variables MASTER\_ADDR and MASTER\_PORT, respectively.

Parameters:

*   **auto\_requeue** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether automatic job resubmission is enabled or not. How and under which conditions a job gets rescheduled gets determined by the owner of this plugin.
    
*   **requeue\_signal** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Signals`](https://docs.python.org/3/library/signal.html#signal.Signals "(in Python v3.15)")\]) – The signal that SLURM will send to indicate that the job should be requeued. Defaults to SIGUSR1 on Unix.
    

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

Returns `True` if the current process was launched on a SLURM cluster.

It is possible to use the SLURM scheduler to request resources and then launch processes manually using a different environment. For this, the user can set the job name in SLURM to ‘bash’ or ‘interactive’ (srun –job- name=interactive). This will then avoid the detection of `SLURMEnvironment` and another environment can be detected automatically.

Return type:

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

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

#### `static resolve_root_node_address(nodes)` {#lightning.pytorch.plugins.environments.SLURMEnvironment.resolve_root_node_address}

The node selection format in SLURM supports several formats.

This function selects the first host name from :rtype: [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")

*   a space-separated list of host names, e.g., ‘host0 host1 host3’ yields ‘host0’ as the root
    
*   a comma-separated list of host names, e.g., ‘host0,host1,host3’ yields ‘host0’ as the root
    
*   the range notation with brackets, e.g., ‘host\[5-9\]’ yields ‘host5’ as the root
    

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

Whether the environment creates the subprocesses or not.

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

The main address through which all processes connect and communicate.

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