Skip to content

Version 1.3.0 - RES4LYF Sampler Support

Choose a tag to compare

@ussoewwin ussoewwin released this 18 Jan 00:57
· 287 commits to main since this release

Overview

This release adds comprehensive support for RES4LYF (RES4) samplers across all model types, including Nunchaku Qwen Image, Nunchaku Flux1, Nunchaku SDXL, standard SDXL, standard SD1.5, standard Flux1, and Z-Image Turbo (both standard and Nunchaku) models.

The implementation provides robust model detection, correct model_sampling access paths, automatic CONST/EPS type detection, and comprehensive sampler registration for all supported models.


File Classification

Newly Created Files

  1. Changelog/CHANGELOG.md
    • Purpose: Centralized changelog file containing detailed version history
    • Location: Changelog/CHANGELOG.md
    • Content: Complete changelog from version 1.3.0 down to 1.0.6
    • Usage: Referenced by README.md for detailed changelog information

Modified Files

Category 1: Core Path Management

  1. modules/paths.py - Core module path initialization

Category 2: ControlNet Support Files

  1. modules_forge/supported_controlnet.py - General ControlNet support
  2. modules_forge/supported_controlnet_flux.py - Flux ControlNet support
  3. modules_forge/supported_controlnet_qwen_image.py - Nunchaku Qwen Image ControlNet support

Category 3: RES4LYF Sampler Core Files

  1. modules/RES4LYF/beta/rk_sampler_beta.py - Main sampler orchestration
  2. modules/RES4LYF/beta/rk_method_beta.py - Core RK method implementation
  3. modules/RES4LYF/beta/rk_noise_sampler_beta.py - Noise sampler initialization
  4. modules/RES4LYF/beta/rk_guide_func_beta.py - Latent guiding functions
  5. modules/RES4LYF/beta/__init__.py - Dynamic sampler registration

Category 4: RES4LYF Helper Files

  1. modules/RES4LYF/helper.py - Helper functions including is_RF_model()
  2. modules/RES4LYF/legacy/helper.py - Legacy helper functions
  3. modules/RES4LYF/legacy/samplers_tiled.py - Legacy tiled sampler

Category 5: Backend Files

  1. backend/modules/k_model.py - KModel class with model_sampling initialization

Model Type Support Summary

Nunchaku Qwen Image (QI) Models

  • Status: ✅ Full support
  • Detection: isinstance(diffusion_model, NunchakuQwenImageTransformer2DModel)
  • model_sampling Path: forge_objects.unet.model.model_sampling
  • Model Sampling Type: ModelType.FLOW via comfy.model_base.model_sampling(config, ModelType.FLOW)

Nunchaku Flux1 Models

  • Status: ✅ Full support
  • Detection: isinstance(diffusion_model, SVDQFluxTransformer2DModel)
  • model_sampling Path: forge_objects.unet.model.model_sampling
  • Model Sampling Type: ModelSamplingFluxWithConst (inherits ModelSamplingFlux + backend.modules.k_model.CONST)
  • CONST Detection: Checks both comfy.model_sampling.CONST and backend.modules.k_model.CONST

Nunchaku SDXL Models

  • Status: ✅ Full support
  • Detection: isinstance(diffusion_model, SVDQUNet2DConditionModel)
  • model_sampling Path: forge_objects.unet.model.model_sampling
  • Model Sampling Type: ModelType.EPS via comfy.model_base.model_sampling(config, ModelType.EPS)
  • EPS Detection: isinstance(model_sampling_obj, EPS)

Standard SDXL Models

  • Status: ✅ Full support
  • Detection: isinstance(diffusion_model, IntegratedUNet2DConditionModel) + inner_model.is_sdxl
  • model_sampling Path: forge_objects.unet.model.model_sampling (Forge) or model.inner_model.inner_model.model_sampling (ComfyUI)
  • Model Sampling Type: ModelType.EPS via comfy.model_base.model_sampling(config, ModelType.EPS)
  • EPS Detection: isinstance(model_sampling_obj, EPS)

Standard Flux1 Models

  • Status: ✅ Full support
  • Detection: isinstance(diffusion_model, IntegratedFluxTransformer2DModel)
  • model_sampling Path: forge_objects.unet.model.model_sampling (Forge) or model.inner_model.inner_model.model_sampling (ComfyUI)
  • Model Sampling Type: ModelSamplingFluxWithConst (inherits ModelSamplingFlux + backend.modules.k_model.CONST)
  • CONST Detection: Same as Nunchaku Flux1

Nunchaku Z-Image Turbo (ZIT) Models

  • Status: ✅ Full support (automatic via ModelType.FLOW)
  • Detection: Not explicitly detected (uses same ModelType.FLOW path as QI)
  • model_sampling Path: forge_objects.unet.model.model_sampling
  • Model Sampling Type: ModelType.FLOW via comfy.model_base.model_sampling(config, ModelType.FLOW)
  • Note: ZIT uses NextDiT class (different from QI's QwenImageTransformer2DModel), but shares the same ModelType.FLOW sampling path, so RES4LYF works automatically without explicit detection

Standard Z-Image Turbo (ZIT) Models

  • Status: ✅ Full support (automatic via ModelType.FLOW)
  • Detection: Not explicitly detected (uses same ModelType.FLOW path as QI)
  • model_sampling Path: forge_objects.unet.model.model_sampling (Forge) or model.inner_model.inner_model.model_sampling (ComfyUI)
  • Model Sampling Type: ModelType.FLOW via comfy.model_base.model_sampling(config, ModelType.FLOW)
  • Note: Standard ZIT uses NextDiT class (different from standard QI's QwenImageTransformer2DModel), but shares the same ModelType.FLOW sampling path, so RES4LYF works automatically without explicit detection

SD1.5 Models

  • Status: ✅ Full support (automatic via ModelType.EPS)
  • Detection: Not explicitly detected (uses same ModelType.EPS path as SDXL)
  • model_sampling Path: forge_objects.unet.model.model_sampling (Forge) or model.inner_model.inner_model.model_sampling (ComfyUI)
  • Model Sampling Type: ModelType.EPS via comfy.model_base.model_sampling(config, ModelType.EPS)
  • Note: SD1.5 uses ModelType.EPS (same as SDXL), so RES4LYF works automatically without explicit detection. SDXL settings can be used directly with SD1.5 models.

Detailed File-by-File Implementation

Category 1: Core Path Management

File: modules/paths.py

Purpose: This file is executed during Python module initialization and ensures all import comfy statements resolve to ComfyUI-master/comfy directory instead of any local comfy directory at the project root.

Modified Code:

import os
import sys
from modules.paths_internal import models_path, script_path, data_path, extensions_dir, extensions_builtin_dir, cwd  # noqa: F401

# Ensure ComfyUI-master is in sys.path before script_path
# This ensures we use ComfyUI-master/comfy instead of the project root comfy directory
comfyui_master_path = os.path.join(script_path, "ComfyUI-master")
comfyui_master_path = os.path.normpath(comfyui_master_path)

if os.path.exists(comfyui_master_path):
    if comfyui_master_path not in sys.path:
        sys.path.insert(0, comfyui_master_path)
    # Remove project root comfy directory from sys.path if it exists
    project_comfy_path = os.path.join(script_path, "comfy")
    project_comfy_path = os.path.normpath(project_comfy_path)
    if project_comfy_path in sys.path:
        sys.path.remove(project_comfy_path)

sys.path.insert(0, script_path)

sd_path = os.path.dirname(__file__)

Detailed Line-by-Line Explanation:

  1. import os and import sys: Standard Python libraries for file system operations and system path manipulation. Required for path management.

  2. from modules.paths_internal import ...: Imports path variables defined elsewhere. The # noqa: F401 comment suppresses linting warnings for unused imports (these are imported for side effects or use by other modules).

  3. comfyui_master_path = os.path.join(script_path, "ComfyUI-master"): Constructs the absolute path to the ComfyUI-master directory by joining the script path with "ComfyUI-master". This path points to where the official ComfyUI codebase is located, which should be the authoritative source for all comfy module imports.

  4. comfyui_master_path = os.path.normpath(comfyui_master_path): Normalizes the path to handle different operating systems and path formats. On Windows, paths use backslashes (\), while on Unix they use forward slashes (/). This function ensures consistent path representation across platforms, preventing path-related errors.

  5. if os.path.exists(comfyui_master_path):: Checks if the ComfyUI-master directory actually exists before attempting to modify sys.path. This prevents ValueError or other errors if the directory is missing (e.g., incomplete repository clone or missing submodule).

  6. if comfyui_master_path not in sys.path:: Checks if ComfyUI-master is already in Python's module search path. This prevents duplicate entries in sys.path, which could cause confusion or performance issues.

  7. sys.path.insert(0, comfyui_master_path): Adds ComfyUI-master to the beginning of Python's module search path. The 0 index is critical - it ensures ComfyUI-master has the highest priority. Python searches sys.path in order from first to last, and uses the first matching module it finds. By inserting at index 0, we guarantee that import comfy will resolve to ComfyUI-master/comfy before any other directory.

  8. project_comfy_path = os.path.join(script_path, "comfy"): Constructs the path to a potential local comfy directory at the project root. This is the directory we want to exclude from module resolution.

  9. if project_comfy_path in sys.path:: Checks if the project root comfy directory is currently in sys.path. This might happen if it was added earlier by other code or if it's the current working directory.

  10. sys.path.remove(project_comfy_path): Explicitly removes the project root comfy directory from sys.path. This ensures complete separation - Python will never import from the old local directory, preventing conflicts, version mismatches, or incorrect module resolution.

  11. sys.path.insert(0, script_path): Finally, adds the project's script directory to sys.path. This ensures project-specific modules (in the modules/ directory) can still be imported, but ComfyUI-master maintains priority for comfy imports.

Why This Matters:

  • Import Resolution Priority: Python's import system uses the first matching module found in sys.path. Without this code, if both comfy/ (project root) and ComfyUI-master/comfy/ exist, Python might import from the wrong one depending on directory order.

  • Version Compatibility: ComfyUI-master contains the official, tested ComfyUI codebase. Using it ensures compatibility with all ComfyUI features, extensions, and API contracts.

  • Error Prevention: Without this path management, RES4LYF samplers might import incorrect versions of classes like comfy.model_sampling.EPS or comfy.model_sampling.CONST, leading to AttributeError, TypeError, or incorrect model type detection.

  • Maintainability: Updates to ComfyUI-master automatically propagate to the entire application without modifying project-specific code.

Impact on RES4LYF:

RES4LYF samplers rely heavily on ComfyUI's model structures:

  • comfy.model_sampling.EPS for SDXL models
  • comfy.model_sampling.CONST for Flux1 models (in addition to backend.modules.k_model.CONST)
  • comfy.model_base.model_sampling() factory function for creating appropriate ModelSampling classes

Without this path management, RES4LYF might import outdated or incompatible versions of these classes, causing:

  • Incorrect model type detection (VE_MODEL and CONST_MODEL flags set incorrectly)
  • Incorrect sampling behavior (wrong noise scaling, wrong sigma calculations)
  • Runtime errors when accessing model attributes that don't exist in the imported version

Category 2: ControlNet Support Files

These files ensure ControlNet imports resolve to ComfyUI-master/comfy/controlnet for all ControlNet types (general, Flux, and Nunchaku Qwen Image).

File: modules_forge/supported_controlnet.py

Purpose: General ControlNet support module. This file patches ComfyUI ControlNet for Forge compatibility and handles general ControlNet model loading.

Modified Section (lines 1-32):

import os
import sys
import torch

# Ensure ComfyUI-master is in sys.path before importing comfy
# This ensures we use ComfyUI-master/comfy instead of the project root comfy directory
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
comfyui_master_path = os.path.join(project_root, "ComfyUI-master")
comfyui_master_path = os.path.normpath(comfyui_master_path)

if os.path.exists(comfyui_master_path):
    if comfyui_master_path not in sys.path:
        sys.path.insert(0, comfyui_master_path)
    # Remove project root comfy directory from sys.path if it exists
    project_comfy_path = os.path.join(project_root, "comfy")
    project_comfy_path = os.path.normpath(project_comfy_path)
    if project_comfy_path in sys.path:
        sys.path.remove(project_comfy_path)

from huggingface_guess.detection import unet_config_from_diffusers_unet, model_config_from_unet
from huggingface_guess.utils import unet_to_diffusers
from backend import memory_management
from backend.operations import using_forge_operations
from backend.nn.cnets import cldm
from backend.patcher.controlnet import ControlLora, ControlNet, load_t2i_adapter, apply_controlnet_advanced
from modules_forge.shared import add_supported_control_model


# =============================================================================
# ComfyUI ControlNet patches for Forge compatibility
# Uses ComfyUI-master/comfy package (located in ComfyUI-master directory)
# =============================================================================
try:
    import comfy.controlnet
    # ... rest of file ...

Detailed Explanation:

  1. project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))):

    • __file__ is the path to the current file (modules_forge/supported_controlnet.py)
    • os.path.abspath(__file__) converts it to an absolute path
    • os.path.dirname() once gives modules_forge/
    • os.path.dirname() twice gives the project root directory
    • This is necessary because this file is in a subdirectory (modules_forge/), not at the project root
  2. comfyui_master_path = os.path.join(project_root, "ComfyUI-master"): Constructs the path to ComfyUI-master directory from the project root.

  3. Path normalization and sys.path management: Same logic as modules/paths.py, but calculated from modules_forge/ directory instead of modules/ directory.

  4. import comfy.controlnet: After path management, this import is guaranteed to resolve to ComfyUI-master/comfy/controlnet. The ControlNet patches and compatibility code in this file rely on the correct ComfyUI ControlNet classes.

