在M3 Mac上使用Diffusers运行Flux.1


8 个月前

在M3芯片的Mac上运行Flux.1并使用Diffusers。

什么是扩散器?

[GitHub - huggingface/diffusers: 🤗 Diffusers: 用于图像和音频的最先进的扩散模型...]

🤗 扩散器:用于图像和音频生成的最先进扩散模型,支持PyTorch和FLAX。 ……

github.com

https://github.com/huggingface/diffusers)1. 创建一个虚拟环境 python3 -m venv fluxtest source fluxtest/bin/activate

  1. 通过命令行界面登录Hugging Face

https://huggingface.co/docs/huggingface_hub/main/en/guides/clipip install -U "huggingface_hub[cli]" huggingface-cli login

  1. 安装包 pip install torch==2.3.1 pip install git+https://github.com/huggingface/diffusers.git pip install transformers==4.43.3 sentencepiece==0.2.0 accelerate==0.33.0 protobuf==5

  2. 运行一个Python脚本 ``` import torch from diffusers import FluxPipeline import diffusers

_flux_rope = diffusers.models.transformers.transformer_flux.rope def new_flux_rope(pos: torch.Tensor, dim: int, theta: int) -> torch.Tensor: assert dim % 2 == 0, "The dimension must be even." if pos.device.type == "mps": return _flux_rope(pos.to("cpu"), dim, theta).to(device=pos.device) else: return _flux_rope(pos, dim, theta)

diffusers.models.transformers.transformer_flux.rope = new_flux_rope

pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", revision='refs/pr/1', torch_dtype=torch.bfloat16).to("mps")

prompt = "japanese girl, photo-realistic" out = pipe( prompt=prompt, guidance_scale=0., height=1024, width=1024, num_inference_steps=4, max_sequence_length=256, ).images[0] out.save("image.png") ```

python image.py

输出

从Lucataco那里得到了脚本!

在M3 Mac上使用ComfyUI运行Flux.1 在M3 Mac上使用ComfyUI运行FLUX.1

什么是FLUX.1

https://koji-kanao.medium.com/run-flux-1-with-comfyui-on-m3-mac-132424976761)

FluxAI 中文

© 2025. All Rights Reserved