siliconflow / onediff

OneDiff: An out-of-the-box acceleration library for diffusion models.
https://github.com/siliconflow/onediff/wiki
Apache License 2.0
1.69k stars 102 forks source link

webui首次开启onediff后,Lora不生效 #1141

Open frc99 opened 1 day ago

frc99 commented 1 day ago

1、onediff==1.2.1.dev28 ,oneflow==0.9.1.dev20241019+cu118 目前仍然存在这个问题,首次编译完Lora不生效,添加环境变量export ONEFLOW_MLIR_ENABLE_INFERENCE_OPTIMIZATION=0仍然不生效。

Originally posted by @frc99 in https://github.com/siliconflow/onediff/issues/574#issuecomment-2472784089

2、Lora粘连问题,如果上一次请求使用了lora A,那么下一次请求使用lora B 不生效,仍然是lora A的效果


我想1、2都源于一个问题,webui onediff extensions 在使用了controlnet后,lora不再生效

frc99 commented 15 hours ago

通过观察,我发现不加controlnet的情况下,执行了替换shared.sd_model.model.diffusion_model = onediff_shared.current_unet_graph.graph_module ,因此lora生效;而加了controlnet之后,我尝试加了几个地方,都失败了,希望能给予我一些帮助,谢谢


也有可能是加载这个conv2d的lora权重时出的问题...但是直接用onediff_shared.current_unet_graph.graph_module替换p.sd_model.model.diffusion_model会报错 image

def hijacked_activate(activate_func): import networks

if hasattr(activate_func, "_onediff_hijacked"):
    return activate_func

def activate(self, p, params_list):
    activate_func(self, p, params_list)
    print("hijacking activated")
    print("p.sd_model.model.diffusion_model",type(p.sd_model.model.diffusion_model))
    print("onediff_shared.current_unet_graph.graph_module",type(onediff_shared.current_unet_graph.graph_module))
    if isinstance(p.sd_model.model.diffusion_model, DeployableModule):
        onediff_sd_model: DeployableModule = p.sd_model.model.diffusion_model
        for name, sub_module in onediff_sd_model.named_modules():
            if not isinstance(
                sub_module,
                (
                    torch.nn.Linear,
                    torch.nn.Conv2d,
                    torch.nn.GroupNorm,
                    torch.nn.LayerNorm,
                ),
            ):
                continue
            networks.network_apply_weights(sub_module)
            if is_oneflow_backend() and isinstance(sub_module, torch.nn.Conv2d):
                # TODO(WangYi): refine here
                from onediff.infer_compiler.backends.oneflow.param_utils import (
                    update_graph_related_tensor,
                )

                try:
                    update_graph_related_tensor(sub_module)
                except:
                    pass

activate._onediff_hijacked = True
return activate