Fix: FLUX.2 encode_prompt dtype and add bitsandbytes int8+bfloat16 warning#13798
Open
CoderSATTY wants to merge 1 commit into
Open
Fix: FLUX.2 encode_prompt dtype and add bitsandbytes int8+bfloat16 warning#13798CoderSATTY wants to merge 1 commit into
CoderSATTY wants to merge 1 commit into
Conversation
Two related fixes for Flux2Pipeline:
1. Add a warning for bitsandbytes 8-bit + bfloat16 quantization.
This combination causes precision loss and corrupted images in
FLUX models. The warning alerts users immediately at pipeline
initialization and suggests using NF4 4-bit quantization instead.
2. Fix encode_prompt() for pre-computed embedding workflows.
- Skips prompt string formatting if embeddings are already provided.
- Automatically casts pre-computed embeddings to the exact precision
(dtype) expected by the pipeline. This prevents silent image
corruption when loading embeddings from a different pipeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes #13772
Two related fixes for the
Flux2Pipeline:Added a defensive warning for bitsandbytes 8-bit + bfloat16 quantization.
This specific combination causes precision loss (bfloat16 is internally downcasted to float16 during MatMul) which accumulates and corrupts images in FLUX models. The warning alerts users at pipeline initialization and suggests using NF4 4-bit quantization instead.
Fixed
encode_prompt()for pre-computed embedding workflows.dtype) anddeviceexpected by the pipeline. This prevents the silent precision mismatches that were causing corrupted/noisy outputs when passing embeddings between different pipeline instances.Testing
BitsAndBytesConfig(load_in_8bit=True)andtorch.bfloat16.NF4quantization.Before submitting
Who can review?
@yiyixuxu @sayakpaul