Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Api call #6

Open
saaldigital-cw opened this issue Jul 31, 2023 · 13 comments
Open

Api call #6

saaldigital-cw opened this issue Jul 31, 2023 · 13 comments

Comments

@saaldigital-cw
Copy link

How can i use the refiner within an api call. I tried that but did non work?

payload["alwayson_scripts"]= {
"refiner": {
'args': [
{
'enable': True,
'model_name': item["StableDiffusionParams"]["Redefiner"]["Model"],
'steps': item["StableDiffusionParams"]["Redefiner"]["Steps"]
}
]
}
}

@altoiddealer
Copy link

Also interested in this

@saaldigital-cw
Copy link
Author

I found a way..you have to add something like this:

payload["alwayson_scripts"]= {
"refiner": {
'args': [
True, modelnameWithId,NumberSteps
]
}
}

@markheaps
Copy link

markheaps commented Aug 6, 2023

I did this, but not sure how I know if it's using the refiner or not. I didn't get an error, but at the same time didn't see any indication that it was used.

payload = {
"prompt": prompt,
"negative_prompt": negative_prompt,
"batch_size": batch_size,
"steps": base_steps,
"width": width,
"height": height,
"sampler_index": "Euler a",
"seed": seed,
"refiner": {
'args': [True, "sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]",refine_steps]
}
}

INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 10 images in a total of 1 batches.
100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [01:49<00:00, 3.14s/it]

whereas when I run it in the webui, the first thing its says is its loading the refiner
Loading refiner...

100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [00:22<00:00, 1.52it/s]
Total progress: 175it [15:25, 5.29s/it]
Total progress: 175it [15:25, 1.11s/it]

@altoiddealer
Copy link

It would be great if the refiner added something to the metadata… been meaning to put in an enhancement suggestion in Refiner repo (probably one there already)

@saaldigital-cw
Copy link
Author

-You can check it if you use the same seed+see if the image look different
-In the console i see that he will load the redefiner model and make a small pause before processing the last refine_steps steps

@markheaps
Copy link

Yea best I can tell its not doing anything. No pause, the picture seems to be the same.

But yes, I notice the pause in when running from the GUI so I know what your talking about.

@altoiddealer
Copy link

So I did make an enhancement suggestion in Refiner repo, to add metadata to the output images (model + steps).

they did implement this yesterday, so after you update the extension, you should be able to easily tell if the refiner was used or not by just looking at the metadata.

@altoiddealer
Copy link

altoiddealer commented Aug 10, 2023

I did this, but not sure how I know if it's using the refiner or not. I didn't get an error, but at the same time didn't see any indication that it was used.

payload = { "prompt": prompt, "negative_prompt": negative_prompt, "batch_size": batch_size, "steps": base_steps, "width": width, "height": height, "sampler_index": "Euler a", "seed": seed, "refiner": { 'args': [True, "sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]",refine_steps] } }

INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 10 images in a total of 1 batches. 100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [01:49<00:00, 3.14s/it]

whereas when I run it in the webui, the first thing its says is its loading the refiner Loading refiner...

100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [00:22<00:00, 1.52it/s] Total progress: 175it [15:25, 5.29s/it] Total progress: 175it [15:25, 1.11s/it]

You're close. I was able to figure out what you were missing, and also another thing that could be preventing it from working.

  1. Make sure you are using latest version of Refiner extension
  2. Make sure that the hash of the weights is visible in the checkpoints dropdown of your A1111 UI for your refiner model (don't worry about the dropdown in Refiner tab). By default, it will not have the weights there until you load it as a checkpoint. (Make sure "[8d0ce6c016]" is after the refiner model name in A1111 UI).
  3. If you have the refiner model in the models/Stable-diffusion directory then you have the correct arg for the model. However, if you use a subfolder like I do, then you need to update this arg to include the subdirectory followed by a double backslash.
    In my case I have it in a subdirectory "sdxl" so my arg is:
    "sdxl\\sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]"
  4. Replace "refine_steps" with the value for the percentage of refiner steps. Default and recommended is 20.

With all that said here is what is working for me

        'alwayson_scripts': {
            'refiner': {
            'args': [
                True,
                "sdxl\\sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]",
                20
            ]
            }
            }

As with using it in the A1111 UI, the cmd window will indeed show "loading Refiner" on first gen, and you will be able to see the metadata in the image confirming this.

@markheaps
Copy link

Can you point me in the right diretion of where to look for 2) "Make sure that the hash of the weights is visible in the checkpoints dropdown of your A1111 UI".

image image

I've completed 1, 3 and 4. After generation the picutre metadata only shows the mbb model used in in image browsing,
Model hash: 8b322c8033, Model: mbbxlAlpha_v01

whereas one completed by the GUI shows boththe mbb and refiner.
Model hash: 8b322c8033, Model: mbbxlAlpha_v01, Refiner model: sd_xl_refiner_1.0_0.9vae, Refiner steps: 4,

Here is my latest code snips

payload = {
"prompt": prompt,
"negative_prompt": negative_prompt,
"batch_size": batch_size,
"steps": base_steps,
"width": width,
"height": height,
"sampler_index": "Euler a",
"seed": seed,
"refiner": {
'args': [True, "sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]",refine_percent]
}
}

option_payload = {
    "sd_model_checkpoint": "mbbxlAlpha_v01.safetensors [8b322c8033]"
}

response = requests.post(url=f'{url}/sdapi/v1/options', json=option_payload)

response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)

@altoiddealer
Copy link

altoiddealer commented Aug 12, 2023

Your code snipet reads “refine_percent” where it should read “20”

from your screenshot, the hash is visible in the UI “[8d0ce6c016]”. If you never loaded the model, it wouldn’t be displayed there and actually wouldn’t load it via api

@markheaps
Copy link

refine_percent is just a variable that I have set to 20. I can try hard coding it but don't expect any differance.

@markheaps
Copy link

Should "refiner" show up when I do:

http://127.0.0.1:7860/sdapi/v1/options

I don't see it if so.

@markheaps
Copy link

Ugg. Ok, figured it out. I looked at your example before and didn't think I needed 'alwayson_scripts': { wrapper. Once I added that it worked. If you don't wrap it in that and just have it directly as was my sample code, it doesn't work.

All good now.

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

No branches or pull requests

3 participants