stable-diffusion-webui
stable-diffusion-webui copied to clipboard
[Feature Request]: Allow extensions to declare priority level
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits
What would your feature do ?
Hi,
At the moment, it seems that extensions execute in alphabetical order. I propose giving extension developers some way of assigning a "priority level" that supersedes the default order.
Here's a practical example why this would be useful:
My extension, Unprompted, can create img2img masks from the user's text prompt. If used in conjunction with the ControlNet extension on "Only masked" mode, ControlNet throws an error because a mask was not yet generated. If I rename the unprompted folder to _unprompted, however, the two extensions play well together.
I am hoping for a less cumbersome solution.
Proposed workflow
Possibly a new function inside the Script class that simply returns a priority integer.
Additional information
No response
This could be done using the *.d style of ordering. For example:
extensions.d/10_unprompted
extensions.d/20_controlnet
extensions.d/99_sd-dynamic-prompts
There could be some guidelines for choosing an extension priority and with this, changing priorities is a simple directory rename. Personally, I use git-submodules for managing my extensions, so I would be doing this manually anyway, but food for thought (surprised extensions aren't submodules anyway, actually).
Good idea where extension loading/execution order can matter!
EDIT: Fix extension order in example.
I would suggest "load before" and "load after" metadata rather than trying to manage order numbers (which essentially means asking users to order by hand in the worst say possible). For ex, unprompted would have metadata that says it has to "load before" "controlnet".
Numbed lists ala sysvinit are rough enough when priorities are centrally maintained like in a linux distro (there's a reason they've been slowly abandoned that's not just systemd), and they're utter chaos when everyone has to pick their own numbers independently. (And as an end user I very much do not want to have to sort my extensions, lol.)
That can work as long as it is used to suggest the mod load order, but the actual order is determined by a single separate source. RimWorld does it this way.. mods can define what to load after, which is used in the mod management screen for the "autosort" function. However, the actual order is set by the user (so the metadata is really only assistive to the user).
You can't just rely on it as you can fairly easily create unresolvable situations. For example, A wants to load before B but B wants to load before A. Seems obvious in that small example, but when you have 20 extensions, that looping chain could be 19 long and not the only chain in play.
Of course, once you have the order set, the first one is 1, the second is 2 and so on.. and you're basically back to my suggestion, but you've had to implement a bunch of stuff to get the same result.
(I would maintain a floating patch to remove any attempt to add numbering to extensions. That's how much I hate them, lol.)
It's pretty easy to resolve loops in deterministic ways. You build a graph then traverse it once refusing to go over anything more than once. Beyond that, there are two reasons that I'm not concerned about dependency cycles:
- the maximum number of extensions in an install is not likely to be more than dozens
- most extensions won't have these constraints -- adding numbers adds complexity to every extension when almost no extensions require it.
I would support having some facility for overriding those rules, though I think a first pass could leave that to editing the metadata file in the extension folder.
Surprised to see such dislike for it. If you don't mind, why do you dislike it so much?
The resolving of the loop in a deterministic way like you describe only happens because the extensions are loaded in a sorted order (alphabetical) now. In a way, that means my suggestion is already implemented, because the characters already have a numbered order.
In the opening post, the directories basically went from being named
099ontrolnet
117nprompted
to
095unprompted
099ontrolnet
So my suggestion is really just to make it explicit.. and you can see/change the load order using any file management tool very easily. Editing metadata files means you can't see the whole load order without coding an interface for it (and then that interface needs to also edit the files rather than just rename a directory..). In fact, I've already changed all my extensions to this format (giving different priorities depending on what the extension does, so scripts are loaded late, UI additions loaded early).
As it only takes 2 extensions to create such a loop, I'm not sure why it matters that the number of installed extensions is not more than dozens (out of curiosity, is this an idiom to say "less than 25'? I don't recall coming across it before).
As to point 2, that's not true. Extensions that don't define a priority just get a default priority e.g. 50 to give plenty of room on either side. Though I wouldn't be surprised to find this isn't true in all locales, as numbers are sorted before letters in common locales, any extensions without a priority will naturally load after those that do, so you don't even have to give them a default priority.
Makes me wonder if there are already dependencies like this that just happen to be correct due to name choices! :)
There are downsides to this approach though for sure. The one that immediately jumps to mind is that you could install the same extension multiple times with different priorities. I don't imagine that going well!
Glad to see some productive discussion here. Anyone know if A1111 has commented on extension priority elsewhere?
It's getting a little tiresome having to recommend renaming the extension folder to everybody. I might whip up a PR for this if it doesn't exist yet.
Makes me wonder if there are already dependencies like this that just happen to be correct due to name choices! :)
I'm in the opposite boat. I wrote an extension that wants to execute first the vast majority of the time, but almost never does thanks to the name choice.
At this point I should just double-down and rename Unprompted to Zprompt or something.
Is there any update on this? I have a very specific order for my extension -- after ControlNet, before Dynamic Prompts -- and up until now I've been fine with using naming, but I really think this should be a core feature. I like the "before" "after" paradigm myself.