docs: record why clone_latent's nested-tensor aliasing is safe

_refine_latent rejects nested latents at the door and every other caller
returns the clone unmodified, so the alias is unreachable. Noted so the next
audit does not re-open it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
digital-garbage
2026-08-22 18:53:06 +03:00
co-authored by Claude Opus 5
parent c96186aaee
commit d77b3e2eed
+13
View File
@@ -538,6 +538,19 @@ def refinement_state_path(refinement_key, mode, prefix="refine", extension="json
def clone_latent(latent):
"""Shallow-clone a LATENT dict, deep-copying its tensor values.
A NestedTensor (LTXAV / H3 packed audio+video) is NOT a torch.Tensor, so it is carried over
BY REFERENCE and the "clone" aliases the caller's samples. That is safe here, and an audit
should not re-open it: `latent_samples` returns None for a nested value, so
`latent_is_plain_video_tensor` is False and `_refine_latent` rejects the latent outright
(`_raise_wrong_latent`) before reaching this function. Every other caller returns the clone
unmodified — the two writes in `_refine_latent` REPLACE the "samples" key rather than
mutating it in place, so nothing can reach through the alias.
The sampler's own `_clone_latent` unbinds and clones each stream, because it works on
latents that ARE nested.
"""
if not isinstance(latent, dict):
return None