diff --git a/modules/res4lyf/TASK.md b/modules/res4lyf/TASK.md index 4fa0d1e82..62c2d42b1 100644 --- a/modules/res4lyf/TASK.md +++ b/modules/res4lyf/TASK.md @@ -1,5 +1,5 @@ # TASK: Schedulers - + ## Notes This is a codebase for diffusion schedulers implemented for `diffusers` library and ported from `res4lyf` repository at @@ -8,16 +8,17 @@ Ported schedulers codebase is in `modules/res4lyf`, do not modify any other file ## Testing -Current focus is on following code-paths: -- using `epsilon` prediction type -- using `StableDiffusionXLPipeline` pipeline for *text2image* +All schedulers were tested using prediction type `epsilon` and `StableDiffusionXLPipeline` pipeline for *text2image*: WORKING GOOD! + +Shifting focus to testing prediction type `flow_prediction` and `ZImagePipeline` pipeline for *text2image* ## Results -- *ETDRKScheduler, LawsonScheduler, ABNorsettScheduler, RESSinglestepScheduler, RESSinglestepSDEScheduler, PECScheduler, etc.*: - do NOT modify behavior and codebase for these schedulers as they produce good outputs under all circumstances - if needed, you can use them as gold-standard references to compare other schedulers against -- *RESUnifiedScheduler*, *DEISMultistepScheduler, RESMultistepScheduler* - work fine with `rk_type=res_2s`, `rk_type=deis_1s` and similar single-step params, - but with `rk_type=res_2m`, `rk_type=deis_2m` and similar multi-step params - image looks fine in early steps, but then degrages at the final steps with what looks like too much noise +- so far all tested schedules produce blocky/pixelated and unresolved output + +## TODO + +- focus on a single scheduler only. lets pick abnorsett_2m +- validate config params: is this ok? + config={'num_train_timesteps': 1000, 'beta_start': 0.0001, 'beta_end': 0.02, 'beta_schedule': 'linear', 'prediction_type': 'flow_prediction', 'variant': 'abnorsett_2m', 'use_analytic_solution': True, 'timestep_spacing': 'linspace', 'steps_offset': 0, 'use_flow_sigmas': True, 'shift': 3, 'base_shift': 0.5, 'max_shift': 1.15, 'base_image_seq_len': 256, 'max_image_seq_len': 4096} +- check code diff --git a/modules/sd_samplers_diffusers.py b/modules/sd_samplers_diffusers.py index dee2ed6ae..c209b749f 100644 --- a/modules/sd_samplers_diffusers.py +++ b/modules/sd_samplers_diffusers.py @@ -97,12 +97,14 @@ except Exception as e: if os.environ.get('SD_SAMPLER_DEBUG', None) is not None: errors.display(e, 'Samplers') - config = { # beta_start, beta_end are typically per-scheduler, but we don't want them as they should be taken from the model itself as those are values model was trained on # prediction_type is ideally set in model as well, but it maybe needed that we do auto-detect of model type in the future 'All': { 'num_train_timesteps': 1000, 'beta_start': 0.0001, 'beta_end': 0.02, 'beta_schedule': 'linear', 'prediction_type': 'epsilon' }, + 'Res4Lyf': { 'timestep_spacing': 'linspace', "steps_offset": 0, "rescale_betas_zero_snr": False, "use_karras_sigmas": False, "use_exponential_sigmas": False, "use_beta_sigmas": False, "use_flow_sigmas": False, "shift": 1, "base_shift": 0.5, "max_shift": 1.15, "use_dynamic_shifting": False }, +} +config.update({ 'UniPC': { 'flow_shift': 1, 'predict_x0': True, 'sample_max_value': 1.0, 'solver_order': 2, 'solver_type': 'bh2', 'thresholding': False, 'use_beta_sigmas': False, 'use_exponential_sigmas': False, 'use_flow_sigmas': False, 'use_karras_sigmas': False, 'lower_order_final': True, 'timestep_spacing': 'linspace', 'final_sigmas_type': 'zero', 'rescale_betas_zero_snr': False }, 'DDIM': { 'clip_sample': False, 'set_alpha_to_one': True, 'steps_offset': 0, 'clip_sample_range': 1.0, 'sample_max_value': 1.0, 'timestep_spacing': 'leading', 'rescale_betas_zero_snr': False, 'thresholding': False }, @@ -162,62 +164,62 @@ config = { 'DDPM Parallel': {}, # res4lyf - 'ABNorsett 2M': { 'variant': 'abnorsett_2m' }, - 'ABNorsett 3M': { 'variant': 'abnorsett_3m' }, - 'ABNorsett 4M': { 'variant': 'abnorsett_4m' }, - 'Lawson 2S A': { 'variant': 'lawson2a_2s' }, - 'Lawson 2S B': { 'variant': 'lawson2b_2s' }, - 'Lawson 4S': { 'variant': 'lawson4_4s' }, - 'ETD-RK 2S': { 'variant': 'etdrk2_2s' }, - 'ETD-RK 3S A': { 'variant': 'etdrk3_a_3s' }, - 'ETD-RK 3S B': { 'variant': 'etdrk3_b_3s' }, - 'ETD-RK 4S A': { 'variant': 'etdrk4_4s' }, - 'ETD-RK 4S B': { 'variant': 'etdrk4_4s_alt' }, - 'RES-Unified 2M': { 'rk_type': 'res_2m' }, - 'RES-Unified 3M': { 'rk_type': 'res_3m' }, - 'RES-Unified 2S': { 'rk_type': 'res_2s' }, - 'RES-Unified 3S': { 'rk_type': 'res_3s' }, - 'RES-Singlestep 2S': { 'variant': 'res_2s' }, - 'RES-Singlestep 3S': { 'variant': 'res_3s' }, - 'RES-Multistep 2M': { 'variant': 'res_2m' }, - 'RES-Multistep 3M': { 'variant': 'res_3m' }, - 'RES-SDE 2S': { 'variant': 'res_2s' }, - 'RES-SDE 3S': { 'variant': 'res_3s' }, - 'DEIS-Multistep': { 'order': 2 }, - 'DEIS-Unified 1S': { 'rk_type': 'deis_1s' }, - 'DEIS-Unified 2M': { 'rk_type': 'deis_2m' }, - 'PEC 423': { 'variant': 'pec423_2h2s' }, - 'PEC 433': { 'variant': 'pec433_2h3s' }, - 'Sigmoid Sigma': { 'profile': 'sigmoid' }, - 'Sine Sigma': { 'profile': 'sine' }, - 'Easing Sigma': { 'profile': 'easing' }, - 'Arcsine Sigma': { 'profile': 'arcsine' }, - 'Smoothstep Sigma': { 'profile': 'smoothstep' }, - 'Langevin Dynamics': { }, - 'Euclidean Flow': { 'metric_type': 'euclidean' }, - 'Hyperbolic Flow': { 'metric_type': 'hyperbolic' }, - 'Spherical Flow': { 'metric_type': 'spherical' }, - 'Lorentzian Flow': { 'metric_type': 'lorentzian' }, - 'Linear-RK 2': { 'variant': 'rk2' }, - 'Linear-RK 3': { 'variant': 'rk3' }, - 'Linear-RK 4': { 'variant': 'rk4' }, - 'Linear-RK Euler': { 'variant': 'euler' }, - 'Linear-RK Heun': { 'variant': 'heun'}, - 'Linear-RK Ralston': { 'variant': 'ralston'}, - 'Lobatto 2': { 'variant': 'lobatto_iiia_2s' }, - 'Lobatto 3': { 'variant': 'lobatto_iiia_3s' }, - 'Lobatto 4': { 'variant': 'lobatto_iiia_4s' }, - 'Radau IIA 2': { 'variant': 'radau_iia_2s' }, - 'Radau IIA 3': { 'variant': 'radau_iia_3s' }, - 'Gauss-Legendre 2S': { 'variant': 'gauss-legendre_2s' }, - 'Gauss-Legendre 3S': { 'variant': 'gauss-legendre_3s' }, - 'Gauss-Legendre 4S': { 'variant': 'gauss-legendre_4s' }, - 'Runge-Kutta 4/4': { }, - 'Runge-Kutta 5/7': { }, - 'Runge-Kutta 6/7': { }, - 'Specialized-RK 3S': { 'variant': 'ssprk3_3s' }, - 'Specialized-RK 4S': { 'variant': 'ssprk4_4s' }, -} + 'ABNorsett 2M': { 'variant': 'abnorsett_2m', **config['Res4Lyf'] }, + 'ABNorsett 3M': { 'variant': 'abnorsett_3m', **config['Res4Lyf'] }, + 'ABNorsett 4M': { 'variant': 'abnorsett_4m', **config['Res4Lyf'] }, + 'Lawson 2S A': { 'variant': 'lawson2a_2s', **config['Res4Lyf'] }, + 'Lawson 2S B': { 'variant': 'lawson2b_2s', **config['Res4Lyf'] }, + 'Lawson 4S': { 'variant': 'lawson4_4s', **config['Res4Lyf'] }, + 'ETD-RK 2S': { 'variant': 'etdrk2_2s', **config['Res4Lyf'] }, + 'ETD-RK 3S A': { 'variant': 'etdrk3_a_3s', **config['Res4Lyf'] }, + 'ETD-RK 3S B': { 'variant': 'etdrk3_b_3s', **config['Res4Lyf'] }, + 'ETD-RK 4S A': { 'variant': 'etdrk4_4s', **config['Res4Lyf'] }, + 'ETD-RK 4S B': { 'variant': 'etdrk4_4s_alt', **config['Res4Lyf'] }, + 'RES-Unified 2M': { 'rk_type': 'res_2m', **config['Res4Lyf'] }, + 'RES-Unified 3M': { 'rk_type': 'res_3m', **config['Res4Lyf'] }, + 'RES-Unified 2S': { 'rk_type': 'res_2s', **config['Res4Lyf'] }, + 'RES-Unified 3S': { 'rk_type': 'res_3s', **config['Res4Lyf'] }, + 'RES-Singlestep 2S': { 'variant': 'res_2s', **config['Res4Lyf'] }, + 'RES-Singlestep 3S': { 'variant': 'res_3s', **config['Res4Lyf'] }, + 'RES-Multistep 2M': { 'variant': 'res_2m', **config['Res4Lyf'] }, + 'RES-Multistep 3M': { 'variant': 'res_3m', **config['Res4Lyf'] }, + 'RES-SDE 2S': { 'variant': 'res_2s', **config['Res4Lyf'] }, + 'RES-SDE 3S': { 'variant': 'res_3s', **config['Res4Lyf'] }, + 'DEIS-Multistep': { 'order': 2, **config['Res4Lyf'] }, + 'DEIS-Unified 1S': { 'rk_type': 'deis_1s', **config['Res4Lyf'] }, + 'DEIS-Unified 2M': { 'rk_type': 'deis_2m', **config['Res4Lyf'] }, + 'PEC 423': { 'variant': 'pec423_2h2s', **config['Res4Lyf'] }, + 'PEC 433': { 'variant': 'pec433_2h3s', **config['Res4Lyf'] }, + 'Sigmoid Sigma': { 'profile': 'sigmoid', **config['Res4Lyf'] }, + 'Sine Sigma': { 'profile': 'sine', **config['Res4Lyf'] }, + 'Easing Sigma': { 'profile': 'easing', **config['Res4Lyf'] }, + 'Arcsine Sigma': { 'profile': 'arcsine', **config['Res4Lyf'] }, + 'Smoothstep Sigma': { 'profile': 'smoothstep', **config['Res4Lyf'] }, + 'Langevin Dynamics': { **config['Res4Lyf'] }, + 'Euclidean Flow': { 'metric_type': 'euclidean', **config['Res4Lyf'] }, + 'Hyperbolic Flow': { 'metric_type': 'hyperbolic', **config['Res4Lyf'] }, + 'Spherical Flow': { 'metric_type': 'spherical', **config['Res4Lyf'] }, + 'Lorentzian Flow': { 'metric_type': 'lorentzian', **config['Res4Lyf'] }, + 'Linear-RK 2': { 'variant': 'rk2', **config['Res4Lyf'] }, + 'Linear-RK 3': { 'variant': 'rk3', **config['Res4Lyf'] }, + 'Linear-RK 4': { 'variant': 'rk4', **config['Res4Lyf'] }, + 'Linear-RK Euler': { 'variant': 'euler', **config['Res4Lyf'] }, + 'Linear-RK Heun': { 'variant': 'heun', **config['Res4Lyf'] }, + 'Linear-RK Ralston': { 'variant': 'ralston', **config['Res4Lyf'] }, + 'Lobatto 2': { 'variant': 'lobatto_iiia_2s', **config['Res4Lyf'] }, + 'Lobatto 3': { 'variant': 'lobatto_iiia_3s', **config['Res4Lyf'] }, + 'Lobatto 4': { 'variant': 'lobatto_iiia_4s', **config['Res4Lyf'] }, + 'Radau IIA 2': { 'variant': 'radau_iia_2s', **config['Res4Lyf'] }, + 'Radau IIA 3': { 'variant': 'radau_iia_3s', **config['Res4Lyf'] }, + 'Gauss-Legendre 2S': { 'variant': 'gauss-legendre_2s', **config['Res4Lyf'] }, + 'Gauss-Legendre 3S': { 'variant': 'gauss-legendre_3s', **config['Res4Lyf'] }, + 'Gauss-Legendre 4S': { 'variant': 'gauss-legendre_4s', **config['Res4Lyf'] }, + 'Runge-Kutta 4/4': { **config['Res4Lyf'] }, + 'Runge-Kutta 5/7': { **config['Res4Lyf'] }, + 'Runge-Kutta 6/7': { **config['Res4Lyf'] }, + 'Specialized-RK 3S': { 'variant': 'ssprk3_3s', **config['Res4Lyf'] }, + 'Specialized-RK 4S': { 'variant': 'ssprk4_4s', **config['Res4Lyf'] }, +}) samplers_data_diffusers = [ SamplerData('Default', None, [], {}),