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:
+9
-1
@@ -22,6 +22,14 @@ class SaveLatentAbsolute:
|
|||||||
CATEGORY = "latent"
|
CATEGORY = "latent"
|
||||||
OUTPUT_NODE = True
|
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):
|
def save(self, samples, path, overwrite=False):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
if not path.endswith(".latent"):
|
if not path.endswith(".latent"):
|
||||||
@@ -42,7 +50,7 @@ class SaveLatentAbsolute:
|
|||||||
if isinstance(value, torch.Tensor):
|
if isinstance(value, torch.Tensor):
|
||||||
devices[key] = str(value.device)
|
devices[key] = str(value.device)
|
||||||
tensors[key] = value.contiguous()
|
tensors[key] = value.contiguous()
|
||||||
else:
|
elif self._is_json_serializable(value):
|
||||||
non_tensors[key] = value
|
non_tensors[key] = value
|
||||||
|
|
||||||
metadata = {"devices": json.dumps(devices)}
|
metadata = {"devices": json.dumps(devices)}
|
||||||
|
|||||||
Reference in New Issue
Block a user