Skip to content

Repository files navigation

CodeQL ComfyUI Registry

Negative Rejection Steering

NRS seeks to replace the 'naive' linear interpolation of Classifier Free Guidance with a more nuanced and composable steering of the generation process with better mathematical basis.

TL;DR:

  1. CFG is a bad 'knob'
  2. NRS replaces CFG with 3 new knobs.
  3. NRS lets you to create cooler outputs than CFG.

Contributing: See CONTRIBUTING.md for development setup and guidelines.

Tip

Skip to the Beginner How-To if you want to just get started.

Math Demonstration

Expand for explanation of algorithm Graph of NRS vs CFG

NRS is Applied in Three Steps:

  1. V-Space: Optional pre-NRS step If the model is not using v-prediction, we transform the EPS cond and uncond into v-prediction space before continuing, then revert to eps-space before return.
  2. Skewing: The conditioned output tensor is skewed away from the direction of the rejection of the unconditioned tensor on the conditioned tensor. This lengthens the tensor in a direction perpendicular to its direction without affecting the positive guidance. The tensor is displaced by the rejection multiplied by the Skew parameter.1
  3. Stretching: The skewed tensor is stretched towards the direction of the original conditioned tensor based on its difference from the projection of uncond on cond. The stretch is multiplied by the Stretch parameter.1
  4. Squashing: The skewed and stretched tensor is rescaled towards the original length of the conditioned tensor. 100% squashing outputs the original length of the conditioned tensor simply 'steered' towards the skewed & squashed version's direction.1

Interactive Graph on Math3D.org

Examples of NRS Effects

Skew Skew Example Stretch Stretch Example Squash Squash Example

Generation details for reproduction
Prompt
Tool Stable Diffusion WebUI reForge
Sampler DPM++ 2M
Scheduler Align Your Steps
Steps 25
Dimensions 912 x 624
Seed 1334103348
Model Lobotomized Mix v1.5
Embeddings Lazy Embeddings for ALL illustrious NoobAI..., Smooth Embeddings
Positive lazypos, [Smooth_Quality|SmoothNoob_Quality], BREAK
very awa, masterpiece, best quality, year 2024, newest, highres, absurdres,
1girl, samurai archer, cyberpunk cityscape, rain-soaked rooftop, neon reflection puddles, volumetric mist,
photorealistic, digital art,
dramatic rim lighting, shallow depth of field, low angle viewpoint
Negative lazyloli, lazynsfw, BREAK
lazyhand, SmoothNegative_Hands-neg, BREAK
[Smooth_Negative-neg|SmoothNoob_Negative-neg], BREAK
lowres, worst quality, worst aesthetic, bad quality, jpeg artifacts, scan artifacts,
blurry, deformed anatomy, bad hands, extra fingers, missing fingers, mutated hands,
watermark, logo, text, nsfw

Explanation of Effects

Skew

Skew changes the 'direction' of your generation, altering the image generation to 'steer' away from negative prompt elements as they conflict with your positive prompt. Increasing Skew will change scene composition, geometry, and scene elements to ensure that the final image aligns with the intention of your prompt pair.

Stretch

Stretch changes the intensity of generated elements that align more with your positive prompt than the negative. This 'hits the gas' on any elements that are more strongly aligned with your positive prompt than your negative, and 'hit the brakes' on the opposite.

Squash

Squash is the speed limit. At 0.0 Squash, each diffusion step receives the full intensity you set from Skew and Stretch, while 1.0 Squash ensures each step has only the original step size output by the model. This setting will only remove intensity unless you have a non-zero Skew value. Squash will 'soften' the effects of Skew and Stretch as it's raised, but the 'removed' Skew and Stretch intensity is replaced by enhanced micro-detailing and 'burn'. Squash should generally be left low and used as a 'finishing' step after dialing in a decent Skew and Stretch value.

Beginner How-To

  1. Set Skew to 1/2 of your normal CFG Scale setting and Stretch to your full normal CFG Scale. Set Squash to 0.0.
    Alternatively, try starting with the default of 2/5/0.75, or at 1/1/1 to get a baseline.
  2. Test some outputs. Results should be similar in quality to CFG.
  3. Adjust Skew to change the intensity of your outputs adherence to your positive and negative prompts. This primarily effects composition of the output.
  4. Adjust Stretch to intensify your positive prompt's aspects and colors where they differ from the negative prompt. This primarily effects color and texture.
  5. Adjust Squash to soften Skew and Stretch's effects. The intensity removed from Skew and Stretch will generally become additional micro-detailing and elements.

Tip

You can experiment with negative values for each setting as well. This can be useful to understand how the model interpreting your negative prompt.

Warning

Don't set NRS values to negatives if there are things in your negative prompt you actually don't want to see.

Setup & Installation

ComfyUI

ComfyUI Setup Instructions

Installation

Install via ComfyUI Manager or manually clone this repository into your ComfyUI/custom_nodes/ directory.

Usage

  1. Important: Ignore the CFG setting on your KSampler node - NRS replaces CFG entirely
  2. Connect your model through the Negative Rejection Steering node before sampling
  3. Configure NRS parameters (Skew/Stretch/Squash) instead of using CFG

Basic Workflow

Model → NRS Node → KSampler

Pro tip: To verify NRS is working correctly, set CFG to an extremely high value (like 30). If your output looks normal, NRS is functioning properly. If the output appears "turbo fried," check your node connections.

Sampler Compatibility: NRS now supports advanced samplers including WanKSamplerAdvanced, RES4LYF samplers, and FLOW models (WAN21, Flux) with enhanced prediction type detection.

ComfyUI Workflow Example

Automatic1111 / Forge / reForge

WebUI Setup Instructions

Installation

  1. Install the extension through the Extensions tab in your WebUI
  2. Enable the extension and restart your WebUI

Usage

Once installed and enabled, the NRS settings panel will appear in your generation interface. When NRS is active:

  • CFG Scale is ignored - the WebUI may still show the CFG setting, but it has no effect
  • Use the NRS parameters (Skew/Stretch/Squash) to control generation instead
  • Follow the same parameter guidelines from the Beginner How-To section

StabilityMatrix Integration

NRS is available as a natively supported module in StabilityMatrix, providing an easy installation and management option for users of that platform.

Submitted User Examples

User CFG NRS
Mohnjiles from StabilityMatrix CFG Example NRS Example

Footnotes

  1. All operations are done per feature across the step's batch, width, and height. 2 3

About

Extension for Forge-based UIs (Forge, reForge, etc) and ComfyUI to replace CFG with Negative Rejection Steering

Resources

Contributing

Stars

16 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages