mirror of
https://github.com/huggingface/diffusers.git
synced 2026-06-09 00:21:19 +08:00
Some checks failed
Run dependency tests / check_dependencies (push) Waiting to run
Run Torch dependency tests / check_torch_dependencies (push) Waiting to run
Fast GPU Tests on main / Setup Torch Pipelines CUDA Slow Tests Matrix (push) Waiting to run
Fast GPU Tests on main / Torch Pipelines CUDA Tests (push) Blocked by required conditions
Fast GPU Tests on main / Torch CUDA Tests (lora) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (models) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (others) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (schedulers) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (single_file) (push) Waiting to run
Fast GPU Tests on main / PyTorch Compile CUDA tests (push) Waiting to run
Fast GPU Tests on main / PyTorch xformers CUDA tests (push) Waiting to run
Fast GPU Tests on main / Examples PyTorch CUDA tests on Ubuntu (push) Waiting to run
Fast tests on main / ${{ matrix.config.name }} (map[framework:pytorch image:diffusers/diffusers-pytorch-cpu name:Fast PyTorch CPU tests on Ubuntu report:torch_cpu runner:aws-general-8-plus]) (push) Waiting to run
Fast tests on main / ${{ matrix.config.name }} (map[framework:pytorch_examples image:diffusers/diffusers-pytorch-cpu name:PyTorch Example CPU tests on Ubuntu report:torch_example_cpu runner:aws-general-8-plus]) (push) Waiting to run
Secret Leaks / trufflehog (push) Waiting to run
Update Diffusers metadata / update_metadata (push) Waiting to run
Build documentation / build (push) Has been cancelled
* change syntax * make style
3.4 KiB
3.4 KiB
AWS Neuron
Diffusers 功能可在 AWS Inf2 实例上使用,这些是由 Neuron 机器学习加速器驱动的 EC2 实例。这些实例旨在提供更好的计算性能(更高的吞吐量、更低的延迟)和良好的成本效益,使其成为 AWS 用户将扩散模型部署到生产环境的良好选择。
Optimum Neuron 是 Hugging Face 库与 AWS 加速器之间的接口,包括 AWS Trainium 和 AWS Inferentia。它支持 Diffusers 中的许多功能,并具有类似的 API,因此如果您已经熟悉 Diffusers,学习起来更容易。一旦您创建了 AWS Inf2 实例,请安装 Optimum Neuron。
python -m pip install --upgrade-strategy eager optimum[neuronx]
Tip
我们提供预构建的 Hugging Face Neuron 深度学习 AMI(DLAMI)和用于 Amazon SageMaker 的 Optimum Neuron 容器。建议正确设置您的环境。
下面的示例演示了如何在 inf2.8xlarge 实例上使用 Stable Diffusion XL 模型生成图像(一旦模型编译完成,您可以切换到更便宜的 inf2.xlarge 实例)。要生成一些图像,请使用 [~optimum.neuron.NeuronStableDiffusionXLPipeline] 类,该类类似于 Diffusers 中的 [StableDiffusionXLPipeline] 类。
与 Diffusers 不同,您需要将管道中的模型编译为 Neuron 格式,即 .neuron。运行以下命令将模型导出为 .neuron 格式。
optimum-cli export neuron --model stabilityai/stable-diffusion-xl-base-1.0 \
--batch_size 1 \
--height 1024 `# 生成图像的高度(像素),例如 768, 1024` \
--width 1024 `# 生成图像的宽度(像素),例如 768, 1024` \
--num_images_per_prompt 1 `# 每个提示生成的图像数量,默认为 1` \
--auto_cast matmul `# 仅转换矩阵乘法操作` \
--auto_cast_type bf16 `# 将操作从 FP32 转换为 BF16` \
sd_neuron_xl/
现在使用预编译的 SDXL 模型生成一些图像。
>>> from optimum.neuron import Neu
ronStableDiffusionXLPipeline
>>> stable_diffusion_xl = NeuronStableDiffusionXLPipeline.from_pretrained("sd_neuron_xl/")
>>> prompt = "a pig with wings flying in floating US dollar banknotes in the air, skyscrapers behind, warm color palette, muted colors, detailed, 8k"
>>> image = stable_diffusion_xl(prompt).images[0]
欢迎查看Optimum Neuron 文档中更多不同用例的指南和示例!
