MCPcopy Index your code
hub / github.com/Kosinkadink/ComfyUI-Advanced-ControlNet

github.com/Kosinkadink/ComfyUI-Advanced-ControlNet @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
549 symbols 1,456 edges 25 files 6 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ComfyUI-Advanced-ControlNet

Nodes for scheduling ControlNet strength across timesteps and batched latents, as well as applying custom weights and attention masks. The ControlNet nodes here fully support sliding context sampling, like the one used in the ComfyUI-AnimateDiff-Evolved nodes. Currently supports ControlNets, T2IAdapters, ControlLoRAs, ControlLLLite, SparseCtrls, SVD-ControlNets, and Reference.

Custom weights allow replication of the "My prompt is more important" feature of Auto1111's sd-webui ControlNet extension via Soft Weights, and the "ControlNet is more important" feature can be granularly controlled by changing the uncond_multiplier on the same Soft Weights.

ControlNet preprocessors are available through comfyui_controlnet_aux nodes.

Features

  • Timestep and latent strength scheduling
  • Attention masks
  • Replicate "My prompt is more important" feature from sd-webui-controlnet extension via Soft Weights, and allow softness to be tweaked via base_multiplier
  • Replicate "ControlNet is more important" feature from sd-webui-controlnet extension via uncond_multiplier on Soft Weights
  • uncond_multiplier=0.0 gives identical results of auto1111's feature, but values between 0.0 and 1.0 can be used without issue to granularly control the setting.
  • ControlNet, T2IAdapter, and ControlLoRA support for sliding context windows
  • ControlLLLite support
  • ControlNet++ support
  • CtrLoRA support
  • Relevant models linked on CtrLoRA github page
  • SparseCtrl support
  • SVD-ControlNet support
  • Stable Video Diffusion ControlNets trained by CiaraRowles: Depth, Lineart
  • Reference support
  • Supports reference_attn, reference_adain, and refrence_adain+attn modes. style_fidelity and ref_weight are equivalent to style_fidelity and control_weight in Auto1111, respectively, and strength of the Apply ControlNet is the balance between ref-influenced result and no-ref result. There is also a Reference ControlNet (Finetune) node that allows adjust the style_fidelity, weight, and strength of attn and adain separately.

Table of Contents:

Scheduling Explanation

The two core concepts for scheduling are Timestep Keyframes and Latent Keyframes.

Timestep Keyframes hold the values that guide the settings for a controlnet, and begin to take effect based on their start_percent, which corresponds to the percentage of the sampling process. They can contain masks for the strengths of each latent, control_net_weights, and latent_keyframes (specific strengths for each latent), all optional.

Latent Keyframes determine the strength of the controlnet for specific latents - all they contain is the batch_index of the latent, and the strength the controlnet should apply for that latent. As a concept, latent keyframes achieve the same affect as a uniform mask with the chosen strength value.

advcn_image

Nodes

The ControlNet nodes provided here are the Apply Advanced ControlNet and Load Advanced ControlNet Model (or diff) nodes. The vanilla ControlNet nodes are also compatible, and can be used almost interchangeably - the only difference is that at least one of these nodes must be used for Advanced versions of ControlNets to be used (important for sliding context sampling, like with AnimateDiff-Evolved).

Key: - 🟩 - required inputs - 🟨 - optional inputs - 🟦 - start as widgets, can be converted to inputs - 🟥 - optional input/output, but not recommended to use unless needed - 🟪 - output

Apply Advanced ControlNet

image

Same functionality as the vanilla Apply Advanced ControlNet (Advanced) node, except with Advanced ControlNet features added to it. Automatically converts any ControlNet from ControlNet loaders into Advanced versions.

