Skip to content
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

Added command line argument --electron to open the WebUI as a Electron app. #12694

Closed
wants to merge 2 commits into from

Conversation

diegocr
Copy link
Contributor

@diegocr diegocr commented Aug 20, 2023

Description

So... --autolaunch is cool, but my default browser is using the discrete GPU and consuming around +1GB of VRAM.

Hence, thought on supporting a --electron option so that instead of the default browser we do launch the WebUI as a standalone Electron app, which i can configure to use the integrated GPU and allows me to close the default browser to regain the VRAM it does uses.

The --electron option does requires supplying --autolaunch as well, and obviously NodeJS and the Electron package being installed. If there is any issue finding Electron, we will still fallback to use the default browser.

Screenshots/videos:

sd-webui-electron

Checklist:

…ndalone Electron app.

Signed-off-by: Diego Casorran <dcasorran@gmail.com>
@diegocr diegocr requested a review from AUTOMATIC1111 as a code owner August 20, 2023 11:53
@AUTOMATIC1111
Copy link
Owner

Feels crippling to only be able to use one browser tab...

Anyway, since this requires some external software, it's probably going to be some time until I get to test it. If anyone uses this and has something to report, please do.

@diegocr
Copy link
Contributor Author

diegocr commented Aug 21, 2023

Thanks for the review / feedback. Well, let's say this is a preliminary version, if there is acceptance / demand from the users i was intending to improve it over time, for what multiple tabs concerns we could use this component but it will require setting up a normal electron app instead of just opening the URL from the command-line.

@w-e-w
Copy link
Collaborator

w-e-w commented Aug 23, 2023

@diegocr so I have a look and I found that it's actually pretty simple to turn this into an extension
/~https://github.com/w-e-w/stable-diffusion-webui-electron

I sent you a collaborator invite to my repo, you may do anything you like
since I reusing your code from theis PR, I have set the license to be the same AGPL, you may also change this if you like
I have no intention of maintaining it, since I know next to nothing about electron and node, if you want I can transfer the repo to you

I feel like this is very rough but from my testing it does work
if you can confirm that the extension is good and that I have not done something stupid with node we can then add it to the extension index, (after thers a proper readme and instructions)

the extension also includes auto setup of electron provided that note is installed and added to path, only tested on Windows

this should be back with compatible with at least quite a few versions of webui, but I only tested with 1.5.2 and dev

I didn't add the --electron argument because you can just enable or disable the extension

@diegocr
Copy link
Contributor Author

diegocr commented Aug 24, 2023

Well, I will need to learn extensions development here, since i only started using SD early this month and basically have no idea about anything, but thanks for the boilerplate code in that repo which could help me to get started.

the extension also includes auto setup of electron provided that note is installed

Personally i would discourage installing Electron from within the extension, i think it will turn a nuisance having to keep it up-to-date when we could just rely on the globally-installed one.

I didn't add the --electron argument because you can just enable or disable the extension

Can you confirm there is some way to turn extensions on/off from the command line? at first glance i didn't found a suitable one in cmd_args.py and i think it will be a little odd if we have to go to a browser to launch Electron :)

@w-e-w
Copy link
Collaborator

w-e-w commented Aug 24, 2023

Personally i would discourage installing Electron from within the extension, i think it will turn a nuisance having to keep it up-to-date when we could just rely on the globally-installed one.

do whatever you think it's best I have no idea no concept of how node and electron works, I already sent you an invite you can do any modification you wish, if your face problems I'm willing to try and answer your questions
or I recommend you to join auto's discord srever, possibly easy to ask questions and there also others, see Wiki collaboration for the discord invite link

Can you confirm there is some way to turn extensions on/off from the command line? at first glance i didn't found a suitable one in cmd_args.py and i think it will be a little odd if we have to go to a browser to launch Electron :)

I didn't add the argument because my I think if someone don't want to use electron they could just disable extension

when possible I would suggest adding stuff as a setting in the setting tab as opposed to a arg, as it is generally more user friendly this way
you can add more settings in the settings page to
like maybe there's a way for you to lunch in full screen

