From 61da34ad0b8a0f9b844ea123b1f206fad419c793 Mon Sep 17 00:00:00 2001 From: Changyi Yang <112288487+ChangyiYang@users.noreply.github.com> Date: Mon, 16 Feb 2026 02:39:45 -0500 Subject: [PATCH] [diffusion] fix: fix LoRA weight snapshot aliasing in unmerge logic (#18883) --- python/sglang/multimodal_gen/runtime/layers/lora/linear.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/sglang/multimodal_gen/runtime/layers/lora/linear.py b/python/sglang/multimodal_gen/runtime/layers/lora/linear.py index a062479d1..e83f75a49 100644 --- a/python/sglang/multimodal_gen/runtime/layers/lora/linear.py +++ b/python/sglang/multimodal_gen/runtime/layers/lora/linear.py @@ -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