Inputs

  • 🟩positive: conditioning (positive).
  • 🟩negative: conditioning (negative).
  • 🟩control_net: loaded controlnet; will be converted to Advanced version automatically by this node, if it's a supported type.
  • 🟩image: images to guide controlnets - if the loaded controlnet requires it, they must preprocessed images. If one image provided, will be used for all latents. If more images provided, will use each image separately for each latent. If not enough images to meet latent count, will repeat the images from the beginning to match vanilla ControlNet functionality.
  • 🟨mask_optional: attention masks to apply to controlnets; basically, decides what part of the image the controlnet to apply to (and the relative strength, if the mask is not binary). Same as image input, if you provide more than one mask, each can apply to a different latent.
  • 🟨timestep_kf: timestep keyframes to guide controlnet effect throughout sampling steps.
  • 🟨latent_kf_override: override for latent keyframes, useful if no other features from timestep keyframes is needed. NOTE: this latent keyframe will be applied to ALL timesteps, regardless if there are other latent keyframes attached to connected timestep keyframes.
  • 🟨weights_override: override for weights, useful if no other features from timestep keyframes is needed. NOTE: this weight will be applied to ALL timesteps, regardless if there are other weights attached to connected timestep keyframes.
  • 🟦strength: strength of controlnet; 1.0 is full strength, 0.0 is no effect at all.
  • 🟦start_percent: sampling step percentage at which controlnet should start to be applied - no matter what start_percent is set on timestep keyframes, they won't take effect until this start_percent is reached.
  • 🟦stop_percent: sampling step percentage at which controlnet should stop being applied - no matter what start_percent is set on timestep keyframes, they won't take effect once this end_percent is reached.

Outputs

  • 🟪positive: conditioning (positive) with applied controlnets
  • 🟪negative: conditioning (negative) with applied controlnets

Load Advanced ControlNet Model

image

Loads a ControlNet model and converts it into an Advanced version that supports all the features in this repo. When used with Apply Advanced ControlNet node, there is no reason to use the timestep_keyframe input on this node - use timestep_kf on the Apply node instead.

Inputs

  • 🟥timestep_keyframe: optional and likely unnecessary input to have ControlNet use selected timestep_keyframes - should not be used unless you need to. Useful if this node is not attached to Apply Advanced ControlNet node, but still want to use Timestep Keyframe, or to use TK_SHORTCUT outputs from ControlWeights in the same scenario. Will be overriden by the timestep_kf input on Apply Advanced ControlNet node, if one is provided there.
  • 🟨model: model to plug into the diff version of the node. Some controlnets are designed for receive the model; if you don't know what this does, you probably don't want tot use the diff version of the node.

Outputs

  • 🟪CONTROL_NET: loaded Advanced ControlNet

Timestep Keyframe

image

Scheduling node across timesteps (sampling steps) based on the set start_percent. Chaining Timestep Keyframes allows ControlNet scheduling across sampling steps (percentage-wise), through a timestep keyframe schedule.

Inputs

  • 🟨prev_timestep_kf: used to chain Timestep Keyframes together to create a schedule. The order does not matter - the Timestep Keyframes sort themselves automatically by their start_percent. Any Timestep Keyframe contained in the prev_timestep_keyframe that contains the same start_percent as the Timestep Keyframe will be overwritten.
  • 🟨cn_weights: weights to apply to controlnet while this Timestep Keyframe is in effect. Must be compatible with the loaded controlnet, or will throw an error explaining what weight types are compatible. If inherit_missing is True, if no control_net_weight is passed in, will attempt to reuse the last-used weights in the timestep keyframe schedule. If Apply Advanced ControlNet node has a weight_override, the weight_override will be used during sampling instead of control_net_weight.
  • 🟨latent_keyframe: latent keyframes to apply to controlnet while this Timestep Keyframe is in effect. If inherit_missing is True, if no latent_keyframe is passed in, will attempt to reuse the last-used weights in the timestep keyframe schedule. If Apply Advanced ControlNet node has a latent_kf_override, the latent_lf_override will be used during sampling instead of latent_keyframe.
  • 🟨mask_optional: attention masks to apply to controlnets; basically, decides what part of the image the controlnet to apply to (and the relative strength, if the mask is not binary). Same as mask_optional on the Apply Advanced ControlNet node, can apply either one maks to all latents, or individual masks for each latent. If inherit_missing is True, if no mask_optional is passed in, will attempt to reuse the last-used mask_optional in the timestep keyframe schedule. It is NOT overriden by mask_optional on the Apply Advanced ControlNet node; will be used together.
  • 🟦start_percent: sampling step percentage at which this Timestep Keyframe qualifies to be used. Acts as the 'key' for the Timestep Keyframe in the timestep keyframe schedule.
  • 🟦strength: strength of the controlnet; multiplies the controlnet by this value, basically, applied alongside the strength on the Apply ControlNet node. If set to 0.0 will not have any effect during the duration of this Timestep Keyframe's effect, and will increase sampling speed by not doing any work.
  • 🟦null_latent_kf_strength: strength to assign to latents that are unaccounted for in the passed in latent_keyframes. Has no effect if no latent_keyframes are passed in, or no batch_indeces are unaccounted in the latent_keyframes for during sampling.
  • 🟦inherit_missing: determines if should reuse values from previous Timestep Keyframes for optional values (control_net_weights, latent_keyframe, and mask_option) that are not included on this TimestepKeyframe. To inherit only specific inputs, use default inputs.
  • 🟦guarantee_steps: when 1 or greater, even if a Timestep Keyframe's start_percent ahead of this one in the schedule is closer to current sampling percentage, this Timestep Keyframe will still be used for the specified amount of steps before moving on to the next selected Timestep Keyframe in the following step. Whether the Timestep Keyframe is used or not, its inputs will still be accounted for inherit_missing purposes.

Outputs

  • 🟪TIMESTEP_KF: the created Timestep Keyframe, that can either be linked to another or into a Timestep Keyframe input.

Timestep Keyframe Interpolation

image

Allows to create Timestep Keyframe with interpolated strength values in a given percent range. (The first generated keyframe will have guarantee_steps=1, rest that follow will have guarantee_steps=0).

Inputs

  • 🟨prev_timestep_kf: used to chain Timestep Keyframes together to create a schedule. The order does not matter - the Timestep Keyframes sort themselves automatically by their start_percent. Any Timestep Keyframe contained in the prev_timestep_keyframe that contains the same start_percent as the Timestep Keyframe will be overwritten.
  • 🟨cn_weights: weights to apply to controlnet while this Timestep Keyframe is in effect. Must be compatible with the loaded controlnet, or will throw an error explaining what weight types are compatible. If inherit_missing is True, if no control_net_weight is passed in, will attempt to reuse the last-used weights in the timestep keyframe schedule. If Apply Advanced ControlNet node has a weight_override, the weight_override will be used during sampling instead of control_net_weight.
  • 🟨latent_keyframe: latent keyframes to apply to controlnet while this Timestep Keyframe is in effect. If inherit_missing is True, if no latent_keyframe is passed in, will attempt to reuse the last-used weights in the timestep keyframe schedule. If Apply Advanced ControlNet node has a latent_kf_override, the latent_lf_override will be used during sampling instead of latent_keyframe.
  • 🟨mask_optional: attention masks to apply to controlnets; basically, decides what part of the image the controlnet to apply to (and the relative strength, if the mask is not binary). Same as mask_optional on the Apply Advanced ControlNet node, can apply either one maks to all latents, or individual masks for each latent. If inherit_missing is True, if no mask_optional is passed in, will attempt to reuse the last-used mask_optional in the timestep keyframe schedule. It is NOT overriden by mask_optional on the Apply Advanced ControlNet node; will be used together.
  • 🟦start_percent: sampling step percentage at which the first generated Timestep Keyframe qualifies to be used.
  • 🟦end_percent: sampling step percentage at which the last generated Timestep Keyframe q

Core symbols most depended-on inside this repo

format
called by 74
adv_control/logger.py
to
called by 66
adv_control/control_lllite.py
get
called by 60
adv_control/utils.py
default
called by 17
adv_control/utils.py
add
called by 16
adv_control/utils.py
copy
called by 9
adv_control/control.py
clone
called by 9
adv_control/utils.py
copy_to_advanced
called by 9
adv_control/utils.py

Shape

Method 352
Class 112
Function 85

Languages

Python98%
TypeScript2%

Modules by API surface

adv_control/utils.py101 symbols
adv_control/control_reference.py98 symbols
adv_control/control.py58 symbols
adv_control/control_plusplus.py38 symbols
adv_control/control_sparsectrl.py32 symbols
adv_control/nodes_deprecated.py30 symbols
adv_control/nodes_weight.py27 symbols
adv_control/control_lllite.py26 symbols
adv_control/nodes_keyframes.py24 symbols
adv_control/nodes_sparsectrl.py18 symbols
adv_control/dinklink.py18 symbols
adv_control/nodes_main.py12 symbols

For agents

$ claude mcp add ComfyUI-Advanced-ControlNet \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact