Apply x_embedder to controlnet to match hidden_states shape #691
+72
−2
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.
Motivation
Resolves #608, potentially other Controlnet related issues. After ComfyUI updated their Controlnet nodes it seems to have broken the Nunchaku implementation.
Nunchaku applies x_embedder to hidden_states in one of the forward calls but never applies the same to controlnet: https://github.com/nunchaku-tech/nunchaku/blob/ab324e25cc32420f36dfcab4d0f2180417f2d1d4/nunchaku/models/transformers/transformer_flux.py#L947
This mismatch doesnt get caught until the C++ FluxModel https://github.com/nunchaku-tech/nunchaku/blob/ab324e25cc32420f36dfcab4d0f2180417f2d1d4/src/FluxModel.cpp#L1286
Modifications
Ensure the controlnet tensor shapes match the expected hidden_states shape, and apply the x_embedder if applicable. Also adds some further assertions to fail earlier.
I imagine this would probably be better fixed at nunchaku/models/transformers/transformer_flux.py but I don't know diffusers well enough to test it outside of ComfyUI.