Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix frozen dataclass instance error in apply_to_collection #10927

Merged
merged 13 commits into from Jan 5, 2022
5 changes: 4 additions & 1 deletion pytorch_lightning/utilities/apply_func.py
Expand Up @@ -144,7 +144,10 @@ def apply_to_collection(
)
if not field_init or (not include_none and v is None): # retain old value
v = getattr(data, field_name)
setattr(result, field_name, v)
try:
setattr(result, field_name, v)
except Exception:
abhi-rf marked this conversation as resolved.
Show resolved Hide resolved
raise dataclasses.FrozenInstanceError("Cannot apply function to Frozen dataclass instance")
return result

# data is neither of dtype, nor a collection
Expand Down