if you do think adding command line arguments is necessary then it can be added in preload.py
like so /~https://github.com/w-e-w/a1111-sd-webui-lycoris/blob/main/preload.py

@catboxanon
Copy link
Collaborator

I personally think this should be made an extension as w-e-w has shown an example of. The benefit is it gives you the opportunity to maintain it yourself.

@HinaHyugaHime
Copy link
Contributor

Feels crippling to only be able to use one browser tab...

Anyway, since this requires some external software, it's probably going to be some time until I get to test it. If anyone uses this and has something to report, please do.

tested on 1.6.0-RC can confirm working only requiring --autolaunch after installing properly but wouldnt hurt to put a tutorial(on their end) on how to install NPM and electron on windows and linux.

@HinaHyugaHime
Copy link
Contributor

Description

So... --autolaunch is cool, but my default browser is using the discrete GPU and consuming around +1GB of VRAM.

Hence, thought on supporting a --electron option so that instead of the default browser we do launch the WebUI as a standalone Electron app, which i can configure to use the integrated GPU and allows me to close the default browser to regain the VRAM it does uses.

The --electron option does requires supplying --autolaunch as well, and obviously NodeJS and the Electron package being installed. If there is any issue finding Electron, we will still fallback to use the default browser.

Screenshots/videos:

sd-webui-electron

Checklist:

can vouch for after using, also improves gen speed a got a 1-3it/s boost vs having in web browser.

@levicki
Copy link

levicki commented Oct 10, 2023

@diegocr

which i can configure to use the integrated GPU

Out of curiosity, what is stopping you from configuring the browser to use the integrated GPU?

I also think this should be an extension.

@w-e-w
Copy link
Collaborator

w-e-w commented Oct 10, 2023

@levicki

Out of curiosity, what is stopping you from configuring the browser to use the integrated GPU?

depending on the system there could be strange issues
this is from a while back so I don't remember the details but if I recall correctly
I experienced stutter if I forces the browser to use the GPU that the monitor is not connected to, I would experience lots of stutter when scrolling down a web page, I think back then I connect my monitors to dGPU while have the acceleration done on iGPU

I currently have all my monitors connected to my iGPU, and the browser uses iGPU so this is not an issue for me

@levicki
Copy link

levicki commented Oct 11, 2023

@w-e-w

There's almost no scrolling in SD Web UI so even that would be a weak excuse.

Whatever the reason, I think it's easier that people are asked to avoid unsupported hadware and software configurations than to bundle Electron and Node.js as a band-aid. It should at least be fully optional if not done as an extension.

Also, Electron is based on Chrome so I highly doubt it's less memory intensive than any browser based on Chrome (i.e. all except Firefox), not to mention having to add a Node.js to the mix probably with another bunch of packages as if vetting what gets installed from PyPI isn't hard enough already and doesn't create large enough attack surface.

Finally, if they can't set their main browser to iGPU, then they can surely install one of the numerous 3rd-party browsers (Opera, Vivaldi, Brave, Chrome, Firefox, etc), set that one to run on an iGPU, and use it exclusively to run stable diffusion? Why burden everyone with Electron and Node.js integration to cater for something that can be solved locally by installing a second browser and fiddling with some graphics card control panel settings?

@w-e-w
Copy link
Collaborator

w-e-w commented Oct 11, 2023

There's almost no scrolling in SD Web UI so even that would be a weak excuse.

the default Autolaunch uses the default browser, what you meant the configuration of the default browser and it's not use only for web UI, it has nothing to do with unsupported Hardware

than to bundle Electron and Node.js as a band-aid

but yes I do agree that this is an extension and I have already made it so
see #12694 (comment)
I even have another extension that lets you choose whatever thing that you wish to launch it with
/~https://github.com/w-e-w/sd-webui-custom-autolaunch (working progress they might be some bugs)

Also, Electron is based on Chrome so I highly doubt it's less memory intensive than any browser based on Chrome

you completely missed the point, the concerned is about VRAM not system RAM

if they can't set their main browser to iGPU, then they can surely install one of the numerous 3rd-party browsers

this this electron business is basically a 3rd-party browsers and launched with configuration without hardware installation

@diegocr
Copy link
Contributor Author

diegocr commented Oct 11, 2023

