---
title: FLUX.2-klein-base-4B-text-encoder-1B-distill
canonical_url: "https://www.modelscope.cn/models/DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill"
md_url: "https://www.modelscope.cn/models/DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill.md"
repository: DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill
chinese_name: "蒸馏1B版 FLUX.2-klein-base-4B 文本编码器 V1"
last_updated: 2026-04-28
pipeline_tag: text-to-image-synthesis
tasks:
  - text-to-image-synthesis
model_type:
  - qwen3
architectures:
  - Qwen3ForCausalLM
parameters: 1.3B
tensor_type:
  - F16
library_name:
  - safetensors
  - pytorch
frameworks:
  - Pytorch
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 371
stars: 4
---

# FLUX.2-klein-base-4B-text-encoder-1B-distill

> FLUX.2-klein-base-4B-text-encoder-1B-distill - DistilLab 在 ModelScope 开源的模型。FLUX.2-klein-base-4B-text-encoder-1B-distill

DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill 是 ModelScope 魔搭社区上的 1.3B 参数text-to-image-synthesis模型，可用 deploy_task text/emb、lmdeploy_turbomind 0.9.1、sglang 0.5.2 部署。

- **Repository**: DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill
- **Tasks**: text-to-image-synthesis
- **Parameters**: 1.3B
- **Inference backends**: deploy_task text/emb, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 371
- **Stars**: 4
- **Last updated**: 2026-04-28

Source: https://www.modelscope.cn/models/DistilLab/FLUX.2-klein-base-4B-text-encoder-1B-distill

---

# 蒸馏1B版FLUX.2-klein-base-4B文本编码器V1

## 模型特点

我们从 FLUX.2-klein-base-4B 的文本编码器中蒸馏出一个 **1B 参数量**的轻量化版本，解决原版文本编码器在部分设备上显存占用过大、推理速度慢的问题。该模型具备以下特点：
1.  在 220 万条文本数据上完成知识蒸馏，最终蒸馏损失降至 3.6
2.  参数量从4B 精简至 1B，显著降低显存占用并提升推理速度，fp16文件仅2.42GB大小
3.  对长文本、中等文本、短文本均能生成与原版编码器对齐的文本嵌入

## 效果展示

这是将FLUX.2-klein-base-4B的文本编码模型换成我们的编码模型后生成的图像效果：
![生成结果](./gen_images.png)

## 使用方法

### 推理环境
我们的推理是在一台 V100 32GB 显卡上进行（您可以在显存更低的显卡上进行推理）的，torch环境设置如下：
```
python 3.12
pytorch 2.10.0
cuda 12.8
```
### 目录构建
在进行推理之前，您需要构建一个如下格式的目录：
```dir
project/ 
├── models/ 
│   └── encoder_fp16
│   		├── config.json # 我们的模型配置文件 
│   		└── model.safetensors # 我们的模型
├── images/ # 这个目录用来存储生成的图像文件 
└── infer.py # 推理代码
```
您下载的模型文件名为 
```
student_fp16_v1.safetensors
``` 
因此，您需要在将模型放到 encoder_fp16 文件夹下后将其重命名为
```
model.safetensors
``` 

### 推理代码
将如下推理代码放到infer.py文件中：
```python
import torch
from diffusers import Flux2KleinPipeline
from transformers import Qwen3ForCausalLM
from torchvision.utils import make_grid, save_image
from torchvision.transforms.functional import to_tensor
  
DEVICE =  "cuda"  if torch.cuda.is_available() else  "cpu"
MODEL_ID =  "black-forest-labs/FLUX.2-klein-base-4B"
CACHE_DIR =  "models"
YOUR_LAYERS = (-7, -5, -3)
PROMPT = [
"""
Two fluffy cats, playful fighting, soft fur,
natural background, vivid realistic scene
""",
# """
# add more prompt you want
# """
]
SAVE_IMAGES =  r"images"
LIGHT_MODEL_PATH =  "models"
print("\nLoad the official model\n")
pipe = Flux2KleinPipeline.from_pretrained(
MODEL_ID,
torch_dtype=torch.float16,
cache_dir=CACHE_DIR,
text_encoder=None,
)
print("\nLoad your own encoding model\n")

light_encoder = Qwen3ForCausalLM.from_pretrained(
LIGHT_MODEL_PATH,
torch_dtype=torch.float16,
subfolder="encoder_fp16"
)
print("\nComponent replacement\n")
pipe.text_encoder = light_encoder
pipe.to(DEVICE)

print("\nmodel inference...\n")
image = pipe(
prompt=PROMPT,
text_encoder_out_layers=YOUR_LAYERS,
height=1024,
width=1024,
guidance_scale=7,
num_inference_steps=36,
).images
tensors = [to_tensor(img) for img in image]
grid = make_grid(tensors, nrow=1, padding=2)
save_image(grid, SAVE_IMAGES +  '/'  +  "output.png")
print("Generation completed.")
```

## 局限性
尽管在大量数据上进行了训练，但仍然在一些局限性：

-   模型基于原版编码器蒸馏得到，**对部分生成细节的编码可能略逊于原版**
-   部分场景下可能出现文本渲染缺失、语义理解偏差等问题
-   暂未完成大规模数据集上的量化指标验证

如在使用中遇到问题，欢迎反馈与交流。

## 注意事项
⚠️本模型仅作科研学习用途。
使用规范遵循原版 black-forest-labs/FLUX.2-klein-base-4B 要求。

## 证书（开源协议）
本模型基于FLUX.2-klein-base-4B原版模型衍生开发，整体遵循Apache 2.0开源协议授权使用， 完整协议条款可查阅：https://www.apache.org/licenses/LICENSE-2.0 

## 致谢
感谢 black-forest-labs 官方提供的 FLUX.2-klein-base-4B 模型，以及 Hugging Face diffusers 库提供的开源代码和推理支持。本工作离不开所有开源贡献者的支持。
