glucauze / sd-webui-faceswaplab

Extended faceswap extension for StableDiffusion web-ui with multiple faceswaps, inpainting, checkpoints, ....
https://glucauze.github.io/sd-webui-faceswaplab/
GNU Affero General Public License v3.0
715 stars 92 forks source link

Speedup WebUI launch by improving faceswaplab code #39

Closed dhwz closed 11 months ago

dhwz commented 11 months ago

Can you please try to improve the startup time, something is completely not right here if you compare it to the loading time of any other extension.

13.5secs for loading the script (can this be improved?) and 7sec to run extensions installer (even if it's already completely installed, that shouldn't be necessary?)

So ~20sec of the 50sec are only based on that single extension.

slow_startup
glucauze commented 11 months ago

Yep, that's a problem indeed. Are you using an SSD?

For the installation I had a lot of trouble getting something to work. I had something more efficient but it didn't work very well in some cases.

For the script part, it's because I calculate the hash of the model on startup to check that it's valid. I may change this later.

I don't have time to deal with it this week. In the meantime, you can comment on the corresponding code in install.py and configure.py

dhwz commented 11 months ago

Ok thx for your reply, I can patch it for now, maybe a simple option in settings to skip the hash calculation and installation check would already help. What's the reason you've to check the hash every time, are you afraid users downloading malicious code?

glucauze commented 11 months ago

It can avoid that indeed. I am not sure it is really necessary for onnx.

But above all I wanted to make sure that the model was the right one. I had several issues where the problem was a bad download.

glucauze commented 11 months ago

I have started v1.2.2 which should improve this : https://github.com/glucauze/sd-webui-faceswaplab/tree/v1.2.2

dhwz commented 11 months ago

ok tried to test, but there is an error

*** Error running install.py for extension /home/dragon/stable-diffusion-webui/extensions/sd-webui-faceswaplab.
*** Command: "/home/dragon/stable-diffusion-webui/venv/bin/python3.10" "/home/dragon/stable-diffusion-webui/extensions/sd-webui-faceswaplab/install.py"
*** Error code: 1
*** stderr: /home/dragon/stable-diffusion-webui/venv/lib/python3.10/site-packages/pytorch_lightning/utilities/distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
***   rank_zero_deprecation(
*** Traceback (most recent call last):
***   File "/home/dragon/stable-diffusion-webui/extensions/sd-webui-faceswaplab/install.py", line 66, in <module>
***     check_time = timeit.timeit(check_install, number=1)
***   File "/usr/lib/python3.10/timeit.py", line 234, in timeit
***     return Timer(stmt, setup, timer, globals).timeit(number)
***   File "/usr/lib/python3.10/timeit.py", line 178, in timeit
***     timing = self.inner(it, self.timer)
***   File "<timeit-src>", line 6, in inner
***   File "/home/dragon/stable-diffusion-webui/extensions/sd-webui-faceswaplab/install.py", line 12, in check_install
***     ) or shared.opts.data.get("faceswaplab_use_gpu", False)
*** AttributeError: 'NoneType' object has no attribute 'data'

I've removed or shared.opts.data.get("faceswaplab_use_gpu", False) from install.py for further testing.

"Load script" is great now ~0.3secs But "run extensions installers" is still a bit slow with 5secs

glucauze commented 11 months ago

Thx for your feedback. I still need to work on it. Just to have an idea, what env are you using ? SDNext or A1111 ?

dhwz commented 11 months ago

A1111

glucauze commented 11 months ago

That's weird, i don't have this error on my side and that line was used in 1.2.1 :/

dhwz commented 11 months ago

Oh wait I'm using the latest development version so you may try these

glucauze commented 11 months ago

I will give it a try. You are using the dev branch ? https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/dev or something else ?

Think i got why. Will fix it in a minute.

Are you using GPU ?

glucauze commented 11 months ago

This should be fixed in last push.

dhwz commented 11 months ago

Thx, ok now except for the 5secs install delay everything is fine.

glucauze commented 11 months ago

The 5s delay is weird. I don't get that on Linux but on Windows sometimes. I will see if i can do better. I will merge this branch for now after some testing.