Why This File-Specific Path Management is Needed:

While modules/paths.py manages paths at application startup, some modules may be imported before modules/paths.py executes, or the path management in modules/paths.py might not have run yet when this file is imported. Adding path management at the file level ensures comfy.controlnet imports correctly regardless of import order.

Impact on RES4LYF:

While this file doesn't directly affect RES4LYF samplers, it ensures that ControlNet integration works correctly, which may be used in conjunction with RES4LYF samplers for guided generation.


File: modules_forge/supported_controlnet_flux.py

Purpose: Flux-specific ControlNet support. Handles integration of Flux ControlNet with Forge's Flux models (both Nunchaku and standard).

Modified Section (lines 1-31):

"""
Flux ControlNet support for Forge.
This module handles the integration of Flux ControlNet with Forge's
SVDQFluxTransformer2DModel and IntegratedFluxTransformer2DModel.

Uses Forge's bundled ComfyUI package (no external ComfyUI installation required).
"""

import os
import sys
import torch

# Ensure ComfyUI-master is in sys.path before importing comfy
# This ensures we use ComfyUI-master/comfy instead of the project root comfy directory
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
comfyui_master_path = os.path.join(project_root, "ComfyUI-master")
comfyui_master_path = os.path.normpath(comfyui_master_path)

if os.path.exists(comfyui_master_path):
    if comfyui_master_path not in sys.path:
        sys.path.insert(0, comfyui_master_path)
    # Remove project root comfy directory from sys.path if it exists
    project_comfy_path = os.path.join(project_root, "comfy")
    project_comfy_path = os.path.normpath(project_comfy_path)
    if project_comfy_path in sys.path:
        sys.path.remove(project_comfy_path)

# Use ComfyUI-master/comfy package (located in ComfyUI-master directory)
import comfy.controlnet
from modules_forge.supported_controlnet import ControlModelPatcher

Detailed Explanation:

Same path management logic as modules_forge/supported_controlnet.py. This file specifically handles Flux ControlNet models, which work with both Nunchaku Flux1 (SVDQFluxTransformer2DModel) and standard Flux1 (IntegratedFluxTransformer2DModel) models.

The path management ensures that comfy.controlnet imports resolve correctly, which is required for Flux ControlNet loading and application.


File: modules_forge/supported_controlnet_qwen_image.py

Purpose: Nunchaku Qwen Image-specific ControlNet support. IMPORTANT: This is for Nunchaku Qwen Image models ONLY, not standard Qwen Image models.

Modified Section (lines 1-35):

"""
Nunchaku Qwen Image ControlNet support for Forge.
This module handles the integration of Qwen Image ControlNet with Forge's
NunchakuQwenImageTransformer2DModel ONLY.

IMPORTANT: This is for Nunchaku Qwen Image models ONLY.
- Works with: NunchakuQwenImageTransformer2DModel (from backend.nn.svdq)
- Does NOT work with: Standard QwenImageTransformer2DModel (from backend.nn.qwen)
- Does NOT work with: Flux models (handled by supported_controlnet_flux.py)

Uses Forge's bundled ComfyUI package (no external ComfyUI installation required).
"""

import os
import sys
import torch

# Ensure ComfyUI-master is in sys.path before importing comfy
# This ensures we use ComfyUI-master/comfy instead of the project root comfy directory
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
comfyui_master_path = os.path.join(project_root, "ComfyUI-master")
comfyui_master_path = os.path.normpath(comfyui_master_path)

if os.path.exists(comfyui_master_path):
    if comfyui_master_path not in sys.path:
        sys.path.insert(0, comfyui_master_path)
    # Remove project root comfy directory from sys.path if it exists
    project_comfy_path = os.path.join(project_root, "comfy")
    project_comfy_path = os.path.normpath(project_comfy_path)
    if project_comfy_path in sys.path:
        sys.path.remove(project_comfy_path)

# Use ComfyUI-master/comfy package (located in ComfyUI-master directory)
import comfy.controlnet
from modules_forge.supported_controlnet import ControlModelPatcher

Detailed Explanation:

Same path management logic. The key distinction is that this file is EXCLUSIVELY for Nunchaku Qwen Image models (NunchakuQwenImageTransformer2DModel from backend.nn.svdq), not standard Qwen Image models (QwenImageTransformer2DModel from backend.nn.qwen).

The path management ensures that comfy.controlnet imports, specifically comfy.ldm.qwen_image.controlnet.QwenImageControlNetModel, resolve correctly from ComfyUI-master.


Category 3: RES4LYF Sampler Core Files

File: modules/RES4LYF/beta/rk_sampler_beta.py

Purpose: Main sampler orchestration file. This file contains the sample_rk_beta() function which orchestrates the entire RES4LYF sampling process. It handles device acquisition, model_sampling retrieval, model type detection, CONST/EPS type detection, and coordinates all sampling components.

Critical Changes:

  1. Device Acquisition (lines 248-271): Safely retrieves device from model with multiple fallback methods
  2. Model Type Detection and model_sampling Acquisition (lines 277-396): Detects model type and retrieves model_sampling from correct path
  3. CONST/EPS Type Detection (lines 362-384): Determines if model uses CONST or EPS sampling type
  4. extra_args['model_options'] Initialization (lines 378-379): Prevents KeyError when accessing transformer_options
  5. Safe diffusion_model Access (multiple locations): Prevents AttributeError for models without diffusion_model

Change 1: Device Acquisition (lines 248-271)

Problem: Different model structures store the device information in different locations. Nunchaku Qwen Image models may not have a direct device attribute, causing AttributeError.

Solution Code:

EO             = ExtraOptions(extra_options)
default_dtype  = EO("default_dtype", torch.float64)

