欢迎光临
我们一直在努力

使用 Diffuser 运行 Fluxn Mac

什么是扩散器?

github-readme-tag”>

使用 Diffuser 运行 Fluxn Mac

拥抱脸
/
扩散器

? diffusers:最先进的扩散模型,用于 pytorch 和 flax 中的图像和音频生成。

使用 Diffuser 运行 Fluxn Mac

使用 Diffuser 运行 Fluxn Mac使用 Diffuser 运行 Fluxn Mac使用 Diffuser 运行 Fluxn Mac使用 Diffuser 运行 Fluxn Mac使用 Diffuser 运行 Fluxn Mac

? diffusers 是最先进的预训练扩散模型的首选库,用于生成图像、音频甚至分子的 3d 结构。无论您是在寻找简单的推理解决方案还是训练自己的扩散模型,? diffusers 都是一个支持两者的模块化工具箱。我们的库的设计重点是可用性而不是性能,简单而不是简单,可定制性而不是抽象。

? diffusers 提供三个核心组件:

  • 最先进的扩散管道,只需几行代码即可在推理中运行。
  • 可互换的噪声调度器,用于不同的扩散速度和输出质量。
  • 预训练模型可用作构建块,并与调度程序相结合,用于创建您自己的端到端扩散系统。

安装

我们建议在 pypi 或 conda 的虚拟环境中安装 ? diffusers。有关安装 pytorch 和 flax 的更多详细信息,请参阅他们的官方文档。

pytorch

与点(官方…

在 github 上查看

什么是助焊剂

https://blackforestlabs.ai/announcing-black-forest-labs/

1. 创建虚拟环境

python3 -m venv fluxtest
source fluxtest/bin/activate

2. 通过 cli 登录 hugging face

https://huggingface.co/docs/huggingface_hub/main/en/guides/cli

pip install -u "huggingface_hub[cli]"
huggingface-cli login

3.安装包

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

4. 运行python脚本

图像.py

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脚本生成图像。

python image.py

输出

使用 Diffuser 运行 Fluxn Mac

赞(0) 打赏
未经允许不得转载:码农资源网 » 使用 Diffuser 运行 Fluxn Mac
分享到

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册