FLUX.2 klein 4B GGUF

提供商unsloth
分类image-to-image
许可证apache-2.0
下载量2.7K
星标11

简介

FLUX.2 klein 4B GGUF 是由 unsloth 团队量化压缩的轻量化图像生成模型,主打图生图(Image-to-Image)能力。它将原版 FLUX 的强大生成质量与 GGUF 格式的低显存占用相结合,极大地降低了运行门槛。对于个人开发者或 AI 爱好者来说,这意味着无需顶级 H100 显卡,在主流家用 GPU 甚至部分大内存 Mac 上即可流畅运行。它非常适合用于图像风格迁移、细节重绘或基于参考图的二次创作,是追求效率与质量平衡的理想选择。

核心亮点

  • GGUF 量化大幅降低显存占用,家用显卡可跑
  • 专注于图生图,支持高质量的图像风格转换
  • 由 unsloth 优化,推理速度快且部署简单
  • Apache-2.0 协议,对商业应用极其友好

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("unsloth/FLUX.2-klein-4B-GGUF")
tokenizer = AutoTokenizer.from_pretrained("unsloth/FLUX.2-klein-4B-GGUF")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download unsloth/FLUX.2-klein-4B-GGUF

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download unsloth/FLUX.2-klein-4B-GGUF config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('unsloth/FLUX.2-klein-4B-GGUF')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/unsloth/FLUX.2-klein-4B-GGUF

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/unsloth/FLUX.2-klein-4B-GGUF

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('unsloth/FLUX.2-klein-4B-GGUF')
tokenizer = AutoTokenizer.from_pretrained('unsloth/FLUX.2-klein-4B-GGUF')

模型下载

我们推荐使用命令行或者 ModelScope SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 ModelScope:

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model unsloth/FLUX.2-klein-4B-GGUF

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model unsloth/FLUX.2-klein-4B-GGUF README.md --local_dir ./dir

更多更丰富的命令行下载选项,可参见具体文档

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('unsloth/FLUX.2-klein-4B-GGUF')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/unsloth/FLUX.2-klein-4B-GGUF.git

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/unsloth/FLUX.2-klein-4B-GGUF.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook 快速开发

下载并安装 ModelScope library

下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

模型加载和推理

模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'unsloth/FLUX.2-klein-4B-GGUF')

完整文档

来源: HuggingFace

---
base_model: black-forest-labs/FLUX.2-klein-4B
license: apache-2.0
language:

  • en

pipeline_tag: image-to-image
tags:
  • text-to-image

  • gguf

  • unsloth

  • image-editing

  • flux

  • diffusion-single-file

library_name: ggml
widget:
  • text: two astronauts playing basketball on mars

output:
url: assets/flux2klein4b.png
---

This is a GGUF quantized version of FLUX.2-klein-4B. <br>
unsloth/FLUX.2-klein-4B-GGUF uses Unsloth Dynamic 2.0 methodology for SOTA performance.

  • Important layers are upcasted to higher precision.

<div>
<div style="display: flex; gap: 5px; align-items: center; ">
<a href="https://github.com/unslothai/unsloth/">
<img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
</a>
<a href="https://discord.gg/unsloth">
<img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
</a>
<a href="https://docs.unsloth.ai/basics/unsloth-dynamic-2.0-ggufs">
<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
</a>
</div>
</div>

---
!Teaser
!Teaser
!Teaser

The FLUX.2 [klein] model family are our fastest image models to date. FLUX.2 [klein] unifies generation and editing in a single compact architecture, delivering state-of-the-art quality with end-to-end inference in as low as under a second. Built for applications that require real-time image generation without sacrificing quality, and runs on consumer hardware, with as little as 13GB VRAM.

FLUX.2 [klein] 4B is a 4 billion parameter rectified flow transformer capable of generating images from text descriptions and supports multi-reference editing capabilities.

Fully open under Apache 2.0. Our most accessible model runs on consumer GPUs like the RTX 3090/4070. Compact but capable: supports text-to-image, image editing, and multi-reference at quality that punches above its size. Built for local development, edge deployment, and production use.

For more information, please read our blog post.

Key Features