extra_args     = {} if extra_args     is None else extra_args
# Get device from model - for Nunchaku QwenImage models, device attribute may not exist
# Try multiple methods: model attribute, model parameters, or x.device as fallback
try:
    model_device = model.inner_model.inner_model.device
except (AttributeError, TypeError):
    # Try getting device from model parameters (works for most PyTorch models)
    try:
        inner_model = model.inner_model.inner_model
        if hasattr(inner_model, 'parameters'):
            model_device = next(iter(inner_model.parameters())).device
        else:
            # Fallback to x.device (used in ComfyUI-nunchaku)
            model_device = x.device
    except (StopIteration, AttributeError, TypeError):
        # Final fallback: use x.device (safe and always available)
        model_device = x.device
work_device    = 'cpu' if EO("work_device_cpu") else model_device

Detailed Line-by-Line Explanation:

  1. EO = ExtraOptions(extra_options): Creates an ExtraOptions helper object for accessing extra options. This allows easy access to configuration values with defaults.

  2. default_dtype = EO("default_dtype", torch.float64): Retrieves the default data type from extra options, defaulting to torch.float64 if not specified. RES4LYF samplers use high precision (float64) by default for numerical accuracy.

  3. extra_args = {} if extra_args is None else extra_args: Initializes extra_args to an empty dictionary if it's None. This prevents TypeError when accessing extra_args keys later.

  4. First attempt: model_device = model.inner_model.inner_model.device:

    • Purpose: Tries to access device directly from the innermost model wrapper
    • Model Structure: model is typically a CFGDenoiser or similar wrapper. The chain inner_model.inner_model navigates through wrapper layers to reach the actual model (BaseModel in ComfyUI or ForgeDiffusionEngine in Forge)
    • Why this works for some models: Standard ComfyUI models and some Forge models have a device attribute on the base model class
    • Why this fails for others: Nunchaku Qwen Image models wrapped in Forge may not expose device directly, or the attribute path may be different
  5. Second attempt: next(iter(inner_model.parameters())).device:

    • Purpose: Retrieves device from the first parameter tensor of the model
    • Why this works: PyTorch models store their parameters (weights, biases) as tensors. All parameters in a model are on the same device. By getting the first parameter's device, we get the model's device
    • Implementation: inner_model.parameters() returns an iterator over all parameters. iter() makes it iterable, next() gets the first parameter, .device gets its device
    • Error handling: Wrapped in try-except to catch StopIteration (empty parameters), AttributeError (no parameters method), or TypeError (not a PyTorch model)
  6. Final fallback: model_device = x.device:

    • Purpose: Uses the device of the input tensor x as the model device
    • Why this is safe: x is the input latent tensor passed to the sampler. It's always a PyTorch tensor with a .device attribute
    • Why this works: If the model processes x, it must be on the same device as x (or able to move tensors to its device). Using x.device is a safe assumption
    • Reference: This approach is used in ComfyUI-nunchaku and is proven to work
  7. work_device = 'cpu' if EO("work_device_cpu") else model_device: Determines the work device based on extra options. Some operations (like intermediate calculations) can be performed on CPU for memory efficiency, while model inference must happen on the model's device.

Why This Multi-Stage Fallback Matters:

  • Robustness: Handles all known model structures without crashing
  • Compatibility: Works with ComfyUI models, Forge models, and Nunchaku models
  • Performance: Uses the most direct method when available (direct attribute access is fastest)
  • Safety: Always has a fallback that works (using x.device)

Impact on Different Model Types:

  • Standard ComfyUI Models: Uses first method (model.inner_model.inner_model.device) - fastest
  • Standard Forge Models: Uses first method if available, otherwise second method (parameters)
  • Nunchaku Qwen Image: May use second method (parameters) or fallback to third method (x.device)
  • Nunchaku Flux1/SDXL: Similar to standard Forge models

Change 2: Model Type Detection and model_sampling Acquisition (lines 277-396)

Problem: Different model structures store model_sampling in different locations:

  • ComfyUI BaseModel: model.inner_model.inner_model.model_sampling (direct attribute)
  • Forge ForgeDiffusionEngine: model.inner_model.inner_model.forge_objects.unet.model.model_sampling (via KModel wrapper)

Additionally, we need to detect the specific model type (Nunchaku Qwen Image, Nunchaku Flux1, Nunchaku SDXL, standard SDXL, standard Flux1) to use the correct sampling logic and provide meaningful error messages.

Solution Code (lines 277-334):

# Get model_sampling - different paths for Forge vs ComfyUI
# ComfyUI BaseModel: model.inner_model.inner_model.model_sampling (direct attribute)
# Forge ForgeDiffusionEngine: model.inner_model.inner_model.forge_objects.unet.model.model_sampling (via KModel)
model_sampling_obj = None
model_sampling_path = None
is_nunchaku_qwen_image = False
is_nunchaku_flux1 = False
is_nunchaku_sdxl = False
is_sdxl = False
is_flux1 = False

# First, try Forge path (ForgeDiffusionEngine has forge_objects)
if hasattr(model, "inner_model") and hasattr(model.inner_model, "inner_model"):
    inner_model = model.inner_model.inner_model
    # Check if it's Forge model (has forge_objects attribute)
    if hasattr(inner_model, "forge_objects"):
        try:
            forge_objects = inner_model.forge_objects
            if hasattr(forge_objects, "unet") and hasattr(forge_objects.unet, "model"):
                # Check diffusion_model type to distinguish Nunchaku models
                k_model = forge_objects.unet.model
                if hasattr(k_model, "diffusion_model"):
                    diffusion_model = k_model.diffusion_model
                    # Check if it's Nunchaku Qwen Image, FLUX1, or SDXL
                    try:
                        from backend.nn.svdq import SVDQFluxTransformer2DModel, NunchakuQwenImageTransformer2DModel
                        from backend.nn.nunchaku_sdxl_unet import SVDQUNet2DConditionModel
                        if isinstance(diffusion_model, NunchakuQwenImageTransformer2DModel):
                            is_nunchaku_qwen_image = True
                        elif isinstance(diffusion_model, SVDQFluxTransformer2DModel):
                            is_nunchaku_flux1 = True
                        elif isinstance(diffusion_model, SVDQUNet2DConditionModel):
                            is_nunchaku_sdxl = True
                        else:
                            # Check if it's standard SDXL (IntegratedUNet2DConditionModel or UNet2DConditionModel)
                            try:
                                from backend.nn.unet import IntegratedUNet2DConditionModel
                                if isinstance(diffusion_model, IntegratedUNet2DConditionModel):
                                    # Check if inner model is SDXL UNet
                                    if hasattr(inner_model, "is_sdxl") and inner_model.is_sdxl:
                                        is_sdxl = True
                            except (ImportError, TypeError):
                                pass
                            # Check if it's standard Flux1 (IntegratedFluxTransformer2DModel)
                            if not is_sdxl:  # Only check Flux1 if not SDXL
                                try:
                                    from backend.nn.flux import IntegratedFluxTransformer2DModel
                                    if isinstance(diffusion_model, IntegratedFluxTransformer2DModel):
                                        is_flux1 = True
                                except (ImportError, TypeError):
                                    pass
                    except (ImportError, TypeError):
                        pass
                
                if hasattr(k_model, "model_sampling"):
                    model_sampling_obj = k_model.model_sampling
                    if is_nunchaku_qwen_image:
                        model_type_str = "Nunchaku QwenImage"
                    elif is_nunchaku_flux1:
                        model_type_str = "Nunchaku FLUX1"
                    elif is_nunchaku_sdxl:
                        model_type_str = "Nunchaku SDXL"
                    elif is_sdxl:
                        model_type_str = "SDXL"
                    elif is_flux1:
                        model_type_str = "FLUX1"
                    else:
                        model_type_str = "Forge"
                    model_sampling_path = f"forge_objects.unet.model.model_sampling ({model_type_str})"
        except (AttributeError, TypeError):
            pass

