[diffusion] fix: fix LoRA weight snapshot aliasing in unmerge logic (#18883)
This commit is contained in:
@@ -48,7 +48,9 @@ class BaseLayerWithLoRA(nn.Module):
|
|||||||
self.base_layer: nn.Module = base_layer
|
self.base_layer: nn.Module = base_layer
|
||||||
|
|
||||||
self.merged: bool = False
|
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
|
# 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)
|
# (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
|
# Default to True to prevent using uninitialized weights; set to False when weights are loaded
|
||||||
|
|||||||
Reference in New Issue
Block a user