mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-15 10:13:22 -03:00
280181f92e
The sampler field now accepts either a manual string or a SAMPLER connection. When wired, the sampler name is extracted from the KSAMPLER object's sampler_function __name__ (sample_euler -> euler), with special-casing for dpm_fast/dpm_adaptive local closures and uni_pc/uni_pc_bh2 function names. - sampler input declared as "STRING,SAMPLER" with widgetType STRING, mirroring the existing model field union pattern - shared collect_overwrite_params() handles the non-str branch so the node and the metadata extractor conversion logic stay in sync; unrecognized sampler functions are logged and skipped - note: ddim is constructed by ComfyUI as euler with random inpaint, so the ddim name is unrecoverable and extracts as euler
52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
"""Shared helpers for Metadata Overwrite node metadata collection.
|
|
|
|
Used by both the MetadataOverwriteLM node (execution time) and the
|
|
MetadataOverwriteExtractor (hook time) so the conversion/filtering logic
|
|
cannot drift between the two paths.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any, Dict
|
|
|
|
from ..utils.utils import model_patcher_to_name, sampler_object_to_name
|
|
from .constants import CLIP_SKIP_SENTINEL, METADATA_OVERWRITE_FIELDS
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def collect_overwrite_params(values: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Convert node input values into non-default overwrite parameters.
|
|
|
|
For most fields, a falsy value (empty string, 0) means "not set" and is
|
|
skipped. clip_skip uses a dedicated sentinel (-25) so that a wired value
|
|
of 0 is preserved. The ``model`` field accepts either a manual string or
|
|
a wired MODEL (ModelPatcher) connection; in the latter case the source
|
|
model name is extracted from the patcher's ``cached_patcher_init`` and
|
|
stored as a ComfyUI-style relative path. The ``sampler`` field likewise
|
|
accepts a manual string or a wired SAMPLER (KSAMPLER) connection, from
|
|
which the sampler name is extracted via the sampler function's name.
|
|
"""
|
|
result: Dict[str, Any] = {}
|
|
for key in METADATA_OVERWRITE_FIELDS:
|
|
value = values.get(key)
|
|
if key == "model" and not isinstance(value, str):
|
|
value = model_patcher_to_name(value)
|
|
if value is None:
|
|
logger.warning(
|
|
"Could not extract model name from wired MODEL input "
|
|
"(no cached_patcher_init); model metadata overwrite skipped"
|
|
)
|
|
elif key == "sampler" and not isinstance(value, str):
|
|
value = sampler_object_to_name(value)
|
|
if value is None:
|
|
logger.warning(
|
|
"Could not extract sampler name from wired SAMPLER input "
|
|
"(unrecognized sampler function); sampler metadata overwrite skipped"
|
|
)
|
|
if key == "clip_skip":
|
|
if value != CLIP_SKIP_SENTINEL:
|
|
result[key] = value
|
|
elif value:
|
|
result[key] = value
|
|
return result
|