deepfakes/faceswap · error · ValueError
Hex color codes should start with a '#' and be 6 characters
Error message
Hex color codes should start with a '#' and be 6 characters long. Got: '{value}' What it means
Apple Silicon GPU stats plugin (lib/gpu_stats/apple_silicon.py) sanity-checks the Torch MPS backend by calling torch.mps.driver_allocated_memory(). If that call raises RuntimeError, Faceswap wraps it as FaceswapError, since a broken MPS stack means no usable Apple GPU.
Source
Thrown at lib/config/objects.py:400
if self.datatype is list:
if not isinstance(value, (str, list)):
raise ValueError(f"[{self._name}] List values should be set as a Str or List. Got "
f"{type(value)} ({value})")
value = cast(T, self._parse_list(value))
if not isinstance(value, self.datatype):
raise ValueError(
f"[{self._name}] Expected {self.datatype} got {type(value)} ({value})")
if isinstance(self.choices, list) and self.choices:
assert isinstance(value, (list, str))
value = cast(T, self._validate_selection(value))
if self.choices == "colorchooser":
assert isinstance(value, str)
if not value.startswith("#") or len(value) != 7:
raise ValueError(f"Hex color codes should start with a '#' and be 6 "
f"characters long. Got: '{value}'")
self._value = value
def set_name(self, name: str) -> None:
"""Set the logging name for this object for display purposes
Parameters
----------
name
The name to assign to this option
"""
logger.debug("Setting name to '%s'", name)
assert isinstance(name, str) and name
self._name = name
def __call__(self) -> T:
"""Obtain the currently stored configuration valueView on GitHub (pinned to f530cb7508)
Solutions
- Verify MPS outside Faceswap: `python -c "import torch; print(torch.backends.mps.is_available()); print(torch.mps.driver_allocated_memory())"` and read the original error
- Reinstall a torch build matching your macOS/arch (e.g. pip install --force-reinstall torch on native arm64, no Rosetta)
- Update macOS/Xcode command line tools so Metal drivers match the torch build; as a fallback run with CPU (`--cpu`) while the GPU stack is repaired
Example fix
# before python faceswap.py --apple-silicon train ... # -> FaceswapError wrapping torch.mps RuntimeError # after # 1) verify the stack python -c "import torch; print(torch.backends.mps.is_available())" # 2) reinstall matching torch, then retry pip uninstall -y torch && pip install torch # 3) meanwhile run CPU-only python faceswap.py --cpu train ...
Defensive patterns
Strategy: validation
Validate before calling
import re
def valid_hex_color(v: str) -> bool:
return bool(re.fullmatch(r"#[0-9a-fA-F]{6}", v))
assert valid_hex_color(option_value), f"bad color: {option_value!r}" Type guard
import re
def is_hex_color(v) -> bool:
"""True when v is a '#rrggbb' string accepted by colorchooser options."""
return isinstance(v, str) and bool(re.fullmatch(r"#[0-9a-fA-F]{6}", v)) Try / catch
try:
option.set(color)
except ValueError:
r, g, b = tuple(int(color.lstrip("#")[i:i+2], 16) for i in (0, 2, 4))
option.set("#%02x%02x%02x" % (r, g, b)) Prevention
- Normalize all colors to '#rrggbb' at config load time
- Use a shared to_hex(r,g,b) helper instead of string concatenation
- Reject 3/4/8-digit hex at the UI boundary
When it happens
Trigger: Selecting apple Silicon GPU stats (e.g. `faceswap.py --apple-silicon` or auto-detection on an M-series Mac) with a torch build lacking MPS support, a too-old macOS/torch version, or a corrupted Metal/torch install; also when torch imports but the MPS device is unavailable.
Common situations: Upgrading/downgrading torch or macOS and breaking MPS; conda envs shipping CPU-only torch on ARM; running under Rosetta where MPS is unavailable; beta macOS with incompatible Metal drivers.
Related errors
- An unhandled exception occurred initializing the device via
- Dataclass params {sorted(required)} should be a subset of di
- There was an error reading from the Nvidia Machine Learning
- You do not have enough GPU memory available to train the sel
- {arch}' is not compatible with your version of Keras. The mi
AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15).
Data as JSON: /api/errors/ede30864f2fc7db8.
Report an issue: GitHub.