---
title: Fabric
description: >-
  Fabric accelerates your PyTorch training or inference code with minimal
  changes required.
canonical: >-
  https://lightning.ai/docs/fabric/stable/full-api-reference/api/generated/lightning.fabric.fabric.Fabric
---
# Fabric {#fabric}

### `class lightning.fabric.fabric.Fabric(*, accelerator='auto', strategy='auto', devices='auto', num_nodes=1, precision=None, plugins=None, callbacks=None, loggers=None)` {#lightning.fabric.fabric.Fabric}

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

Fabric accelerates your PyTorch training or inference code with minimal changes required.

Key Features:

*   Automatic placement of models and data onto the device.
    
*   Automatic support for mixed and double precision (smaller memory footprint).
    
*   Seamless switching between hardware (CPU, GPU, TPU) and distributed training strategies (data-parallel training, sharded training, etc.).
    
*   Automated spawning of processes, no launch utilities required.
    
*   Multi-node support.
    

Parameters:

*   **accelerator** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Accelerator`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.accelerators.Accelerator.md#lightning.fabric.accelerators.Accelerator "lightning.fabric.accelerators.accelerator.Accelerator")\]) – The hardware to run on. Possible choices are: `"cpu"`, `"cuda"`, `"mps"`, `"gpu"`, `"tpu"`, `"auto"`. Defaults to `"auto"`.
    
*   **strategy** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Strategy`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.strategies.Strategy.md#lightning.fabric.strategies.Strategy "lightning.fabric.strategies.strategy.Strategy")\]) – Strategy for how to run across multiple devices. Possible choices are: `"dp"`, `"ddp"`, `"ddp_spawn"`, `"deepspeed"`, `"fsdp"`, `"auto"`. Defaults to `"auto"`.
    
