-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add sd-webui extension #401
Conversation
This pull request depends on the merging of #379 |
|
||
## Installation Guide | ||
|
||
1. Install and set up Stable Diffusion web UI based on [this commit snapshot](https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/4afaaf8a020c1df457bcf7250cb1c7f609699fa7). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块是不是改成:
git clone 到这个 commit 的操作。
|
||
1. Install and set up Stable Diffusion web UI based on [this commit snapshot](https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/4afaaf8a020c1df457bcf7250cb1c7f609699fa7). | ||
|
||
Perform the following [manual installation](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-NVidia-GPUs#manual-installation) process: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分安装是不是直接指向官方的就可以了,不用重复
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的操作和 manual installation 还不一样。我之前照着官方文档操作,中间出现各种问题。现在这些操作、及其顺序,也是反复调试出来的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我觉得最好确认下,我第一次玩的时候,因为网络问题确实很麻烦。
但是解决了网络问题后,是直接运行 webui.sh 就全自动安装了。
而且我觉得sd-webui这么流行,如果最新版本这么难安装(还没有现成解决方案),不符合常理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的“手动安装建议“,主要是针对”要使用 onediff 插件“的情况。如果只是用 sd-webui,自动安装也可以。但是如果要用 onediff,至少 checkpoint 函数这个就很难绕过去。
因为目前的自动安装指定了较旧的 generative-models 的版本,其使用了自己写的 checkpoint 函数,很多 forward 都套了这个函数。而最新版使用了 torch 的 checkpoint 函数,onediff 就能正常运行了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两天重新思考了一下,我们可以先让 sd-webui 自动安装(包括 onediff 插件的依赖),然后再修复与 oneflow_compile 冲突的地方。这样可以大大简化安装过程。
pip install pydantic==1.10.13 | ||
``` | ||
|
||
2. Install OneFlow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指向 onediff readme
pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu118 | ||
``` | ||
|
||
3. Intall onediff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指向 onediff readme
cp sd_xl_base_1.0.safetensors stable-diffusion-webui/models/Stable-diffusion/ | ||
``` | ||
|
||
To improve the speed of the first startup of the service, download [openai/clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) ahead of time and change the model path in [the code](https://github.com/Stability-AI/generative-models/blob/059d8e9cd9c55aea1ef2ece39abf605efb8b7cc9/sgm/modules/encoders/modules.py#L338). The example code is as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是 sd web ui 的 trick 么,还是 onediff 执行需要的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是 trick。只是 sd-webui 依赖这个模型。如果不提前下载,启动时会比较慢。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是 trick。只是 sd-webui 依赖这个模型。如果不提前下载,启动时会比较慢。
好的,可以注明下不是 onediff 的约束。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得是否可以直接删掉这类说明?因为它其实不是 onediff 的问题,也不是别人都会遇到的问题(比如没有 GFW 网速很快的区域)。
越复杂的话,别人尝试的难度就越大。(当然上面的指定 commit 和跑通 onediff 息息相关,不能省)
可以此 readme 是假定用户能顺利跑通 sd-webui,然后想来尝试 onediff sd-webui 插件。
这类跑通的经验,可以另外做一个章节或者另外一个文档,”Trouble Shooting“里集中说明。
return not is_img2img | ||
|
||
def run(self, p): | ||
global _compiled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有 self 的话,就别用 global
把 _compiled 存在 Script 对象上?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile 函数中把编译结果赋值给 _compiled
。
而 compile 函数注册到 script_callbacks.on_model_loaded,当模型加载时进行编译。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._compiled 比较正常,全局变量不好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是可以改的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 compile 函数中拿不到具体的 Script 对象实例,也就无法访问其中的变量。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile(shared.sd_model, self)
这样就拿到了吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没有改?还是不能改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前回复到 Slack、没有同步到这里。
还不能这么改。因为注册到 script_callbacks 的函数只有一个入参 model。
|
||
![raw_webui](images/raw_webui.jpg) | ||
|
||
To enable onediff plugin acceleration, select `onediff` in Script and click the `Generate` button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enable onediff plugin acceleration, select `onediff` in Script and click the `Generate` button. | |
To enable OneDiff extension acceleration, select `onediff` in Script and click the `Generate` button. |
- OneDiff 作为产品名的话应该有大小写?
- sd-webui 里好像有称呼插件为 extension 的惯用说法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script 是 UI 里的下拉列表的名字。
launch.run_pip("install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/master_open_source/cu122") | ||
if not launch.is_installed("onediff"): | ||
print("onediff is not installed! Installing...") | ||
launch.run_pip("install git+https://github.com/Oneflow-Inc/diffusers.git onediff") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
launch.run_pip("install git+https://github.com/Oneflow-Inc/diffusers.git onediff") | |
launch.run_pip("install git+https://github.com/Oneflow-Inc/onediff.git") |
仓库已经更新成 onediff 了
# print(f"Expected tensor size:{tensor_size/gb:0.1f}GB, cuda free:{mem_free_cuda/gb:0.1f}GB " | ||
# f"torch free:{mem_free_torch/gb:0.1f} total:{mem_free_total/gb:0.1f} steps:{steps}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调试信息可以删除了?
Refiner 的配置有一个 bug。需要将 sd_xl_refiner.yaml 中 context_dim 的值由 list 改为 int。 无论是 base 还是 refiner model,都是通过 set_sd_model 保存到 model_data 中(即 modules.shared.sd_model)。也就是说,用 refiner 前会先卸载 base。推理下一个图片时,会重新加载 base model(从 nvidia-smi 可以观察到显存变化)。 打开 refiner 和 onediff 开关后的执行过程如下:
需要注意的是,加载 refiner 后虽然会调用 compile 函数,但是需要显式设置 shared.sd_model.model.diffusion_model。因为 Script.run 只会进入一次,其中设置 shared 的操作已经做过了、不会再次执行。 但是这样的话,使用 compile 只会更慢,因为每次请求都要编译两个模型。 |
refiner 配置的 bug,是 genertive models 的问题对吧,不是我们引入的 |
是说如果同时使用了base 和 refiner 的加速,会导致这两个模型轮流切换,每次都会触发编译? |
是 genertive models 的问题。参考 generative-models/issues/162models/issues/162
是的 |
No description provided.