[Fix] diffusion/flux: use true_cfg_scale as the FLUX CFG weight (#44260)
This commit is contained in:
@@ -125,6 +125,12 @@ class FluxPipelineConfig(ImagePipelineConfig):
|
||||
def prepare_sigmas(self, sigmas, num_inference_steps):
|
||||
return self._prepare_sigmas(sigmas, num_inference_steps)
|
||||
|
||||
def get_classifier_free_guidance_scale(self, batch, guidance_scale: float) -> float:
|
||||
# true_cfg_scale is the CFG weight when given, as in diffusers FluxPipeline.
|
||||
if batch.true_cfg_scale is not None:
|
||||
return batch.true_cfg_scale
|
||||
return guidance_scale
|
||||
|
||||
def prepare_latent_shape(self, batch, batch_size, num_frames):
|
||||
height = 2 * (
|
||||
batch.height // (self.vae_config.arch_config.vae_scale_factor * 2)
|
||||
|
||||
@@ -1411,7 +1411,7 @@ class SamplingParams:
|
||||
"--true-cfg-scale",
|
||||
type=float,
|
||||
dest="true_cfg_scale",
|
||||
help="True CFG scale for models that distinguish distilled guidance from standard CFG (e.g., Qwen-Image)",
|
||||
help="True CFG scale for models that distinguish distilled guidance from standard CFG (e.g., Qwen-Image, FLUX.1)",
|
||||
)
|
||||
add_argument(
|
||||
"--guidance-rescale",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from sglang.multimodal_gen.configs.pipeline_configs.flux import (
|
||||
Flux2PipelineConfig,
|
||||
FluxPipelineConfig,
|
||||
)
|
||||
|
||||
|
||||
class TestFluxTrueCFGScale(unittest.TestCase):
|
||||
def test_true_cfg_scale_is_the_cfg_weight(self):
|
||||
for config in (FluxPipelineConfig(), Flux2PipelineConfig()):
|
||||
with self.subTest(config=type(config).__name__):
|
||||
batch = SimpleNamespace(true_cfg_scale=4.0)
|
||||
self.assertEqual(
|
||||
config.get_classifier_free_guidance_scale(batch, 3.5), 4.0
|
||||
)
|
||||
|
||||
def test_guidance_scale_is_the_cfg_weight_without_true_cfg_scale(self):
|
||||
batch = SimpleNamespace(true_cfg_scale=None)
|
||||
self.assertEqual(
|
||||
FluxPipelineConfig().get_classifier_free_guidance_scale(batch, 3.5), 3.5
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user