Fix latent save node to skip non-serializable values in metadata

LATENT dicts can contain nested tensors or other non-JSON-serializable
objects. Filter them out instead of crashing on json.dumps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 00:06:10 +01:00
parent 64b6c23f61
commit e5ca7a1224
+9 -1
View File
@@ -22,6 +22,14 @@ class SaveLatentAbsolute:
CATEGORY = "latent"
OUTPUT_NODE = True
@staticmethod
def _is_json_serializable(value):
try:
json.dumps(value)
return True
except (TypeError, ValueError):
return False
def save(self, samples, path, overwrite=False):
path = os.path.expanduser(path)
if not path.endswith(".latent"):
@@ -42,7 +50,7 @@ class SaveLatentAbsolute:
if isinstance(value, torch.Tensor):
devices[key] = str(value.device)
tensors[key] = value.contiguous()
else:
elif self._is_json_serializable(value):
non_tensors[key] = value
metadata = {"devices": json.dumps(devices)}