huggingface/transformers · error · KeyError
Key {key} is not a valid field of SizeDict.
Error message
Key {key} is not a valid field of SizeDict. What it means
Error "Key {key} is not a valid field of SizeDict." thrown in huggingface/transformers.
Source
Thrown at src/transformers/image_utils.py:1050
return getattr(self, key)
return default
def __iter__(self):
# Yield only non-None (key, value) pairs so dict(self) excludes missing values.
for f in fields(self):
val = getattr(self, f.name)
if val is not None:
yield f.name, val
def __hash__(self):
return hash((self.height, self.width, self.longest_edge, self.shortest_edge, self.max_height, self.max_width))
def __contains__(self, key):
return hasattr(self, key) and getattr(self, key) is not None
def __setitem__(self, key, value):
if not hasattr(self, key):
raise KeyError(f"Key {key} is not a valid field of SizeDict.")
object.__setattr__(self, key, value)
def __eq__(self, other):
if isinstance(other, dict):
return dict(self) == other
if isinstance(other, SizeDict):
return tuple(getattr(self, f.name) for f in fields(self)) == tuple(
getattr(other, f.name) for f in fields(self)
)
return NotImplemented
def __or__(self, other) -> "SizeDict":
if isinstance(other, dict | SizeDict):
merged = dict(self)
merged.update(dict(other))
return SizeDict(**merged)
return NotImplemented
View on GitHub (pinned to a597f97485)
Solutions
- Set only valid SizeDict fields such as 'height', 'width', 'shortest_edge', 'longest_edge', 'max_height', 'max_width'.
When it happens
Trigger: Raised in SizeDict assignment when attempting to set a key that is not a declared field.
Common situations: Assigning arbitrary attributes to a SizeDict instead of its allowed size-related fields.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/fa56a597ea331ba2.
Report an issue: GitHub.