Skip to content
Python

disable ltx stage 2, default wan 2.2 to all phases

Chris Maloneeabb490af487
diff --git a/shared/utils/self_refiner.py b/shared/utils/self_refiner.py
index 063ed98..3754592 100644
--- a/shared/utils/self_refiner.py
+++ b/shared/utils/self_refiner.py
@@ -26,9 +26,17 @@ def normalize_self_refiner_plan(plan_input):
max_phase = 0
for rule in plan_input:
p = int(rule.get("phase", 0))
- if p not in phases: phases[p] = []
- phases[p].append(rule)
if p > max_phase: max_phase = p
+ max_phase = max(max_phase, 2)
+
+ for rule in plan_input:
+ p = int(rule.get("phase", 0))
+
+ targets = [p] if p >= 0 else range(max_phase + 1)
+
+ for t_phase in targets:
+ if t_phase not in phases: phases[t_phase] = []
+ phases[t_phase].append(rule)
normalized = []
for i in range(max_phase + 1):
@@ -49,13 +57,21 @@ def ensure_refiner_list(plan_data):
rule["phase"] = 0
return plan_data
-def add_refiner_rule(current_rules, range_val, steps_val, phase_val=None):
+def add_refiner_rule(current_rules, range_val, steps_val, phase_val=None, max_phases_val=1):
new_start, new_end = int(range_val[0]), int(range_val[1])
+ if new_start >= new_end:
+ from gradio import Info
+ Info(f"Start step ({new_start}) must be smaller than End step ({new_end}).")
+ return current_rules
+
phase_idx = 0
+
if phase_val is not None:
if isinstance(phase_val, str):
- if "Phase" in phase_val or "Stage" in phase_val:
+ if "All" in phase_val:
+ phase_idx = -1
+ elif "Phase" in phase_val or "Stage" in phase_val:
try:
phase_idx = int(phase_val.split()[-1]) - 1
except:
@@ -66,16 +82,19 @@ def add_refiner_rule(current_rules, range_val, steps_val, phase_val=None):
except:
phase_idx = 0
- if new_start >= new_end:
- from gradio import Info
- Info(f"Start step ({new_start}) must be smaller than End step ({new_end}).")
- return current_rules
-
for rule in current_rules:
- if rule.get('phase', 0) == phase_idx:
+ r_phase = rule.get('phase', 0)
+
+ phases_overlap = (phase_idx == -1) or (r_phase == -1) or (phase_idx == r_phase)
+
+ if phases_overlap:
if new_start <= rule['end'] and new_end >= rule['start']:
from gradio import Info
- Info(f"Overlap detected in {phase_val or 'Phase ' + str(phase_idx+1)}! Steps {new_start}-{new_end} conflict with existing rule {rule['start']}-{rule['end']}.")
+
+ p_name_existing = "All Phases" if r_phase == -1 else f"Phase/Stage {r_phase+1}"
+ p_name_new = "All Phases" if phase_idx == -1 else f"Phase/Stage {phase_idx+1}"
+
+ Info(f"Overlap detected! {p_name_new} steps {new_start}-{new_end} conflict with existing {p_name_existing} rule.")
return current_rules
new_rule = {
@@ -85,6 +104,7 @@ def add_refiner_rule(current_rules, range_val, steps_val, phase_val=None):
"steps": int(steps_val),
"phase": phase_idx
}
+
updated_list = current_rules + [new_rule]
return sorted(updated_list, key=lambda x: (x.get('phase', 0), x['start']))
diff --git a/wgp.py b/wgp.py
index 4c5e82d..f39a7c6 100644
--- a/wgp.py
+++ b/wgp.py
@@ -9346,13 +9346,19 @@ def change_guidance_phases(state, guidance_phases, refiner_phase_val):
label = "Phase 1-2" if guidance_phases == 3 else ("Model / Guidance Switch Threshold" if multiple_submodels else "Guidance Switch Threshold")
is_ltx = get_model_family(model_type) == "ltx2"
prefix = "Stage" if is_ltx else "Phase"
- new_choices = [f"{prefix} {i+1}" for i in range(guidance_phases)]
- new_val = new_choices[0]
- if refiner_phase_val:
- try:
- idx = int(refiner_phase_val.split()[-1]) - 1
- if 0 <= idx < len(new_choices): new_val = new_choices[idx]
- except: pass
+
+ if is_ltx:
+ new_choices = ["Stage 1", "Stage 2"]
+ new_val = "Stage 1"
+ else:
+ new_choices = [f"All {prefix}s"] + [f"{prefix} {i+1}" for i in range(guidance_phases)]
+ new_val = new_choices[0]
+
+ if refiner_phase_val:
+ if "All" in str(refiner_phase_val) and "All" in new_choices[0]:
+ new_val = new_choices[0]
+ elif refiner_phase_val in new_choices:
+ new_val = refiner_phase_val
return (gr.update(visible=guidance_phases >= 3 and visible_phases >= 3 and multiple_submodels), gr.update(visible=guidance_phases >= 2 and visible_phases >= 2), gr.update(visible=guidance_phases >= 2 and visible_phases >= 2, label=label), gr.update(visible=guidance_phases >= 3 and visible_phases >= 3), gr.update(visible=guidance_phases >= 2 and visible_phases >= 2), gr.update(visible=guidance_phases >= 3 and visible_phases >= 3), gr.update(visible=guidance_phases >= 2, choices=new_choices, value=new_val))
@@ -10430,24 +10436,48 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
self_refiner_setting = gr.Dropdown(choices=[("Disabled", 0),("Enabled with P1-Norm", 1), ("Enabled with P2-Norm", 2)], value=ui_get("self_refiner_setting", 0), scale=1, label="Self Refiner")
refiner_val = ensure_refiner_list(ui_get("self_refiner_plan", []))
self_refiner_plan = refiner_val if update_form else gr.State(value=refiner_val)
- refiner_prefix_str = "Stage" if get_model_family(model_type) == "ltx2" else "Phase"
+
+ is_ltx_ui = get_model_family(model_type) == "ltx2"
+ refiner_prefix_str = "Stage" if is_ltx_ui else "Phase"
refiner_prefix_component = gr.Text(value=refiner_prefix_str, visible=False)
+ is_ltx_component = gr.Checkbox(value=is_ltx_ui, visible=False)
with gr.Column(visible=(update_form and ui_get("self_refiner_setting", 0) > 0)) as self_refiner_rules_ui:
gr.Markdown("#### Refiner Plan")
with gr.Row(elem_id="refiner-input-row"):
current_phase_count = int(guidance_phases_value) if guidance_phases_value else 1
-
- refiner_choices = [f"{refiner_prefix_str} {i+1}" for i in range(current_phase_count)]
- refiner_phase = gr.Dropdown(choices=refiner_choices, value=refiner_choices[0], label="Apply to", scale=1, visible=current_phase_count >= 2)
+ if is_ltx_ui:
+ refiner_choices = ["Stage 1", "Stage 2"]
+ refiner_default = "Stage 1"
+ else:
+ refiner_choices = [f"All {refiner_prefix_str}s"] + [f"{refiner_prefix_str} {i+1}" for i in range(current_phase_count)]
+ refiner_default = refiner_choices[0]
+
+ refiner_phase = gr.Dropdown(choices=refiner_choices, value=refiner_default, label="Apply to", scale=1, visible=current_phase_count >= 2)
refiner_range = RangeSlider(minimum=1, maximum=100, value=(1, 10), step=1, label="Step Range", info="Start - End", scale=3)
refiner_mult = gr.Slider(label="Iterations", value=3, minimum=1, maximum=5, step=1, scale=2)
refiner_add_btn = gr.Button("➕ Add", variant="primary", scale=0, min_width=100)
if not update_form:
- refiner_add_btn.click(fn=add_refiner_rule, inputs=[self_refiner_plan, refiner_range, refiner_mult, refiner_phase], outputs=[self_refiner_plan])
+ def check_ltx_stage_2(is_ltx_flag, selected_val):
+ if is_ltx_flag and str(selected_val) == "Stage 2":
+ gr.Info("Stage 2 is currently disabled for Self-Refiner in LTX-2.")
+ return "Stage 1"
+ return gr.update()
+
+ refiner_phase.select(
+ fn=check_ltx_stage_2,
+ inputs=[is_ltx_component, refiner_phase],
+ outputs=[refiner_phase]
+ )
+
+ refiner_add_btn.click(
+ fn=add_refiner_rule,
+ inputs=[self_refiner_plan, refiner_range, refiner_mult, refiner_phase, guidance_phases],
+ outputs=[self_refiner_plan]
+ )
self_refiner_setting.change(fn=lambda s: gr.update(visible=s > 0), inputs=[self_refiner_setting], outputs=[self_refiner_rules_ui])
@gr.render(inputs=[self_refiner_plan, guidance_phases, refiner_prefix_component])
@@ -10458,7 +10488,10 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
for plan in plans:
with gr.Row(elem_classes="rule-row"):
phase = plan.get('phase', 0)
- phase_label = f"{p_prefix} {phase + 1} | " if phase_count >= 2 or phase > 0 else ""
+ if phase == -1:
+ phase_label = f"All {p_prefix}s | "
+ else:
+ phase_label = f"{p_prefix} {phase + 1} | " if phase_count >= 2 or phase > 0 else ""
text_display = f"{phase_label}Steps **{plan['start']} - {plan['end']}** : **{plan['steps']}x** iterations"
gr.Markdown(text_display, elem_classes="rule-card")
@@ -10734,7 +10767,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
NAG_col, remove_background_sound , speakers_locations_row, embedded_guidance_row, guidance_phases_row, guidance_row, resolution_group, cfg_free_guidance_col, control_net_weights_row, guide_selection_row, image_mode_tabs,
min_frames_if_references_col, motion_amplitude_col, video_prompt_type_alignment, prompt_enhancer_btn, tab_inpaint, tab_t2v, resolution_row, loras_tab, post_processing_tab, temperature_row, *custom_settings_rows, top_pk_row,
number_frames_row, negative_prompt_row,
- self_refiner_col, pause_row, refiner_prefix_component, refiner_phase]+\
+ self_refiner_col, pause_row, refiner_prefix_component, refiner_phase, is_ltx_component]+\
image_start_extra + image_end_extra + image_refs_extra # presets_column,
if update_form:
locals_dict = locals()