1. Our fastest distilled model for sub-second image generation.
2. Best suited for interactive workflows, production deployments, and latency-critical applications.
3. Text-to-image and image-to-image multi-reference editing in a single unified model.
4. Runs on consumer GPUs (~13GB VRAM).
5. Open weights available for commercial use under the Apache 2.0 license.

Usage

We provide a reference implementation of FLUX.2 [klein] 4B, as well as sampling code, in a dedicated GitHub repository. Developers and creatives looking to build on top of FLUX.2 [klein] 4B are encouraged to use this as a starting point.

API Endpoints

The FLUX.2 [klein] 4B model is available via the BFL API:

FLUX.2 [klein] 4B is also available in both ComfyUI and Diffusers.

Using with Diffusers 🧨

To use FLUX.2 [klein] 4B with the 🧨 Diffusers python library, first install or upgrade diffusers:

shell
pip install -U diffusers
Then you can use Flux2KleinPipeline to run the model:
python
import torch
from diffusers import Flux2KleinPipeline

device = "cuda"
dtype = torch.bfloat16

pipe = Flux2KleinPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-4B", torch_dtype=dtype)
pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU

prompt = "A cat holding a sign that says hello world"
image = pipe(
prompt,
height=1024,
width=1024,
guidance_scale=4.0,
num_inference_steps=4,
generator=torch.Generator(device=device).manual_seed(0)
).images[0]
image.save("flux-klein.png")

---
Limitations

  • This model is not intended or able to provide factual information.
  • While the model can output text, text rendered may be inaccurate or subject to distortion.
  • As a statistical model, this checkpoint may represent or amplify biases observed in the training data.
  • The model may fail to generate output that matches the prompts.
  • Prompt following is heavily influenced by the prompting style.

Out-of-Scope Use

The model and its derivatives may not be used:

  • In any way that violates applicable law.
  • For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; including but not limited to the solicitation, creation, acquisition, or dissemination of child exploitative content.
  • To generate or disseminate deceptive, fraudulent, misleading or otherwise harmful content.
  • To generate or disseminate personal identifiable information that can be used to harm an individual.
  • To harass, abuse, threaten, stalk, or bully individuals or groups of individuals.
  • To create non-consensual intimate imagery or illegal pornographic content.
  • For fully automated decision making or high risk applications that adversely impact an individual's legal rights or otherwise create or modify a binding, enforceable obligation.

Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.

Hardware

The FLUX.2 [klein] 4B model fits in ~13GB VRAM and is accessible on NVIDIA RTX 3090/4070 and above.

---
Responsible AI Development

Black Forest Labs is committed to the responsible development and deployment of our models. Prior to releasing the FLUX.2 family of models, we evaluated and mitigated a number of risks in our model checkpoints and hosted services, including the generation of unlawful content, including child sexual abuse material (CSAM) and nonconsensual intimate imagery (NCII). We implemented a series of pre-release mitigations to help prevent misuse by third parties, with additional post-release mitigations to help address residual risks:

1. Pre-training mitigation. We filtered pre-training data for multiple categories of "not safe for work" (NSFW) and known child sexual abuse material (CSAM) to help prevent a user generating unlawful content in response to text prompts or uploaded images. We have partnered with the https://www.iwf.org.uk/, an independent nonprofit organization dedicated to preventing online abuse, to filter known CSAM from the training data.
2. Post-training mitigation. Subsequently, we undertook multiple rounds of targeted fine-tuning to provide additional mitigation against potential abuse, including both text-to-image (T2I) and image-to-image (I2I) attacks. By inhibiting certain behaviors and suppressing certain concepts in the trained model, these techniques can help to prevent a user generating synthetic CSAM or NCII from a text prompt, or transforming an uploaded image into synthetic CSAM or NCII.
3. Ongoing evaluation. Throughout this process, we conducted multiple internal and external third-party evaluations of model checkpoints to identify further opportunities for mitigation. External third-party evaluations focused on eliciting CSAM and NCII through adversarial testing with (i) text-only prompts, (ii) a single uploaded reference image with text prompts, and (iii) multiple uploaded reference images with text prompts. Based on this feedback, we conducted further safety fine-tuning to produce our open-weight FLUX.2 [klein] models.
4. Release decision. After safety fine-tuning and prior to release, we conducted a final third-party evaluation of the proposed release checkpoints, focused on T2I and I2I generation of synthetic CSAM and NCII, including a comparison with other op