Lightning-AI/pytorch-lightning · critical · ImportError
PyTorch >= 2.6 requires DeepSpeed >= 0.16.0. Detected DeepSp
Error message
PyTorch >= 2.6 requires DeepSpeed >= 0.16.0. Detected DeepSpeed version: {deepspeed_version}. Please upgrade by running `pip install -U 'deepspeed>=0.16.0'`. What it means
PyTorch 2.6 changed torch.load to default to weights_only=True, and DeepSpeed only supported that in 0.16.0+. If the env has torch>=2.6 with an older deepspeed, DeepSpeedStrategy.__init__ raises ImportError demanding an upgrade, because loading full checkpoints would otherwise break.
Source
Thrown at src/lightning/fabric/strategies/deepspeed.py:253
per worker.
exclude_frozen_parameters: Exclude frozen parameters when saving checkpoints.
"""
if not _DEEPSPEED_AVAILABLE:
raise ImportError(
"To use the `DeepSpeedStrategy`, you must have DeepSpeed installed."
" Install it by running `pip install -U deepspeed`."
)
if _TORCH_GREATER_EQUAL_2_6 and not _DEEPSPEED_GREATER_EQUAL_0_16:
# Starting with PyTorch 2.6, `torch.load` defaults to `weights_only=True` when loading full checkpoints.
# DeepSpeed added support for this behavior in version 0.16.0.
import deepspeed
deepspeed_version = deepspeed.__version__
raise ImportError(
f"PyTorch >= 2.6 requires DeepSpeed >= 0.16.0. "
f"Detected DeepSpeed version: {deepspeed_version}. "
"Please upgrade by running `pip install -U 'deepspeed>=0.16.0'`."
)
super().__init__(
accelerator=accelerator,
parallel_devices=parallel_devices,
cluster_environment=cluster_environment,
precision=precision,
process_group_backend=process_group_backend,
)
self._backward_sync_control = None # DeepSpeed handles gradient accumulation internally
self._timeout: Optional[timedelta] = timeout
self.config = self._load_config(config)
if self.config is None:
# User has not overridden config, set defaultsView on GitHub (pinned to 9fed5c27d2)
Solutions
- pip install -U 'deepspeed>=0.16.0'
- Or pin torch<2.6 until deepspeed can be upgraded
- Add a version-compatibility check to your environment setup so mismatches fail early with context
Example fix
# before torch==2.6.0, deepspeed==0.15.4 # after (shell) pip install -U 'deepspeed>=0.16.0'
Defensive patterns
Strategy: validation
Validate before calling
import torch
from importlib.metadata import version
if tuple(int(x) for x in torch.__version__.split(".")[:2]) >= (2, 6) \
and tuple(int(x) for x in version("deepspeed").split(".")[:2]) < (0, 16):
raise RuntimeError("upgrade deepspeed: pip install -U 'deepspeed>=0.16.0'") Type guard
def deepspeed_torch_compatible() -> bool:
import torch
try:
from importlib.metadata import version
ds = tuple(int(x) for x in version("deepspeed").split(".")[:2])
except Exception:
return False
t = tuple(int(x) for x in torch.__version__.split(".")[:2])
return not (t >= (2, 6) and ds < (0, 16)) Try / catch
try:
strategy = DeepSpeedStrategy()
except ImportError as e:
raise RuntimeError(f"environment incompatible: {e}") from e Prevention
- Upgrade torch and deepspeed together
- Pin compatible ranges in requirements (torch>=2.6 -> deepspeed>=0.16)
When it happens
Trigger: torch >= 2.6 installed together with deepspeed < 0.16.0, then constructing DeepSpeedStrategy (even if you never load a full checkpoint).
Common situations: Upgrading torch to 2.6+ in an env with a pinned old deepspeed; stale lockfiles after a base-image torch bump.
Related errors
- `precision={precision!r})` is not supported in DeepSpeed. `p
- To use the `DeepSpeedStrategy`, you must have DeepSpeed inst
- Currently only one optimizer is supported with DeepSpeed. Go
- The `{type(self).__name__}` does not support setting up the
- `{empty_init=}` is not a valid choice with `DeepSpeedStrateg
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/e3c415be16304779.
Report an issue: GitHub.