lllyasviel / stable-diffusion-webui-forge

GNU Affero General Public License v3.0
7.5k stars 724 forks source link

Generate Forever is broken for quite sometime #1292

Open akaGik-jit opened 1 month ago

akaGik-jit commented 1 month ago

I know you have been busy fixing bugs in forge but can you please fix the generate forever button. Every time I click it UI starts to misbehave and I have to restart again. Thank you for Forge. It has been extremely helpful for my lowvram setup.

lllyasviel commented 1 month ago

i just tested and works without any problems?

akaGik-jit commented 1 month ago

i just tested and works without any problems?

For some reason mine is broken. I will try again after updating.

akaGik-jit commented 1 month ago

Just updated Forge and generate forever is working again. Thank you very much. One thing I want to say is when I change prompt or image size it still generates old parameters and after cancelling generate forever and interrupting it keeps on going by itself with old parameters. Restarting again fixes it. I am using stability matrix and 2gb vram gpu maybe that's the reason. I will delete everything and try again. Again thank you very much because of you I can use sd 1.5 and SDXL on on my laptop.😁

matt-c1 commented 1 month ago

@lllyasviel

i just tested and works without any problems?

Steps to reproduce:

  1. Start generate forever in the txt2img tab
  2. Switch to the img2img tab
  3. (possibly wait until one image completes)
  4. Switch back to txt2img
  5. Now the progress bar is broken
  6. Click "Cancel generate forever"
  7. Now the button will change from "Interrupt" to "Generate" and previews will stop showing, as if generation was paused
  8. But the generation will go on forever in the background, until the page is refreshed

