File size: 2,421 Bytes
0edd0cf
 
 
d71310e
 
 
 
08be3bf
 
 
d71310e
6313156
d71310e
6313156
d71310e
6313156
d71310e
4bca587
6313156
d71310e
6313156
d71310e
6313156
d71310e
 
 
 
 
 
 
6313156
 
 
4bca587
6313156
d71310e
 
 
 
 
 
 
 
 
6313156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0edd0cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
pipeline_tag: image-to-image
---
# FLUX\.2\-klein\-4B 整合GGUF权重包


```Plain Text
---
license: apache-2.0
---
```

## 模型说明

本仓库为**整合版权重仓库**,仅做文件归集、整合打包,无任何权重训练、微调、参数修改操作:

- **GGUF量化Transformer主干**:来源于 `unsloth/FLUX.2-klein-4B-GGUF`
采用 Unsloth Dynamic 2\.0 量化方案。

- **VAE、模型配置、原生配套资源**:来源于官方基座 `black-forest-labs/FLUX.2-klein-4B`

## 原始来源链接

- GGUF量化主干模型:[https://huggingface\.co/unsloth/FLUX\.2\-klein\-4B\-GGUF](https://huggingface.co/unsloth/FLUX.2-klein-4B-GGUF)

- FLUX\.2\-klein\-4B 官方原始基座:[https://huggingface\.co/black\-forest\-labs/FLUX\.2\-klein\-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B)

## 修改说明

本项目仅将两个上游仓库资源整合归集:将 Unsloth 量化的 GGUF Transformer 权重,与官方完整 VAE、模型配置文件合并为一体,方便本地diffusers  GGUF 推理、。**未修改权重参数、未微调、未重量化、未蒸馏**。



## 快速使用 / 推理示例

### 安装依赖

```Plain Text
pip install torch sdnq diffusers huggingface-hub
```

### 完整可运行代码

```Plain Text
import torch
from sdnq import SDNQConfig
from diffusers import Flux2KleinPipeline, Flux2Transformer2DModel, GGUFQuantizationConfig
from huggingface_hub import hf_hub_download

device = "cuda"
dtype = torch.bfloat16

gguf_path = hf_hub_download(
    repo_id="csssss/com2ai-klein-4b",
    filename="transformer/flux-2-klein-4b-Q8_0.gguf",
)

config_path = hf_hub_download(
    repo_id="csssss/com2ai-klein-4b",
    filename="transformer/config.json",
)

transformer = Flux2Transformer2DModel.from_single_file(
    gguf_path, 
    quantization_config=GGUFQuantizationConfig(compute_dtype=dtype),
    torch_dtype=dtype,
    config=config_path
)

pipe = Flux2KleinPipeline.from_pretrained(
    "csssss/com2ai-klein-4b",
    transformer=transformer,
    torch_dtype=dtype
)

pipe.enable_model_cpu_offload()

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

image.save("flux-klein.png")
print("✅ 图像生成成功,已保存为 flux-klein.png")
```