[Feature] Enable LoRA adapter injection for BAGEL (#2490)
Signed-off-by: Zhengyuan Su <su.zhengyuan@u.nus.edu> Signed-off-by: Claude <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
328de586aa
commit
486d77d797
6 files changed
+392
-31
No files matched your search
@@ -366,13 +366,17 @@ class DiffusionLoRAManager:
|
||||
fully_sharded_loras=False,
|
||||
)
|
||||
|
||||
for component_name in ("transformer", "transformer_2", "dit"):
|
||||
for component_name in ("transformer", "transformer_2", "dit", "bagel"):
|
||||
if not hasattr(self.pipeline, component_name):
|
||||
continue
|
||||
component = getattr(self.pipeline, component_name)
|
||||
if not isinstance(component, nn.Module):
|
||||
continue
|
||||
|
||||
# Collect replacements first to avoid mutating the module tree
|
||||
# while iterating over named_modules().
|
||||
pending_replacements: list[tuple[str, str, nn.Module, list[str]]] = []
|
||||
|
||||
for module_name, module in component.named_modules(remove_duplicate=False):
|
||||
# Don't recurse into already-replaced LoRA wrappers. Their
|
||||
# original LinearBase lives under "base_layer", and replacing
|
||||
@@ -401,6 +405,9 @@ class DiffusionLoRAManager:
|
||||
if not should_replace:
|
||||
continue
|
||||
|
||||
pending_replacements.append((module_name, full_module_name, module, packed_modules_list))
|
||||
|
||||
for module_name, full_module_name, module, packed_modules_list in pending_replacements:
|
||||
lora_layer = from_layer_diffusion(
|
||||
layer=module,
|
||||
max_loras=1,
|
||||
|
||||
Reference in new issue
Block a user