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

fixes sampler.name; refactored apply_sampler, confirm_sampler, build_sampler_dict; valslist ready to apply when returned from process_axis #4909

Closed
wants to merge 8 commits into from

Conversation

Gerschel
Copy link
Contributor

Sorry, I had a long week.
Final try to do a pull request. If I screw it up, going to bed.

#4860

Fixes apply_sampler() using name instead of index while respecting the function and keeping case insensitivity.

@cluder
Copy link
Contributor

cluder commented Nov 24, 2022

Tested and seems to work @AUTOMATIC1111 this would be an important fix as its currently broken

apply_sampler should not build or check for errors, it should
only apply the sampler to the process handed to it.

process_axis, when axis was "Samplers", did not finish processing
the valslist. For this, I implemented build_samplers_valslist.

build_samplers_dict was being called twice, once in apply, and once
in confirm_samplers, I pulled this out from confirm and put it into
an if opt.label == samplers block in process_axis

build_samplers_dict was modified to return a dictionary with a different
structure.
I believe this new structure makes it more clear for readers.
The previous structure was a dictionary where the first key was the
lowercase version of sampler.name, and adjacent was a key that was an
alias, both set with the same int value, for all samplers.
Because dictionaries are now ordered, dict.get(val) would return the first
match.
Also, this structure did not include the proper name needed by
Process.sampler_name. The structure is now
    {Sampler.name: [Sampler.name.lower(), alias1, ...], }
Now you can check if user value is in set of flattened dict.values(),
    "set(chain(*dict.values()))"
and grab Sampler.name from the key directly.

The building of valslist, utilizes this structure, function is
    build_samplers_valslist
It iterates through (previously confirmed) user supplied values,
steps through each dict.values until it matches, then appends
the proper name from key into list
@Gerschel
Copy link
Contributor Author

Code now works for aliases from sampler.aliases; and sampler.name; case insensitive. Did a refactor of apply_sampler, confirm_sampler, and build_samplers_dict.
Added a new function build_sampler_valslist.
Added comments for these changes for future maintainers to have something to go on.
valslist for opt.type samplers is now finalized in process_axis, this way apply_sampler just does one task.

@Gerschel Gerschel changed the title somehow deleted line before commiting, undeleted; fix apply_sampler refactored apply_sampler, confirm_sampler, build_sampler_dict; valslist ready to apply when returned from process_axis Nov 26, 2022
@Gerschel Gerschel changed the title refactored apply_sampler, confirm_sampler, build_sampler_dict; valslist ready to apply when returned from process_axis fixes sampler.name; refactored apply_sampler, confirm_sampler, build_sampler_dict; valslist ready to apply when returned from process_axis Nov 26, 2022
@AUTOMATIC1111
Copy link
Owner

well done with spotting and fixing the problem but i don't welcome refactors and i disagree with using a dictionary this way; I uploaded my fix so I will be closing this

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.

3 participants