Skip to content

Alternative Skip Layer Guidance (SLG) node implementation #8759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025

Conversation

city96
Copy link
Contributor

@city96 city96 commented Jul 2, 2025

This PR adds a version of skip layer guidance (SLG) that only runs two passes, instead of running an extra one (current master). This cuts down on some of the compute overhead[1].

It also matches the logic found in deepbeepmeep/Wan2GP#61 and the results are closer to the outputs of ComfyUI-WanVideoWrapper by @kijai

I was playing around with this for a bit, and was getting better outputs when using it with Wan 2.1 than I was with the current SkipLayerGuidanceDiT node, though it works with other DiT models as well since the code is generic.

Here are some samples for comparison: (imgsli link)

slg_comp

Workflow screenshots

No SLG
no_slg

Old SLG
old_slg

New SLG
new_slg

Kijai SLG
kijai_slg

Speed figures for the L40 GPU I was testing on via runpod:

slg mode speed
None 20/20 [00:50<00:00, 2.53s/it]
Old 20/20 [01:16<00:00, 3.83s/it]
New 20/20 [00:51<00:00, 2.56s/it]

[1] I had to add a way to replace calc_cond_batch to do this, because that's the only place where cond/uncond are clearly separated and model_options is exposed.

Other ideas I considered:

  • pre_cfg_function - can replace uncond here with a separate pass, but that still has the compute overhead - Could add a force_cfg1_optimization arg to model options that forces skipping uncond, but that could cause issues for other things using pre_cfg_function depending on the order.
  • model_function_wrapper applied here - only exposes transformer options, would have to manually add skip block to only the uncond. Separating cond/uncond here is also messy if they're batched.
  • Inside the actual model where blocks_replace gets applied - replacement function doesn't have access to transformer_options / same issue with cond/uncond being batched
  • Custom guider - too much code duplication, annoying to refactor workflows around custom sampler just to use SLG.

I think it might be better to use a wrapper/hook but I haven't used that system enough to know whether it's possible or not. Tagging @Kosinkadink based on the PR for the original hooks update in case there's a better way, though I think this current version is relatively clean.

@comfyanonymous comfyanonymous merged commit d927730 into comfyanonymous:master Jul 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants