Views
No views yet
| Prompt: A meme with a happy expression. | Prompt: A meme with a sleepy expression. | Prompt: A meme with a surprised expression. |
|---|---|---|
![]() | ![]() | ![]() |
git clone https://github.com/modelscope/DiffSynth-Studio.git
cd DiffSynth-Studio
pip install -e .1from diffsynth.diffusion.template import TemplatePipeline
2from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig
3import torchpipe = Flux2ImagePipeline.from_pretrained(
torch_dtype=torch.bfloat16,
device="cuda",
model_configs=[
ModelConfig(model_id="black-forest-labs/FLUX.2-klein-base-4B", origin_file_pattern="transformer/*.safetensors"),
ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="text_encoder/*.safetensors"),
ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
],
tokenizer_config=ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="tokenizer/"),
)
template = TemplatePipeline.from_pretrained(
torch_dtype=torch.bfloat16,
device="cuda",
model_configs=[ModelConfig(model_id="DiffSynth-Studio/Template-KleinBase4B-PandaMeme")],
)
image = template(
pipe,
prompt="A meme with a sleepy expression.",
seed=0, cfg_scale=4, num_inference_steps=50,
template_inputs = [{}],
negative_template_inputs = [{}],
)
image.save("image_PandaMeme_sleepy.jpg")
image = template(
pipe,
prompt="A meme with a happy expression.",
seed=0, cfg_scale=4, num_inference_steps=50,
template_inputs = [{}],
negative_template_inputs = [{}],
)
image.save("image_PandaMeme_happy.jpg")
image = template(
pipe,
prompt="A meme with a surprised expression.",
seed=0, cfg_scale=4, num_inference_steps=50,
template_inputs = [{}],
negative_template_inputs = [{}],
)
image.save("image_PandaMeme_surprised.jpg")1from diffsynth.diffusion.template import TemplatePipeline
2from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig
3import torch
4
5```python
6vram_config = {
7 "offload_dtype": "disk",
8 "offload_device": "disk",
9 "onload_dtype": torch.float8_e4m3fn,
10 "onload_device": "cpu",
11 "preparing_dtype": torch.float8_e4m3fn,
12 "preparing_device": "cuda",
13 "computation_dtype": torch.bfloat16,
14 "computation_device": "cuda",
15}
16pipe = Flux2ImagePipeline.from_pretrained(
17 torch_dtype=torch.bfloat16,
18 device="cuda",
19 model_configs=[
20 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-base-4B", origin_file_pattern="transformer/*.safetensors", **vram_config),
21 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
22 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
23 ],
24 tokenizer_config=ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="tokenizer/"),
25 vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
26)
27template = TemplatePipeline.from_pretrained(
28 torch_dtype=torch.bfloat16,
29 device="cuda",
30 model_configs=[ModelConfig(model_id="DiffSynth-Studio/Template-KleinBase4B-PandaMeme")],
31 lazy_loading=True,
32)
33image = template(
34 pipe,
35 prompt="A meme with a sleepy expression.",
36 seed=0, cfg_scale=4, num_inference_steps=50,
37 template_inputs = [{}],
38 negative_template_inputs = [{}],
39)
40image.save("image_PandaMeme_sleepy.jpg")
41image = template(
42 pipe,
43 prompt="A meme with a happy expression.",
44 seed=0, cfg_scale=4, num_inference_steps=50,
45 template_inputs = [{}],
46 negative_template_inputs = [{}],
47)
48image.save("image_PandaMeme_happy.jpg")
49image = template(
50 pipe,
51 prompt="A meme with a surprised expression.",
52 seed=0, cfg_scale=4, num_inference_steps=50,
53 template_inputs = [{}],
54 negative_template_inputs = [{}],
55)
56image.save("image_PandaMeme_surprised.jpg")1modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "flux2/Template-KleinBase4B-PandaMeme/*" --local_dir ./data/diffsynth_example_dataset
2
3accelerate launch examples/flux2/model_training/train.py \
4 --dataset_base_path data/diffsynth_example_dataset/flux2/Template-KleinBase4B-PandaMeme \
5 --dataset_metadata_path data/diffsynth_example_dataset/flux2/Template-KleinBase4B-PandaMeme/metadata.jsonl \
6 --extra_inputs "template_inputs" \
7 --max_pixels 1048576 \
8 --dataset_repeat 50 \
9 --model_id_with_origin_paths "black-forest-labs/FLUX.2-klein-4B:text_encoder/*.safetensors,black-forest-labs/FLUX.2-klein-base-4B:transformer/*.safetensors,black-forest-labs/FLUX.2-klein-4B:vae/diffusion_pytorch_model.safetensors" \
10 --template_model_id_or_path "DiffSynth-Studio/Template-KleinBase4B-PandaMeme:" \
11 --tokenizer_path "black-forest-labs/FLUX.2-klein-4B:tokenizer/" \
12 --learning_rate 1e-4 \
13 --num_epochs 2 \
14 --remove_prefix_in_ckpt "pipe.template_model." \
15 --output_path "./models/train/Template-KleinBase4B-PandaMeme_full" \
16 --trainable_models "template_model" \
17 --use_gradient_checkpointing \
18 --find_unused_parameters