black-forest-labs/flux

GitHub: black-forest-labs/flux

Black Forest Labs FLUX.1 系列开放权重图像生成与编辑模型的官方本地推理代码库,支持文生图、图像编辑、结构条件控制等多种生成任务。

Stars: 25620 | Forks: 1891

# FLUX 由 Black Forest Labs 提供:https://bfl.ai。 我们的 API 文档可以在这里找到:[docs.bfl.ai](https://docs.bfl.ai/)。 ![grid](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/12969f82f8181958.jpg) 本仓库包含使用我们的 Flux 开放权重模型进行图像生成和编辑的最简推理代码。 ## 本地安装 ``` cd $HOME && git clone https://github.com/black-forest-labs/flux cd $HOME/flux python3.10 -m venv .venv source .venv/bin/activate pip install -e ".[all]" ``` ### 支持 TensorRT 的本地安装 如果你想安装支持 [TensorRT](https://github.com/NVIDIA/TensorRT) 的仓库,目前你需要改为安装 NVIDIA 提供的 PyTorch 镜像。首先安装 [enroot](https://github.com/NVIDIA/enroot),接下来按照以下步骤操作: ``` cd $HOME && git clone https://github.com/black-forest-labs/flux enroot import 'docker://$oauthtoken@nvcr.io#nvidia/pytorch:25.01-py3' enroot create -n pti2501 nvidia+pytorch+25.01-py3.sqsh enroot start --rw -m ${PWD}/flux:/workspace/flux -r pti2501 cd flux pip install -e ".[tensorrt]" --extra-index-url https://pypi.nvidia.com ``` ### 开放权重模型 我们提供了丰富的开放权重模型套件。有关各个模型的更多信息,请参阅 **用法** 下的链接。 | 名称 | 用法 | HuggingFace 仓库 | 许可证 | | --------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- | --------------------------------------------------------------------- | | `FLUX.1 [schnell]` | [文生图](docs/text-to-image.md) | https://huggingface.co/black-forest-labs/FLUX.1-schnell | [apache-2.0](model_licenses/LICENSE-FLUX1-schnell) | | `FLUX.1 [dev]` | [文生图](docs/text-to-image.md) | https://huggingface.co/black-forest-labs/FLUX.1-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Fill [dev]` | [图像内/外补绘制](docs/fill.md) | https://huggingface.co/black-forest-labs/FLUX.1-Fill-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Canny [dev]` | [结构条件控制](docs/structural-conditioning.md) | https://huggingface.co/black-forest-labs/FLUX.1-Canny-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Depth [dev]` | [结构条件控制](docs/structural-conditioning.md) | https://huggingface.co/black-forest-labs/FLUX.1-Depth-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Canny [dev] LoRA` | [结构条件控制](docs/structural-conditioning.md) | https://huggingface.co/black-forest-labs/FLUX.1-Canny-dev-lora | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Depth [dev] LoRA` | [结构条件控制](docs/structural-conditioning.md) | https://huggingface.co/black-forest-labs/FLUX.1-Depth-dev-lora | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Redux [dev]` | [图像变体](docs/image-variation.md) | https://huggingface.co/black-forest-labs/FLUX.1-Redux-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Kontext [dev]` | [图像编辑](docs/image-editing.md) | https://huggingface.co/black-forest-labs/FLUX.1-Kontext-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | | `FLUX.1 Krea [dev]` | [文生图](docs/text-to-image.md) | https://huggingface.co/black-forest-labs/FLUX.1-Krea-dev | [FLUX.1-dev Non-Commercial License](model_licenses/LICENSE-FLUX1-dev) | 自动编码器的权重也在 [apache-2.0](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md) 协议下发布,可以在上面的 HuggingFace 仓库中找到。 ## API 用法 我们的 API 提供对所有模型的访问权限,包括我们的 Pro 级别非开放权重模型。查看我们的 API 文档 [docs.bfl.ai](https://docs.bfl.ai/) 以了解更多信息。 ## 商业用途模型许可 你可以在这里获取我们模型的商业使用许可:https://bfl.ai/pricing/licensing 由于费用是基于每月使用量计算的,我们提供了通过 BFL API 自动跟踪你使用情况的代码。要启用使用情况跟踪,请在 CLI 中选择 *track_usage*,或者在我们提供的演示中勾选相应的复选框。 ### 示例:启用使用情况跟踪使用 FLUX.1 Kontext 我们提供了一个参考实现,用于在启用商业许可的使用情况跟踪下运行 FLUX.1。 只要使用情况报告准确,就可以根据需要对其进行自定义。 要使报告逻辑生效,你需要在运行前将 API key 设置为环境变量: ``` export BFL_API_KEY="your_api_key_here" ``` 你可以像这样在激活跟踪的情况下调用 `FLUX.1 Kontext [dev]`: ``` python -m flux kontext --track_usage --loop ``` 对于单次生成: ``` python -m flux kontext --track_usage --prompt "replace the logo with the text 'Black Forest Labs'" ``` 上述报告逻辑对于 FLUX.1 [dev] 和 FLUX.1 Tools [dev] 的工作方式类似。 **请注意,只有在将我们的一个或多个开放权重模型用于商业用途时才需要此操作。有关商业许可的更多信息,请访问 [BFL 帮助中心](https://help.bfl.ai/collections/6939000511-licensing)。** ## 引用 如果你发现提供的代码或模型对你的研究有用,请考虑引用它们: ``` @misc{labs2025flux1kontextflowmatching, title={FLUX.1 Kontext: Flow Matching for In-Context Image Generation and Editing in Latent Space}, author={Black Forest Labs and Stephen Batifol and Andreas Blattmann and Frederic Boesel and Saksham Consul and Cyril Diagne and Tim Dockhorn and Jack English and Zion English and Patrick Esser and Sumith Kulal and Kyle Lacey and Yam Levi and Cheng Li and Dominik Lorenz and Jonas Müller and Dustin Podell and Robin Rombach and Harry Saini and Axel Sauer and Luke Smith}, year={2025}, eprint={2506.15742}, archivePrefix={arXiv}, primaryClass={cs.GR}, url={https://arxiv.org/abs/2506.15742}, } @misc{flux2024, author={Black Forest Labs}, title={FLUX}, year={2024}, howpublished={\url{https://github.com/black-forest-labs/flux}}, } ```
标签:AIGC, PyTorch, TensorRT, 人工智能, 凭据扫描, 图像生成, 文档结构分析, 模型推理, 深度学习, 用户模式Hook绕过, 逆向工具