deepset-ai/haystack · error · ValueError
The disk device can only be used as a part of device maps
Error message
The disk device can only be used as a part of device maps
What it means
ComponentDevice.from_single raises ValueError when the given Device is a DISK device. A single disk device is meaningless in Haystack; offloading to disk is only expressible as part of a multi-device map (as accelerate uses it).
Source
Thrown at haystack/utils/device.py:286
The component device representation.
"""
device = Device.from_str(device_str)
return cls.from_single(device)
@classmethod
def from_single(cls, device: Device) -> "ComponentDevice":
"""
Create a component device representation from a single device.
Disks cannot be used as single devices.
:param device:
The device.
:returns:
The component device representation.
"""
if device.type == DeviceType.DISK:
raise ValueError("The disk device can only be used as a part of device maps")
return cls(_single_device=device)
@classmethod
def from_multiple(cls, device_map: DeviceMap) -> "ComponentDevice":
"""
Create a component device representation from a device map.
:param device_map:
The device map.
:returns:
The component device representation.
"""
return cls(_multiple_devices=device_map)
def _validate(self) -> None:
"""
Validate the component device representation.View on GitHub (pinned to e318778c9b)
Solutions
- Use a real compute device ('cpu', 'cuda', 'mps', 'xpu') for the component
- If you need multi-device/disk offloading, build a DeviceMap via ComponentDevice.from_multiple/DeviceMap with disk entries
- Remove 'disk' from single-device config and rely on accelerate's own offloading if applicable
Example fix
// before
comp = ComponentDevice.from_str("disk")
// after
comp = ComponentDevice.from_str("cpu")
# or for disk offloading use a DeviceMap: ComponentDevice.from_multiple(DeviceMap({"layer0": Device(DeviceType.DISK, None), "layer1": Device(DeviceType.CUDA, 0)})) Defensive patterns
Strategy: validation
Validate before calling
def component_device_from_str_safe(s: str):
if s.strip().lower() == "disk":
raise ValueError("disk is only valid inside a DeviceMap")
return ComponentDevice.from_str(s) Type guard
def is_single_computable_device(d: Device) -> bool:
return d.type != DeviceType.DISK Try / catch
try:
comp = ComponentDevice.from_str(cfg_device)
except ValueError as e:
print(f"{cfg_device} unusable as a single device: {e}")
comp = ComponentDevice.from_str("cpu") Prevention
- Never set a component's single device to 'disk'
- Use DeviceMap/from_multiple when disk offloading is needed
- Restrict allowed device values in your config schema
When it happens
Trigger: Calling ComponentDevice.from_str('disk') or ComponentDevice.from_single(Device(type=DeviceType.DISK, ...)) — note from_str delegates to from_single.
Common situations: Setting a pipeline component's device to 'disk' in config hoping to offload to disk; translating accelerate device maps that use 'disk' for some layers and mistakenly extracting it as the single component device.
Related errors
- Unknown device type string '{string}'
- Device id must be >= 0, got {id}
- The component device can neither be empty nor contain both a
- Only single devices can be converted to PyTorch format
- Only single devices can be converted to spaCy format
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/faeaf2fcafbfb981.
Report an issue: GitHub.