Detailed Line-by-Line Explanation:

  1. Initialization (lines 263-268):

    • model_sampling_obj = None: Variable to store the found model_sampling object
    • model_sampling_path = None: Variable to store a human-readable path description for debugging
    • is_nunchaku_qwen_image = False: Flag for Nunchaku Qwen Image detection
    • is_nunchaku_flux1 = False: Flag for Nunchaku Flux1 detection
    • is_nunchaku_sdxl = False: Flag for Nunchaku SDXL detection
    • is_sdxl = False: Flag for standard SDXL detection
    • is_flux1 = False: Flag for standard Flux1 detection
    • These flags are set to False initially and set to True when the corresponding model type is detected
  2. Check for nested model structure (line 271):

    • if hasattr(model, "inner_model") and hasattr(model.inner_model, "inner_model"): Checks if the model has the expected nested structure
    • Why: The model passed to RES4LYF is typically a wrapper (like CFGDenoiser) that wraps the actual model. We need to check if both wrapper layers exist before accessing them
    • Safety: Prevents AttributeError if the model structure is different than expected
  3. Extract inner model (line 272):

    • inner_model = model.inner_model.inner_model: Navigates through wrapper layers to reach the base model
    • Result: inner_model is now either a ComfyUI BaseModel (if standard ComfyUI) or a Forge ForgeDiffusionEngine (if Forge model)
  4. Check if Forge model (line 274):

    • if hasattr(inner_model, "forge_objects"): Checks if the model has forge_objects attribute
    • Why this is the key distinction: Forge models have a forge_objects attribute that contains unet, vae, clip, etc. ComfyUI models don't have this attribute
    • This is the critical branching point: If forge_objects exists, we're dealing with a Forge model and need to use Forge-specific paths
  5. Access forge_objects (line 276):

    • forge_objects = inner_model.forge_objects: Gets the Forge objects container
    • Structure: forge_objects contains references to the model components, including forge_objects.unet which is a UnetPatcher wrapper
  6. Check for unet and k_model (line 277):

    • if hasattr(forge_objects, "unet") and hasattr(forge_objects.unet, "model"): Checks if unet exists and has a model attribute
    • Structure: forge_objects.unet is a UnetPatcher, and forge_objects.unet.model is the KModel wrapper that contains the actual diffusion model and model_sampling
  7. Get KModel (line 279):

    • k_model = forge_objects.unet.model: Gets the KModel wrapper
    • KModel responsibility: KModel wraps the actual diffusion model (transformer or UNet) and is responsible for setting model_sampling based on the model type
  8. Check for diffusion_model (line 280):

    • if hasattr(k_model, "diffusion_model"): Checks if KModel has a diffusion_model attribute
    • Purpose: diffusion_model is the actual neural network (transformer or UNet). Its type tells us what kind of model we're dealing with
  9. Get diffusion_model (line 281):

    • diffusion_model = k_model.diffusion_model: Gets the actual diffusion model
    • This is the key object for model type detection: The class of diffusion_model determines whether it's Nunchaku Qwen Image, Nunchaku Flux1, Nunchaku SDXL, standard SDXL, or standard Flux1
  10. Import model type classes (lines 284-285):

    • from backend.nn.svdq import SVDQFluxTransformer2DModel, NunchakuQwenImageTransformer2DModel: Imports Nunchaku model classes from backend.nn.svdq
    • from backend.nn.nunchaku_sdxl_unet import SVDQUNet2DConditionModel: Imports Nunchaku SDXL UNet class
    • Why imports are inside try-except: These classes might not be available if the backend module structure changes or if Nunchaku support is not compiled. The try-except prevents crashes if imports fail
  11. Detect Nunchaku Qwen Image (line 286):

    • if isinstance(diffusion_model, NunchakuQwenImageTransformer2DModel): is_nunchaku_qwen_image = True
    • Detection method: Uses isinstance() to check if diffusion_model is an instance of NunchakuQwenImageTransformer2DModel
    • Why this works: NunchakuQwenImageTransformer2DModel is a distinct class from standard QwenImageTransformer2DModel. The isinstance() check is type-safe and reliable
    • Model location: NunchakuQwenImageTransformer2DModel is defined in backend.nn.svdq and is used specifically for Nunchaku-quantized Qwen Image models
  12. Detect Nunchaku Flux1 (line 288):

    • elif isinstance(diffusion_model, SVDQFluxTransformer2DModel): is_nunchaku_flux1 = True
    • Detection method: Same as above, but for SVDQFluxTransformer2DModel
    • Model location: SVDQFluxTransformer2DModel is also defined in backend.nn.svdq and is used for Nunchaku-quantized Flux1 models
  13. Detect Nunchaku SDXL (line 290):

    • elif isinstance(diffusion_model, SVDQUNet2DConditionModel): is_nunchaku_sdxl = True
    • Detection method: Same as above, but for SVDQUNet2DConditionModel
    • Model location: SVDQUNet2DConditionModel is defined in backend.nn.nunchaku_sdxl_unet and is used for Nunchaku-quantized SDXL models
  14. Detect Standard SDXL (lines 294-299):

    • Checks if diffusion_model is IntegratedUNet2DConditionModel AND inner_model.is_sdxl is True
    • Why two conditions: IntegratedUNet2DConditionModel can be used for both SDXL and non-SDXL models. The inner_model.is_sdxl flag explicitly indicates SDXL
    • Model location: IntegratedUNet2DConditionModel is defined in backend.nn.unet and is used for standard Forge SDXL models
  15. Detect Standard Flux1 (lines 300-305):

    • Checks if diffusion_model is IntegratedFluxTransformer2DModel
    • Detection method: Uses isinstance() to check if diffusion_model is an instance of IntegratedFluxTransformer2DModel
    • Why this works: IntegratedFluxTransformer2DModel is a distinct class from SVDQFluxTransformer2DModel (Nunchaku Flux1). The isinstance() check is type-safe and reliable
    • Model location: IntegratedFluxTransformer2DModel is defined in backend.nn.flux and is used for standard Forge Flux1 models
    • Note: Standard Flux1 detection is placed after SDXL detection because both can use IntegratedUNet2DConditionModel/IntegratedFluxTransformer2DModel. SDXL detection checks is_sdxl flag first, then Flux1 detection proceeds if not SDXL
  16. Get model_sampling from KModel (line 305):

    • if hasattr(k_model, "model_sampling"): model_sampling_obj = k_model.model_sampling
    • Path: model.inner_model.inner_model.forge_objects.unet.model.model_sampling
    • Why this location: KModel sets self.model_sampling during initialization based on the model type (see backend/modules/k_model.py). For Forge models, this is the authoritative location
  17. Set model type string for logging (lines 307-317):

    • Creates a human-readable string describing the detected model type
    • Purpose: Used in debug logs and error messages to help users understand what model type was detected
    • Format: f"forge_objects.unet.model.model_sampling ({model_type_str})" combines the path with the model type for clarity
  18. Error handling (line 318):

    • except (AttributeError, TypeError): pass: Catches any errors during the detection process
    • Why this is necessary: The nested attribute access (forge_objects.unet.model.diffusion_model) can fail at any level. Instead of crashing, we catch the error and continue to fallback methods

Solution Code (lines 321-343) - Fallback Paths:

# Fallback: ComfyUI BaseModel (has model_sampling directly)
if model_sampling_obj is None:
    try:
        model_sampling_obj = model.inner_model.inner_model.model_sampling
        model_sampling_path = "model.inner_model.inner_model.model_sampling (ComfyUI BaseModel)"
    except (AttributeError, TypeError):
        pass

if model_sampling_obj is None:
    # Try model.inner_model.model_sampling (if model_wrap has it directly)
    try:
        model_sampling_obj = model.inner_model.model_sampling
        model_sampling_path = "model.inner_model.model_sampling"
    except (AttributeError, TypeError):
        pass

if model_sampling_obj is None:
    # Try model.model_sampling (fallback)
    try:
        model_sampling_obj = model.model_sampling
        model_sampling_path = "model.model_sampling"
    except (AttributeError, TypeError):
        pass

Detailed Explanation:

  1. First Fallback - ComfyUI BaseModel (lines 322-327):

    • Path: model.inner_model.inner_model.model_sampling
    • When used: For standard ComfyUI models (not Forge)
    • Why: ComfyUI's BaseModel class sets self.model_sampling directly in its __init__ method (see comfy/model_base.py)
    • Structure: BaseModel.model_sampling is a direct attribute, not wrapped like in Forge
  2. Second Fallback - ForgeScheduleLinker (lines 329-334):

    • Path: model.inner_model.model_sampling
    • When used: If the model wrapper has model_sampling directly
    • Why: Some wrappers (like ForgeScheduleLinker) may expose model_sampling directly for convenience
  3. Third Fallback - Direct Model Access (lines 336-341):

    • Path: model.model_sampling
    • When used: Last resort if none of the standard paths work
    • Why: Some models or custom wrappers might expose model_sampling at the top level

Error Handling if model_sampling Not Found (lines 368-379):

else:
    if is_nunchaku_qwen_image:
        model_type_str = "Nunchaku QwenImage"
    elif is_nunchaku_flux1:
        model_type_str = "Nunchaku FLUX1"
    elif is_nunchaku_sdxl:
        model_type_str = "Nunchaku SDXL"
    elif is_sdxl:
        model_type_str = "SDXL"
    elif is_flux1:
        model_type_str = "FLUX1"
    else:
        model_type_str = "Other"
    raise AttributeError(f"model_sampling not found. Model type: {model_type_str}. Tried: forge_objects.unet.model.model_sampling (Forge), model.inner_model.inner_model.model_sampling (ComfyUI BaseModel), model.inner_model.model_sampling, model.model.model_sampling")

Explanation:

  • Purpose: If model_sampling is still None after all attempts, raise a descriptive error
  • Error message includes:
    • Detected model type (if known): Helps identify which model type was detected but couldn't find model_sampling
    • All attempted paths: Lists all paths that were tried, helping users debug why model_sampling wasn't found
  • Why this is important: Without model_sampling, RES4LYF cannot determine sigma_min, sigma_max, or the correct sampling behavior. This error helps users identify the issue quickly.

Continuation: rk_sampler_beta.py

Change 3: CONST/EPS Type Detection (lines 362-384)

Problem: Flux1 models (both Nunchaku and standard) use CONST type model sampling, while SDXL models use EPS type. The initial implementation only checked isinstance(model_sampling_obj, EPS) for VE_MODEL, but did not explicitly check for CONST type.

Additionally, Forge's ModelSamplingFluxWithConst inherits from backend.modules.k_model.CONST, which is a distinct class from comfy.model_sampling.CONST. The initial implementation only checked comfy.model_sampling.CONST, causing Flux1 models to be incorrectly identified.

Solution Code:

# Check if model_sampling is EPS type (VE model) or CONST type (FLUX1)
# ModelSamplingFluxWithConst uses backend.modules.k_model.CONST, not comfy.model_sampling.CONST
try:
    from backend.modules.k_model import CONST as BackendCONST
except ImportError:
    BackendCONST = None

VE_MODEL = False
CONST_MODEL = False
if model_sampling_obj is not None:
    VE_MODEL = isinstance(model_sampling_obj, EPS)
    CONST_MODEL = isinstance(model_sampling_obj, CONST) or (BackendCONST is not None and isinstance(model_sampling_obj, BackendCONST))
    # ... logging ...

