mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
feat: Enhance WanVideoLoraSelect with improved low_mem_load and merge_loras options for better LORA management, see #363
This commit is contained in:
@@ -14,7 +14,8 @@ class WanVideoLoraSelect:
|
|||||||
def INPUT_TYPES(cls):
|
def INPUT_TYPES(cls):
|
||||||
return {
|
return {
|
||||||
"required": {
|
"required": {
|
||||||
"low_mem_load": ("BOOLEAN", {"default": False, "tooltip": "Load the LORA model with less VRAM usage, slower loading"}),
|
"low_mem_load": ("BOOLEAN", {"default": False, "tooltip": "Load LORA models with less VRAM usage, slower loading. This affects ALL LoRAs, not just the current ones. No effect if merge_loras is False"}),
|
||||||
|
"merge_loras": ("BOOLEAN", {"default": True, "tooltip": "Merge LoRAs into the model, otherwise they are loaded on the fly. Always disabled for GGUF and scaled fp8 models. This affects ALL LoRAs, not just the current one"}),
|
||||||
"text": (IO.STRING, {
|
"text": (IO.STRING, {
|
||||||
"multiline": True,
|
"multiline": True,
|
||||||
"dynamicPrompts": True,
|
"dynamicPrompts": True,
|
||||||
@@ -29,7 +30,7 @@ class WanVideoLoraSelect:
|
|||||||
RETURN_NAMES = ("lora", "trigger_words", "active_loras")
|
RETURN_NAMES = ("lora", "trigger_words", "active_loras")
|
||||||
FUNCTION = "process_loras"
|
FUNCTION = "process_loras"
|
||||||
|
|
||||||
def process_loras(self, text, low_mem_load=False, **kwargs):
|
def process_loras(self, text, low_mem_load=False, merge_loras=True, **kwargs):
|
||||||
loras_list = []
|
loras_list = []
|
||||||
all_trigger_words = []
|
all_trigger_words = []
|
||||||
active_loras = []
|
active_loras = []
|
||||||
@@ -39,6 +40,9 @@ class WanVideoLoraSelect:
|
|||||||
if prev_lora is not None:
|
if prev_lora is not None:
|
||||||
loras_list.extend(prev_lora)
|
loras_list.extend(prev_lora)
|
||||||
|
|
||||||
|
if not merge_loras:
|
||||||
|
low_mem_load = False # Unmerged LoRAs don't need low_mem_load
|
||||||
|
|
||||||
# Get blocks if available
|
# Get blocks if available
|
||||||
blocks = kwargs.get('blocks', {})
|
blocks = kwargs.get('blocks', {})
|
||||||
selected_blocks = blocks.get("selected_blocks", {})
|
selected_blocks = blocks.get("selected_blocks", {})
|
||||||
@@ -65,6 +69,7 @@ class WanVideoLoraSelect:
|
|||||||
"blocks": selected_blocks,
|
"blocks": selected_blocks,
|
||||||
"layer_filter": layer_filter,
|
"layer_filter": layer_filter,
|
||||||
"low_mem_load": low_mem_load,
|
"low_mem_load": low_mem_load,
|
||||||
|
"merge_loras": merge_loras,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add to list and collect active loras
|
# Add to list and collect active loras
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ app.registerExtension({
|
|||||||
// Restore saved value if exists
|
// Restore saved value if exists
|
||||||
let existingLoras = [];
|
let existingLoras = [];
|
||||||
if (this.widgets_values && this.widgets_values.length > 0) {
|
if (this.widgets_values && this.widgets_values.length > 0) {
|
||||||
// 0 for low_mem_load, 1 for text widget, 2 for loras widget
|
// 0 for low_mem_load, 1 for merge_loras, 2 for text widget, 3 for loras widget
|
||||||
const savedValue = this.widgets_values[2];
|
const savedValue = this.widgets_values[3];
|
||||||
existingLoras = savedValue || [];
|
existingLoras = savedValue || [];
|
||||||
}
|
}
|
||||||
// Merge the loras data
|
// Merge the loras data
|
||||||
const mergedLoras = mergeLoras(this.widgets[1].value, existingLoras);
|
const mergedLoras = mergeLoras(this.widgets[2].value, existingLoras);
|
||||||
|
|
||||||
// Add flag to prevent callback loops
|
// Add flag to prevent callback loops
|
||||||
let isUpdating = false;
|
let isUpdating = false;
|
||||||
@@ -49,7 +49,7 @@ app.registerExtension({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Remove loras that are not in the value array
|
// Remove loras that are not in the value array
|
||||||
const inputWidget = this.widgets[1];
|
const inputWidget = this.widgets[2];
|
||||||
const currentLoras = value.map(l => l.name);
|
const currentLoras = value.map(l => l.name);
|
||||||
|
|
||||||
// Use the constant pattern here as well
|
// Use the constant pattern here as well
|
||||||
@@ -79,7 +79,7 @@ app.registerExtension({
|
|||||||
this.lorasWidget = result.widget;
|
this.lorasWidget = result.widget;
|
||||||
|
|
||||||
// Update input widget callback
|
// Update input widget callback
|
||||||
const inputWidget = this.widgets[1];
|
const inputWidget = this.widgets[2];
|
||||||
inputWidget.options.getMaxHeight = () => 100;
|
inputWidget.options.getMaxHeight = () => 100;
|
||||||
this.inputWidget = inputWidget;
|
this.inputWidget = inputWidget;
|
||||||
// Wrap the callback with autocomplete setup
|
// Wrap the callback with autocomplete setup
|
||||||
|
|||||||
Reference in New Issue
Block a user