---
title: SingleDeviceStrategy
description: Strategy that handles communication on a single device.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.strategies.SingleDeviceStrategy
---
# SingleDeviceStrategy {#singledevicestrategy}

### `class lightning.pytorch.strategies.SingleDeviceStrategy(device='cpu', accelerator=None, checkpoint_io=None, precision_plugin=None)` {#lightning.pytorch.strategies.SingleDeviceStrategy}

Bases: [`Strategy`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.strategies.Strategy.md#lightning.pytorch.strategies.Strategy "lightning.pytorch.strategies.strategy.Strategy")

Strategy that handles communication on a single device.

#### `all_gather(tensor, group=None, sync_grads=False)` {#lightning.pytorch.strategies.SingleDeviceStrategy.all_gather}

Perform a all\_gather on all processes.

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

#### `barrier(*args, **kwargs)` {#lightning.pytorch.strategies.SingleDeviceStrategy.barrier}

Synchronizes all processes which blocks processes until the whole group enters this function.

Parameters:

**name** – an optional name to pass into barrier.

Return type:

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

#### `broadcast(obj, src=0)` {#lightning.pytorch.strategies.SingleDeviceStrategy.broadcast}

Broadcasts an object to all processes.

Parameters:

*   **obj** ([`TypeVar`](https://docs.python.org/3/library/typing.html#typing.TypeVar "(in Python v3.15)")(`TBroadcast`)) – the object to broadcast
    
*   **src** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – source rank
    

Return type:

[`TypeVar`](https://docs.python.org/3/library/typing.html#typing.TypeVar "(in Python v3.15)")(`TBroadcast`)

#### `model_to_device()` {#lightning.pytorch.strategies.SingleDeviceStrategy.model_to_device}

Moves the model to the correct device.

Return type:

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

#### `reduce(tensor, *args, **kwargs)` {#lightning.pytorch.strategies.SingleDeviceStrategy.reduce}

Reduces a tensor from several distributed processes to one aggregated tensor. Since this strategy only operates with a single device, the reduction is simply the identity.

Parameters:

*   **tensor** (`Union`\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]) – the tensor to sync and reduce
    
*   **\*args** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – ignored
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – ignored
    

Return type:

`Union`\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]

Returns:

the unmodified input as reduction is not needed for single process operation

#### `property is_global_zero: bool` {#lightning.pytorch.strategies.SingleDeviceStrategy.is_global_zero}

Whether the current process is the rank zero process not only on the local node, but for all nodes.

#### `property root_device: device` {#lightning.pytorch.strategies.SingleDeviceStrategy.root_device}

Returns the root device.

---

**Navigation**

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