[diffusion] fix: fix LoRA weight snapshot aliasing in unmerge logic (#18883)

This commit is contained in:
Changyi Yang
2026-02-16 02:39:45 -05:00
committed by GitHub
parent d85884ca57
commit 61da34ad0b

View File

@@ -48,7 +48,9 @@ class BaseLayerWithLoRA(nn.Module):
self.base_layer: nn.Module = base_layer
self.merged: bool = False
self.cpu_weight = base_layer.weight.to("cpu")
# Immutable base-weight snapshot; `to("cpu")` may alias CPU storage.
# Use `clone()` so merge updates cannot mutate this backup tensor.
self.cpu_weight = base_layer.weight.detach().to("cpu").clone()
# indicates adapter weights don't contain this layer
# (which shouldn't normally happen, but we want to separate it from the case of erroneous merging)
# Default to True to prevent using uninitialized weights; set to False when weights are loaded