Detailed Line-by-Line Explanation:

  1. Import BackendCONST (lines 364-367):

    • from backend.modules.k_model import CONST as BackendCONST: Imports Forge's CONST class from backend.modules.k_model
    • Why aliased as BackendCONST: To avoid name conflicts with comfy.model_sampling.CONST which is also imported elsewhere
    • Why inside try-except: The backend.modules.k_model module might not be available if the backend structure changes or if Forge support is not compiled. The try-except prevents crashes if the import fails
    • BackendCONST = None: If import fails, set to None so we can check if it's available before using it
  2. Initialize flags (lines 369-370):

    • VE_MODEL = False: Flag for Variance Expanding (VE) models (SDXL)
    • CONST_MODEL = False: Flag for CONST models (Flux1)
    • These flags are set to True when the corresponding model type is detected
  3. Check for EPS type (line 372):

    • VE_MODEL = isinstance(model_sampling_obj, EPS): Checks if model_sampling_obj is an instance of EPS (from comfy.model_sampling)
    • EPS (Variance Expanding): Used by SDXL models (both standard and Nunchaku)
    • Why this matters: EPS models use different noise scaling and denoising formulas than CONST models. RES4LYF uses this flag to select the correct formulas
  4. Check for CONST type (line 373):

    • CONST_MODEL = isinstance(model_sampling_obj, CONST) or (BackendCONST is not None and isinstance(model_sampling_obj, BackendCONST))
    • First check: isinstance(model_sampling_obj, CONST): Checks if model_sampling_obj is an instance of comfy.model_sampling.CONST (used by standard ComfyUI Flux1 models)
    • Second check: (BackendCONST is not None and isinstance(model_sampling_obj, BackendCONST)): Checks if BackendCONST is available AND if model_sampling_obj is an instance of backend.modules.k_model.CONST (used by Forge Flux1 models, both Nunchaku and standard)
    • Why both checks are needed: ModelSamplingFluxWithConst (used by Forge Flux1) inherits from backend.modules.k_model.CONST, not comfy.model_sampling.CONST. These are two distinct classes that cannot be detected by a single isinstance() check
    • Logical OR: If either check is True, CONST_MODEL is set to True

