Alternative Skip Layer Guidance (SLG) node implementation #8759
+76
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
Workflow screenshots
No SLG

Old SLG

New SLG

Kijai SLG

Speed figures for the L40 GPU I was testing on via runpod:
[1] I had to add a way to replace
calc_cond_batch
to do this, because that's the only place wherecond
/uncond
are clearly separated andmodel_options
is exposed.Other ideas I considered:
pre_cfg_function
- can replaceuncond
here with a separate pass, but that still has the compute overhead - Could add aforce_cfg1_optimization
arg to model options that forces skipping uncond, but that could cause issues for other things usingpre_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.blocks_replace
gets applied - replacement function doesn't have access to transformer_options / same issue withcond
/uncond
being batchedI 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.