MCPcopy Create free account
hub / github.com/Lightricks/ComfyUI-LTXVideo / execute

Method execute

conditioning_saver.py:29–69  ·  view source on GitHub ↗
(cls, conditioning: list, filename: str, dtype: str)

Source from the content-addressed store, hash-verified

27
28 @classmethod
29 def execute(cls, conditioning: list, filename: str, dtype: str) -> io.NodeOutput:
30 if not conditioning or len(conditioning) == 0:
31 raise ValueError("Conditioning is empty")
32
33 embeddings_folder = Path(folder_paths.get_folder_paths("embeddings")[0])
34 embeddings_folder.mkdir(parents=True, exist_ok=True)
35
36 sanitized_filename = "".join(
37 c for c in filename if c.isalnum() or c in ("_", "-", ".")
38 )
39 if not sanitized_filename:
40 sanitized_filename = "conditioning"
41
42 output_path = embeddings_folder / f"{sanitized_filename}.safetensors"
43
44 target_dtype = torch.bfloat16 if dtype == "bfloat16" else torch.float16
45
46 tensors_to_save: dict[str, torch.Tensor] = {}
47
48 for idx, (cond_tensor, cond_options) in enumerate(conditioning):
49 tensor_converted = cond_tensor.to(dtype=target_dtype).contiguous()
50 tensors_to_save[f"conditioning_data_{idx}"] = tensor_converted
51
52 if "attention_mask" in cond_options:
53 mask = cond_options["attention_mask"].contiguous()
54 tensors_to_save[f"attention_mask_{idx}"] = mask
55
56 metadata = {
57 "num_conditionings": str(len(conditioning)),
58 "dtype": dtype,
59 "created_at": str(datetime.now()),
60 }
61
62 comfy.utils.save_torch_file(
63 tensors_to_save, str(output_path), metadata=metadata
64 )
65
66 file_size_mb = output_path.stat().st_size / (1024 * 1024)
67 return io.NodeOutput(
68 ui=ui.PreviewText(f"Saved: {output_path.name} ({file_size_mb:.2f} MB)")
69 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected