@@ -73,7 +73,6 @@ def __init__(
7373 chroma_use_t5_mask : bool = False ,
7474 chroma_t5_mask_pad : int = 1 ,
7575 qwen_image_zero_cond_t : bool = False ,
76- flow_shift : float = float ("inf" ),
7776 image_resize_method : str = "crop" ,
7877 verbose : bool = True ,
7978 ):
@@ -132,7 +131,6 @@ def __init__(
132131 chroma_use_t5_mask: Use T5 mask for Chroma.
133132 chroma_t5_mask_pad: T5 mask padding size of Chroma.
134133 qwen_image_zero_cond_t: Enable zero_cond_t for Qwen image.
135- flow_shift: Shift value for Flow models like SD3.x or WAN (default: auto).
136134 image_resize_method: Method to resize images for init, mask, control and reference images ("crop" or "resize").
137135 verbose: Print verbose output.
138136
@@ -187,7 +185,6 @@ def __init__(
187185 self .chroma_use_t5_mask = chroma_use_t5_mask
188186 self .chroma_t5_mask_pad = chroma_t5_mask_pad
189187 self .qwen_image_zero_cond_t = qwen_image_zero_cond_t
190- self .flow_shift = flow_shift
191188 self .image_resize_method = image_resize_method
192189 self ._stack = contextlib .ExitStack ()
193190
@@ -284,7 +281,6 @@ def __init__(
284281 chroma_use_t5_mask = self .chroma_use_t5_mask ,
285282 chroma_t5_mask_pad = self .chroma_t5_mask_pad ,
286283 qwen_image_zero_cond_t = self .qwen_image_zero_cond_t ,
287- flow_shift = self .flow_shift ,
288284 verbose = self .verbose ,
289285 )
290286 )
@@ -346,6 +342,7 @@ def generate_image(
346342 eta : float = 0.0 ,
347343 timestep_shift : int = 0 ,
348344 sigmas : Optional [str ] = None ,
345+ flow_shift : float = float ("inf" ),
349346 # slg_params
350347 skip_layers : List [int ] = [7 , 8 , 9 ],
351348 skip_layer_start : float = 0.01 ,
@@ -379,6 +376,13 @@ def generate_image(
379376 cache_max_continuous_cached_steps : int = - 1 ,
380377 cache_taylorseer_n_derivatives : int = 1 ,
381378 cache_taylorseer_skip_interval : int = 1 ,
379+ cache_spectrum_w : float = 0.40 ,
380+ cache_spectrum_m : int = 3 ,
381+ cache_spectrum_lam : float = 1.0 ,
382+ cache_spectrum_window_size : int = 2 ,
383+ cache_spectrum_flex_window : float = 0.5 ,
384+ cache_spectrum_warmup_steps : int = 4 ,
385+ cache_spectrum_stop_percent : float = 0.9 ,
382386 scm_mask : str = "" ,
383387 scm_policy : Literal ["dynamic" , "static" ] = "dynamic" ,
384388 # ---
@@ -412,6 +416,7 @@ def generate_image(
412416 eta: Eta in DDIM, only for DDIM and TCD.
413417 timestep_shift: Shift timestep for NitroFusion models, default: 0, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant.
414418 sigmas: Custom sigma values for the sampler, comma-separated (e.g. "14.61,7.8,3.5,0.0").
419+ flow_shift: Shift value for Flow models like SD3.x or WAN (default: auto).
415420 skip_layers: Layers to skip for SLG steps (SLG will be enabled at step int([STEPS]x[START]) and disabled at int([STEPS]x[END])).
416421 skip_layer_start: SLG enabling point.
417422 skip_layer_end: SLG disabling point.
@@ -552,17 +557,17 @@ def sd_preview_callback(
552557 rel_size_x , rel_size_y = self ._parse_tile_size (vae_relative_tile_size , as_float = True )
553558
554559 # -------------------------------------------
555- # Scheduler/ Sample Method
560+ # Sample Method/Scheduler
556561 # -------------------------------------------
557562
558- scheduler = self ._validate_and_set_input (scheduler , SCHEDULER_MAP , "scheduler" , allow_none = True )
559- if scheduler is None :
560- scheduler = sd_cpp .sd_get_default_scheduler (self .model )
561-
562563 sample_method = self ._validate_and_set_input (sample_method , SAMPLE_METHOD_MAP , "sample_method" , allow_none = True )
563564 if sample_method is None :
564565 sample_method = sd_cpp .sd_get_default_sample_method (self .model )
565566
567+ scheduler = self ._validate_and_set_input (scheduler , SCHEDULER_MAP , "scheduler" , allow_none = True )
568+ if scheduler is None :
569+ scheduler = sd_cpp .sd_get_default_scheduler (self .model , sample_method )
570+
566571 # -------------------------------------------
567572 # Sigmas
568573 # -------------------------------------------
@@ -590,6 +595,7 @@ def sd_preview_callback(
590595 # -------------------------------------------
591596
592597 _cache_params = sd_cpp .sd_cache_params_t (
598+ # General cache params
593599 mode = cache_mode ,
594600 reuse_threshold = cache_reuse_threshold ,
595601 start_percent = cache_start_percent ,
@@ -602,8 +608,18 @@ def sd_preview_callback(
602608 residual_diff_threshold = cache_residual_diff_threshold ,
603609 max_warmup_steps = cache_max_warmup_steps ,
604610 max_continuous_cached_steps = cache_max_continuous_cached_steps ,
611+ # Taylorseer cache params
605612 taylorseer_n_derivatives = cache_taylorseer_n_derivatives ,
606613 taylorseer_skip_interval = cache_taylorseer_skip_interval ,
614+ # Spectrum cache params
615+ spectrum_w = cache_spectrum_w ,
616+ spectrum_m = cache_spectrum_m ,
617+ spectrum_lam = cache_spectrum_lam ,
618+ spectrum_window_size = cache_spectrum_window_size ,
619+ spectrum_flex_window = cache_spectrum_flex_window ,
620+ spectrum_warmup_steps = cache_spectrum_warmup_steps ,
621+ spectrum_stop_percent = cache_spectrum_stop_percent ,
622+ # General SCM params
607623 scm_mask = scm_mask .encode ("utf-8" ),
608624 scm_policy_dynamic = scm_policy ,
609625 )
@@ -646,6 +662,7 @@ def sd_preview_callback(
646662 shifted_timestep = timestep_shift ,
647663 custom_sigmas = _custom_sigmas ,
648664 custom_sigmas_count = _custom_sigmas_count ,
665+ flow_shift = flow_shift ,
649666 )
650667
651668 _params = sd_cpp .sd_img_gen_params_t (
@@ -738,6 +755,7 @@ def generate_video(
738755 eta : float = 0.0 ,
739756 timestep_shift : int = 0 ,
740757 sigmas : Optional [str ] = None ,
758+ flow_shift : float = float ("inf" ),
741759 # slg_params
742760 skip_layers : List [int ] = [7 , 8 , 9 ],
743761 skip_layer_start : float = 0.01 ,
@@ -813,6 +831,7 @@ def generate_video(
813831 eta: Eta in DDIM, only for DDIM and TCD.
814832 timestep_shift: Shift timestep for NitroFusion models, default: 0, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant.
815833 sigmas: Custom sigma values for the sampler, comma-separated (e.g. "14.61,7.8,3.5,0.0").
834+ flow_shift: Shift value for Flow models like SD3.x or WAN (default: auto).
816835 skip_layers: Layers to skip for SLG steps (SLG will be enabled at step int([STEPS]x[START]) and disabled at int([STEPS]x[END])).
817836 skip_layer_start: SLG enabling point.
818837 skip_layer_end: SLG disabling point.
@@ -965,13 +984,9 @@ def sd_preview_callback(
965984 rel_size_x , rel_size_y = self ._parse_tile_size (vae_relative_tile_size , as_float = True )
966985
967986 # -------------------------------------------
968- # Scheduler/ Sample Method
987+ # Sample Method/Scheduler
969988 # -------------------------------------------
970989
971- scheduler = self ._validate_and_set_input (scheduler , SCHEDULER_MAP , "scheduler" , allow_none = True )
972- if scheduler is None :
973- scheduler = sd_cpp .sd_get_default_scheduler (self .model )
974-
975990 # "sample_method_count" is not valid here (it will crash)
976991 sample_method = self ._validate_and_set_input (
977992 sample_method ,
@@ -982,19 +997,23 @@ def sd_preview_callback(
982997 if sample_method is None :
983998 sample_method = sd_cpp .sd_get_default_sample_method (self .model )
984999
985- # High Noise
986- high_noise_scheduler = self ._validate_and_set_input (
987- high_noise_scheduler , SCHEDULER_MAP , "high_noise_scheduler" , allow_none = True
988- )
989- if high_noise_scheduler is None :
990- high_noise_scheduler = scheduler
1000+ scheduler = self ._validate_and_set_input (scheduler , SCHEDULER_MAP , "scheduler" , allow_none = True )
1001+ if scheduler is None :
1002+ scheduler = sd_cpp .sd_get_default_scheduler (self .model , sample_method )
9911003
1004+ # High Noise
9921005 high_noise_sample_method = self ._validate_and_set_input (
9931006 high_noise_sample_method , SAMPLE_METHOD_MAP , "high_noise_sample_method" , allow_none = True
9941007 )
9951008 if high_noise_sample_method is None :
9961009 high_noise_sample_method = sample_method
9971010
1011+ high_noise_scheduler = self ._validate_and_set_input (
1012+ high_noise_scheduler , SCHEDULER_MAP , "high_noise_scheduler" , allow_none = True
1013+ )
1014+ if high_noise_scheduler is None :
1015+ high_noise_scheduler = scheduler
1016+
9981017 # -------------------------------------------
9991018 # Sigmas
10001019 # -------------------------------------------
@@ -1043,6 +1062,7 @@ def sd_preview_callback(
10431062 shifted_timestep = timestep_shift ,
10441063 custom_sigmas = _custom_sigmas ,
10451064 custom_sigmas_count = _custom_sigmas_count ,
1065+ flow_shift = flow_shift ,
10461066 )
10471067
10481068 # -------------------------------------------
@@ -1099,6 +1119,7 @@ def sd_preview_callback(
10991119 shifted_timestep = timestep_shift ,
11001120 custom_sigmas = _custom_sigmas ,
11011121 custom_sigmas_count = _custom_sigmas_count ,
1122+ flow_shift = flow_shift ,
11021123 )
11031124
11041125 _params = sd_cpp .sd_vid_gen_params_t (
@@ -1978,4 +1999,5 @@ def __del__(self) -> None:
19781999 "dbcache" : SDCacheMode .SD_CACHE_DBCACHE ,
19792000 "taylorseer" : SDCacheMode .SD_CACHE_TAYLORSEER ,
19802001 "cachedit" : SDCacheMode .SD_CACHE_CACHE_DIT ,
2002+ "spectrum" : SDCacheMode .SD_CACHE_SPECTRUM ,
19812003}
0 commit comments