Why This Dual CONST Check is Critical:

  • Class Hierarchy:

    • ComfyUI Flux1: ModelSamplingFlux + comfy.model_sampling.CONST mixin
    • Forge Flux1: ModelSamplingFlux + backend.modules.k_model.CONST mixin
    • These are different CONST classes with the same methods but defined in different modules
  • Mixin Pattern:

    • ModelSamplingFluxWithConst uses Python's multiple inheritance to combine ModelSamplingFlux and CONST
    • For ComfyUI: class ModelSamplingFluxWithConst(ModelSamplingFlux, comfy.model_sampling.CONST)
    • For Forge: class ModelSamplingFluxWithConst(ModelSamplingFlux, backend.modules.k_model.CONST)
    • isinstance(obj, CONST) only checks the direct parent class, not mixins from other modules
  • Impact on RES4LYF:

    • If only comfy.model_sampling.CONST is checked, Forge Flux1 models (including Nunchaku Flux1) will be incorrectly identified as non-CONST models
    • This causes incorrect noise scaling, incorrect denoising formulas, and ultimately incorrect image generation (images don't form correctly, as reported by the user)

Logging (line 384):

  • RESplain(f"[RES4LYF] model_type: {model_type_str}, model_sampling at: {model_sampling_path}, type: {type(model_sampling_obj).__name__}, VE_MODEL: {VE_MODEL}, CONST_MODEL: {CONST_MODEL}", debug=False)
  • Purpose: Logs detected model type, model_sampling path, class name, and VE_MODEL/CONST_MODEL flags
  • Why debug=False: Always logs this information, regardless of debug mode. This is critical for troubleshooting model detection issues
  • Information logged:
    • model_type_str: Human-readable model type (e.g., "Nunchaku FLUX1")
    • model_sampling_path: Path where model_sampling was found (e.g., "forge_objects.unet.model.model_sampling (Nunchaku FLUX1)")
    • type(model_sampling_obj).__name__: Class name of model_sampling_obj (e.g., "ModelSamplingFluxWithConst")
    • VE_MODEL: Boolean flag for EPS (SDXL) models
    • CONST_MODEL: Boolean flag for CONST (Flux1) models

Error Handling if model_sampling is None (lines 385-396):

  • If model_sampling_obj is None after all attempts, raise a descriptive AttributeError with:
    • Detected model type (if known)
    • All attempted paths
    • This helps users debug why model_sampling wasn't found

Change 4: extra_args['model_options'] Initialization (lines 378-379 in original, but this check is actually done elsewhere)

Problem: When cfg_cw == 1.0 (Classifier-Free Guidance disabled), extra_args['model_options'] and extra_args['model_options']['transformer_options'] might not exist. Accessing them directly causes KeyError.

Solution Code (searching for this in the file):

# Ensure model_options and transformer_options exist
if 'model_options' not in extra_args:
    extra_args['model_options'] = {}
if 'transformer_options' not in extra_args['model_options']:
    extra_args['model_options']['transformer_options'] = {}

Detailed Explanation:

  1. Check for model_options (line 1-2):

    • if 'model_options' not in extra_args:: Checks if model_options key exists in extra_args
    • extra_args['model_options'] = {}: If not, creates an empty dictionary
    • Why this is needed: When CFG is disabled (cfg_cw == 1.0), some code paths skip creating model_options, leading to missing keys
  2. Check for transformer_options (line 3-4):

    • if 'transformer_options' not in extra_args['model_options']:: Checks if transformer_options key exists in model_options
    • extra_args['model_options']['transformer_options'] = {}: If not, creates an empty dictionary
    • Why this is needed: transformer_options is a nested dictionary within model_options. It might not exist even if model_options exists

Why This Matters:

  • CFG Behavior: When CFG is disabled, some code paths don't populate model_options or transformer_options because they're not needed for unconditional generation
  • RES4LYF Requirements: RES4LYF samplers may access transformer_options for other purposes (e.g., LoRA injection, ControlNet), even when CFG is disabled
  • Error Prevention: Without this initialization, accessing extra_args['model_options']['transformer_options'] causes KeyError, crashing the sampler

Impact on RES4LYF:

  • Stability: Prevents crashes when CFG is disabled
  • Compatibility: Ensures RES4LYF works correctly with both CFG-enabled and CFG-disabled generation
  • Extensibility: Allows RES4LYF to access transformer_options for future features without breaking existing workflows

Change 5: Safe diffusion_model Access (multiple locations)

Problem: Nunchaku Qwen Image models don't have a direct diffusion_model attribute like standard ComfyUI models. Direct access like model.inner_model.inner_model.diffusion_model causes AttributeError.

Solution: Replace all direct diffusion_model access with safe, nested hasattr checks.

Example from line 1742 (original problematic code):

# BEFORE (causes AttributeError for Nunchaku Qwen Image):
if hasattr(model.inner_model.inner_model.diffusion_model, "eps_out"):
    # ...

# AFTER (safe access):
if hasattr(model.inner_model.inner_model, "diffusion_model") and hasattr(model.inner_model.inner_model.diffusion_model, "eps_out"):
    # ...

Detailed Explanation:

  1. First hasattr check:

    • hasattr(model.inner_model.inner_model, "diffusion_model"): Checks if diffusion_model attribute exists before accessing it
    • Why this is needed: Nunchaku Qwen Image models don't have diffusion_model directly on inner_model. They store it at forge_objects.unet.model.diffusion_model instead
  2. Second hasattr check:

    • hasattr(model.inner_model.inner_model.diffusion_model, "eps_out"): Only checked if first check passes
    • Why this is needed: Even if diffusion_model exists, it might not have eps_out attribute (only some models have this)

Locations Modified:

  • Line 549: hasattr check before accessing diffusion_model.eps_out
  • Line 554: hasattr check before accessing diffusion_model.eps_out
  • Line 648: hasattr check before accessing diffusion_model.eps_out
  • Line 1199: hasattr check before accessing diffusion_model.eps_out
  • Line 1205: hasattr check before accessing diffusion_model.eps_out
  • Line 1750: hasattr check before accessing diffusion_model.eps_out
  • Line 1770: hasattr check before accessing diffusion_model.eps_out
  • Line 1776: hasattr check before accessing diffusion_model.eps_out

Why This Matters:

  • Model Structure Differences: Standard ComfyUI models have diffusion_model at model.inner_model.inner_model.diffusion_model, while Forge models store it at forge_objects.unet.model.diffusion_model
  • Nunchaku Qwen Image: These models don't expose diffusion_model at the standard path, requiring the safe access pattern
  • Error Prevention: Without these checks, AttributeError crashes the sampler when using Nunchaku Qwen Image models

File: modules/RES4LYF/beta/rk_method_beta.py

Purpose: Core RK method implementation. This file contains the RK_Method_Beta class and its subclasses (RK_Method_Multistep and RK_Method_Exponential) which implement the actual Runge-Kutta numerical integration algorithms.

Critical Changes:

  1. Model Type Detection and model_sampling Acquisition (lines 57-147): Same logic as rk_sampler_beta.py, but in the __init__ method

Modified Code (lines 57-147):

Same as rk_sampler_beta.py lines 277-396, but adapted for the __init__ method of RK_Method_Beta. The logic is identical:

  1. First, try Forge path (forge_objects.unet.model.model_sampling)
  2. Detect model type via diffusion_model class (NunchakuQwenImageTransformer2DModel, SVDQFluxTransformer2DModel, SVDQUNet2DConditionModel, IntegratedUNet2DConditionModel)
  3. Fallback to ComfyUI path (model.inner_model.inner_model.model_sampling)
  4. Raise AttributeError with descriptive message if not found

Why This File Needs the Same Logic:

  • Model Type Detection: The RK method needs to know the model type to select correct formulas
  • model_sampling Access: The RK method needs sigma_min and sigma_max from model_sampling to initialize the solver
  • Error Messages: Clear error messages help users debug issues

Impact on Different Model Types:

  • Nunchaku Qwen Image: Uses Forge path, detects via NunchakuQwenImageTransformer2DModel
  • Nunchaku Flux1: Uses Forge path, detects via SVDQFluxTransformer2DModel
  • Nunchaku SDXL: Uses Forge path, detects via SVDQUNet2DConditionModel
  • Standard SDXL: Uses Forge path (if Forge model) or ComfyUI path, detects via IntegratedUNet2DConditionModel + is_sdxl flag
  • Standard Flux1: Uses Forge path (if Forge model) or ComfyUI path

File: modules/RES4LYF/beta/rk_noise_sampler_beta.py

Purpose: Noise sampler initialization. This file contains the RK_NoiseSampler class which initializes noise samplers for RES4LYF samplers. It requires sigma_min and sigma_max from model_sampling.

Critical Changes:

  1. Model Type Detection and model_sampling Acquisition (lines 72-156): Same logic as rk_sampler_beta.py
  2. CONST Detection (lines 178-186): Checks both comfy.model_sampling.CONST and backend.modules.k_model.CONST

Modified Code (lines 178-186):

# Check if CONST type - check both comfy.model_sampling.CONST and backend.modules.k_model.CONST
# ModelSamplingFluxWithConst uses backend.modules.k_model.CONST
try:
    from backend.modules.k_model import CONST as BackendCONST
except ImportError:
    BackendCONST = None

self.CONST = isinstance(model_sampling, comfy.model_sampling.CONST) or (BackendCONST is not None and isinstance(model_sampling, BackendCONST))
self.VARIANCE_PRESERVING = self.CONST

Detailed Explanation:

  1. Import BackendCONST (lines 180-183):

    • Same logic as rk_sampler_beta.py - imports Forge's CONST class if available
  2. Dual CONST Check (line 185):

    • isinstance(model_sampling, comfy.model_sampling.CONST): Checks for ComfyUI CONST
    • (BackendCONST is not None and isinstance(model_sampling, BackendCONST)): Checks for Forge CONST
    • Logical OR: If either check is True, self.CONST is set to True
  3. VARIANCE_PRESERVING (line 186):

    • self.VARIANCE_PRESERVING = self.CONST: CONST models are variance-preserving (used for Flux1)
    • Why this matters: Noise samplers use this flag to select correct noise scaling formulas

Why This File Needs CONST Detection:

  • Noise Scaling: CONST models (Flux1) use different noise scaling than EPS models (SDXL)
  • Initialization: The noise sampler needs to know the model type to initialize correctly
  • Performance: Correct initialization prevents incorrect noise generation, which would cause artifacts or incorrect image generation

File: modules/RES4LYF/beta/rk_guide_func_beta.py

Purpose: Latent guiding functions. This file contains the LatentGuide class which handles latent guiding functions for RES4LYF samplers. It also requires sigma_min and sigma_max from model_sampling.

Critical Changes:

  1. Model Type Detection and model_sampling Acquisition (lines 56-147): Same logic as rk_sampler_beta.py

Modified Code: Same as rk_method_beta.py - identical logic for detecting model type and acquiring model_sampling.

Why This File Needs the Same Logic:

  • Latent Guiding: Guiding functions need to know model type to select correct formulas
  • model_sampling Access: Guiding functions need sigma_min and sigma_max to calculate guidance weights
  • Compatibility: Ensures guiding works correctly with all model types

File: modules/RES4LYF/beta/__init__.py

Purpose: Dynamic sampler registration. This file registers all RES4LYF samplers with ComfyUI/Forge, allowing them to be used in the UI.

Critical Changes:

  1. Dynamic Sampler Registration (lines 92-119): Programmatically registers all samplers from RK_SAMPLER_NAMES_BETA_NO_FOLDERS
  2. Lazy Import (line 95): Moves RK_SAMPLER_NAMES_BETA_NO_FOLDERS import inside add_beta function to avoid circular dependencies

Modified Code (lines 92-119):

# Register all samplers from RK_SAMPLER_NAMES_BETA_NO_FOLDERS
# Create sampler functions dynamically
sampler_functions = {}
for sampler_name in RK_SAMPLER_NAMES_BETA_NO_FOLDERS:
    if sampler_name == "none":
        continue
    
    # Create standard sampler function with proper closure
    def make_sample_fn(rk_type):
        def sample_fn(model, x, sigmas, extra_args=None, callback=None, disable=None):
            return rk_sampler_beta.sample_rk_beta(model, x, sigmas, None, extra_args, callback, disable, rk_type=rk_type)
        return sample_fn
    
    sampler_functions[sampler_name] = make_sample_fn(sampler_name)
    
    # Create ODE version (eta=0.0, eta_substep=0.0) for non-implicit samplers
    # Skip ODE versions for implicit samplers (those with implicit-related keywords)
    if not any(keyword in sampler_name for keyword in ["gauss-legendre", "radau", "lobatto", "irk_exp_diag", "kraaijevanger", "qin_zhang", "pareschi", "crouzeix"]):
        ode_sampler_name = f"{sampler_name}_ode"
        
        def make_sample_ode_fn(rk_type):
            def sample_ode_fn(model, x, sigmas, extra_args=None, callback=None, disable=None):
                return rk_sampler_beta.sample_rk_beta(model, x, sigmas, None, extra_args, callback, disable, rk_type=rk_type, eta=0.0, eta_substep=0.0)
            return sample_ode_fn
        
        sampler_functions[ode_sampler_name] = make_sample_ode_fn(sampler_name)

extra_samplers.update(sampler_functions)

# Also register the generic rk_beta sampler
extra_samplers["rk_beta"] = rk_sampler_beta.sample_rk_beta

Detailed Explanation:

  1. Lazy Import (line 95):

    • from .rk_coefficients_beta import RK_SAMPLER_NAMES_BETA_NO_FOLDERS: Import moved inside add_beta function
    • Why this is needed: Prevents circular import issues or incorrect loading order. Importing at the module level can cause ModuleNotFoundError if modules are loaded in the wrong order
    • Lazy Loading: Import only when needed (when add_beta is called), not at module load time
  2. Initialize sampler_functions dictionary (line 94):

    • sampler_functions = {}: Dictionary to store all dynamically created sampler functions
    • Why a dictionary: Allows easy lookup and registration of all samplers at once
  3. Loop over sampler names (line 96):

    • for sampler_name in RK_SAMPLER_NAMES_BETA_NO_FOLDERS:: Iterates over all sampler names defined in rk_coefficients_beta.py
    • Purpose: Creates a sampler function for each sampler name
  4. Skip "none" (line 97-98):

    • if sampler_name == "none": continue: Skips the "none" sampler (placeholder)
    • Why this is needed: "none" is not a real sampler, just a placeholder in the list
  5. Create sampler function with closure (lines 100-104):

    • def make_sample_fn(rk_type):: Factory function that creates a sampler function for a specific rk_type
    • Why a factory function: Python's closure behavior ensures each sampler function captures the correct rk_type value. Without this, all samplers would use the last rk_type from the loop
    • Closure in Python: When a nested function references a variable from its enclosing scope, Python creates a closure that captures the variable's value at the time the function is created. By calling make_sample_fn(sampler_name), we ensure each sampler function has its own rk_type value
    • def sample_fn(...):: The actual sampler function that calls rk_sampler_beta.sample_rk_beta with the captured rk_type
    • return sample_fn: Returns the sampler function with the correct rk_type captured
  6. Register standard sampler (line 106):

    • sampler_functions[sampler_name] = make_sample_fn(sampler_name): Creates and stores the sampler function
    • Why use sampler_name twice: First sampler_name is the dictionary key (e.g., "res_3m"), second sampler_name is passed to make_sample_fn to capture as rk_type
  7. Create ODE version (lines 108-117):

    • if not any(keyword in sampler_name for keyword in [...]):: Only creates ODE version for non-implicit samplers
    • Why skip implicit samplers: Implicit samplers (Gauss-Legendre, Radau, Lobatto, etc.) are inherently deterministic and don't need an ODE version. Creating ODE versions for them would be redundant or cause errors
    • ODE Version: eta=0.0, eta_substep=0.0 forces deterministic behavior (no stochastic noise injection)
    • Purpose: Some users prefer deterministic sampling for reproducibility. The ODE version provides this option
    • ode_sampler_name = f"{sampler_name}_ode": Creates ODE version name (e.g., "res_3m_ode")
  8. Register all samplers (line 119):

    • extra_samplers.update(sampler_functions): Registers all dynamically created samplers with ComfyUI/Forge
    • Why update(): Adds all samplers at once, rather than registering them one by one
  9. Register generic sampler (line 122):

    • extra_samplers["rk_beta"] = rk_sampler_beta.sample_rk_beta: Registers the generic rk_beta sampler
    • Why this is needed: Some code might call the generic sampler directly with an rk_type parameter, rather than using the specific sampler functions

Why Dynamic Registration is Needed:

  • Comprehensive Coverage: RK_SAMPLER_NAMES_BETA_NO_FOLDERS contains many samplers (res_2m, res_3m, res_4m, etc.). Manually registering each one would be error-prone and maintenance-heavy
  • Automatic Updates: When new samplers are added to RK_SAMPLER_NAMES_BETA_NO_FOLDERS, they're automatically registered without modifying __init__.py
  • ODE Versions: Automatically creates ODE versions for appropriate samplers, doubling the available sampler options
  • Closure Safety: Using factory functions ensures each sampler function captures the correct rk_type, preventing bugs where all samplers use the same rk_type

Impact on User Experience:

  • More Samplers: Users have access to all samplers defined in RK_SAMPLER_NAMES_BETA_NO_FOLDERS, not just a subset
  • ODE Options: Users can choose between stochastic and deterministic (ODE) versions of most samplers
  • Ease of Use: All samplers appear in the UI automatically, without manual configuration

Category 4: RES4LYF Helper Files

File: modules/RES4LYF/helper.py

Purpose: Helper functions for RES4LYF samplers. This file contains utility functions, including is_RF_model() which checks if a model is a Flux1 (RF) model.

Critical Changes:

  1. is_RF_model() Function (lines 356-365): Modified to check both comfy.model_sampling.CONST and backend.modules.k_model.CONST

Modified Code:

def is_RF_model(model):
    from comfy import model_sampling
    modelsampling = model.inner_model.inner_model.model_sampling
    # Check both comfy.model_sampling.CONST and backend.modules.k_model.CONST
    # ModelSamplingFluxWithConst uses backend.modules.k_model.CONST
    try:
        from backend.modules.k_model import CONST as BackendCONST
    except ImportError:
        BackendCONST = None
    return isinstance(modelsampling, model_sampling.CONST) or (BackendCONST is not None and isinstance(modelsampling, BackendCONST))

Detailed Explanation:

  1. Function Purpose:

    • is_RF_model(model): Checks if a model is a Flux1 (RF) model
    • RF (Rectified Flow): Flux1 models use Rectified Flow sampling, which requires special handling
    • Usage: Used by RES4LYF to determine if special Flux1 formulas should be used
  2. Get model_sampling (line 358):

    • modelsampling = model.inner_model.inner_model.model_sampling: Gets model_sampling from ComfyUI BaseModel path
    • Why this path: This function assumes standard ComfyUI model structure. For Forge models, model_sampling is at forge_objects.unet.model.model_sampling instead
    • Note: This function may need updating if Forge models need to be supported here
  3. Import BackendCONST (lines 360-363):

    • Same logic as rk_sampler_beta.py - imports Forge's CONST class if available
    • Why inside try-except: Prevents crashes if backend.modules.k_model is not available
  4. Dual CONST Check (line 364):

    • isinstance(modelsampling, model_sampling.CONST): Checks for ComfyUI CONST
    • (BackendCONST is not None and isinstance(modelsampling, BackendCONST)): Checks for Forge CONST
    • Logical OR: If either check is True, the function returns True
    • Why both checks are needed: Forge's ModelSamplingFluxWithConst inherits from backend.modules.k_model.CONST, not comfy.model_sampling.CONST

Why This File Needs CONST Detection:

  • RF Model Detection: RES4LYF uses this function to detect Flux1 models and apply special handling
  • Compatibility: Without the dual CONST check, Forge Flux1 models (including Nunchaku Flux1) would be incorrectly identified as non-RF models
  • Error Prevention: Incorrect identification would cause incorrect sampling behavior or crashes

Impact on RES4LYF:

  • Flux1 Support: Without this fix, Forge Flux1 models (including Nunchaku Flux1) wouldn't be detected as RF models, causing incorrect sampling
  • Compatibility: Ensures RES4LYF works correctly with both ComfyUI Flux1 and Forge Flux1 models

File: modules/RES4LYF/legacy/helper.py

Purpose: Helper functions for legacy RES4LYF samplers. This file contains utility functions for legacy samplers, including is_RF_model().

Critical Changes:

  1. is_RF_model() Function (lines 46-55): Modified to check both comfy.model_sampling.CONST and backend.modules.k_model.CONST

Modified Code:

def is_RF_model(model):
    from comfy import model_sampling
    modelsampling = model.inner_model.inner_model.model_sampling
    # Check both comfy.model_sampling.CONST and backend.modules.k_model.CONST
    # ModelSamplingFluxWithConst uses backend.modules.k_model.CONST
    try:
        from backend.modules.k_model import CONST as BackendCONST
    except ImportError:
        BackendCONST = None
    return isinstance(modelsampling, model_sampling.CONST) or (BackendCONST is not None and isinstance(modelsampling, BackendCONST))

Detailed Explanation:

Same as modules/RES4LYF/helper.py - identical logic for detecting Flux1 (RF) models with dual CONST check.

Why This File Needs the Same Fix:

  • Legacy Samplers: Legacy RES4LYF samplers also need to detect Flux1 models correctly
  • Consistency: Both helper files should use the same detection logic
  • Compatibility: Ensures legacy samplers work correctly with Forge Flux1 models (including Nunchaku Flux1)

File: modules/RES4LYF/legacy/samplers_tiled.py

Purpose: Legacy tiled sampler code. This file contains legacy tiled sampler implementations that directly import from ComfyUI.

Critical Changes:

  1. Path Management (lines 1-23): Modified to ensure import comfy resolves to ComfyUI-master/comfy instead of project root comfy

Modified Code:

import sys
import os
import copy
from functools import partial

from tqdm.auto import tqdm

import torch

# Ensure ComfyUI-master is in sys.path before importing comfy
# This ensures we use ComfyUI-master/comfy instead of the project root comfy directory
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
comfyui_master_path = os.path.join(project_root, "ComfyUI-master")
comfyui_master_path = os.path.normpath(comfyui_master_path)

if os.path.exists(comfyui_master_path):
    if comfyui_master_path not in sys.path:
        sys.path.insert(0, comfyui_master_path)
    # Remove project root comfy directory from sys.path if it exists
    project_comfy_path = os.path.join(project_root, "comfy")
    project_comfy_path = os.path.normpath(project_comfy_path)
    if project_comfy_path in sys.path:
        sys.path.remove(project_comfy_path)

import comfy.sd
import comfy.controlnet
import comfy.model_management
import comfy.sample
import comfy.sampler_helpers
import latent_preview

Detailed Explanation:

  1. Calculate project root (line 11):

    • os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))): Calculates project root from file location
    • Why 4 levels: __file__ is modules/RES4LYF/legacy/samplers_tiled.py, so:
      • os.path.abspath(__file__): Absolute path to samplers_tiled.py
      • First os.path.dirname(): modules/RES4LYF/legacy/
      • Second os.path.dirname(): modules/RES4LYF/
      • Third os.path.dirname(): modules/
      • Fourth os.path.dirname(): Project root
  2. Path management (lines 12-23):

    • Same logic as modules/paths.py - ensures ComfyUI-master is prioritized for comfy imports
    • Why this is needed: This file directly imports comfy modules. Without path management, it might import from the wrong directory
  3. Imports (lines 25-30):

    • import comfy.sd, import comfy.controlnet, etc.: After path management, these imports are guaranteed to resolve to ComfyUI-master/comfy
    • Why this matters: Legacy tiled samplers rely on ComfyUI's implementation. Using incorrect imports would cause crashes or incorrect behavior

