Pose: gate adapter LoRA with the start/end window; default end 0.7 to reduce style drift
Browse files- anima_pose/control.py +9 -2
- app.py +0 -0
anima_pose/control.py
CHANGED
|
@@ -102,6 +102,7 @@ class _LoRAWrap:
|
|
| 102 |
self.down = down
|
| 103 |
self.up = up
|
| 104 |
self.scale = scale
|
|
|
|
| 105 |
self.org_forward = None
|
| 106 |
|
| 107 |
def apply(self):
|
|
@@ -115,6 +116,8 @@ class _LoRAWrap:
|
|
| 115 |
|
| 116 |
def forward(self, x, *args, **kwargs):
|
| 117 |
y = self.org_forward(x, *args, **kwargs)
|
|
|
|
|
|
|
| 118 |
delta = F.linear(F.linear(x.to(self.down.dtype), self.down), self.up)
|
| 119 |
return y + (delta * self.scale).to(y.dtype)
|
| 120 |
|
|
@@ -138,8 +141,10 @@ def encode_control_latent(pipe, skeleton: Image.Image, height: int, width: int)
|
|
| 138 |
class PoseControlSession:
|
| 139 |
"""Context manager: attach the pose adapter to ``pipe.dit`` for one generation.
|
| 140 |
|
| 141 |
-
``set_active(bool)`` gates the control tokens
|
| 142 |
-
the
|
|
|
|
|
|
|
| 143 |
"""
|
| 144 |
|
| 145 |
def __init__(self, pipe, adapter: PoseAdapter, control_latent: torch.Tensor, strength: float):
|
|
@@ -154,6 +159,8 @@ class PoseControlSession:
|
|
| 154 |
|
| 155 |
def set_active(self, active: bool):
|
| 156 |
self.active = bool(active)
|
|
|
|
|
|
|
| 157 |
|
| 158 |
def __enter__(self):
|
| 159 |
dit = self.pipe.dit
|
|
|
|
| 102 |
self.down = down
|
| 103 |
self.up = up
|
| 104 |
self.scale = scale
|
| 105 |
+
self.active = True
|
| 106 |
self.org_forward = None
|
| 107 |
|
| 108 |
def apply(self):
|
|
|
|
| 116 |
|
| 117 |
def forward(self, x, *args, **kwargs):
|
| 118 |
y = self.org_forward(x, *args, **kwargs)
|
| 119 |
+
if not self.active:
|
| 120 |
+
return y
|
| 121 |
delta = F.linear(F.linear(x.to(self.down.dtype), self.down), self.up)
|
| 122 |
return y + (delta * self.scale).to(y.dtype)
|
| 123 |
|
|
|
|
| 141 |
class PoseControlSession:
|
| 142 |
"""Context manager: attach the pose adapter to ``pipe.dit`` for one generation.
|
| 143 |
|
| 144 |
+
``set_active(bool)`` gates the control tokens *and* the adapter LoRA per denoising
|
| 145 |
+
step (start/end window). Outside the window the DiT is exactly the base model, so the
|
| 146 |
+
late (detail/style) steps are not pulled toward the adapter's training-set look.
|
| 147 |
+
(ComfyUI keeps the LoRA on for the whole call; with end=1.0 this is identical.)
|
| 148 |
"""
|
| 149 |
|
| 150 |
def __init__(self, pipe, adapter: PoseAdapter, control_latent: torch.Tensor, strength: float):
|
|
|
|
| 159 |
|
| 160 |
def set_active(self, active: bool):
|
| 161 |
self.active = bool(active)
|
| 162 |
+
for wrap in self._wraps:
|
| 163 |
+
wrap.active = self.active
|
| 164 |
|
| 165 |
def __enter__(self):
|
| 166 |
dit = self.pipe.dit
|
app.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|