(I'm using Firefox on Linux.)

Other issues reporting on the same problem:

  1. https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/875
  2. https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/929
  3. https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/1004
  4. https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/1190

I'm replying here because only this issue got an official reply so far, but all issues except 875 could be closed as duplicate, I think.

Jonseed commented 1 month ago

@akaGik-jit I'm also having the issue that you mentioned, where stopping generate forever doesn't stop it, and it continues using old parameters. I'm not sure what is happening, but one thought is that it is sending multiple commands to generate forever that somehow get queued up, and even though you stop it in the browser, these generate commands are still sent to the server?

DashCub commented 1 month ago

I'm using Forge installed through StabilityMatrix and having the same issue. It's updated to the current latest version. After starting Generate Forever, the first bath will generate normally (progress bar, preview, grid image works normally). But after the first batch, previews stop working, grids will still process for a few batches but it also stops working eventually. The prompts are also locked in (changing the prompts won't affect the output). After clicking 'Cancel generate forever', the UI stops showing the progress/preview but it keeps generating in the background. Only restarting the whole UI stops it from generating.

As4shi commented 4 weeks ago

I managed to partially fix this.

Some weird stuff is going with background tabs, causing the generate button to get spammed. I added some extra checks to prevent this. However, while switching browser tabs or minimizing the window is working, switching between UI tabs (txt2img, img2img etc) is still kinda broken.

Edit: Found another issue, if the tab is completely in the background it will stop generating after a while until it has focus again. But at least it won't break when you come back to it. Ymmv depending on your browser.

Check below for more info, but either way, here is the code:

File: javascript\contextMenus.js Function: generateOnRepeat

let generateOnRepeat = function(genbuttonid, interruptbuttonid) {
        let genbutton = gradioApp().querySelector(genbuttonid);

        // I'm not familiar with gradio, perhaps there is a way to do this with the existing genbutton variable
        let genbutton_ = document.getElementById(genbuttonid.slice(1));
        let genbutton_state = genbutton_.getAttribute('data-state') === 'clicked';

        let interruptbutton = gradioApp().querySelector(interruptbuttonid);
        if (!interruptbutton.offsetParent) {
            if (!genbutton_state) { // Might not be necessary to check this here, but shouldn't cause problems either
                genbutton_.setAttribute('data-state', 'clicked');
                genbutton.click();
            }
        }
        clearInterval(window.generateOnRepeatInterval);
        window.generateOnRepeatInterval = setInterval(function() {
            genbutton_state = genbutton_.getAttribute('data-state') === 'clicked';

            // If interrupt is not visible and generate has not been clicked
            // then you click the button
            if (!interruptbutton.offsetParent && !genbutton_state) {
                genbutton_.setAttribute('data-state', 'clicked');
                genbutton.click();
            // If interrupt is visible and generate has been clicked
            // That means generation has started, so we can set it back to not-clicked
            // to allow it to trigger again once it finishes
            } else if (interruptbutton.offsetParent && genbutton_state) {
                genbutton_.setAttribute('data-state', 'not-clicked')
            }
        },
        500);
    };

Function: cancelGenerateForever

    let cancelGenerateForever = function() {
        clearInterval(window.generateOnRepeatInterval);
        txt2img_gen_button = document.getElementById('txt2img_generate');
        txt2img_gen_button.setAttribute('data-state', 'not-clicked')
        img2img_gen_button = document.getElementById('img2img_generate');
        img2img_gen_button.setAttribute('data-state', 'not-clicked')

    };

If you switch to another UI tab and come back before the generation finishes, it might cause the generation button to be triggered again and will cause a similar issue, but so far I've been able to just cancel the generate forever and it does reflect prompt edits with some delay*, turning this into pretty much a visual glitch.

Waiting for the generation to finish and then coming back to the same tab won't cause this problem, but it will stop the current "generate forever", and you will need to hit "cancel generate forever" once and start it again.

At least it is still better than how it was before imo.

*By delay I mean it might take a couple generations for your prompt changes to show. This is probably caused by multiple generations being queued instead of one at a time, which was the original issue too, but now in a smaller scale.

I hope it helps a bit at least. I didn't make this into a fork/pull request since it still has issues, but feel free to use it.

coghazard commented 4 weeks ago

I'll also mention that this is compounding with the issue where default settings aren't being saved (#1129, #1323), because having to reload the UI to stop infinite generation also means losing your modified settings.

Ryoidenshii commented 3 weeks ago

I am reporting that this bug is still present in the latest version of the UI. None has changed. This is not "invalid" if a numerous people are reporting the same issue, you know...

I also have tried to reinstall everything just now, and started "Generate Forever" on a completely clean installation, not even changing any settings. I haven't been using Hires, the promt consisted of 3 tags. The bug appeared immediately when I switched tabs.

As4shi commented 3 weeks ago

@Ryoidenshii this was initially marked as invalid due to a lack of steps to reproduce the issue, not because it was fixed, hence why no other related issues were marked as invalid.

Nothing has changed in the official version, what exists atm is the partial fix I provided above. You need to apply the fix manually, but it is literally copy pasting so should be pretty easy.

If the partial fix I provided above is not enough you can roll back to a previous version. I'm pretty sure this wasn't present before the gradio 4.4 update, so look for that commit.

Btw, I wouldn't expect an official fix anytime soon, there are probably more important things to develop right now.

arvidsson89 commented 1 week ago

I wish this would be fixed. Every time it happens, and sooner or later it does, to change the prompt you need to restart forge. For me the most common way it happens is when you change to another tab in the same browser window while generating, not sure how long it takes to break, maybe 1 full generation. Even if I keep it in a single window on another monitor this happens sooner or later though, and it seems once its close to bugging out the preview window is severely delayed.

The effects that I see:

  1. Generations doesnt respond to prompt changes
  2. If you cancel generate forever, the gui will show the generate button, but the CLI window will keep generating forever, once a new image is completely generated it will show up in the preview window, and stay there until the next image is completely generated, then the preview window will show that image, and so on.
  3. This goes on until forge is completely closed. Its very annoying since it wastes time to constantly have to restart.

This is literally the only problem I have with forge right now, hope it will be fixed. In all other aspects, I love forge.