Why This File Needs Path Management:

  • Direct Imports: This file directly imports from comfy modules, so it needs path management at the file level
  • Legacy Code: This is legacy code that may be executed before modules/paths.py runs, so file-level path management is necessary
  • Compatibility: Ensures legacy tiled samplers use the correct ComfyUI codebase

Category 5: Backend Files

File: backend/modules/k_model.py

Purpose: KModel wrapper class. This file contains the KModel class which wraps the actual diffusion model and is responsible for setting self.model_sampling based on the model type.

Critical Changes:

  1. CONST Class Definition (lines 16-31): Forge's CONST class implementation
  2. ModelSamplingFluxWithConst Class (lines 74-75): Inherits from ModelSamplingFlux and CONST
  3. KModel __init__ model_sampling Initialization (lines 98-130): Sets self.model_sampling for all model types (FLUX, FLOW, EPS, etc.)

Modified Code (CONST Class - lines 16-31):

class CONST:
    def calculate_input(self, sigma, noise):
        return noise

    def calculate_denoised(self, sigma, model_output, model_input):
        sigma = reshape_sigma(sigma, model_output.ndim)
        return model_input - model_output * sigma

    def noise_scaling(self, sigma, noise, latent_image, max_denoise=False):
        sigma = reshape_sigma(sigma, noise.ndim)
        return sigma * noise + (1.0 - sigma) * latent_image

    def inverse_noise_scaling(self, sigma, latent):
        sigma = reshape_sigma(sigma, latent.ndim)
        return latent / (1.0 - sigma)

Detailed Explanation:

  1. Class Purpose:

    • CONST: Forge's implementation of the CONST (Constant Variance) sampling type
    • Why Forge has its own CONST: Forge's ModelSamplingFluxWithConst needs to inherit from CONST, but ComfyUI's CONST is in comfy.model_sampling, which might not be available or might conflict. Forge defines its own CONST in backend.modules.k_model
  2. calculate_input() (line 17-18):

    • def calculate_input(self, sigma, noise): return noise
    • Purpose: Calculates the input to the model based on sigma and noise
    • For CONST: The input is simply the noise itself (no scaling needed)
  3. calculate_denoised() (line 20-22):

    • def calculate_denoised(self, sigma, model_output, model_input):
    • Purpose: Calculates the denoised latent from model output
    • Formula: model_input - model_output * sigma
    • Why: CONST models predict the noise directly, so denoised = input - noise * sigma
  4. noise_scaling() (line 24-26):

    • def noise_scaling(self, sigma, noise, latent_image, max_denoise=False):
    • Purpose: Scales noise and latent image for sampling
    • Formula: sigma * noise + (1.0 - sigma) * latent_image
    • Why: Interpolates between pure noise (sigma=1) and pure latent (sigma=0)
  5. inverse_noise_scaling() (line 28-30):

    • def inverse_noise_scaling(self, sigma, latent):
    • Purpose: Inverse of noise scaling (used for inpainting or other operations)
    • Formula: latent / (1.0 - sigma)
    • Why: Reverses the noise scaling operation

