ArtVentureX / sd-webui-agent-scheduler

599 stars 60 forks source link

enabling hires fix through api causes the task to fail. #249

Closed Xerophayze closed 1 month ago

Xerophayze commented 1 month ago

Im running into a problem utilizing hires fix through the api. Here is what I am doing. I am using webui forge and your extension seems to work great. I think its something with how i am forming the api package that is causing the problem because in the webui itself i can render an image using agent scheduler with hires fix enabled and it works fine. but when I do it through the api it does the first pass render of the initial image, then as soon as it tries to engage the hires fix it erros out and the task fails. I have copied the errors below.

Error in the webui console: ERROR:sd:[AgentScheduler] Task a2823ee1-4ca0-4822-adc1-50cba1328672 failed: '>' not supported between instances of 'NoneType' and 'int'

error in the generation info box in agent scheduler: Status: failed Error: '>' not supported between instances of 'NoneType' and 'int'

Here is the code in my backend node.js system that is building the package to send to the api: const payload = { prompt: prompt, aspect_ratio: aspectRatio, steps: steps, cfg: cfg, base_resolution: baseResolution, checkpoint: checkpoint, seed: seed };

    if (highResFix) {
        payload.enable_hr = true;
        payload.hr_upscaler = "4x_NMKD-Siax_200k";
        payload.hr_second_pass_steps = 10;
        payload.denoising_strength = 0.2;
        payload.hr_scale = 2;
    }

I feel like something is missing and hoping you might be able to fill in the gap.

Xerophayze commented 1 month ago

Here is what the json looks like when i export the job, it looks like some of the hires settings are not getting passed through to the api. Im thinking that this api needs to be formatted a little differently for the hires fix when i submit it via api. Are there any examples or suggestions that could be made on this: "enable_hr":true, "firstphase_width":0, "firstphase_height":0, "hr_scale":2, "hr_upscaler":null, "hr_second_pass_steps":0, "hr_resize_x":0, "hr_resize_y":0, "hr_checkpoint_name":null, "hr_sampler_name":null, "hr_prompt":"", "hr_negative_prompt":"",

Xerophayze commented 1 month ago

I believe this is what my json package would look like when getting submitted to the api.

{ "prompt": "Your prompt text", "cfg_scale": 7, "steps": 50, "height": 512, "width": 512, "seed": 12345, "override_settings": { "sd_model_checkpoint": "Your checkpoint" }, "alwayson_scripts": { "Your always-on scripts" }, "enable_hr": true, "hr_upscaler": "4x_NMKD-Siax_200k", "hr_second_pass_steps": 10, "denoising_strength": 0.2, "hr_scale": 2, "hr_resize_x": 0, "hr_resize_y": 0, "hr_checkpoint_name": "Use same checkpoint", "hr_sampler_name": "Use same sampler", "hr_prompt": "", "hr_negative_prompt": "" }

Xerophayze commented 1 month ago

Ok never mind, i figured it all out. i was able to figure out the final format that works for what I need to do. for a while there it was telling me "bad sampler name" for the sampler being used for hi res fix, but i found out that i do not need that variable to be specified and let it go to null and it uses the sampler being used to generate the image. this is all being done with webui forge edition: version: f0.0.17v1.8.0rc-latest-276-g29be1da7  •  python: 3.10.11  •  torch: 2.1.2+cu121  •  xformers: N/A  •  gradio: 3.41.2  •  checkpoint: d048a83385

here is the final json format:

