---
title: DeepSpeedPrecision
description: Precision plugin for DeepSpeed integration.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.plugins.precision.DeepSpeedPrecision
---
# DeepSpeedPrecision {#deepspeedprecision}

### `class lightning.pytorch.plugins.precision.DeepSpeedPrecision(precision)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision}

Bases: [`Precision`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.plugins.precision.Precision.md#lightning.pytorch.plugins.precision.Precision "lightning.pytorch.plugins.precision.precision.Precision")

Precision plugin for DeepSpeed integration.

Warning

This is an [experimental](/docs/pytorch/2.6.6/reference/versioning.md#experimental-api) feature.

Parameters:

**precision** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'32-true'`, `'16-true'`, `'bf16-true'`, `'16-mixed'`, `'bf16-mixed'`\]) – Full precision (32-true), half precision (16-true, bf16-true) or mixed precision (16-mixed, bf16-mixed).

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If unsupported `precision` is provided.

#### `backward(tensor, model, optimizer, *args, **kwargs)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.backward}

Performs back-propagation using DeepSpeed’s engine.

Parameters:

*   **tensor** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – the loss tensor
    
*   **model** ([`LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.module.LightningModule")) – the model to be optimized
    
*   **optimizer** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[`Steppable`\]) – ignored for DeepSpeed
    
*   **\*args** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – additional positional arguments for the `deepspeed.DeepSpeedEngine.backward()` call
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – additional keyword arguments for the `deepspeed.DeepSpeedEngine.backward()` call
    

Return type:

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

#### `clip_gradients(optimizer, clip_val=0.0, gradient_clip_algorithm=GradClipAlgorithmType.NORM)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.clip_gradients}

DeepSpeed handles gradient clipping internally.

Return type:

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

#### `convert_input(data)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.convert_input}

Convert model inputs (forward) to the floating point precision type of this plugin.

This is a no-op in the base precision plugin, since we assume the data already has the desired type (default is torch.float32).

Return type:

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

#### `convert_module(module)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.convert_module}

Convert the module parameters to the precision type this plugin handles.

This is optional and depends on the precision limitations during optimization.

Return type:

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

#### `module_init_context()` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.module_init_context}

Instantiate module parameters or tensors in the precision type this plugin handles.

This is optional and depends on the precision limitations during optimization.

Return type:

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

#### `optimizer_step(optimizer, model, closure, **kwargs)` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.optimizer_step}

Hook to run the optimizer step.

Return type:

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

#### `tensor_init_context()` {#lightning.pytorch.plugins.precision.DeepSpeedPrecision.tensor_init_context}

Controls how tensors get created (device, dtype).

Return type:

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

---

**Navigation**

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