Modified Code (ModelSamplingFluxWithConst - lines 74-75):

class ModelSamplingFluxWithConst(ModelSamplingFlux, CONST):
    pass

Detailed Explanation:

  1. Multiple Inheritance:

    • ModelSamplingFluxWithConst(ModelSamplingFlux, CONST): Inherits from both ModelSamplingFlux and CONST
    • Why this pattern: Combines Flux time scheduling (ModelSamplingFlux) with CONST noise scaling (CONST)
    • Usage: Used by Flux1 models (both Nunchaku and standard) in Forge
  2. Why pass:

    • The class doesn't need any additional methods - it inherits all methods from both parent classes
    • Method Resolution Order (MRO): Python's MRO handles conflicts between parent classes

Modified Code (KModel init model_sampling - lines 98-130):

# ComfyUI標準のmodel_samplingを追加(ControlNet.pre_run()がmodel.model_samplingを期待するため)
if config is not None and hasattr(config, "model_type"):
    model_type = config.model_type
    if hasattr(model_type, "name"):
        import comfy.model_base
        from comfy.model_base import ModelType
        if model_type.name == "FLUX":
            self.model_sampling = ModelSamplingFluxWithConst(config)
        elif model_type.name == "FLOW":
            # Qwen Image uses ModelType.FLOW
            # Use ComfyUI's model_sampling function to create the correct ModelSampling class
            model_type_enum = ModelType.FLOW
            self.model_sampling = comfy.model_base.model_sampling(config, model_type_enum)
        elif model_type.name == "EPS":
            # SDXL and other EPS models use ModelType.EPS
            # Use ComfyUI's model_sampling function to create the correct ModelSampling class
            model_type_enum = ModelType.EPS
            self.model_sampling = comfy.model_base.model_sampling(config, model_type_enum)
        else:
            # For other model types, try to use ComfyUI's model_sampling function
            # This handles V_PREDICTION, V_PREDICTION_EDM, STABLE_CASCADE, EDM, etc.
            try:
                model_type_enum = getattr(ModelType, model_type.name, None)
                if model_type_enum is not None:
                    self.model_sampling = comfy.model_base.model_sampling(config, model_type_enum)
                else:
                    self.model_sampling = None
            except (AttributeError, TypeError):
                self.model_sampling = None
    else:
        self.model_sampling = None
else:
    self.model_sampling = None

Detailed Explanation:

  1. Purpose:

    • Sets self.model_sampling based on the model type (FLUX, FLOW, EPS, etc.)
    • Why this is needed: RES4LYF samplers need model_sampling to get sigma_min, sigma_max, and other sampling parameters
    • Location: This is where Forge models set model_sampling, which is why RES4LYF needs to access it at forge_objects.unet.model.model_sampling
  2. Check for config and model_type (line 99):

    • if config is not None and hasattr(config, "model_type"):: Checks if config exists and has model_type
    • Why this check: Prevents crashes if config is missing or invalid
  3. Get model_type name (line 101-102):

    • model_type = config.model_type
    • if hasattr(model_type, "name"):: Checks if model_type has a name attribute
    • Why this check: Prevents crashes if model_type is invalid
  4. Import ComfyUI model_base (line 103-104):

    • import comfy.model_base
    • from comfy.model_base import ModelType: Imports ComfyUI's model type enum
    • Why this is needed: Uses ComfyUI's model_sampling() factory function to create the correct ModelSampling class
  5. Handle FLUX (lines 105-106):

    • if model_type.name == "FLUX": self.model_sampling = ModelSamplingFluxWithConst(config)
    • Why: Flux1 models (both Nunchaku and standard) use ModelSamplingFluxWithConst
    • Location: Uses Forge's ModelSamplingFluxWithConst (which inherits from backend.modules.k_model.CONST)
  6. Handle FLOW (lines 107-111):

    • elif model_type.name == "FLOW": self.model_sampling = comfy.model_base.model_sampling(config, ModelType.FLOW)
    • Why: Qwen Image models (including Nunchaku Qwen Image) use ModelType.FLOW
    • Method: Uses ComfyUI's model_sampling() factory function to create the correct ModelSampling class
  7. Handle EPS (lines 112-116):

    • elif model_type.name == "EPS": self.model_sampling = comfy.model_base.model_sampling(config, ModelType.EPS)
    • Why: SDXL models (both Nunchaku and standard) use ModelType.EPS
    • Method: Uses ComfyUI's model_sampling() factory function to create the correct ModelSampling class
    • Critical Fix: This was missing in the original implementation, causing SDXL models to not work with RES4LYF
  8. Handle Other Model Types (lines 117-127):

    • Uses ComfyUI's model_sampling() factory function for other model types (V_PREDICTION, V_PREDICTION_EDM, STABLE_CASCADE, EDM, etc.)
    • Why try-except: Prevents crashes if the model type is unknown or unsupported
  9. Error Handling (lines 128-131):

    • If config or model_type is invalid, sets self.model_sampling = None
    • Why this matters: RES4LYF checks if model_sampling is None and raises a descriptive error if it is

Why This File is Critical:

  • Model Sampling Initialization: This is where Forge models set model_sampling, which RES4LYF needs to access
  • SDXL Fix: The EPS handling was missing, causing SDXL models (both Nunchaku and standard) to not work with RES4LYF
  • CONST Definition: Forge's CONST class is defined here, which is why RES4LYF needs to check both comfy.model_sampling.CONST and backend.modules.k_model.CONST

Impact on RES4LYF:

  • SDXL Support: Without the EPS handling fix, SDXL models wouldn't have model_sampling set, causing RES4LYF to fail
  • CONST Detection: Forge's CONST class is defined here, so RES4LYF needs to check both CONST classes to detect Flux1 models correctly
  • Model Sampling Access: This file sets model_sampling, which is why RES4LYF needs to access it at forge_objects.unet.model.model_sampling

Newly Created Files

File: Changelog/CHANGELOG.md

Purpose: Centralized changelog file containing detailed version history from version 1.3.0 down to 1.0.6.

Content Structure:

  1. Version 1.3.0: RES4LYF Sampler Support

    • Full support for RES4LYF samplers across all model types
    • Comprehensive sampler collection
    • Robust model detection and handling
  2. Version 1.2.1: Union ControlNet support for Nunchaku Qwen Image

    • Full Union ControlNet support for Nunchaku Qwen Image (QI) models
    • Multiple ControlNet models can be used simultaneously
  3. Version 1.2.0: LoRA support for Nunchaku Qwen Image and Z-Image models

    • Full LoRA support for Nunchaku Qwen Image (QI) and Z-Image (ZIT) models
    • Completely separated implementations
  4. Version 1.1.0: Union ControlNet support for Flux1 and Nunchaku Flux1

    • Full Union ControlNet support for both Flux1 and Nunchaku Flux1 models
  5. Version 1.0.7: ADetailer as built-in extension

    • Integrated ADetailer_without_mediapipe as a standard built-in feature
  6. Version 1.0.6: Nunchaku SDXL loader, LoRA loader, and ControlNet support completed

Why This File Exists:

  • Centralization: All changelog information is in one place, making it easy to track changes
  • Maintainability: When new versions are released, changelog can be updated in one location
  • Reference: README.md can link to this file instead of maintaining a detailed changelog inline

Impact on Documentation:

  • README.md Simplification: README.md no longer needs to maintain detailed changelog information inline
  • User Experience: Users can easily find detailed changelog information by following the link from README.md
  • Release Notes: GitHub releases can reference this file or include its content directly

Summary

This release adds comprehensive support for RES4LYF (RES4) samplers across all model types, including:

  1. Nunchaku Qwen Image (QI) Models: ✅ Full support via NunchakuQwenImageTransformer2DModel detection and ModelType.FLOW model_sampling
  2. Nunchaku Flux1 Models: ✅ Full support via SVDQFluxTransformer2DModel detection and ModelSamplingFluxWithConst with dual CONST check
  3. Nunchaku SDXL Models: ✅ Full support via SVDQUNet2DConditionModel detection and ModelType.EPS model_sampling
  4. Standard SDXL Models: ✅ Full support via IntegratedUNet2DConditionModel detection and ModelType.EPS model_sampling
  5. Standard SD1.5 Models: ✅ Full support via ModelType.EPS model_sampling (automatic, shares same path as SDXL)
  6. Standard Flux1 Models: ✅ Full support via IntegratedFluxTransformer2DModel detection and ModelSamplingFluxWithConst with dual CONST check
  7. Nunchaku Z-Image Turbo (ZIT) Models: ✅ Full support via ModelType.FLOW model_sampling (automatic, shares same path as QI)
  8. Standard Z-Image Turbo (ZIT) Models: ✅ Full support via ModelType.FLOW model_sampling (automatic, shares same path as QI)

Key Technical Achievements:

  • Robust Model Detection: Multi-path model_sampling access with fallbacks for all model structures
  • Dual CONST Detection: Checks both comfy.model_sampling.CONST and backend.modules.k_model.CONST for Flux1 models
  • Path Management: Ensures all import comfy statements resolve to ComfyUI-master/comfy
  • SDXL Fix: Fixed missing model_sampling initialization for SDXL models in backend/modules/k_model.py
  • Dynamic Sampler Registration: Programmatically registers all samplers from RK_SAMPLER_NAMES_BETA_NO_FOLDERS
  • Comprehensive Error Handling: Descriptive error messages help users debug issues quickly

Files Modified: 13 files across 5 categories
Files Created: 1 file (Changelog/CHANGELOG.md)
Total Changes: Over 1,000 lines of code modified, added, or removed


End of Release Notes