[{"id":"974d4051-1485-46a2-b455-e8900d4b369b","api_task_id":null,"api_task_callback":null,"name":null,"type":"txt2img","status":"pending","params":{"args":{"prompt":"Wide angle mixed media artwork, (Dreamlike underwater cityscape:1.2), Geometric abstraction, Glowing coral reefs, Luminescent marine life, (Aquamarine hues:1.3), Floating jellyfish, Swirling currents, Enveloping silence, Sunlight dances, (Submerged tranquility:1.2)","negative_prompt":"","styles":null,"seed":-1,"subseed":-1,"subseed_strength":0,"seed_resize_from_h":-1,"seed_resize_from_w":-1,"sampler_name":null,"batch_size":1,"n_iter":1,"steps":8,"cfg_scale":2.5,"width":1024,"height":1024,"restore_faces":null,"tiling":null,"do_not_save_samples":false,"do_not_save_grid":false,"eta":null,"denoising_strength":0.2,"s_min_uncond":null,"s_churn":null,"s_tmax":null,"s_tmin":null,"s_noise":null,"override_settings":{"sd_model_checkpoint":"RealitiesEdgeXLLIGHTNING_TURBOV7.safetensors"},"override_settings_restore_afterwards":true,"refiner_checkpoint":null,"refiner_switch_at":null,"disable_extra_networks":false,"firstpass_image":null,"comments":null,"enable_hr":true,"firstphase_width":0,"firstphase_height":0,"hr_scale":2,"hr_upscaler":"4x_NMKD-Siax_200k","hr_second_pass_steps":10,"hr_resize_x":0,"hr_resize_y":0,"hr_checkpoint_name":"Use same checkpoint","hr_sampler_name":null,"hr_prompt":"","hr_negative_prompt":"","force_task_id":null,"sampler_index":"DPM++ 2M Karras","script_name":null,"send_images":true,"save_images":false,"alwayson_scripts":{},"infotext":null},"checkpoint":"RealitiesEdgeXLLIGHTNING_TURBOV7.safetensors","is_ui":false,"is_img2img":false},"script_params":"eJxrYImdogcABQIBpA==","priority":1716501208500,"result":null,"bookmarked":false,"created_at":1716501208,"updated_at":1716501208}]

and here is the code that puts it all together: Front end code in javascript:

async function generateImage(prompt, aspectRatio, steps, cfg, baseResolution, checkpoint, highResFix, seed, adetailer, adetailerOption1, adetailerOption2) {
    try {
        const payload = {
            prompt: prompt,
            aspect_ratio: aspectRatio,
            steps: steps,
            cfg: cfg,
            base_resolution: baseResolution,
            checkpoint: checkpoint,
            seed: seed
        };

        if (highResFix) {
            payload.enable_hr = true;
            payload.hr_upscaler = "4x_NMKD-Siax_200k";
            payload.hr_second_pass_steps = 10;
            payload.denoising_strength = 0.2;
            payload.hr_scale = 2;
            payload.hr_resize_x = 0;
            payload.hr_resize_y = 0;
            payload.hr_checkpoint_name = "Use same checkpoint";

            payload.hr_prompt = "";
            payload.hr_negative_prompt = "";
        }

        if (adetailer) {
            payload.alwayson_scripts = {
                ADetailer: {
                    args: [
                        true,
                        true,
                        adetailerOption1 === "None" ? false : { ad_model: adetailerOption1 },
                        adetailerOption2 === "None" ? false : { ad_model: adetailerOption2 }
                    ]
                }
            };
        }
   }
}

Backend code in javascript:

const payload = {
        prompt: prompt,
        cfg_scale: cfg,
        steps: steps,
        height: height,
        width: width,
        seed: seed,
        override_settings: { sd_model_checkpoint: checkpoint },
        alwayson_scripts: alwayson_scripts || {},
        enable_hr: enable_hr || false,
        hr_upscaler: hr_upscaler || "4x_NMKD-Siax_200k",
        hr_second_pass_steps: hr_second_pass_steps || 10,
        denoising_strength: denoising_strength || 0.2,
        hr_scale: hr_scale || 2,
        hr_resize_x: hr_resize_x || 0,
        hr_resize_y: hr_resize_y || 0,
        hr_checkpoint_name: hr_checkpoint_name || "Use same checkpoint",

        hr_prompt: hr_prompt || "",
        hr_negative_prompt: hr_negative_prompt || ""
    };