Instructions to use csssss/com2ai-klein-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use csssss/com2ai-klein-4b with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("csssss/com2ai-klein-4b", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -47,11 +47,9 @@ from sdnq import SDNQConfig
|
|
| 47 |
from diffusers import Flux2KleinPipeline, Flux2Transformer2DModel, GGUFQuantizationConfig
|
| 48 |
from huggingface_hub import hf_hub_download
|
| 49 |
|
| 50 |
-
# 设备与精度配置
|
| 51 |
device = "cuda"
|
| 52 |
dtype = torch.bfloat16
|
| 53 |
|
| 54 |
-
# 精准下载本仓库 GGUF 权重与配置文件
|
| 55 |
gguf_path = hf_hub_download(
|
| 56 |
repo_id="csssss/com2ai-klein-4b",
|
| 57 |
filename="transformer/flux-2-klein-4b-Q8_0.gguf",
|
|
@@ -62,7 +60,6 @@ config_path = hf_hub_download(
|
|
| 62 |
filename="transformer/config.json",
|
| 63 |
)
|
| 64 |
|
| 65 |
-
# 加载量化 Transformer
|
| 66 |
transformer = Flux2Transformer2DModel.from_single_file(
|
| 67 |
gguf_path,
|
| 68 |
quantization_config=GGUFQuantizationConfig(compute_dtype=dtype),
|
|
@@ -70,17 +67,14 @@ transformer = Flux2Transformer2DModel.from_single_file(
|
|
| 70 |
config=config_path
|
| 71 |
)
|
| 72 |
|
| 73 |
-
# 加载完整 FLUX 推理管道(含官方VAE)
|
| 74 |
pipe = Flux2KleinPipeline.from_pretrained(
|
| 75 |
"csssss/com2ai-klein-4b",
|
| 76 |
transformer=transformer,
|
| 77 |
torch_dtype=dtype
|
| 78 |
)
|
| 79 |
|
| 80 |
-
# 显存优化
|
| 81 |
pipe.enable_model_cpu_offload()
|
| 82 |
|
| 83 |
-
# 文生图推理示例
|
| 84 |
prompt = "A cat holding a sign that says hello world"
|
| 85 |
image = pipe(
|
| 86 |
prompt=prompt,
|
|
@@ -91,7 +85,6 @@ image = pipe(
|
|
| 91 |
generator=torch.Generator(device=device).manual_seed(0)
|
| 92 |
).images[0]
|
| 93 |
|
| 94 |
-
# 保存结果
|
| 95 |
image.save("flux-klein.png")
|
| 96 |
print("✅ 图像生成成功,已保存为 flux-klein.png")
|
| 97 |
```
|
|
|
|
| 47 |
from diffusers import Flux2KleinPipeline, Flux2Transformer2DModel, GGUFQuantizationConfig
|
| 48 |
from huggingface_hub import hf_hub_download
|
| 49 |
|
|
|
|
| 50 |
device = "cuda"
|
| 51 |
dtype = torch.bfloat16
|
| 52 |
|
|
|
|
| 53 |
gguf_path = hf_hub_download(
|
| 54 |
repo_id="csssss/com2ai-klein-4b",
|
| 55 |
filename="transformer/flux-2-klein-4b-Q8_0.gguf",
|
|
|
|
| 60 |
filename="transformer/config.json",
|
| 61 |
)
|
| 62 |
|
|
|
|
| 63 |
transformer = Flux2Transformer2DModel.from_single_file(
|
| 64 |
gguf_path,
|
| 65 |
quantization_config=GGUFQuantizationConfig(compute_dtype=dtype),
|
|
|
|
| 67 |
config=config_path
|
| 68 |
)
|
| 69 |
|
|
|
|
| 70 |
pipe = Flux2KleinPipeline.from_pretrained(
|
| 71 |
"csssss/com2ai-klein-4b",
|
| 72 |
transformer=transformer,
|
| 73 |
torch_dtype=dtype
|
| 74 |
)
|
| 75 |
|
|
|
|
| 76 |
pipe.enable_model_cpu_offload()
|
| 77 |
|
|
|
|
| 78 |
prompt = "A cat holding a sign that says hello world"
|
| 79 |
image = pipe(
|
| 80 |
prompt=prompt,
|
|
|
|
| 85 |
generator=torch.Generator(device=device).manual_seed(0)
|
| 86 |
).images[0]
|
| 87 |
|
|
|
|
| 88 |
image.save("flux-klein.png")
|
| 89 |
print("✅ 图像生成成功,已保存为 flux-klein.png")
|
| 90 |
```
|