*   **devices** (`Union`\[[`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\], [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Number of devices to train on (`int`), which GPUs to train on (`list` or `str`), or `"auto"`. The value applies per node. Defaults to `"auto"`.
    
*   **num\_nodes** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Number of GPU nodes for distributed training. Defaults to `1`.
    
*   **precision** (`Union`\[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`64`, `32`, `16`\], [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'transformer-engine'`, `'transformer-engine-float16'`, `'16-true'`, `'16-mixed'`, `'bf16-true'`, `'bf16-mixed'`, `'32-true'`, `'64-true'`\], [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'64'`, `'32'`, `'16'`, `'bf16'`\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Double precision (`"64"`), full precision (`"32"`), half precision AMP (`"16-mixed"`), or bfloat16 precision AMP (`"bf16-mixed"`). If `None`, defaults will be used based on the device.
    
*   **plugins** (`Union`\[[`Precision`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.precision.Precision.md#lightning.fabric.plugins.precision.Precision "lightning.fabric.plugins.precision.precision.Precision"), [`ClusterEnvironment`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment.md#lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment "lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment"), [`CheckpointIO`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.io.checkpoint_io.CheckpointIO.md#lightning.fabric.plugins.io.checkpoint_io.CheckpointIO "lightning.fabric.plugins.io.checkpoint_io.CheckpointIO"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[`Union`\[[`Precision`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.precision.Precision.md#lightning.fabric.plugins.precision.Precision "lightning.fabric.plugins.precision.precision.Precision"), [`ClusterEnvironment`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment.md#lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment "lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment"), [`CheckpointIO`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.io.checkpoint_io.CheckpointIO.md#lightning.fabric.plugins.io.checkpoint_io.CheckpointIO "lightning.fabric.plugins.io.checkpoint_io.CheckpointIO")\]\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – One or several custom plugins as a single plugin or list of plugins.
    
*   **callbacks** (`Union`\[[`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – A single callback or a list of callbacks. A callback can contain any arbitrary methods that can be invoked through [`call()`](#lightning.fabric.fabric.Fabric.call "lightning.fabric.fabric.Fabric.call") by the user.
    
*   **loggers** (`Union`\[[`Logger`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.loggers.Logger.md#lightning.fabric.loggers.Logger "lightning.fabric.loggers.logger.Logger"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[`Logger`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.loggers.Logger.md#lightning.fabric.loggers.Logger "lightning.fabric.loggers.logger.Logger")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – A single logger or a list of loggers. See [`log()`](#lightning.fabric.fabric.Fabric.log "lightning.fabric.fabric.Fabric.log") for more information.
    

Example:

```python
# Basic usage
fabric = Fabric(accelerator="gpu", devices=2)

# Set up model and optimizer
model = MyModel()
optimizer = torch.optim.Adam(model.parameters())
model, optimizer = fabric.setup(model, optimizer)

# Training loop
for batch in dataloader:
    optimizer.zero_grad()
    loss = model(batch)
    fabric.backward(loss)
    optimizer.step()
```

#### `_filter_kwargs_for_callback(method, kwargs)` {#lightning.fabric.fabric.Fabric._filter_kwargs_for_callback}

Filter keyword arguments to only include those that match the callback method’s signature.

Parameters:

*   **method** ([`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.15)")) – The callback method to inspect
    
*   **kwargs** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – The keyword arguments to filter
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]

Returns:

A filtered dictionary of keyword arguments that match the method’s signature

#### `_setup_dataloader(dataloader, use_distributed_sampler=True, move_to_device=True)` {#lightning.fabric.fabric.Fabric._setup_dataloader}

Set up a single dataloader for accelerated training.

Parameters:

*   **dataloader** ([`DataLoader`](https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader "(in PyTorch v2.15)")) – The dataloader to accelerate.
    
*   **use\_distributed\_sampler** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), automatically wraps or replaces the sampler on the dataloader for distributed training. If you have a custom sampler defined, set this argument to `False`.
    
*   **move\_to\_device** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), moves the data returned by the dataloader automatically to the correct device. Set this to `False` and alternatively use [`to_device()`](#lightning.fabric.fabric.Fabric.to_device "lightning.fabric.fabric.Fabric.to_device") manually on the returned data.
    

Return type:

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

Returns:

The wrapped dataloader.

#### `all_gather(data, group=None, sync_grads=False)` {#lightning.fabric.fabric.Fabric.all_gather}

Gather tensors or collections of tensors from multiple processes.

This method needs to be called on all processes and the tensors need to have the same shape across all processes, otherwise your program will stall forever.

Parameters:

*   **data** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\]) – int, float, tensor of shape (batch, …), or a (possibly nested) collection thereof.
    
*   **group** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – the process group to gather results from. Defaults to all processes (world).
    
*   **sync\_grads** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – flag that allows users to synchronize gradients for the `all_gather` operation
    

Return type:

`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\]

Returns:

A tensor of shape (world\_size, batch, …), or if the input was a collection the output will also be a collection with tensors of this shape. For the special case where world\_size is 1, no additional dimension is added to the tensor(s).

#### `all_reduce(data, group=None, reduce_op='mean')` {#lightning.fabric.fabric.Fabric.all_reduce}

Reduce tensors or collections of tensors from multiple processes.

The reduction on tensors is applied in-place, meaning the result will be placed back into the input tensor. This method needs to be called on all processes and the tensors need to have the same shape across all processes, otherwise your program will stall forever.

Parameters:

*   **data** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\]) – int, float, tensor of shape (batch, …), or a (possibly nested) collection thereof. Tensor will be modified in-place.
    
*   **group** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – the process group to reduce results across. Defaults to all processes (world).
    
*   **reduce\_op** (`Union`\[[`ReduceOp`](https://docs.pytorch.org/docs/stable/distributed.html#torch.distributed.ReduceOp "(in PyTorch v2.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – the reduction operation. Defaults to ‘mean’. Can also be a string ‘sum’ or ReduceOp. Some strategies may limit the choices here.
    

Return type:

`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\]

Returns:

A tensor of the same shape as the input with values reduced pointwise across processes. The same is applied to tensors in a collection if a collection is given as input.

#### `autocast()` {#lightning.fabric.fabric.Fabric.autocast}

A context manager to automatically convert operations for the chosen precision.

Use this only if the forward method of your model does not cover all operations you wish to run with the chosen precision setting.

Return type:

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

#### `backward(tensor, *args, model=None, **kwargs)` {#lightning.fabric.fabric.Fabric.backward}

Replaces `loss.backward()` in your training loop. Handles precision automatically for you.

Parameters:

*   **tensor** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – The tensor (loss) to back-propagate gradients from.
    
*   **\*args** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional positional arguments passed to the underlying backward function.
    
*   **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[`_FabricModule`\]) – Optional model instance for plugins that require the model for backward(). Required when using DeepSpeed strategy with multiple models.
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional named keyword arguments passed to the underlying backward function.
    

Return type:

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

Note

When using `strategy="deepspeed"` and multiple models were set up, it is required to pass in the model as argument here.

Example:

```python
loss = criterion(output, target)
fabric.backward(loss)

# With DeepSpeed and multiple models
fabric.backward(loss, model=model)
```

#### `barrier(name=None)` {#lightning.fabric.fabric.Fabric.barrier}

Wait for all processes to enter this call.

Use this to synchronize all parallel processes, but only if necessary, otherwise the overhead of synchronization will cause your program to slow down. This method needs to be called on all processes. Failing to do so will cause your program to stall forever.

Return type:

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

#### `broadcast(obj, src=0)` {#lightning.fabric.fabric.Fabric.broadcast}

Send a tensor from one process to all others.

This method needs to be called on all processes. Failing to do so will cause your program to stall forever.

Parameters:

*   **obj** ([`TypeVar`](https://docs.python.org/3/library/typing.html#typing.TypeVar "(in Python v3.15)")(`TBroadcast`)) – The object to broadcast to all other members. Any serializable object is supported, but it is most efficient with the object being a [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)").
    
*   **src** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – The (global) rank of the process that should send the data to all others.
    

Return type:

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

Returns:

The transferred data, the same value on every rank.

#### `call(hook_name, *args, **kwargs)` {#lightning.fabric.fabric.Fabric.call}

Trigger the callback methods with the given name and arguments.

Not all objects registered via `Fabric(callbacks=...)` must implement a method with the given name. The ones that have a matching method name will get called.

Parameters:

*   **hook\_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – The name of the callback method.
    
*   **\*args** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional positional arguments that get passed down to the callback method.
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional keyword arguments that get passed down to the callback method. Keyword arguments that are not present in the callback’s signature will be filtered out automatically, allowing callbacks to have different signatures for the same hook.
    

Return type:

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

Example:

```python
class MyCallback:
    def on_train_epoch_end(self, results):
        ...

fabric = Fabric(callbacks=[MyCallback()])
fabric.call("on_train_epoch_end", results={...})
```

#### `clip_gradients(module, optimizer, clip_val=None, max_norm=None, norm_type=2.0, error_if_nonfinite=True)` {#lightning.fabric.fabric.Fabric.clip_gradients}

Clip the gradients of the model to a given max value or max norm.

Parameters:

*   **module** (`Union`\[[`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), `_FabricModule`\]) – The module whose parameters should be clipped.
    
*   **optimizer** (`Union`\[[`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)"), `_FabricOptimizer`\]) – The optimizer referencing the parameters to be clipped.
    
*   **clip\_val** (`Union`\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"), [`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – If passed, gradients will be clipped to this value. Cannot be used together with `max_norm`.
    
*   **max\_norm** (`Union`\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"), [`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – If passed, clips the gradients in such a way that the p-norm of the resulting parameters is no larger than the given value. Cannot be used together with `clip_val`.
    
*   **norm\_type** (`Union`\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"), [`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – The type of norm if `max_norm` was passed. Can be `'inf'` for infinity norm. Defaults to 2-norm.
    
*   **error\_if\_nonfinite** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An error is raised if the total norm of the gradients is NaN or infinite. Only applies when `max_norm` is used.
    

Return type:

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

Returns:

The total norm of the gradients (before clipping was applied) as a scalar tensor if `max_norm` was passed, otherwise `None`.

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If both `clip_val` and `max_norm` are provided, or if neither is provided.

Example:

```python
# Clip by value
fabric.clip_gradients(model, optimizer, clip_val=1.0)

# Clip by norm
total_norm = fabric.clip_gradients(model, optimizer, max_norm=1.0)
```

#### `init_module(empty_init=None)` {#lightning.fabric.fabric.Fabric.init_module}

Instantiate the model and its parameters under this context manager to reduce peak memory usage.

The parameters get created on the device and with the right data type right away without wasting memory being allocated unnecessarily.

Parameters:

**empty\_init** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]) – Whether to initialize the model with empty weights (uninitialized memory). If `None`, the strategy will decide. Some strategies may not support all options. Set this to `True` if you are loading a checkpoint into a large model.

Return type:

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

#### `init_tensor()` {#lightning.fabric.fabric.Fabric.init_tensor}

Tensors that you instantiate under this context manager will be created on the device right away and have the right data type depending on the precision setting in Fabric.

Return type:

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

#### `launch(function=<function _do_nothing>, *args, **kwargs)` {#lightning.fabric.fabric.Fabric.launch}

Launch and initialize all the processes needed for distributed execution.

Parameters:

*   **function** ([`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.15)")\[\[[`Fabric`](#lightning.fabric.fabric.Fabric "lightning.fabric.fabric.Fabric")\], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – Optional function to launch when using a spawn/fork-based strategy, for example, when using the XLA strategy (`accelerator="tpu"`). The function must accept at least one argument, to which the Fabric object itself will be passed. If not provided, only process initialization will be performed.
    
*   **\*args** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional positional arguments to be passed to the function.
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Optional keyword arguments to be passed to the function.
    

Return type:

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

Returns:

Returns the output of the function that ran in worker process with rank 0.

Raises:

*   [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError "(in Python v3.15)") – If called when script was launched through the CLI.
    
*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If function is provided but not callable, or if function doesn’t accept required arguments.
    

Note

The `launch()` method should only be used if you intend to specify accelerator, devices, and so on in the code (programmatically). If you are launching with the Lightning CLI, `fabric run ...`, remove `launch()` from your code.

The `launch()` is a no-op when called multiple times and no function is passed in.

Example:

```python
def train_function(fabric):
    model, optimizer = fabric.setup(model, optimizer)
    # ... training code ...

fabric = Fabric(accelerator="tpu", devices=8)
fabric.launch(train_function)
```

#### `load(path, state=None, strict=True, *, weights_only=None)` {#lightning.fabric.fabric.Fabric.load}

Load a checkpoint from a file and restore the state of objects (modules, optimizers, etc.).

How and which processes load gets determined by the strategy. This method must be called on all processes!

Parameters:

*   **path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – A path to where the file is located.
    
*   **state** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), `Union`\[[`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), [`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]\]\]) – A dictionary of objects whose state will be restored in-place from the checkpoint path. If no state is given, then the checkpoint will be returned in full.
    
*   **strict** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to enforce that the keys in `state` match the keys in the checkpoint.
    
*   **weights\_only** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]) – Defaults to `None`. If `True`, restricts loading to `state_dicts` of plain `torch.Tensor` and other primitive types. If loading a checkpoint from a trusted source that contains an `nn.Module`, use `weights_only=False`. If loading checkpoint from an untrusted source, we recommend using `weights_only=True`. For more information, please refer to the [PyTorch Developer Notes on Serialization Semantics](https://docs.pytorch.org/docs/main/notes/serialization.html#id3).
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]

Returns:

The remaining items that were not restored into the given state dictionary. If no state dictionary is given, the full checkpoint will be returned.

Example:

```python
# Load full checkpoint
checkpoint = fabric.load("checkpoint.pth")

# Load into existing objects
state = {"model": model, "optimizer": optimizer}
remainder = fabric.load("checkpoint.pth", state)
epoch = remainder.get("epoch", 0)
```

#### `load_raw(path, obj, strict=True, *, weights_only=None)` {#lightning.fabric.fabric.Fabric.load_raw}

Load the state of a module or optimizer from a single state-dict file.

Use this for loading a raw PyTorch model checkpoint created without Fabric. This is conceptually equivalent to `obj.load_state_dict(torch.load(path))`, but is agnostic to the strategy being used.

Parameters:

*   **path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – A path to where the file is located
    
*   **obj** (`Union`\[[`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), [`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)")\]) – A [`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)") or [`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)") instance.
    
*   **strict** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to enforce that the keys in the module’s state-dict match the keys in the checkpoint. Does not apply to optimizers.
    
*   **weights\_only** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]) –
    
    Defaults to `None`. If `True`, restricts loading to `state_dicts` of plain `torch.Tensor` and other primitive types. If loading a checkpoint from a trusted source that contains an `nn.Module`, use `weights_only=False`. If loading checkpoint from an untrusted source, we recommend using `weights_only=True`. For more information, please refer to the [PyTorch Developer Notes on Serialization Semantics](https://docs.pytorch.org/docs/main/notes/serialization.html#id3).
    

Return type:

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

#### `log(name, value, step=None)` {#lightning.fabric.fabric.Fabric.log}

Log a scalar to all loggers that were added to Fabric.

Parameters:

*   **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – The name of the metric to log.
    
*   **value** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – The metric value to collect. If the value is a [`torch.Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), it gets detached from the graph automatically.
    
*   **step** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Optional step number. Most Logger implementations auto-increment the step value by one with every log call. You can specify your own value here.
    

Return type:

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

#### `log_dict(metrics, step=None)` {#lightning.fabric.fabric.Fabric.log_dict}

Log multiple scalars at once to all loggers that were added to Fabric.

Parameters:

*   **metrics** ([`Mapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – A dictionary where the key is the name of the metric and the value the scalar to be logged. Any [`torch.Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)") in the dictionary get detached from the graph automatically.
    
*   **step** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Optional step number. Most Logger implementations auto-increment this value by one with every log call. You can specify your own value here.
    

Return type:

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

#### `no_backward_sync(module, enabled=True)` {#lightning.fabric.fabric.Fabric.no_backward_sync}

Skip gradient synchronization during backward to avoid redundant communication overhead.

Use this context manager when performing gradient accumulation to speed up training with multiple devices. Both the model’s `.forward()` and the `fabric.backward()` call need to run under this context.

Parameters:

*   **module** (`_FabricModule`) – The module for which to control the gradient synchronization. Must be a module that was set up with [`setup()`](#lightning.fabric.fabric.Fabric.setup "lightning.fabric.fabric.Fabric.setup") or [`setup_module()`](#lightning.fabric.fabric.Fabric.setup_module "lightning.fabric.fabric.Fabric.setup_module").
    
*   **enabled** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether the context manager is enabled or not. `True` means skip the sync, `False` means do not skip.
    

Return type:

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

Returns:

A context manager that controls gradient synchronization.

Raises:

[**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If the module was not set up with Fabric first.

Note

For strategies that don’t support gradient sync control, a warning is emitted and the context manager becomes a no-op. For single-device strategies, it is always a no-op.

Example:

```python
# Accumulate gradients over 8 batches
for batch_idx, batch in enumerate(dataloader):
    with fabric.no_backward_sync(model, enabled=(batch_idx % 8 != 0)):
        output = model(batch)
        loss = criterion(output, target)
        fabric.backward(loss)

    if batch_idx % 8 == 0:
        optimizer.step()
        optimizer.zero_grad()
```

#### `print(*args, **kwargs)` {#lightning.fabric.fabric.Fabric.print}

Print something only on the first process. If running on multiple machines, it will print from the first process in each machine.

Arguments passed to this method are forwarded to the Python built-in [`print()`](#lightning.fabric.fabric.Fabric.print "lightning.fabric.fabric.Fabric.print") function.

Return type:

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

#### `rank_zero_first(local=False)` {#lightning.fabric.fabric.Fabric.rank_zero_first}

The code block under this context manager gets executed first on the main process (rank 0) and only when completed, the other processes get to run the code in parallel.

Parameters:

**local** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Set this to `True` if the **local** rank should be the one going first. Useful if you are downloading data and the filesystem isn’t shared between the nodes.

Return type:

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

Example:

```python
with fabric.rank_zero_first():
    dataset = MNIST("datasets/", download=True)
```

#### `run(*args, **kwargs)` {#lightning.fabric.fabric.Fabric.run}

All the code inside this run method gets accelerated by Fabric.

You can pass arbitrary arguments to this function when overriding it.

Return type:

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

#### `save(path, state, filter=None)` {#lightning.fabric.fabric.Fabric.save}

Save checkpoint contents to a file.

How and which processes save gets determined by the strategy. For example, the ddp strategy saves checkpoints only on process 0, while the fsdp strategy saves files from every rank. This method must be called on all processes!

Parameters:

*   **path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – A path to where the file(s) should be saved.
    
*   **state** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), `Union`\[[`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), [`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]\]) – A dictionary with contents to be saved. If the dict contains modules or optimizers, their state-dict will be retrieved and converted automatically.
    
*   **filter** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.15)")\[\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\], [`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]\]\]) – An optional dictionary containing filter callables that return a boolean indicating whether the given item should be saved (`True`) or filtered out (`False`). Each filter key should match a state key, where its filter will be applied to the `state_dict` generated.
    

Raises:

*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If filter is not a dictionary or contains non-callable values.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If filter keys don’t match state keys.
    

Return type:

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

Example:

```python
state = {"model": model, "optimizer": optimizer, "epoch": epoch}
fabric.save("checkpoint.pth", state)

# With filter
def param_filter(name, param):
    return "bias" not in name  # Save only non-bias parameters

fabric.save("checkpoint.pth", state, filter={"model": param_filter})
```

#### `static seed_everything(seed=None, workers=None, verbose=True)` {#lightning.fabric.fabric.Fabric.seed_everything}

Helper function to seed everything without explicitly importing Lightning.

See [`seed_everything()`](/docs/fabric/2.6.6/full-api-reference/utilities.md#lightning.fabric.utilities.seed.seed_everything "lightning.fabric.utilities.seed.seed_everything") for more details.

Return type:

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

#### `setup(module, *optimizers, scheduler=None, move_to_device=True, _reapply_compile=True)` {#lightning.fabric.fabric.Fabric.setup}

Set up a model and its optimizers for accelerated training.

Parameters:

*   **module** ([`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)")) – A [`torch.nn.Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)") to set up.
    
*   **\*optimizers** ([`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)")) – The optimizer(s) to set up. Can be zero or more optimizers.
    
*   **scheduler** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[`_LRScheduler`\]) – An optional learning rate scheduler to set up. Must be provided after optimizers if used.
    
*   **move\_to\_device** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), moves the model to the correct device. Set this to `False` and alternatively use [`to_device()`](#lightning.fabric.fabric.Fabric.to_device "lightning.fabric.fabric.Fabric.to_device") manually.
    
*   **\_reapply\_compile** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If `True` (default), and the model was ```torch.compile``d before, the corresponding :class:`~torch._dynamo.OptimizedModule` wrapper will be removed and reapplied with the same settings after the model was set up by the strategy (e.g., after the model was wrapped by DDP, FSDP etc.). Set it to ``False``` if compiling DDP/FSDP is causing issues.
    

Return type:

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

Returns:

If no optimizers are passed, returns the wrapped module. If optimizers are passed, returns a tuple containing the wrapped module and optimizers, and optionally the scheduler if provided, in the same order they were passed in.

Note

For certain strategies like FSDP, you may need to set up the model first using [`setup_module()`](#lightning.fabric.fabric.Fabric.setup_module "lightning.fabric.fabric.Fabric.setup_module"), then create the optimizer, and finally set up the optimizer using [`setup_optimizers()`](#lightning.fabric.fabric.Fabric.setup_optimizers "lightning.fabric.fabric.Fabric.setup_optimizers").

Example:

```python
# Basic usage
model, optimizer = fabric.setup(model, optimizer)

# With multiple optimizers and scheduler
model, opt1, opt2, scheduler = fabric.setup(model, opt1, opt2, scheduler=scheduler)

# Model only
model = fabric.setup(model)
```

#### `setup_dataloaders(*dataloaders, use_distributed_sampler=True, move_to_device=True)` {#lightning.fabric.fabric.Fabric.setup_dataloaders}

Set up one or multiple dataloaders for accelerated training. If you need different settings for each dataloader, call this method individually for each one.

Parameters:

*   **\*dataloaders** ([`DataLoader`](https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader "(in PyTorch v2.15)")) – One or more PyTorch [`DataLoader`](https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader "(in PyTorch v2.15)") instances to set up.
    
*   **use\_distributed\_sampler** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), automatically wraps or replaces the sampler on the dataloader(s) for distributed training. If you have a custom sampler defined, set this argument to `False`.
    
*   **move\_to\_device** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), moves the data returned by the dataloader(s) automatically to the correct device. Set this to `False` and alternatively use [`to_device()`](#lightning.fabric.fabric.Fabric.to_device "lightning.fabric.fabric.Fabric.to_device") manually on the returned data.
    

Return type:

`Union`\[[`DataLoader`](https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader "(in PyTorch v2.15)"), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[`DataLoader`](https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader "(in PyTorch v2.15)")\]\]

Returns:

If a single dataloader is passed, returns the wrapped dataloader. If multiple dataloaders are passed, returns a list of wrapped dataloaders in the same order they were passed in.

Example:

```python
# Single dataloader
train_loader = fabric.setup_dataloaders(train_loader)

# Multiple dataloaders
train_loader, val_loader = fabric.setup_dataloaders(train_loader, val_loader)
```

#### `setup_module(module, move_to_device=True, _reapply_compile=True)` {#lightning.fabric.fabric.Fabric.setup_module}

Set up a model for accelerated training or inference.

This is the same as calling `.setup(model)` with no optimizers. It is useful for inference or for certain strategies like FSDP that require setting up the module before the optimizer can be created and set up. See also [`setup_optimizers()`](#lightning.fabric.fabric.Fabric.setup_optimizers "lightning.fabric.fabric.Fabric.setup_optimizers").

Parameters:

*   **module** ([`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)")) – A [`torch.nn.Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)") to set up.
    
*   **move\_to\_device** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If set `True` (default), moves the model to the correct device. Set this to `False` and alternatively use [`to_device()`](#lightning.fabric.fabric.Fabric.to_device "lightning.fabric.fabric.Fabric.to_device") manually.
    
*   **\_reapply\_compile** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If `True` (default), and the model was ```torch.compile``d before, the corresponding :class:`~torch._dynamo.OptimizedModule` wrapper will be removed and reapplied with the same settings after the model was set up by the strategy (e.g., after the model was wrapped by DDP, FSDP etc.). Set it to ``False``` if compiling DDP/FSDP is causing issues.
    

Return type:

`_FabricModule`

Returns:

The wrapped model as a `_FabricModule`.

Example:

```python
# Set up model first (useful for FSDP)
model = fabric.setup_module(model)

# Then create and set up optimizer
optimizer = torch.optim.Adam(model.parameters())
optimizer = fabric.setup_optimizers(optimizer)
```

#### `setup_optimizers(*optimizers)` {#lightning.fabric.fabric.Fabric.setup_optimizers}

Set up one or more optimizers for accelerated training.

Some strategies do not allow setting up model and optimizer independently. For them, you should call `.setup(model, optimizer, ...)` instead to jointly set them up.

Parameters:

**\*optimizers** ([`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)")) – One or more optimizers to set up. Must provide at least one optimizer.

Return type:

`Union`\[`_FabricOptimizer`, [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[`_FabricOptimizer`, [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)")\]\]

Returns:

If a single optimizer is passed, returns the wrapped optimizer. If multiple optimizers are passed, returns a tuple of wrapped optimizers in the same order they were passed in.

Raises:

[**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError "(in Python v3.15)") – If using DeepSpeed or XLA strategies, which require joint model-optimizer setup.

Note

This method cannot be used with DeepSpeed or XLA strategies. Use [`setup()`](#lightning.fabric.fabric.Fabric.setup "lightning.fabric.fabric.Fabric.setup") instead for those strategies.

Example:

```python
# Single optimizer
optimizer = fabric.setup_optimizers(optimizer)

# Multiple optimizers
opt1, opt2 = fabric.setup_optimizers(opt1, opt2)
```

#### `sharded_model()` {#lightning.fabric.fabric.Fabric.sharded_model}

Instantiate a model under this context manager to prepare it for model-parallel sharding. :rtype: [`AbstractContextManager`](https://docs.python.org/3/library/contextlib.html#contextlib.AbstractContextManager "(in Python v3.15)")

Deprecated since version This: context manager is deprecated in favor of [`init_module()`](#lightning.fabric.fabric.Fabric.init_module "lightning.fabric.fabric.Fabric.init_module"), use it instead.

#### `to_device(obj)` {#lightning.fabric.fabric.Fabric.to_device}

Move a [`torch.nn.Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)") or a collection of tensors to the current device, if it is not already on that device.

Parameters:

**obj** (`Union`\[[`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – An object to move to the device. Can be an instance of [`torch.nn.Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)"), a tensor, or a (nested) collection of tensors (e.g., a dictionary).

Return type:

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

Returns:

A reference to the object that was moved to the new device.

#### `property device: device` {#lightning.fabric.fabric.Fabric.device}

The current device this process runs on.

Use this to create tensors directly on the device if needed.

#### `property global_rank: int` {#lightning.fabric.fabric.Fabric.global_rank}

The global index of the current process across all devices and nodes.

#### `property is_global_zero: bool` {#lightning.fabric.fabric.Fabric.is_global_zero}

Whether this rank is rank zero.

#### `property local_rank: int` {#lightning.fabric.fabric.Fabric.local_rank}

The index of the current process among the processes running on the local node.

#### `property logger: Logger` {#lightning.fabric.fabric.Fabric.logger}

Returns the first logger in the list passed to Fabric, which is considered the main logger.

#### `property loggers: list[lightning.fabric.loggers.logger.Logger]` {#lightning.fabric.fabric.Fabric.loggers}

Returns all loggers passed to Fabric.

#### `property node_rank: int` {#lightning.fabric.fabric.Fabric.node_rank}

The index of the current node.

#### `property world_size: int` {#lightning.fabric.fabric.Fabric.world_size}

The total number of processes running across all devices and nodes.

---

**Navigation**

- Parent: [Generated](/docs/fabric/2.6.6/full-api-reference/api/generated.md)
