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

load model from API #4301

Closed
wants to merge 2 commits into from
Closed

load model from API #4301

wants to merge 2 commits into from

Conversation

ArcticFaded
Copy link
Collaborator

@ArcticFaded ArcticFaded commented Nov 4, 2022

This PR allows for the API to load models from checkpoints - it also fixes a typo

@bamarillo
Copy link
Contributor

Isn't get_closet_checkpoint_match a typo? (should be get_closest_checkpoint_match). Can we fix it in this PR?

@iamianM
Copy link

iamianM commented Nov 5, 2022

I see the get for /sdapi/v1/sd-models but not the set. Am I missing something?

Screenshot 2022-11-05 114112

@iamianM
Copy link

iamianM commented Nov 5, 2022

Also any chance you'd be able to add the variation seed/strength to the img2img post request?

@@ -57,6 +57,7 @@ def __init__(self, app: FastAPI, queue_lock: Lock):
self.app.add_api_route("/sdapi/v1/samplers", self.get_samplers, methods=["GET"], response_model=List[SamplerItem])
self.app.add_api_route("/sdapi/v1/upscalers", self.get_upscalers, methods=["GET"], response_model=List[UpscalerItem])
self.app.add_api_route("/sdapi/v1/sd-models", self.get_sd_models, methods=["GET"], response_model=List[SDModelItem])
self.app.add_api_route("/sdapi/v1/sd-models", self.get_sd_models, methods=["POST"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this point to self.set_sd_models ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looks like that's the issue. Is there anyway to make it where you can specify the model to use in the txt2img and img2img request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't, but you can set it in the config, but that is broken for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im going to be remaking this PR to fix the config instead - this should also allow for model reloading

Copy link
Contributor

@aliencaocao aliencaocao Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a override settings field in img2txt and img2img request where you can use specific settings (including using a particular hypernetwork and model) for that inference, then restoring to previous state. Unfortunately, due to long loading times for the model, it doesnt work for model switching, but it is trivial enough to make it load on change. I already have an open PR to enable the hypernetwork loading - though it has not been merged yet. #4120
You can see this PR to see how to add support for reloading model.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a override settings field in img2txt and img2img request where you can use specific settings (including using a particular hypernetwork and model) for that inference, then restoring to previous state. Unfortunately, due to long loading times for the model, it doesnt work for model switching, but it is trivial enough to make it load on change. I already have an open PR to enable the hypernetwork loading - though it has not been merged yet. #4120 You can see this PR to see how to add support for reloading model.

I tried overriding sd_model_checkpoint with the model title, model_name and hash but none seemed to work as the hash for each image came back with the default model hash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as I said, this does not work now, but you can quickly patch to make it work, refer to my PR, just call the reload method for model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I've been thinking about this and I agree that it's probably best done as part of the generation request itself. Otherwise, a user that tries to generate with another model may end up switching the model for pending generations, unless the client has its own internal queuing mechanism (which other clients won't be able to share.)

Has anyone made a PR like #4120 for switching the model within the request itself?

Copy link
Contributor

@aliencaocao aliencaocao Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has anyone made a PR like #4120 for switching the model within the request itself?

I can work on it in early Dec.

@AUTOMATIC1111
Copy link
Owner

with the latest commit it should be possible to change model at runtime by just setting the setting via API like you normally do in UI so I'm closing this

@Jasongenius
Copy link

It's wired that I can't see the things like "/sdapi/v1/txt2img", or "/sdapi/v1/img2img"... I'm a windows usus so what I did is to modify the 'webui-user.bat' file, add a line like "set COMMANDLINE_ARGS=--xformers --autolaunch --listen --api", which allows the "launch.py" to launch the webui with these parameters.
But after several trial, I can only see limited description in the http://127.0.0.1:7860/docs like, like the screenshot shown below.
微信截图_20221124132644
Any advice?

@philpax
Copy link
Contributor

philpax commented Nov 27, 2022

with the latest commit it should be possible to change model at runtime by just setting the setting via API like you normally do in UI so I'm closing this

I've been playing around with this - POSTing to sdapi/v1/options with sd_model_checkpoint works, but specifying sd_model_checkpoint in override_settings of a generation request doesn't. Is this intentional? If so, what's the best way to switch models for a specific request without stepping on other requests' toes? (I have a multi-tenant scenario where multiple clients can be using the API at the same time, so I want to ensure that their gen requests have the models they requested)

@aliencaocao
Copy link
Contributor

aliencaocao commented Nov 27, 2022

@philpax it is intentional, because loading model takes very long and kind of denies others from sending API requests that also loads model.

If you want, you can take a look at my PR on enabling it for hypernetwork, then do a simple patch on your side: #4120

@philpax
Copy link
Contributor

philpax commented Nov 27, 2022

I mean, right now, I have to do POST /options and then POST /txt2img - either way, I have to load a model if the user's requesting a model switch. The two-request solution is prone to race conditions and other queuing shenanigans, unlike being able to specify it in the generation request (which is internally queued). The other issue is that I have multiple clients, not talking to each other, using the same API: they have no way of getting on the same page about the model to use, so I have to issue the options-request every time.

If load times are an issue, consider adding a setting to disable the ability to dynamically load from a request? but imo, being able to switch from a generation request is a sensible default.

(Thanks for the link to the PR - I can do that if all else fails, but I'd like to avoid keeping my own patches, especially as I'm a library author)

@aliencaocao
Copy link
Contributor

Actually load time wont be an issue if you cache model in RAM. I will see if I can make a PR on this soon, but its all up to AUTO whether it gets merged (due to the concerns)

@aliencaocao
Copy link
Contributor

@philpax I have made the PR: #5191

@AUTOMATIC1111 AUTOMATIC1111 deleted the load_model_from_api branch June 1, 2023 05:30
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.

7 participants