chengzeyi / stable-fast

Best inference performance optimization framework for HuggingFace Diffusers on NVIDIA GPUs.
MIT License
1.19k stars 74 forks source link

切换ControlNets #137

Closed callmezhangchenchenokay closed 8 months ago

callmezhangchenchenokay commented 8 months ago

Hello,感谢你优秀的开源工作

在真正的业务之中,我们的场景是经常性的切换ControlNet, 即插即用的一种方式

在sfast, model = compile_model(model),没有找到切换controlnet的接口,而且需要提前加载 所以想问一下有类似switch lora 一样的 解决方案

我注意到一点,load_model的时候不带 controlnet , 之后 controlnet = ControlNetModel.from_pretrained() model.controlnet = controlnet 然后sfast编译模型的时候,hasattr(m, 'controlnet') 为True sfast/compilers/diffusion_pipeline_compiler.py(88) if hasattr(m, 'controlnet'): m.controlnet = compile_unet(m.controlnet, config)

但是最后出来的结果没有controlnet的效果

感谢🙏

callmezhangchenchenokay commented 8 months ago

测试

args.controlnet = '/models/workspace/zhangchenchen/zcc/sd-controlnet-canny/'
model = load_model(
        pipeline_cls,
        args.model,
        variant=args.variant,
        custom_pipeline=args.custom_pipeline,
        scheduler=args.scheduler,
        lora=args.lora,
        controlnet=args.controlnet,
    )
    controlnet = ControlNetModel.from_pretrained('/models/workspace/zhangchenchen/zcc/sd-controlnet-depth/',torch_dtype=torch.float16)
    controlnet.to(torch.device('cuda'))
    model.controlnet = controlnet

这样切换controlnet之后,可以正常工作