Lightning-AI/pytorch-lightning · error · ValueError
Device should be MPS, got {device} instead.
Error message
Device should be MPS, got {device} instead. What it means
The DD:HH:MM:SS string for val_check_interval must have four integer components. After the format check (exactly 4 parts) passes, each part is coerced with int(); if any component is non-numeric (e.g. '0:a:0:0', '0.5:0:0:0', empty string part), the ValueError from int() is converted into this MisconfigurationException.
Source
Thrown at src/lightning/fabric/accelerators/mps.py:41
from lightning.fabric.accelerators.registry import _AcceleratorRegistry
class MPSAccelerator(Accelerator):
"""Accelerator for Metal Apple Silicon GPU devices.
.. warning:: Use of this accelerator beyond import and instantiation is experimental.
"""
@override
def setup_device(self, device: torch.device) -> None:
"""
Raises:
ValueError:
If the selected device is not MPS.
"""
if device.type != "mps":
raise ValueError(f"Device should be MPS, got {device} instead.")
@override
def teardown(self) -> None:
pass
@staticmethod
@override
def parse_devices(devices: Union[int, str, list[int]]) -> Optional[list[int]]:
"""Accelerator device parsing logic."""
from lightning.fabric.utilities.device_parser import _parse_gpu_ids
return _parse_gpu_ids(devices, include_mps=True)
@staticmethod
@override
def get_parallel_devices(devices: Union[int, str, list[int]]) -> list[torch.device]:
"""Gets parallel devices for the Accelerator."""
parsed_devices = MPSAccelerator.parse_devices(devices)View on GitHub (pinned to 9fed5c27d2)
Solutions
- Ensure all four components are plain integers: '0:0:0:1' not '0:0:0:1.5'
- Construct from validated ints: f"{d}:{h}:{m}:{s}" with each an int
- Use timedelta(seconds=float) or a dict {'seconds': 1.5} when fractional units are needed
Example fix
# before trainer = Trainer(val_check_interval="0:0:0:1.5") # after from datetime import timedelta trainer = Trainer(val_check_interval=timedelta(seconds=1.5))
Defensive patterns
Strategy: validation
Validate before calling
def parse_interval(s: str):
parts = s.split(":")
if len(parts) != 4 or not all(p.lstrip("-").isdigit() for p in parts):
raise ValueError("val_check_interval string must be 'DD:HH:MM:SS' with integers")
return s Type guard
def is_valid_interval_str(v) -> bool:
if not isinstance(v, str):
return False
parts = v.split(":")
return len(parts) == 4 and all(p.isdigit() for p in parts) Prevention
- Never put floats in the DD:HH:MM:SS string; use timedelta(seconds=1.5) instead
- Validate the string before constructing the Trainer
- Build the string only from int-typed variables
When it happens
Trigger: Trainer(val_check_interval='0:0:thirty:0'); Trainer(val_check_interval='00:00:00:1.5'); a component with whitespace or a float like '0.5'; empty component '0::0:0'.
Common situations: Building the string from f-strings with unvalidated variables; float seconds intended (e.g. 1.5s) which the format does not support; copy-paste with a missing value leaving an empty slot.
Related errors
- You requested to find {num_devices} devices but only {len(av
- Device should be CUDA, got {device} instead.
- You requested to find {num_devices} devices but there are no
- You requested to find {num_devices} devices but this machine
- `name` must be a str, found {name}
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/00be3ddc36b4cad9.
Report an issue: GitHub.