--- license: other license_name: flux-1-dev-non-commercial-license license_link: LICENSE.md datasets: - Lakonik/t2i-prompts-3m base_model: - black-forest-labs/FLUX.1-dev pipeline_tag: text-to-image library_name: diffusers --- # pi-Flow: Policy-Based Flow Models Distilled 4-step and 8-step FLUX.1 models proposed in the paper: **pi-Flow: Policy-Based Few-Step Generation via Imitation Distillation**
[Hansheng Chen](https://lakonik.github.io/)1, [Kai Zhang](https://kai-46.github.io/website/)2, [Hao Tan](https://research.adobe.com/person/hao-tan/)2, [Leonidas Guibas](https://geometry.stanford.edu/?member=guibas)1, [Gordon Wetzstein](http://web.stanford.edu/~gordonwz/)1, [Sai Bi](https://sai-bi.github.io/)2
1Stanford University, 2Adobe Research
[[arXiv](https://arxiv.org/abs/2510.14974)] [[Code](https://github.com/Lakonik/piFlow)] [[pi-Qwen Demo🤗](https://huggingface.co/spaces/Lakonik/pi-Qwen)] [[pi-FLUX Demo🤗](https://huggingface.co/spaces/Lakonik/pi-FLUX.1)] ![teaser](https://cdn-uploads.huggingface.co/production/uploads/638067fcb334960c987fbeda/H0J1LYUcSS5YqOwZqQ0Jb.jpeg) ## Usage Please first install the [official code repository](https://github.com/Lakonik/piFlow). We provide diffusers pipelines for easy inference. The following code demonstrates how to sample images from the distilled FLUX models. ### 4-NFE GM-FLUX (GMFlow Policy) Note: For the 8-NFE version, replace `gmflux_k8_piid_4step` with `gmflux_k8_piid_8step` and set `num_inference_steps=8`. ```python import torch from diffusers import FlowMatchEulerDiscreteScheduler from lakonlab.pipelines.piflux_pipeline import PiFluxPipeline pipe = PiFluxPipeline.from_pretrained( 'black-forest-labs/FLUX.1-dev', torch_dtype=torch.bfloat16) adapter_name = pipe.load_piflow_adapter( # you may later call `pipe.set_adapters([adapter_name, ...])` to combine other adapters (e.g., style LoRAs) 'Lakonik/pi-FLUX.1', subfolder='gmflux_k8_piid_4step', target_module_name='transformer') pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config( # use fixed shift=3.2 pipe.scheduler.config, shift=3.2, use_dynamic_shifting=False) pipe = pipe.to('cuda') out = pipe( prompt='A portrait photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the Sydney Opera House holding a sign on the chest that says "Welcome Friends"', width=1360, height=768, num_inference_steps=4, generator=torch.Generator().manual_seed(42), ).images[0] out.save('gmflux_4nfe.png') ``` ![gmflux_4nfe](https://cdn-uploads.huggingface.co/production/uploads/638067fcb334960c987fbeda/KJNf9OJjGj5tbCq_WmAIR.png) ### 4-NFE DX-FLUX (DX Policy) ``` import torch from diffusers import FlowMatchEulerDiscreteScheduler from lakonlab.pipelines.piflux_pipeline import PiFluxPipeline pipe = PiFluxPipeline.from_pretrained( 'black-forest-labs/FLUX.1-dev', policy_type='DX', policy_kwargs=dict( segment_size=1 / 3.5, # 1 / (nfe - 1 + final_step_size_scale) shift=3.2), torch_dtype=torch.bfloat16) adapter_name = pipe.load_piflow_adapter( # you may later call `pipe.set_adapters([adapter_name, ...])` to combine other adapters (e.g., style LoRAs) 'Lakonik/pi-FLUX.1', subfolder='dxflux_n10_piid_4step', target_module_name='transformer') pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config( # use fixed shift=3.2 pipe.scheduler.config, shift=3.2, use_dynamic_shifting=False) pipe = pipe.to('cuda') out = pipe( prompt='A portrait photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the Sydney Opera House holding a sign on the chest that says "Welcome Friends"', width=1360, height=768, num_inference_steps=4, generator=torch.Generator().manual_seed(42), ).images[0] out.save('dxflux_4nfe.png') ``` ![dxflux_4nfe](https://cdn-uploads.huggingface.co/production/uploads/638067fcb334960c987fbeda/sSNJFtEecY41TsuciQQFL.png) ## Citation ``` @misc{piflow, title={pi-Flow: Policy-Based Few-Step Generation via Imitation Distillation}, author={Hansheng Chen and Kai Zhang and Hao Tan and Leonidas Guibas and Gordon Wetzstein and Sai Bi}, year={2025}, eprint={2510.14974}, archivePrefix={arXiv}, primaryClass={cs.LG}, url={https://arxiv.org/abs/2510.14974}, } ```