keras-team/keras · error · ValueError
Cannot interpret `dtype` argument. Expected a string or an…
Error message
Cannot interpret `dtype` argument. Expected a string or an instance of DTypePolicy. Received: dtype={identifier} What it means
Raised by the dtype-policy resolver in keras/src/dtype_policies/__init__.py get: the dtype/policy identifier must be a string (dtype name or policy string), a DTypePolicy instance, a serializable dict, or None. The received identifier has another type (e.g. a tuple, a float, or a numpy object), so no standardization path applies and the resolver gives up.
Solutions
- Pass a string like "float32", "mixed_bfloat16", or "float8" policy names
- Pass an existing DTypePolicy instance directly
- Use keras.dtype_policies.serialize/deserialize dicts for config round-trips
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/dtype_policies/__init__.py:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/c789d4fe0c35f79b.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/dtype_policies/__init__.py:112
from keras.src.dtype_policies.dtype_policy import (
_get_quantized_dtype_policy_by_str,
)
if identifier is None:
return dtype_policy.dtype_policy()
if isinstance(identifier, DTypePolicy):
return identifier
if isinstance(identifier, dict):
return deserialize(identifier)
if isinstance(identifier, str):
if identifier.startswith(QUANTIZATION_MODES):
return _get_quantized_dtype_policy_by_str(identifier)
else:
return DTypePolicy(identifier)
try:
return DTypePolicy(backend.standardize_dtype(identifier))
except:
raise ValueError(
"Cannot interpret `dtype` argument. Expected a string "
f"or an instance of DTypePolicy. Received: dtype={identifier}"
)
View on GitHub (pinned to 7a34a03db6)