Out of curiosity, what is stopping you from configuring the browser to use the integrated GPU?

Why would anybody on their right mind do that?

Well, at least beyond the kind of issues @w-e-w did mentioned, but it isn't the case here - this is about regaining the VRAM the main browser might be consuming by closing it, which we couldn't do if we have the WebUI running on it, i suggest you do re-read the initial post with the description, i'm just repeating what i said there.

It should at least be fully optional if not done as an extension.

Again, re-read the description, and if that wasn't enough check the code-changes, you'll find it's fully optional.

...not to mention having to add a Node.js to the mix probably with another bunch of packages as if vetting what gets installed from PyPI isn't hard enough already and doesn't create large enough attack surface.

You're obviously not understanding anything here, sorry to say. This is not installing anything.

...for something that can be solved locally by installing a second browser

Why would i want to mess installing a second browser, when i do already have Electron installed ? it's just a matter of providing options mate, if you don't have Electron installed and want to use a full bloated second browser just for the WebUI then go for it.

Nuff said, cheers :)

@w-e-w
Copy link
Collaborator

w-e-w commented Oct 11, 2023

Out of curiosity, what is stopping you from configuring the browser to use the integrated GPU?

Why would anybody on their right mind do that?

well I do it, my 3090 dGPU is my secondery GPU, I only use it when I need it, for every day task I use iGPU

normally you will connect your monitor to your dGPU and have every thing use dGPU
applications such as games will perform better if you do so, because it doesn't need to copy the data form one gpu to the other (oversimplification)
but don't need gaming performance, I use my GPU mostly for compute task such as stable diffusion
so it make sense to just use iGPU most of the time
my monitors is also connected to iGPU not dGPU

@levicki
Copy link

levicki commented Oct 11, 2023

Why would anybody on their right mind do that?

Because (unless you are using a very old laptop), your iGPU is good enough for most tasks you do in the browser? Nowadays even iGPU has hardware video decoding and it would also free your dGPU VRAM for other tasks that are important to you.

To be clear, I am not against implementing an option to use Electron instead of a browser (you can also add optional support for Microsoft Edge WebView2 if you want), but I must admit it looked a bit silly to go through all that trouble of implementing this when you could have just set the browser to use iGPU to achieve pretty much the same effect.

That said, I just wanted to make sure it's fully optional hence the questions. Carry on.

@diegocr
Copy link
Contributor Author

diegocr commented Oct 12, 2023

Well, some fair points there have to tell, but let me add that for example Chrome is refusing to play HEVC video on the iGPU, so by that alone i won't have the browser using it, together with all other kind of media capabilities that would benefit by using the dGPU on the browser.

@AUTOMATIC1111
Copy link
Owner

I agree with other posters who say this should be an extension. If it becomes really popular and gets updated to automatically install the requirements, we should consider integrating it as a built-in extension.

@w-e-w
Copy link
Collaborator

w-e-w commented Jan 1, 2024

I transferred my extension repo to him but since then he hasn't done anything with it
/~https://github.com/diegocr/stable-diffusion-webui-electron

@diegocr
Copy link
Contributor Author

diegocr commented Jan 1, 2024

Yep, thanks @w-e-w, just too busy with other stuff ;-)

Anyway, I do still feel with the current support / API for extensions we will lack the capability to properly setup this, in a clean way at least... if we do have to rely on kind of a hackpatch to intercept when the app is launched etc.

If as said there is demand for this, i may consider moving forward with it either way, although what i am not so sure about doing is the extension installing nodejs and all dependencies.

Cheers, and HNY! :)

@w-e-w
Copy link
Collaborator

w-e-w commented Jan 1, 2024

there are other ways to intercept the launch
one way is to intercept it in gradio by patching the function inside

@diegocr
Copy link
Contributor Author

diegocr commented Jan 1, 2024

"by patching" ... :-)

I think nothing will be in a more clean way that just providing a command-line argument just like this PR is doing, i think the changes here are minimal and doesn't harm, but yeah if does requires to have the dependencies installed, although i also think no big deal that whoever does want to use this do install them manually if they don't have them already, which i think it's better than over engineering the integration at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants