99from fastvideo .configs .models .dits .flux_2 import Flux2Config
1010from fastvideo .configs .models .encoders import BaseEncoderOutput
1111from fastvideo .configs .models .encoders .base import EncoderArchConfig
12+ from fastvideo .configs .models .encoders .mistral3 import Mistral3TextConfig
1213from fastvideo .configs .models .encoders .qwen3 import Qwen3TextConfig
1314from fastvideo .configs .models .vaes .flux2vae import Flux2VAEConfig
1415from fastvideo .configs .pipelines .base import PipelineConfig , preprocess_text
1718@dataclass
1819class Flux2PipelineConfig (PipelineConfig ):
1920 """Configuration for Flux2 image generation pipeline."""
20-
21+
2122 # Flux2-specific parameters
22- embedded_cfg_scale : float = 4.0
23-
23+ embedded_cfg_scale : float | None = 4.0
24+ flux2_text_encoder_type : str = "mistral3"
25+ text_encoder_out_layers : tuple [int , ...] = (10 , 20 , 30 )
26+
2427 # DiT configuration
2528 dit_config : DiTConfig = field (default_factory = Flux2Config )
2629 dit_precision : str = "bf16"
27-
30+
2831 # VAE configuration
2932 vae_config : VAEConfig = field (default_factory = Flux2VAEConfig )
3033 vae_precision : str = "fp32"
3134 vae_tiling : bool = False # Flux2 is image model, disable tiling by default
3235 vae_sp : bool = False
33-
34- # Text encoder configuration (Flux2 uses Mistral/Qwen)
35- text_encoder_configs : tuple [EncoderConfig , ...] = field (
36- default_factory = lambda : (EncoderConfig (),)
37- )
38- text_encoder_precisions : tuple [str , ...] = field (
39- default_factory = lambda : ("bf16" ,)
40- )
41-
36+
37+ # Text encoder configuration (full Flux2 uses Mistral3)
38+ text_encoder_configs : tuple [EncoderConfig , ...] = field (default_factory = lambda : (Mistral3TextConfig (), ))
39+ text_encoder_precisions : tuple [str , ...] = field (default_factory = lambda : ("bf16" , ))
40+
4241 # Default postprocess function (can be overridden)
4342 @staticmethod
4443 def default_postprocess_text (outputs : BaseEncoderOutput ) -> torch .Tensor :
4544 """Default text postprocessing for Flux2."""
4645 return outputs .last_hidden_state
47-
48- postprocess_text_funcs : tuple [Callable [[BaseEncoderOutput ], torch .Tensor ], ...] = field (
49- default_factory = lambda : (Flux2PipelineConfig .default_postprocess_text ,)
50- )
46+
47+ postprocess_text_funcs : tuple [Callable [[BaseEncoderOutput ], torch .Tensor ],
48+ ...] = field (default_factory = lambda : (Flux2PipelineConfig .default_postprocess_text , ))
5149
5250
5351def flux2_klein_postprocess_text (outputs : BaseEncoderOutput ) -> torch .Tensor :
@@ -57,9 +55,7 @@ def flux2_klein_postprocess_text(outputs: BaseEncoderOutput) -> torch.Tensor:
5755 raise ValueError ("Flux2 Klein requires output_hidden_states=True from text encoder" )
5856 out = torch .stack ([outputs .hidden_states [k ] for k in hidden_states_layers ], dim = 1 )
5957 batch_size , num_channels , seq_len , hidden_dim = out .shape
60- prompt_embeds = out .permute (0 , 2 , 1 , 3 ).reshape (
61- batch_size , seq_len , num_channels * hidden_dim
62- )
58+ prompt_embeds = out .permute (0 , 2 , 1 , 3 ).reshape (batch_size , seq_len , num_channels * hidden_dim )
6359 return prompt_embeds
6460
6561
@@ -79,15 +75,10 @@ class Flux2KleinTextEncoderConfig(EncoderConfig):
7975class Flux2KleinPipelineConfig (Flux2PipelineConfig ):
8076 """Configuration for Flux2 Klein (distilled, 4-step, no guidance)."""
8177 embedded_cfg_scale : float | None = None # Klein distilled: no guidance embedding (matches Diffusers)
82- text_encoder_configs : tuple [EncoderConfig , ...] = field (
83- default_factory = lambda : (Qwen3TextConfig (),)
84- )
85- text_encoder_precisions : tuple [str , ...] = field (
86- default_factory = lambda : ("bf16" ,)
87- )
88- preprocess_text_funcs : tuple [Callable [[str ], str ], ...] = field (
89- default_factory = lambda : (preprocess_text ,)
90- )
91- postprocess_text_funcs : tuple [Callable [[BaseEncoderOutput ], torch .Tensor ], ...] = field (
92- default_factory = lambda : (flux2_klein_postprocess_text ,)
93- )
78+ flux2_text_encoder_type : str = "qwen3"
79+ text_encoder_out_layers : tuple [int , ...] = (9 , 18 , 27 )
80+ text_encoder_configs : tuple [EncoderConfig , ...] = field (default_factory = lambda : (Qwen3TextConfig (), ))
81+ text_encoder_precisions : tuple [str , ...] = field (default_factory = lambda : ("bf16" , ))
82+ preprocess_text_funcs : tuple [Callable [[str ], str ], ...] = field (default_factory = lambda : (preprocess_text , ))
83+ postprocess_text_funcs : tuple [Callable [[BaseEncoderOutput ], torch .Tensor ],
84+ ...] = field (default_factory = lambda : (flux2_klein_postprocess_text , ))
0 commit comments