ssitu / ComfyUI_restart_sampling

ComfyUI nodes for restart sampling based on the paper "Restart Sampling for Improving Generative Processes"
GNU General Public License v3.0
83 stars 6 forks source link

Code formatting + clean up some lints #14

Closed blepping closed 7 months ago

blepping commented 7 months ago

as promised!

this is 95% cosmetic - just ran it through a code formatter and made some style changes (like consistently ending list items with a comma even when it's not strictly necessary, sorting imports).

stuff like:

    sigs = [float(s_max)]
    for x in range(1, n - 1):
        sigs += [float(sigmas_slice[-(1 + int(x * ss))])]
    sigs += [float(s_min), 0.0]

can be written more succinctly by unpacking a comprehension. actually didn't know about this trick until the linter suggested it:

>>> (1, 2, *(x for x in range(4)), 3, 4, 5)
(1, 2, 0, 1, 2, 3, 3, 4, 5)

so if you want to build a sequence with a prefix/suffix it's possible to just unpack a comprehension in the middle. since those immediately get turned into tensors, they didn't even need to be lists and could be immutable tuples instead.

these changes shouldn't affect the results in any way.

the formatting/linter is opinionated and this didn't take much effort so if you prefer the existing style please feel free to simply close this pull.

ssitu commented 7 months ago

Yeah I'm fine with the formatting. Cool trick too!

blepping commented 7 months ago

just noticed i missed the simple test scheduler:

    sigs = []
    for x in range(n):
        sigs += [float(sigmas_slice[-(1 + int(x * ss))])]
    sigs += [0.0]

if you want, you can just change that to:

    sigs = (*(float(sigmas_slice[-(1 + int(x * ss))]) for x in range(n)), 0.0)
ssitu commented 7 months ago

Fixed, thanks!