Upload folder using huggingface_hub (part 7)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-Fun-A14B-Control.py +32 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-Fun-A14B-InP.py +30 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-I2V-A14B.py +30 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-S2V-14B.py +50 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-T2V-A14B.py +27 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-TI2V-5B.py +29 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-VACE-Fun-A14B.py +30 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/krea-realtime-video.py +28 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/README.md +3 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Omni-Base-i2L.py +62 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Omni-Base.py +24 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py +27 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.py +40 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Union-2.1.py +46 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo.py +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-i2L.py +61 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image.py +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/ZImage-i2L-v2.py +33 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Omni-Base-i2L.py +63 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Omni-Base.py +34 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py +38 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.py +51 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Union-2.1.py +57 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo.py +27 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-i2L.py +62 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image.py +27 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/ZImage-i2L-v2.py +45 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Omni-Base.sh +36 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.sh +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.sh +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Union-2.1.sh +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo.sh +16 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image.sh +16 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/ZImage-i2L-v2.sh +19 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/accelerate_config.yaml +22 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/accelerate_config_zero3.yaml +23 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Omni-Base.sh +39 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.sh +19 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.sh +19 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Union-2.1.sh +19 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo.sh +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image.sh +17 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/differential_training/Z-Image-Turbo.sh +25 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/differential_training/validate.py +18 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/npu_training/Z-Image-Turbo-NPU.sh +19 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/trajectory_imitation/Z-Image-Turbo.sh +20 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/trajectory_imitation/validate.py +18 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/train.py +171 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/validate_full/Z-Image-Omni-Base.py +33 -0
- video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/validate_full/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py +24 -0
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-Fun-A14B-Control.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 5 |
+
from modelscope import dataset_snapshot_download
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 15 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-Fun-A14B-Control_high_noise_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
pipe.load_lora(pipe.dit2, "models/train/Wan2.2-Fun-A14B-Control_low_noise_lora/epoch-4.safetensors", alpha=1)
|
| 20 |
+
|
| 21 |
+
video = VideoData("data/example_video_dataset/video1_softedge.mp4", height=480, width=832)
|
| 22 |
+
video = [video[i] for i in range(81)]
|
| 23 |
+
reference_image = VideoData("data/example_video_dataset/video1.mp4", height=480, width=832)[0]
|
| 24 |
+
|
| 25 |
+
# Control video
|
| 26 |
+
video = pipe(
|
| 27 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 28 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 29 |
+
control_video=video, reference_image=reference_image,
|
| 30 |
+
seed=1, tiled=True
|
| 31 |
+
)
|
| 32 |
+
save_video(video, "video_Wan2.2-Fun-A14B-Control.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-Fun-A14B-InP.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 5 |
+
from modelscope import dataset_snapshot_download
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 15 |
+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-Fun-A14B-InP_high_noise_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
pipe.load_lora(pipe.dit2, "models/train/Wan2.2-Fun-A14B-InP_low_noise_lora/epoch-4.safetensors", alpha=1)
|
| 20 |
+
|
| 21 |
+
video = VideoData("data/example_video_dataset/video1.mp4", height=480, width=832)
|
| 22 |
+
|
| 23 |
+
# First and last frame to video
|
| 24 |
+
video = pipe(
|
| 25 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 26 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 27 |
+
input_image=video[0], end_image=video[80],
|
| 28 |
+
seed=0, tiled=True
|
| 29 |
+
)
|
| 30 |
+
save_video(video, "video_Wan2.2-Fun-A14B-InP.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-I2V-A14B.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 5 |
+
from modelscope import dataset_snapshot_download
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-I2V-A14B", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-I2V-A14B", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-I2V-A14B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 15 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-I2V-A14B", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-I2V-A14B_high_noise_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
pipe.load_lora(pipe.dit2, "models/train/Wan2.2-I2V-A14B_low_noise_lora/epoch-4.safetensors", alpha=1)
|
| 20 |
+
|
| 21 |
+
input_image = VideoData("data/example_video_dataset/video1.mp4", height=480, width=832)[0]
|
| 22 |
+
|
| 23 |
+
video = pipe(
|
| 24 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 25 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 26 |
+
input_image=input_image,
|
| 27 |
+
num_frames=49,
|
| 28 |
+
seed=1, tiled=True,
|
| 29 |
+
)
|
| 30 |
+
save_video(video, "video_Wan2.2-I2V-A14B.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-S2V-14B.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import librosa
|
| 4 |
+
from diffsynth.utils.data import VideoData, save_video_with_audio
|
| 5 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 6 |
+
|
| 7 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-S2V-14B", origin_file_pattern="diffusion_pytorch_model*.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-S2V-14B", origin_file_pattern="wav2vec2-large-xlsr-53-english/model.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-S2V-14B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 14 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-S2V-14B", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 15 |
+
],
|
| 16 |
+
audio_processor_config=ModelConfig(model_id="Wan-AI/Wan2.2-S2V-14B", origin_file_pattern="wav2vec2-large-xlsr-53-english/"),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-S2V-14B_lora/epoch-4.safetensors", alpha=1)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
num_frames = 81 # 4n+1
|
| 23 |
+
height = 448
|
| 24 |
+
width = 832
|
| 25 |
+
|
| 26 |
+
prompt = "a person is singing"
|
| 27 |
+
negative_prompt = "画面模糊,最差质量,画面模糊,细节模糊不清,情绪激动剧烈,手快速抖动,字幕,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
|
| 28 |
+
input_image = Image.open("data/example_video_dataset/wans2v/pose.png").convert("RGB").resize((width, height))
|
| 29 |
+
# s2v audio input, recommend 16kHz sampling rate
|
| 30 |
+
audio_path = 'data/example_video_dataset/wans2v/sing.MP3'
|
| 31 |
+
input_audio, sample_rate = librosa.load(audio_path, sr=16000)
|
| 32 |
+
# Pose video input
|
| 33 |
+
pose_video_path = 'data/example_video_dataset/wans2v/pose.mp4'
|
| 34 |
+
pose_video = VideoData(pose_video_path, height=height, width=width)
|
| 35 |
+
|
| 36 |
+
# Speech-to-video with pose
|
| 37 |
+
video = pipe(
|
| 38 |
+
prompt=prompt,
|
| 39 |
+
input_image=input_image,
|
| 40 |
+
negative_prompt=negative_prompt,
|
| 41 |
+
seed=0,
|
| 42 |
+
num_frames=num_frames,
|
| 43 |
+
height=height,
|
| 44 |
+
width=width,
|
| 45 |
+
audio_sample_rate=sample_rate,
|
| 46 |
+
input_audio=input_audio,
|
| 47 |
+
s2v_pose_video=pose_video,
|
| 48 |
+
num_inference_steps=40,
|
| 49 |
+
)
|
| 50 |
+
save_video_with_audio(video[1:], "video_Wan2.2-S2V-14B.mp4", audio_path, fps=16, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-T2V-A14B.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 5 |
+
from modelscope import dataset_snapshot_download
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-T2V-A14B", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-T2V-A14B", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-T2V-A14B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 15 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-T2V-A14B", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-T2V-A14B_high_noise_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
pipe.load_lora(pipe.dit2, "models/train/Wan2.2-T2V-A14B_low_noise_lora/epoch-4.safetensors", alpha=1)
|
| 20 |
+
|
| 21 |
+
video = pipe(
|
| 22 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 23 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 24 |
+
num_frames=49,
|
| 25 |
+
seed=1, tiled=True
|
| 26 |
+
)
|
| 27 |
+
save_video(video, "video_Wan2.2-T2V-A14B.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-TI2V-5B.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.core import load_state_dict
|
| 5 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 6 |
+
from modelscope import dataset_snapshot_download
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 10 |
+
torch_dtype=torch.bfloat16,
|
| 11 |
+
device="cuda",
|
| 12 |
+
model_configs=[
|
| 13 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-TI2V-5B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 14 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-TI2V-5B", origin_file_pattern="diffusion_pytorch_model*.safetensors"),
|
| 15 |
+
ModelConfig(model_id="Wan-AI/Wan2.2-TI2V-5B", origin_file_pattern="Wan2.2_VAE.pth"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/Wan2.2-TI2V-5B_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
|
| 20 |
+
input_image = VideoData("data/example_video_dataset/video1.mp4", height=480, width=832)[0]
|
| 21 |
+
|
| 22 |
+
video = pipe(
|
| 23 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 24 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 25 |
+
input_image=input_image,
|
| 26 |
+
num_frames=49,
|
| 27 |
+
seed=1, tiled=True,
|
| 28 |
+
)
|
| 29 |
+
save_video(video, "video_Wan2.2-TI2V-5B.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/Wan2.2-VACE-Fun-A14B.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="PAI/Wan2.2-VACE-Fun-A14B", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 12 |
+
ModelConfig(model_id="PAI/Wan2.2-VACE-Fun-A14B", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="PAI/Wan2.2-VACE-Fun-A14B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 14 |
+
ModelConfig(model_id="PAI/Wan2.2-VACE-Fun-A14B", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 15 |
+
],
|
| 16 |
+
)
|
| 17 |
+
pipe.load_lora(pipe.vace, "models/train/Wan2.2-VACE-Fun-A14B_high_noise_lora/epoch-4.safetensors", alpha=1)
|
| 18 |
+
pipe.load_lora(pipe.vace2, "models/train/Wan2.2-VACE-Fun-A14B_low_noise_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
|
| 20 |
+
video = VideoData("data/example_video_dataset/video1_softedge.mp4", height=480, width=832)
|
| 21 |
+
video = [video[i] for i in range(17)]
|
| 22 |
+
reference_image = VideoData("data/example_video_dataset/video1.mp4", height=480, width=832)[0]
|
| 23 |
+
|
| 24 |
+
video = pipe(
|
| 25 |
+
prompt="from sunset to night, a small town, light, house, river",
|
| 26 |
+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
|
| 27 |
+
vace_video=video, vace_reference_image=reference_image, num_frames=17,
|
| 28 |
+
seed=1, tiled=True
|
| 29 |
+
)
|
| 30 |
+
save_video(video, "video_Wan2.2-VACE-Fun-A14B.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/wanvideo/model_training/validate_lora/krea-realtime-video.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffsynth.utils.data import save_video, VideoData
|
| 4 |
+
from diffsynth.core import load_state_dict
|
| 5 |
+
from diffsynth.pipelines.wan_video import WanVideoPipeline, ModelConfig
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = WanVideoPipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="krea/krea-realtime-video", origin_file_pattern="krea-realtime-video-14b.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Wan-AI/Wan2.1-T2V-14B", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth"),
|
| 14 |
+
ModelConfig(model_id="Wan-AI/Wan2.1-T2V-14B", origin_file_pattern="Wan2.1_VAE.pth"),
|
| 15 |
+
],
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
pipe.load_lora(pipe.dit, "models/train/krea-realtime-video_lora/epoch-4.safetensors", alpha=1)
|
| 19 |
+
|
| 20 |
+
# Text-to-video
|
| 21 |
+
video = pipe(
|
| 22 |
+
prompt="a cat sitting on a boat",
|
| 23 |
+
num_inference_steps=6, num_frames=81,
|
| 24 |
+
seed=0, tiled=True,
|
| 25 |
+
cfg_scale=1,
|
| 26 |
+
sigma_shift=20,
|
| 27 |
+
)
|
| 28 |
+
save_video(video, "video_krea-realtime-video.mp4", fps=15, quality=5)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
English Document: https://diffsynth-studio-doc.readthedocs.io/en/latest/Model_Details/Z-Image.html
|
| 2 |
+
|
| 3 |
+
中文文档:https://diffsynth-studio-doc.readthedocs.io/zh-cn/latest/Model_Details/Z-Image.html
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Omni-Base-i2L.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import (
|
| 2 |
+
ZImagePipeline, ModelConfig,
|
| 3 |
+
ZImageUnit_Image2LoRAEncode, ZImageUnit_Image2LoRADecode
|
| 4 |
+
)
|
| 5 |
+
from modelscope import snapshot_download
|
| 6 |
+
from safetensors.torch import save_file
|
| 7 |
+
import torch
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
# Use `vram_config` to enable LoRA hot-loading
|
| 11 |
+
vram_config = {
|
| 12 |
+
"offload_dtype": torch.bfloat16,
|
| 13 |
+
"offload_device": "cuda",
|
| 14 |
+
"onload_dtype": torch.bfloat16,
|
| 15 |
+
"onload_device": "cuda",
|
| 16 |
+
"preparing_dtype": torch.bfloat16,
|
| 17 |
+
"preparing_device": "cuda",
|
| 18 |
+
"computation_dtype": torch.bfloat16,
|
| 19 |
+
"computation_device": "cuda",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Load models
|
| 23 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 24 |
+
torch_dtype=torch.bfloat16,
|
| 25 |
+
device="cuda",
|
| 26 |
+
model_configs=[
|
| 27 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 28 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="siglip/model.safetensors"),
|
| 29 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 30 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 31 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="SigLIP2-G384/model.safetensors"),
|
| 32 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="DINOv3-7B/model.safetensors"),
|
| 33 |
+
ModelConfig(model_id="DiffSynth-Studio/Z-Image-Omni-Base-i2L", origin_file_pattern="model.safetensors"),
|
| 34 |
+
],
|
| 35 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Load images
|
| 39 |
+
snapshot_download(
|
| 40 |
+
model_id="DiffSynth-Studio/Z-Image-Omni-Base-i2L",
|
| 41 |
+
allow_file_pattern="assets/style/*",
|
| 42 |
+
local_dir="data/style_input"
|
| 43 |
+
)
|
| 44 |
+
images = [Image.open(f"data/style_input/assets/style/1/{i}.jpg") for i in range(6)]
|
| 45 |
+
|
| 46 |
+
# Image to LoRA
|
| 47 |
+
with torch.no_grad():
|
| 48 |
+
embs = ZImageUnit_Image2LoRAEncode().process(pipe, image2lora_images=images)
|
| 49 |
+
lora = ZImageUnit_Image2LoRADecode().process(pipe, **embs)["lora"]
|
| 50 |
+
save_file(lora, "lora.safetensors")
|
| 51 |
+
|
| 52 |
+
# Generate images
|
| 53 |
+
prompt = "a cat"
|
| 54 |
+
negative_prompt = "泛黄,发绿,模糊,低分辨率,低质量图像,扭曲的肢体,诡异的外观,丑陋,AI感,噪点,网格感,JPEG压缩条纹,异常的肢体,水印,乱码,意义不明的字符"
|
| 55 |
+
image = pipe(
|
| 56 |
+
prompt=prompt,
|
| 57 |
+
negative_prompt=negative_prompt,
|
| 58 |
+
seed=0, cfg_scale=7, num_inference_steps=50,
|
| 59 |
+
positive_only_lora=lora,
|
| 60 |
+
sigma_shift=8
|
| 61 |
+
)
|
| 62 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Omni-Base.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 7 |
+
torch_dtype=torch.bfloat16,
|
| 8 |
+
device="cuda",
|
| 9 |
+
model_configs=[
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="transformer/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="siglip/model.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 14 |
+
],
|
| 15 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 16 |
+
)
|
| 17 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 18 |
+
image = pipe(prompt=prompt, seed=0, num_inference_steps=40, cfg_scale=4)
|
| 19 |
+
image.save("image_Z-Image-Omni-Base.jpg")
|
| 20 |
+
|
| 21 |
+
image = Image.open("image_Z-Image-Omni-Base.jpg")
|
| 22 |
+
prompt = "Change the women's clothes to white cheongsam, keep other content unchanged"
|
| 23 |
+
image = pipe(prompt=prompt, edit_image=image, seed=42, rand_device="cuda", num_inference_steps=40, cfg_scale=4)
|
| 24 |
+
image.save("image_edit_Z-Image-Omni-Base.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 15 |
+
],
|
| 16 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
dataset_snapshot_download(
|
| 20 |
+
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
|
| 21 |
+
local_dir="./",
|
| 22 |
+
allow_file_pattern="data/examples/upscale/low_res.png"
|
| 23 |
+
)
|
| 24 |
+
controlnet_image = Image.open("data/examples/upscale/low_res.png").resize((1024, 1024))
|
| 25 |
+
prompt = "这是一张充满都市气息的户外人物肖像照片。画面中是一位年轻男性,他展现出时尚而自信的形象。人物拥有精心打理的短发发型,两侧修剪得较短,顶部保留一定长度,呈现出流行的Undercut造型。他佩戴着一副时尚的浅色墨镜或透明镜框眼镜,为整体造型增添了潮流感。脸上洋溢着温和友善的笑容,神情放松自然,给人以阳光开朗的印象。他身穿一件经典的牛仔外套,这件单品永不过时,展现出休闲又有型的穿衣风格。牛仔外套的蓝色调与整体氛围十分协调,领口处隐约可见内搭的衣物。照片的背景是典型的城市街景,可以看到模糊的建筑物、街道和行人,营造出繁华都市的氛围。背景经过了恰当的虚化处理,使人物主体更加突出。光线明亮而柔和,可能是白天的自然光,为照片带来清新通透的视觉效果。整张照片构图专业,景深控制得当,完美捕捉了一个现代都市年轻人充满活力和自信的瞬间,展现出积极向上的生活态度。"
|
| 26 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)])
|
| 27 |
+
image.save("image_tile.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 15 |
+
],
|
| 16 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Control
|
| 20 |
+
dataset_snapshot_download(
|
| 21 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 22 |
+
local_dir="./data/example_image_dataset",
|
| 23 |
+
allow_file_pattern="depth/image_1.jpg"
|
| 24 |
+
)
|
| 25 |
+
controlnet_image = Image.open("data/example_image_dataset/depth/image_1.jpg").resize((1024, 1024))
|
| 26 |
+
prompt = "精致肖像,水下少女,蓝裙飘逸,发丝轻扬,光影透澈,气泡环绕,面容恬静,细节精致,梦幻唯美。"
|
| 27 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)])
|
| 28 |
+
image.save("image_control.jpg")
|
| 29 |
+
|
| 30 |
+
# Inpaint
|
| 31 |
+
dataset_snapshot_download(
|
| 32 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 33 |
+
local_dir="./data/example_image_dataset",
|
| 34 |
+
allow_file_pattern="inpaint/*.jpg"
|
| 35 |
+
)
|
| 36 |
+
inpaint_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1024, 1024))
|
| 37 |
+
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1024, 1024))
|
| 38 |
+
prompt = "一只戴着墨镜的猫"
|
| 39 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(inpaint_image=inpaint_image, inpaint_mask=inpaint_mask, scale=0.7)])
|
| 40 |
+
image.save("image_inpaint.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo-Fun-Controlnet-Union-2.1.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Union-2.1.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 15 |
+
],
|
| 16 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Control
|
| 20 |
+
dataset_snapshot_download(
|
| 21 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 22 |
+
local_dir="./data/example_image_dataset",
|
| 23 |
+
allow_file_pattern="depth/image_1.jpg"
|
| 24 |
+
)
|
| 25 |
+
controlnet_image = Image.open("data/example_image_dataset/depth/image_1.jpg").resize((1024, 1024))
|
| 26 |
+
prompt = "精致肖像,水下少女,蓝裙飘逸,发丝轻扬,光影透澈,气泡环绕,面容恬静,细节精致,梦幻唯美。"
|
| 27 |
+
image = pipe(
|
| 28 |
+
prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)],
|
| 29 |
+
num_inference_steps=30,
|
| 30 |
+
)
|
| 31 |
+
image.save("image_control.jpg")
|
| 32 |
+
|
| 33 |
+
# Inpaint
|
| 34 |
+
dataset_snapshot_download(
|
| 35 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 36 |
+
local_dir="./data/example_image_dataset",
|
| 37 |
+
allow_file_pattern="inpaint/*.jpg"
|
| 38 |
+
)
|
| 39 |
+
inpaint_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1024, 1024))
|
| 40 |
+
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1024, 1024))
|
| 41 |
+
prompt = "一只戴着墨镜的猫"
|
| 42 |
+
image = pipe(
|
| 43 |
+
prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(inpaint_image=inpaint_image, inpaint_mask=inpaint_mask, scale=0.7)],
|
| 44 |
+
num_inference_steps=30,
|
| 45 |
+
)
|
| 46 |
+
image.save("image_inpaint.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-Turbo.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 6 |
+
torch_dtype=torch.bfloat16,
|
| 7 |
+
device="cuda",
|
| 8 |
+
model_configs=[
|
| 9 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 12 |
+
],
|
| 13 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 14 |
+
)
|
| 15 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 16 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda")
|
| 17 |
+
image.save("image_Z-Image-Turbo.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image-i2L.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import (
|
| 2 |
+
ZImagePipeline, ModelConfig,
|
| 3 |
+
ZImageUnit_Image2LoRAEncode, ZImageUnit_Image2LoRADecode
|
| 4 |
+
)
|
| 5 |
+
from modelscope import snapshot_download
|
| 6 |
+
from safetensors.torch import save_file
|
| 7 |
+
import torch
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
# Use `vram_config` to enable LoRA hot-loading
|
| 11 |
+
vram_config = {
|
| 12 |
+
"offload_dtype": torch.bfloat16,
|
| 13 |
+
"offload_device": "cuda",
|
| 14 |
+
"onload_dtype": torch.bfloat16,
|
| 15 |
+
"onload_device": "cuda",
|
| 16 |
+
"preparing_dtype": torch.bfloat16,
|
| 17 |
+
"preparing_device": "cuda",
|
| 18 |
+
"computation_dtype": torch.bfloat16,
|
| 19 |
+
"computation_device": "cuda",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Load models
|
| 23 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 24 |
+
torch_dtype=torch.bfloat16,
|
| 25 |
+
device="cuda",
|
| 26 |
+
model_configs=[
|
| 27 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 28 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 29 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 30 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="SigLIP2-G384/model.safetensors"),
|
| 31 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="DINOv3-7B/model.safetensors"),
|
| 32 |
+
ModelConfig(model_id="DiffSynth-Studio/Z-Image-i2L", origin_file_pattern="model.safetensors"),
|
| 33 |
+
],
|
| 34 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Load images
|
| 38 |
+
snapshot_download(
|
| 39 |
+
model_id="DiffSynth-Studio/Z-Image-i2L",
|
| 40 |
+
allow_file_pattern="assets/style/*",
|
| 41 |
+
local_dir="data/Z-Image-i2L_style_input"
|
| 42 |
+
)
|
| 43 |
+
images = [Image.open(f"data/Z-Image-i2L_style_input/assets/style/1/{i}.jpg") for i in range(4)]
|
| 44 |
+
|
| 45 |
+
# Image to LoRA
|
| 46 |
+
with torch.no_grad():
|
| 47 |
+
embs = ZImageUnit_Image2LoRAEncode().process(pipe, image2lora_images=images)
|
| 48 |
+
lora = ZImageUnit_Image2LoRADecode().process(pipe, **embs)["lora"]
|
| 49 |
+
save_file(lora, "lora.safetensors")
|
| 50 |
+
|
| 51 |
+
# Generate images
|
| 52 |
+
prompt = "a cat"
|
| 53 |
+
negative_prompt = "泛黄,发绿,模糊,低分辨率,低质量图像,扭曲的肢体,诡异的外观,丑陋,AI感,噪点,网格感,JPEG压缩条纹,异常的肢体,水印,乱码,意义不明的字符"
|
| 54 |
+
image = pipe(
|
| 55 |
+
prompt=prompt,
|
| 56 |
+
negative_prompt=negative_prompt,
|
| 57 |
+
seed=0, cfg_scale=4, num_inference_steps=50,
|
| 58 |
+
positive_only_lora=lora,
|
| 59 |
+
sigma_shift=8
|
| 60 |
+
)
|
| 61 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/Z-Image.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 6 |
+
torch_dtype=torch.bfloat16,
|
| 7 |
+
device="cuda",
|
| 8 |
+
model_configs=[
|
| 9 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors"),
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 12 |
+
],
|
| 13 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 14 |
+
)
|
| 15 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 16 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda", num_inference_steps=50, cfg_scale=4)
|
| 17 |
+
image.save("image_Z-Image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference/ZImage-i2L-v2.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.diffusion.template import TemplatePipeline
|
| 2 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 3 |
+
from modelscope import snapshot_download
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device="cuda",
|
| 11 |
+
model_configs=[
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 15 |
+
],
|
| 16 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 17 |
+
)
|
| 18 |
+
pipe.enable_lora_hot_loading(pipe.dit)
|
| 19 |
+
template = TemplatePipeline.from_pretrained(
|
| 20 |
+
torch_dtype=torch.bfloat16,
|
| 21 |
+
device="cuda",
|
| 22 |
+
model_configs=[ModelConfig(model_id="DiffSynth-Studio/ZImage-i2L-v2")],
|
| 23 |
+
)
|
| 24 |
+
snapshot_download("DiffSynth-Studio/ZImage-i2L-v2", allow_file_pattern="assets/*", local_dir="data")
|
| 25 |
+
images = [Image.open(f"data/assets/multi_input_{i}.jpg") for i in range(4)]
|
| 26 |
+
image = template(
|
| 27 |
+
pipe,
|
| 28 |
+
prompt="A cat is sitting on a stone",
|
| 29 |
+
seed=0, cfg_scale=4, num_inference_steps=50,
|
| 30 |
+
template_inputs = [{"image": images}],
|
| 31 |
+
negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}],
|
| 32 |
+
)
|
| 33 |
+
image.save("image_output.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Omni-Base-i2L.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import (
|
| 2 |
+
ZImagePipeline, ModelConfig,
|
| 3 |
+
ZImageUnit_Image2LoRAEncode, ZImageUnit_Image2LoRADecode
|
| 4 |
+
)
|
| 5 |
+
from modelscope import snapshot_download
|
| 6 |
+
from safetensors.torch import save_file
|
| 7 |
+
import torch
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
# Use `vram_config` to enable LoRA hot-loading
|
| 11 |
+
vram_config = {
|
| 12 |
+
"offload_dtype": torch.bfloat16,
|
| 13 |
+
"offload_device": "cpu",
|
| 14 |
+
"onload_dtype": torch.bfloat16,
|
| 15 |
+
"onload_device": "cpu",
|
| 16 |
+
"preparing_dtype": torch.bfloat16,
|
| 17 |
+
"preparing_device": "cuda",
|
| 18 |
+
"computation_dtype": torch.bfloat16,
|
| 19 |
+
"computation_device": "cuda",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Load models
|
| 23 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 24 |
+
torch_dtype=torch.bfloat16,
|
| 25 |
+
device="cuda",
|
| 26 |
+
model_configs=[
|
| 27 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 28 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="siglip/model.safetensors", **vram_config),
|
| 29 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 30 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 31 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="SigLIP2-G384/model.safetensors", **vram_config),
|
| 32 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="DINOv3-7B/model.safetensors", **vram_config),
|
| 33 |
+
ModelConfig(model_id="DiffSynth-Studio/Z-Image-Omni-Base-i2L", origin_file_pattern="model.safetensors", **vram_config),
|
| 34 |
+
],
|
| 35 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 36 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Load images
|
| 40 |
+
snapshot_download(
|
| 41 |
+
model_id="DiffSynth-Studio/Z-Image-Omni-Base-i2L",
|
| 42 |
+
allow_file_pattern="assets/style/*",
|
| 43 |
+
local_dir="data/style_input"
|
| 44 |
+
)
|
| 45 |
+
images = [Image.open(f"data/style_input/assets/style/1/{i}.jpg") for i in range(6)]
|
| 46 |
+
|
| 47 |
+
# Image to LoRA
|
| 48 |
+
with torch.no_grad():
|
| 49 |
+
embs = ZImageUnit_Image2LoRAEncode().process(pipe, image2lora_images=images)
|
| 50 |
+
lora = ZImageUnit_Image2LoRADecode().process(pipe, **embs)["lora"]
|
| 51 |
+
save_file(lora, "lora.safetensors")
|
| 52 |
+
|
| 53 |
+
# Generate images
|
| 54 |
+
prompt = "a cat"
|
| 55 |
+
negative_prompt = "泛黄,发绿,模糊,低分辨率,低质量图像,扭曲的肢体,诡异的外观,丑陋,AI感,噪点,网格感,JPEG压缩条纹,异常的肢体,水印,乱码,意义不明的字符"
|
| 56 |
+
image = pipe(
|
| 57 |
+
prompt=prompt,
|
| 58 |
+
negative_prompt=negative_prompt,
|
| 59 |
+
seed=0, cfg_scale=7, num_inference_steps=50,
|
| 60 |
+
positive_only_lora=lora,
|
| 61 |
+
sigma_shift=8
|
| 62 |
+
)
|
| 63 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Omni-Base.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
vram_config = {
|
| 6 |
+
"offload_dtype": torch.bfloat16,
|
| 7 |
+
"offload_device": "cpu",
|
| 8 |
+
"onload_dtype": torch.bfloat16,
|
| 9 |
+
"onload_device": "cpu",
|
| 10 |
+
"preparing_dtype": torch.bfloat16,
|
| 11 |
+
"preparing_device": "cuda",
|
| 12 |
+
"computation_dtype": torch.bfloat16,
|
| 13 |
+
"computation_device": "cuda",
|
| 14 |
+
}
|
| 15 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 16 |
+
torch_dtype=torch.bfloat16,
|
| 17 |
+
device="cuda",
|
| 18 |
+
model_configs=[
|
| 19 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 20 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="siglip/model.safetensors", **vram_config),
|
| 21 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 22 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 23 |
+
],
|
| 24 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 25 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 26 |
+
)
|
| 27 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 28 |
+
image = pipe(prompt=prompt, seed=0, num_inference_steps=40, cfg_scale=4)
|
| 29 |
+
image.save("image_Z-Image-Omni-Base.jpg")
|
| 30 |
+
|
| 31 |
+
image = Image.open("image_Z-Image-Omni-Base.jpg")
|
| 32 |
+
prompt = "Change the women's clothes to white cheongsam, keep other content unchanged"
|
| 33 |
+
image = pipe(prompt=prompt, edit_image=image, seed=42, rand_device="cuda", num_inference_steps=40, cfg_scale=4)
|
| 34 |
+
image.save("image_edit_Z-Image-Omni-Base.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
vram_config = {
|
| 8 |
+
"offload_dtype": torch.bfloat16,
|
| 9 |
+
"offload_device": "cpu",
|
| 10 |
+
"onload_dtype": torch.bfloat16,
|
| 11 |
+
"onload_device": "cpu",
|
| 12 |
+
"preparing_dtype": torch.bfloat16,
|
| 13 |
+
"preparing_device": "cuda",
|
| 14 |
+
"computation_dtype": torch.bfloat16,
|
| 15 |
+
"computation_device": "cuda",
|
| 16 |
+
}
|
| 17 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 18 |
+
torch_dtype=torch.bfloat16,
|
| 19 |
+
device="cuda",
|
| 20 |
+
model_configs=[
|
| 21 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors", **vram_config),
|
| 22 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 23 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 24 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 25 |
+
],
|
| 26 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 27 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
dataset_snapshot_download(
|
| 31 |
+
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
|
| 32 |
+
local_dir="./",
|
| 33 |
+
allow_file_pattern="data/examples/upscale/low_res.png"
|
| 34 |
+
)
|
| 35 |
+
controlnet_image = Image.open("data/examples/upscale/low_res.png").resize((1024, 1024))
|
| 36 |
+
prompt = "这是一张充满都市气息的户外人物肖像照片。画面中是一位年轻男性,他展现出时尚而自信的形象。人物拥有精心打理的短发发型,两侧修剪得较短,顶部保留一定长度,呈现出流行的Undercut造型。他佩戴着一副时尚的浅色墨镜或透明镜框眼镜,为整体造型增添了潮流感。脸上洋溢着温和友善的笑容,神情放松自然,给人以阳光开朗的印象。他身穿一件经典的牛仔外套,这件单品永不过时,展现出休闲又有型的穿衣风格。牛仔外套的蓝色调与整体氛围十分协调,领口处隐约可见内搭的衣物。照片的背景是典型的城市街景,可以看到模糊的建筑物、街道和行人,营造出繁华都市的氛围。背景经过了恰当的虚化处理,使人物主体更加突出。光线明亮而柔和,可能是白天的自然光,为照片带来清新通透的视觉效果。整张照片构图专业,景深控制得当,完美捕捉了一个现代都市年轻人充满活力和自信的瞬间,展现出积极向上的生活态度。"
|
| 37 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)])
|
| 38 |
+
image.save("image_tile.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
vram_config = {
|
| 8 |
+
"offload_dtype": torch.bfloat16,
|
| 9 |
+
"offload_device": "cpu",
|
| 10 |
+
"onload_dtype": torch.bfloat16,
|
| 11 |
+
"onload_device": "cpu",
|
| 12 |
+
"preparing_dtype": torch.bfloat16,
|
| 13 |
+
"preparing_device": "cuda",
|
| 14 |
+
"computation_dtype": torch.bfloat16,
|
| 15 |
+
"computation_device": "cuda",
|
| 16 |
+
}
|
| 17 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 18 |
+
torch_dtype=torch.bfloat16,
|
| 19 |
+
device="cuda",
|
| 20 |
+
model_configs=[
|
| 21 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors", **vram_config),
|
| 22 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 23 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 24 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 25 |
+
],
|
| 26 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 27 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Control
|
| 31 |
+
dataset_snapshot_download(
|
| 32 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 33 |
+
local_dir="./data/example_image_dataset",
|
| 34 |
+
allow_file_pattern="depth/image_1.jpg"
|
| 35 |
+
)
|
| 36 |
+
controlnet_image = Image.open("data/example_image_dataset/depth/image_1.jpg").resize((1024, 1024))
|
| 37 |
+
prompt = "精致肖像,水下少女,蓝裙飘逸,发丝轻扬,光影透澈,气泡环绕,面容恬静,细节精致,梦幻唯美。"
|
| 38 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)])
|
| 39 |
+
image.save("image_control.jpg")
|
| 40 |
+
|
| 41 |
+
# Inpaint
|
| 42 |
+
dataset_snapshot_download(
|
| 43 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 44 |
+
local_dir="./data/example_image_dataset",
|
| 45 |
+
allow_file_pattern="inpaint/*.jpg"
|
| 46 |
+
)
|
| 47 |
+
inpaint_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1024, 1024))
|
| 48 |
+
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1024, 1024))
|
| 49 |
+
prompt = "一只戴着墨镜的猫"
|
| 50 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(inpaint_image=inpaint_image, inpaint_mask=inpaint_mask, scale=0.7)])
|
| 51 |
+
image.save("image_inpaint.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo-Fun-Controlnet-Union-2.1.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from modelscope import dataset_snapshot_download
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
vram_config = {
|
| 8 |
+
"offload_dtype": torch.bfloat16,
|
| 9 |
+
"offload_device": "cpu",
|
| 10 |
+
"onload_dtype": torch.bfloat16,
|
| 11 |
+
"onload_device": "cpu",
|
| 12 |
+
"preparing_dtype": torch.bfloat16,
|
| 13 |
+
"preparing_device": "cuda",
|
| 14 |
+
"computation_dtype": torch.bfloat16,
|
| 15 |
+
"computation_device": "cuda",
|
| 16 |
+
}
|
| 17 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 18 |
+
torch_dtype=torch.bfloat16,
|
| 19 |
+
device="cuda",
|
| 20 |
+
model_configs=[
|
| 21 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Union-2.1.safetensors", **vram_config),
|
| 22 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 23 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 24 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 25 |
+
],
|
| 26 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 27 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Control
|
| 31 |
+
dataset_snapshot_download(
|
| 32 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 33 |
+
local_dir="./data/example_image_dataset",
|
| 34 |
+
allow_file_pattern="depth/image_1.jpg"
|
| 35 |
+
)
|
| 36 |
+
controlnet_image = Image.open("data/example_image_dataset/depth/image_1.jpg").resize((1024, 1024))
|
| 37 |
+
prompt = "精致肖像,水下少女,蓝裙飘逸,发丝轻扬,光影透澈,气泡环绕,面容恬静,细节精致,梦幻唯美。"
|
| 38 |
+
image = pipe(
|
| 39 |
+
prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=0.7)],
|
| 40 |
+
num_inference_steps=30,
|
| 41 |
+
)
|
| 42 |
+
image.save("image_control.jpg")
|
| 43 |
+
|
| 44 |
+
# Inpaint
|
| 45 |
+
dataset_snapshot_download(
|
| 46 |
+
dataset_id="DiffSynth-Studio/example_image_dataset",
|
| 47 |
+
local_dir="./data/example_image_dataset",
|
| 48 |
+
allow_file_pattern="inpaint/*.jpg"
|
| 49 |
+
)
|
| 50 |
+
inpaint_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1024, 1024))
|
| 51 |
+
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1024, 1024))
|
| 52 |
+
prompt = "一只戴着墨镜的猫"
|
| 53 |
+
image = pipe(
|
| 54 |
+
prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(inpaint_image=inpaint_image, inpaint_mask=inpaint_mask, scale=0.7)],
|
| 55 |
+
num_inference_steps=30,
|
| 56 |
+
)
|
| 57 |
+
image.save("image_inpaint.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-Turbo.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
vram_config = {
|
| 5 |
+
"offload_dtype": torch.bfloat16,
|
| 6 |
+
"offload_device": "cpu",
|
| 7 |
+
"onload_dtype": torch.bfloat16,
|
| 8 |
+
"onload_device": "cpu",
|
| 9 |
+
"preparing_dtype": torch.bfloat16,
|
| 10 |
+
"preparing_device": "cuda",
|
| 11 |
+
"computation_dtype": torch.bfloat16,
|
| 12 |
+
"computation_device": "cuda",
|
| 13 |
+
}
|
| 14 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 15 |
+
torch_dtype=torch.bfloat16,
|
| 16 |
+
device="cuda",
|
| 17 |
+
model_configs=[
|
| 18 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 19 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 20 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 21 |
+
],
|
| 22 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 23 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 24 |
+
)
|
| 25 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 26 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda")
|
| 27 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image-i2L.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import (
|
| 2 |
+
ZImagePipeline, ModelConfig,
|
| 3 |
+
ZImageUnit_Image2LoRAEncode, ZImageUnit_Image2LoRADecode
|
| 4 |
+
)
|
| 5 |
+
from modelscope import snapshot_download
|
| 6 |
+
from safetensors.torch import save_file
|
| 7 |
+
import torch
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
# Use `vram_config` to enable LoRA hot-loading
|
| 11 |
+
vram_config = {
|
| 12 |
+
"offload_dtype": torch.bfloat16,
|
| 13 |
+
"offload_device": "cpu",
|
| 14 |
+
"onload_dtype": torch.bfloat16,
|
| 15 |
+
"onload_device": "cpu",
|
| 16 |
+
"preparing_dtype": torch.bfloat16,
|
| 17 |
+
"preparing_device": "cuda",
|
| 18 |
+
"computation_dtype": torch.bfloat16,
|
| 19 |
+
"computation_device": "cuda",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Load models
|
| 23 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 24 |
+
torch_dtype=torch.bfloat16,
|
| 25 |
+
device="cuda",
|
| 26 |
+
model_configs=[
|
| 27 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 28 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 29 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 30 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="SigLIP2-G384/model.safetensors", **vram_config),
|
| 31 |
+
ModelConfig(model_id="DiffSynth-Studio/General-Image-Encoders", origin_file_pattern="DINOv3-7B/model.safetensors", **vram_config),
|
| 32 |
+
ModelConfig(model_id="DiffSynth-Studio/Z-Image-i2L", origin_file_pattern="model.safetensors", **vram_config),
|
| 33 |
+
],
|
| 34 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 35 |
+
vram_limit=0,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Load images
|
| 39 |
+
snapshot_download(
|
| 40 |
+
model_id="DiffSynth-Studio/Z-Image-i2L",
|
| 41 |
+
allow_file_pattern="assets/style/*",
|
| 42 |
+
local_dir="data/Z-Image-i2L_style_input"
|
| 43 |
+
)
|
| 44 |
+
images = [Image.open(f"data/Z-Image-i2L_style_input/assets/style/1/{i}.jpg") for i in range(4)]
|
| 45 |
+
|
| 46 |
+
# Image to LoRA
|
| 47 |
+
with torch.no_grad():
|
| 48 |
+
embs = ZImageUnit_Image2LoRAEncode().process(pipe, image2lora_images=images)
|
| 49 |
+
lora = ZImageUnit_Image2LoRADecode().process(pipe, **embs)["lora"]
|
| 50 |
+
save_file(lora, "lora.safetensors")
|
| 51 |
+
|
| 52 |
+
# Generate images
|
| 53 |
+
prompt = "a cat"
|
| 54 |
+
negative_prompt = "泛黄,发绿,模糊,低分辨率,低质量图像,扭曲的肢体,诡异的外观,丑陋,AI感,噪点,网格感,JPEG压缩条纹,异常的肢体,水印,乱码,意义不明的字符"
|
| 55 |
+
image = pipe(
|
| 56 |
+
prompt=prompt,
|
| 57 |
+
negative_prompt=negative_prompt,
|
| 58 |
+
seed=0, cfg_scale=4, num_inference_steps=50,
|
| 59 |
+
positive_only_lora=lora,
|
| 60 |
+
sigma_shift=8
|
| 61 |
+
)
|
| 62 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/Z-Image.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
vram_config = {
|
| 5 |
+
"offload_dtype": torch.bfloat16,
|
| 6 |
+
"offload_device": "cpu",
|
| 7 |
+
"onload_dtype": torch.bfloat16,
|
| 8 |
+
"onload_device": "cpu",
|
| 9 |
+
"preparing_dtype": torch.bfloat16,
|
| 10 |
+
"preparing_device": "cuda",
|
| 11 |
+
"computation_dtype": torch.bfloat16,
|
| 12 |
+
"computation_device": "cuda",
|
| 13 |
+
}
|
| 14 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 15 |
+
torch_dtype=torch.bfloat16,
|
| 16 |
+
device="cuda",
|
| 17 |
+
model_configs=[
|
| 18 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 19 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 20 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 21 |
+
],
|
| 22 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 23 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 24 |
+
)
|
| 25 |
+
prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."
|
| 26 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda", num_inference_steps=50, cfg_scale=4)
|
| 27 |
+
image.save("image_Z-Image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_inference_low_vram/ZImage-i2L-v2.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.diffusion.template import TemplatePipeline
|
| 2 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 3 |
+
from modelscope import snapshot_download
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
vram_config = {
|
| 9 |
+
"offload_dtype": torch.bfloat16,
|
| 10 |
+
"offload_device": "cpu",
|
| 11 |
+
"onload_dtype": torch.bfloat16,
|
| 12 |
+
"onload_device": "cpu",
|
| 13 |
+
"preparing_dtype": torch.bfloat16,
|
| 14 |
+
"preparing_device": "cuda",
|
| 15 |
+
"computation_dtype": torch.bfloat16,
|
| 16 |
+
"computation_device": "cuda",
|
| 17 |
+
}
|
| 18 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 19 |
+
torch_dtype=torch.bfloat16,
|
| 20 |
+
device="cuda",
|
| 21 |
+
model_configs=[
|
| 22 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image", origin_file_pattern="transformer/*.safetensors", **vram_config),
|
| 23 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
|
| 24 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
|
| 25 |
+
],
|
| 26 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 27 |
+
vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
|
| 28 |
+
)
|
| 29 |
+
pipe.enable_lora_hot_loading(pipe.dit)
|
| 30 |
+
template = TemplatePipeline.from_pretrained(
|
| 31 |
+
torch_dtype=torch.bfloat16,
|
| 32 |
+
device="cuda",
|
| 33 |
+
lazy_loading=True,
|
| 34 |
+
model_configs=[ModelConfig(model_id="DiffSynth-Studio/ZImage-i2L-v2")],
|
| 35 |
+
)
|
| 36 |
+
snapshot_download("DiffSynth-Studio/ZImage-i2L-v2", allow_file_pattern="assets/*", local_dir="data")
|
| 37 |
+
images = [Image.open(f"data/assets/multi_input_{i}.jpg") for i in range(4)]
|
| 38 |
+
image = template(
|
| 39 |
+
pipe,
|
| 40 |
+
prompt="A cat is sitting on a stone",
|
| 41 |
+
seed=0, cfg_scale=4, num_inference_steps=50,
|
| 42 |
+
template_inputs = [{"image": images}],
|
| 43 |
+
negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}],
|
| 44 |
+
)
|
| 45 |
+
image.save("image_output.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Omni-Base.sh
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Omni-Base/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
# This example is tested on 8*A100
|
| 4 |
+
# Text to image training
|
| 5 |
+
accelerate launch --config_file examples/z_image/model_training/full/accelerate_config.yaml examples/z_image/model_training/train.py \
|
| 6 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base \
|
| 7 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base/metadata.csv \
|
| 8 |
+
--max_pixels 1048576 \
|
| 9 |
+
--dataset_repeat 400 \
|
| 10 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Omni-Base:transformer/*.safetensors,Tongyi-MAI/Z-Image-Omni-Base:siglip/model.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 11 |
+
--learning_rate 1e-5 \
|
| 12 |
+
--num_epochs 2 \
|
| 13 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 14 |
+
--output_path "./models/train/Z-Image-Omni-Base_full" \
|
| 15 |
+
--trainable_models "dit" \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--find_unused_parameters \
|
| 18 |
+
--dataset_num_workers 8
|
| 19 |
+
|
| 20 |
+
# Image(s) to image training
|
| 21 |
+
# accelerate launch --config_file examples/z_image/model_training/full/accelerate_config.yaml examples/z_image/model_training/train.py \
|
| 22 |
+
# --dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base \
|
| 23 |
+
# --dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base/metadata.csv \
|
| 24 |
+
# --data_file_keys "image,edit_image" \
|
| 25 |
+
# --extra_inputs "edit_image" \
|
| 26 |
+
# --max_pixels 1048576 \
|
| 27 |
+
# --dataset_repeat 400 \
|
| 28 |
+
# --model_id_with_origin_paths "Tongyi-MAI/Z-Image-Omni-Base:transformer/*.safetensors,Tongyi-MAI/Z-Image-Omni-Base:siglip/model.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 29 |
+
# --learning_rate 1e-5 \
|
| 30 |
+
# --num_epochs 2 \
|
| 31 |
+
# --remove_prefix_in_ckpt "pipe.dit." \
|
| 32 |
+
# --output_path "./models/train/Z-Image-Omni-Base_full_edit" \
|
| 33 |
+
# --trainable_models "dit" \
|
| 34 |
+
# --use_gradient_checkpointing \
|
| 35 |
+
# --find_unused_parameters \
|
| 36 |
+
# --dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-5 \
|
| 11 |
+
--num_epochs 2 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.controlnet." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps_full" \
|
| 14 |
+
--trainable_models "controlnet" \
|
| 15 |
+
--extra_inputs "controlnet_image" \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-5 \
|
| 11 |
+
--num_epochs 2 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.controlnet." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps_full" \
|
| 14 |
+
--trainable_models "controlnet" \
|
| 15 |
+
--extra_inputs "controlnet_image" \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo-Fun-Controlnet-Union-2.1.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1 \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Union-2.1.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-5 \
|
| 11 |
+
--num_epochs 2 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.controlnet." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Union-2.1_full" \
|
| 14 |
+
--trainable_models "controlnet" \
|
| 15 |
+
--extra_inputs "controlnet_image" \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image-Turbo.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
# This example is tested on 8*A100
|
| 4 |
+
accelerate launch --config_file examples/z_image/model_training/full/accelerate_config.yaml examples/z_image/model_training/train.py \
|
| 5 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo \
|
| 6 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo/metadata.csv \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 400 \
|
| 9 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-5 \
|
| 11 |
+
--num_epochs 2 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo_full" \
|
| 14 |
+
--trainable_models "dit" \
|
| 15 |
+
--use_gradient_checkpointing \
|
| 16 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/Z-Image.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
# This example is tested on 8*A100
|
| 4 |
+
accelerate launch --config_file examples/z_image/model_training/full/accelerate_config.yaml examples/z_image/model_training/train.py \
|
| 5 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image \
|
| 6 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image/metadata.csv \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 400 \
|
| 9 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-5 \
|
| 11 |
+
--num_epochs 2 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image_full" \
|
| 14 |
+
--trainable_models "dit" \
|
| 15 |
+
--use_gradient_checkpointing \
|
| 16 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/ZImage-i2L-v2.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/ZImage-i2L-v2/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/ZImage-i2L-v2 \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/ZImage-i2L-v2/metadata.jsonl \
|
| 6 |
+
--max_pixels 1048576 \
|
| 7 |
+
--dataset_repeat 400 \
|
| 8 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 9 |
+
--learning_rate 1e-5 \
|
| 10 |
+
--num_epochs 2 \
|
| 11 |
+
--output_path "./models/train/ZImage-i2L-v2_full" \
|
| 12 |
+
--use_gradient_checkpointing \
|
| 13 |
+
--find_unused_parameters \
|
| 14 |
+
--dataset_num_workers 8 \
|
| 15 |
+
--enable_lora_hot_loading \
|
| 16 |
+
--template_model_id_or_path "DiffSynth-Studio/ZImage-i2L-v2:" \
|
| 17 |
+
--extra_inputs "template_inputs" \
|
| 18 |
+
--remove_prefix_in_ckpt "pipe.template_model." \
|
| 19 |
+
--trainable_models "template_model" # Use `template_model.emb2lora` to freeze the image encoder.
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/accelerate_config.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
compute_environment: LOCAL_MACHINE
|
| 2 |
+
debug: false
|
| 3 |
+
deepspeed_config:
|
| 4 |
+
gradient_accumulation_steps: 1
|
| 5 |
+
offload_optimizer_device: none
|
| 6 |
+
offload_param_device: none
|
| 7 |
+
zero3_init_flag: false
|
| 8 |
+
zero_stage: 2
|
| 9 |
+
distributed_type: DEEPSPEED
|
| 10 |
+
downcast_bf16: 'no'
|
| 11 |
+
enable_cpu_affinity: false
|
| 12 |
+
machine_rank: 0
|
| 13 |
+
main_training_function: main
|
| 14 |
+
mixed_precision: bf16
|
| 15 |
+
num_machines: 1
|
| 16 |
+
num_processes: 8
|
| 17 |
+
rdzv_backend: static
|
| 18 |
+
same_network: true
|
| 19 |
+
tpu_env: []
|
| 20 |
+
tpu_use_cluster: false
|
| 21 |
+
tpu_use_sudo: false
|
| 22 |
+
use_cpu: false
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/full/accelerate_config_zero3.yaml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
compute_environment: LOCAL_MACHINE
|
| 2 |
+
debug: false
|
| 3 |
+
deepspeed_config:
|
| 4 |
+
gradient_accumulation_steps: 1
|
| 5 |
+
offload_optimizer_device: none
|
| 6 |
+
offload_param_device: none
|
| 7 |
+
zero3_init_flag: true
|
| 8 |
+
zero3_save_16bit_model: true
|
| 9 |
+
zero_stage: 3
|
| 10 |
+
distributed_type: DEEPSPEED
|
| 11 |
+
downcast_bf16: 'no'
|
| 12 |
+
enable_cpu_affinity: false
|
| 13 |
+
machine_rank: 0
|
| 14 |
+
main_training_function: main
|
| 15 |
+
mixed_precision: bf16
|
| 16 |
+
num_machines: 1
|
| 17 |
+
num_processes: 8
|
| 18 |
+
rdzv_backend: static
|
| 19 |
+
same_network: true
|
| 20 |
+
tpu_env: []
|
| 21 |
+
tpu_use_cluster: false
|
| 22 |
+
tpu_use_sudo: false
|
| 23 |
+
use_cpu: false
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Omni-Base.sh
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Omni-Base/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
# Text to image training
|
| 4 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 5 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base \
|
| 6 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base/metadata.csv \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 50 \
|
| 9 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Omni-Base:transformer/*.safetensors,Tongyi-MAI/Z-Image-Omni-Base:siglip/model.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-4 \
|
| 11 |
+
--num_epochs 5 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Omni-Base_lora" \
|
| 14 |
+
--lora_base_model "dit" \
|
| 15 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 16 |
+
--lora_rank 32 \
|
| 17 |
+
--use_gradient_checkpointing \
|
| 18 |
+
--find_unused_parameters \
|
| 19 |
+
--dataset_num_workers 8
|
| 20 |
+
|
| 21 |
+
# Image(s) to image training
|
| 22 |
+
# accelerate launch examples/z_image/model_training/train.py \
|
| 23 |
+
# --dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base \
|
| 24 |
+
# --dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Omni-Base/metadata.csv \
|
| 25 |
+
# --data_file_keys "image,edit_image" \
|
| 26 |
+
# --extra_inputs "edit_image" \
|
| 27 |
+
# --max_pixels 1048576 \
|
| 28 |
+
# --dataset_repeat 50 \
|
| 29 |
+
# --model_id_with_origin_paths "Tongyi-MAI/Z-Image-Omni-Base:transformer/*.safetensors,Tongyi-MAI/Z-Image-Omni-Base:siglip/model.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 30 |
+
# --learning_rate 1e-4 \
|
| 31 |
+
# --num_epochs 5 \
|
| 32 |
+
# --remove_prefix_in_ckpt "pipe.dit." \
|
| 33 |
+
# --output_path "./models/train/Z-Image-Omni-Base_lora_edit" \
|
| 34 |
+
# --lora_base_model "dit" \
|
| 35 |
+
# --lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 36 |
+
# --lora_rank 32 \
|
| 37 |
+
# --use_gradient_checkpointing \
|
| 38 |
+
# --find_unused_parameters \
|
| 39 |
+
# --dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-4 \
|
| 11 |
+
--num_epochs 5 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps_lora" \
|
| 14 |
+
--lora_base_model "dit" \
|
| 15 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 16 |
+
--lora_rank 32 \
|
| 17 |
+
--extra_inputs "controlnet_image" \
|
| 18 |
+
--use_gradient_checkpointing \
|
| 19 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-4 \
|
| 11 |
+
--num_epochs 5 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps_lora" \
|
| 14 |
+
--lora_base_model "dit" \
|
| 15 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 16 |
+
--lora_rank 32 \
|
| 17 |
+
--extra_inputs "controlnet_image" \
|
| 18 |
+
--use_gradient_checkpointing \
|
| 19 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo-Fun-Controlnet-Union-2.1.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1 \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo-Fun-Controlnet-Union-2.1/metadata.csv \
|
| 6 |
+
--data_file_keys "image,controlnet_image" \
|
| 7 |
+
--max_pixels 1048576 \
|
| 8 |
+
--dataset_repeat 100 \
|
| 9 |
+
--model_id_with_origin_paths "PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1:Z-Image-Turbo-Fun-Controlnet-Union-2.1.safetensors,Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 10 |
+
--learning_rate 1e-4 \
|
| 11 |
+
--num_epochs 5 \
|
| 12 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 13 |
+
--output_path "./models/train/Z-Image-Turbo-Fun-Controlnet-Union-2.1_lora" \
|
| 14 |
+
--lora_base_model "dit" \
|
| 15 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 16 |
+
--lora_rank 32 \
|
| 17 |
+
--extra_inputs "controlnet_image" \
|
| 18 |
+
--use_gradient_checkpointing \
|
| 19 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image-Turbo.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo/metadata.csv \
|
| 6 |
+
--max_pixels 1048576 \
|
| 7 |
+
--dataset_repeat 50 \
|
| 8 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 9 |
+
--learning_rate 1e-4 \
|
| 10 |
+
--num_epochs 5 \
|
| 11 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 12 |
+
--output_path "./models/train/Z-Image-Turbo_lora" \
|
| 13 |
+
--lora_base_model "dit" \
|
| 14 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 15 |
+
--lora_rank 32 \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/lora/Z-Image.sh
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image/metadata.csv \
|
| 6 |
+
--max_pixels 1048576 \
|
| 7 |
+
--dataset_repeat 50 \
|
| 8 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 9 |
+
--learning_rate 1e-4 \
|
| 10 |
+
--num_epochs 5 \
|
| 11 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 12 |
+
--output_path "./models/train/Z-Image_lora" \
|
| 13 |
+
--lora_base_model "dit" \
|
| 14 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 15 |
+
--lora_rank 32 \
|
| 16 |
+
--use_gradient_checkpointing \
|
| 17 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/differential_training/Z-Image-Turbo.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Z-Image-Turbo is a distilled model.
|
| 2 |
+
# After training, it loses its distillation-based acceleration capability,
|
| 3 |
+
# leading to degraded generation quality at fewer inference steps.
|
| 4 |
+
# This issue can be mitigated by using a pre-trained LoRA model to assist the training process.
|
| 5 |
+
# https://www.modelscope.cn/models/ostris/zimage_turbo_training_adapter
|
| 6 |
+
|
| 7 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo/*" --local_dir ./data/diffsynth_example_dataset
|
| 8 |
+
|
| 9 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 10 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo \
|
| 11 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo/metadata.csv \
|
| 12 |
+
--max_pixels 1048576 \
|
| 13 |
+
--dataset_repeat 50 \
|
| 14 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 15 |
+
--learning_rate 1e-4 \
|
| 16 |
+
--num_epochs 5 \
|
| 17 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 18 |
+
--output_path "./models/train/Z-Image-Turbo_lora_differential" \
|
| 19 |
+
--lora_base_model "dit" \
|
| 20 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 21 |
+
--lora_rank 32 \
|
| 22 |
+
--preset_lora_path "models/ostris/zimage_turbo_training_adapter/zimage_turbo_training_adapter_v1.safetensors" \
|
| 23 |
+
--preset_lora_model "dit" \
|
| 24 |
+
--use_gradient_checkpointing \
|
| 25 |
+
--dataset_num_workers 8
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/differential_training/validate.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 6 |
+
torch_dtype=torch.bfloat16,
|
| 7 |
+
device="cuda",
|
| 8 |
+
model_configs=[
|
| 9 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 12 |
+
],
|
| 13 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 14 |
+
)
|
| 15 |
+
pipe.load_lora(pipe.dit, "./models/train/Z-Image-Turbo_lora_differential/epoch-4.safetensors")
|
| 16 |
+
prompt = "a dog"
|
| 17 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda")
|
| 18 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/npu_training/Z-Image-Turbo-NPU.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
|
| 2 |
+
export CPU_AFFINITY_CONF=1
|
| 3 |
+
|
| 4 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo/*" --local_dir ./data/diffsynth_example_dataset
|
| 5 |
+
|
| 6 |
+
accelerate launch --config_file examples/z_image/model_training/full/accelerate_config.yaml examples/z_image/model_training/train.py \
|
| 7 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo \
|
| 8 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo/metadata.csv \
|
| 9 |
+
--max_pixels 1048576 \
|
| 10 |
+
--dataset_repeat 400 \
|
| 11 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 12 |
+
--learning_rate 1e-5 \
|
| 13 |
+
--num_epochs 2 \
|
| 14 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 15 |
+
--output_path "./models/train/Z-Image-Turbo_full" \
|
| 16 |
+
--trainable_models "dit" \
|
| 17 |
+
--use_gradient_checkpointing \
|
| 18 |
+
--dataset_num_workers 8 \
|
| 19 |
+
--enable_npu_patch
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/trajectory_imitation/Z-Image-Turbo.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "z_image/Z-Image-Turbo/*" --local_dir ./data/diffsynth_example_dataset
|
| 2 |
+
|
| 3 |
+
accelerate launch examples/z_image/model_training/train.py \
|
| 4 |
+
--dataset_base_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo \
|
| 5 |
+
--dataset_metadata_path data/diffsynth_example_dataset/z_image/Z-Image-Turbo/metadata.csv \
|
| 6 |
+
--max_pixels 1048576 \
|
| 7 |
+
--dataset_repeat 50 \
|
| 8 |
+
--model_id_with_origin_paths "Tongyi-MAI/Z-Image-Turbo:transformer/*.safetensors,Tongyi-MAI/Z-Image-Turbo:text_encoder/*.safetensors,Tongyi-MAI/Z-Image-Turbo:vae/diffusion_pytorch_model.safetensors" \
|
| 9 |
+
--learning_rate 1e-4 \
|
| 10 |
+
--num_epochs 5 \
|
| 11 |
+
--remove_prefix_in_ckpt "pipe.dit." \
|
| 12 |
+
--output_path "./models/train/Z-Image-Turbo_lora_distill" \
|
| 13 |
+
--lora_base_model "dit" \
|
| 14 |
+
--lora_target_modules "to_q,to_k,to_v,to_out.0,w1,w2,w3" \
|
| 15 |
+
--lora_rank 32 \
|
| 16 |
+
--lora_checkpoint "./models/train/Z-Image-Turbo_lora/epoch-4.safetensors" \
|
| 17 |
+
--use_gradient_checkpointing \
|
| 18 |
+
--dataset_num_workers 8 \
|
| 19 |
+
--task "trajectory_imitation" \
|
| 20 |
+
--save_steps 10
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/special/trajectory_imitation/validate.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 6 |
+
torch_dtype=torch.bfloat16,
|
| 7 |
+
device="cuda",
|
| 8 |
+
model_configs=[
|
| 9 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 12 |
+
],
|
| 13 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 14 |
+
)
|
| 15 |
+
pipe.load_lora(pipe.dit, "./models/train/Z-Image-Turbo_lora_distill/step-20.safetensors")
|
| 16 |
+
prompt = "a dog"
|
| 17 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda")
|
| 18 |
+
image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/train.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch, os, argparse, accelerate, copy
|
| 2 |
+
from diffsynth.core import UnifiedDataset
|
| 3 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 4 |
+
from diffsynth.diffusion import *
|
| 5 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ZImageTrainingModule(DiffusionTrainingModule):
|
| 9 |
+
def __init__(
|
| 10 |
+
self,
|
| 11 |
+
model_paths=None, model_id_with_origin_paths=None,
|
| 12 |
+
tokenizer_path=None,
|
| 13 |
+
trainable_models=None,
|
| 14 |
+
lora_base_model=None, lora_target_modules="", lora_rank=32, lora_checkpoint=None,
|
| 15 |
+
preset_lora_path=None, preset_lora_model=None,
|
| 16 |
+
use_gradient_checkpointing=True,
|
| 17 |
+
use_gradient_checkpointing_offload=False,
|
| 18 |
+
extra_inputs=None,
|
| 19 |
+
fp8_models=None,
|
| 20 |
+
offload_models=None,
|
| 21 |
+
template_model_id_or_path=None,
|
| 22 |
+
resume_from_checkpoint=None, remove_prefix_in_ckpt=None,
|
| 23 |
+
enable_lora_hot_loading=False,
|
| 24 |
+
device="cpu",
|
| 25 |
+
task="sft",
|
| 26 |
+
enable_npu_patch=True,
|
| 27 |
+
):
|
| 28 |
+
super().__init__()
|
| 29 |
+
# Load models
|
| 30 |
+
model_configs = self.parse_model_configs(model_paths, model_id_with_origin_paths, fp8_models=fp8_models, offload_models=offload_models, device=device)
|
| 31 |
+
tokenizer_config = ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/") if tokenizer_path is None else ModelConfig(tokenizer_path)
|
| 32 |
+
self.pipe = ZImagePipeline.from_pretrained(torch_dtype=torch.bfloat16, device=device, model_configs=model_configs, tokenizer_config=tokenizer_config, enable_npu_patch=enable_npu_patch)
|
| 33 |
+
self.pipe = self.load_training_template_model(self.pipe, template_model_id_or_path, use_gradient_checkpointing, use_gradient_checkpointing_offload)
|
| 34 |
+
self.pipe = self.split_pipeline_units(task, self.pipe, trainable_models, lora_base_model)
|
| 35 |
+
self.resume_from_checkpoint(resume_from_checkpoint, remove_prefix_in_ckpt)
|
| 36 |
+
if enable_lora_hot_loading: self.pipe.dit = self.pipe.enable_lora_hot_loading(self.pipe.dit)
|
| 37 |
+
|
| 38 |
+
# Training mode
|
| 39 |
+
self.switch_pipe_to_training_mode(
|
| 40 |
+
self.pipe, trainable_models,
|
| 41 |
+
lora_base_model, lora_target_modules, lora_rank, lora_checkpoint,
|
| 42 |
+
preset_lora_path, preset_lora_model,
|
| 43 |
+
task=task,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Other configs
|
| 47 |
+
self.use_gradient_checkpointing = use_gradient_checkpointing
|
| 48 |
+
self.use_gradient_checkpointing_offload = use_gradient_checkpointing_offload
|
| 49 |
+
self.extra_inputs = extra_inputs.split(",") if extra_inputs is not None else []
|
| 50 |
+
self.fp8_models = fp8_models
|
| 51 |
+
self.task = task
|
| 52 |
+
self.task_to_loss = {
|
| 53 |
+
"sft:data_process": lambda pipe, *args: args,
|
| 54 |
+
"direct_distill:data_process": lambda pipe, *args: args,
|
| 55 |
+
"sft": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
|
| 56 |
+
"sft:train": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
|
| 57 |
+
"direct_distill": lambda pipe, inputs_shared, inputs_posi, inputs_nega: DirectDistillLoss(pipe, **inputs_shared, **inputs_posi),
|
| 58 |
+
"direct_distill:train": lambda pipe, inputs_shared, inputs_posi, inputs_nega: DirectDistillLoss(pipe, **inputs_shared, **inputs_posi),
|
| 59 |
+
}
|
| 60 |
+
if task == "trajectory_imitation":
|
| 61 |
+
# This is an experimental feature.
|
| 62 |
+
# We may remove it in the future.
|
| 63 |
+
self.loss_fn = TrajectoryImitationLoss()
|
| 64 |
+
self.task_to_loss["trajectory_imitation"] = self.loss_fn
|
| 65 |
+
self.pipe_teacher = copy.deepcopy(self.pipe)
|
| 66 |
+
self.pipe_teacher.requires_grad_(False)
|
| 67 |
+
|
| 68 |
+
def get_pipeline_inputs(self, data):
|
| 69 |
+
inputs_posi = {"prompt": data["prompt"]}
|
| 70 |
+
inputs_nega = {"negative_prompt": ""}
|
| 71 |
+
inputs_shared = {
|
| 72 |
+
# Assume you are using this pipeline for inference,
|
| 73 |
+
# please fill in the input parameters.
|
| 74 |
+
"input_image": data["image"],
|
| 75 |
+
"height": data["image"].size[1],
|
| 76 |
+
"width": data["image"].size[0],
|
| 77 |
+
# Please do not modify the following parameters
|
| 78 |
+
# unless you clearly know what this will cause.
|
| 79 |
+
"cfg_scale": 1,
|
| 80 |
+
"rand_device": self.pipe.device,
|
| 81 |
+
"use_gradient_checkpointing": self.use_gradient_checkpointing,
|
| 82 |
+
"use_gradient_checkpointing_offload": self.use_gradient_checkpointing_offload,
|
| 83 |
+
}
|
| 84 |
+
if self.task == "trajectory_imitation":
|
| 85 |
+
inputs_shared["cfg_scale"] = 2
|
| 86 |
+
inputs_shared["teacher"] = self.pipe_teacher
|
| 87 |
+
inputs_shared = self.parse_extra_inputs(data, self.extra_inputs, inputs_shared)
|
| 88 |
+
return inputs_shared, inputs_posi, inputs_nega
|
| 89 |
+
|
| 90 |
+
def forward(self, data, inputs=None):
|
| 91 |
+
if inputs is None: inputs = self.get_pipeline_inputs(data)
|
| 92 |
+
inputs = self.transfer_data_to_device(inputs, self.pipe.device, self.pipe.torch_dtype)
|
| 93 |
+
for unit in self.pipe.units:
|
| 94 |
+
inputs = self.pipe.unit_runner(unit, self.pipe, *inputs)
|
| 95 |
+
loss = self.task_to_loss[self.task](self.pipe, *inputs)
|
| 96 |
+
return loss
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def z_image_parser():
|
| 100 |
+
parser = argparse.ArgumentParser(description="Simple example of a training script.")
|
| 101 |
+
parser = add_general_config(parser)
|
| 102 |
+
parser = add_image_size_config(parser)
|
| 103 |
+
parser.add_argument("--tokenizer_path", type=str, default=None, help="Path to tokenizer.")
|
| 104 |
+
parser.add_argument("--enable_npu_patch", default=False, action="store_true", help="Whether to use npu fused operator patch to improve performance in NPU.")
|
| 105 |
+
return parser
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
parser = z_image_parser()
|
| 110 |
+
args = parser.parse_args()
|
| 111 |
+
accelerator = accelerate.Accelerator(
|
| 112 |
+
gradient_accumulation_steps=args.gradient_accumulation_steps,
|
| 113 |
+
kwargs_handlers=[accelerate.DistributedDataParallelKwargs(find_unused_parameters=args.find_unused_parameters)],
|
| 114 |
+
)
|
| 115 |
+
dataset = UnifiedDataset(
|
| 116 |
+
base_path=args.dataset_base_path,
|
| 117 |
+
metadata_path=args.dataset_metadata_path,
|
| 118 |
+
repeat=args.dataset_repeat,
|
| 119 |
+
data_file_keys=args.data_file_keys.split(","),
|
| 120 |
+
main_data_operator=UnifiedDataset.default_image_operator(
|
| 121 |
+
base_path=args.dataset_base_path,
|
| 122 |
+
max_pixels=args.max_pixels,
|
| 123 |
+
height=args.height,
|
| 124 |
+
width=args.width,
|
| 125 |
+
height_division_factor=16,
|
| 126 |
+
width_division_factor=16,
|
| 127 |
+
)
|
| 128 |
+
)
|
| 129 |
+
model = ZImageTrainingModule(
|
| 130 |
+
model_paths=args.model_paths,
|
| 131 |
+
model_id_with_origin_paths=args.model_id_with_origin_paths,
|
| 132 |
+
tokenizer_path=args.tokenizer_path,
|
| 133 |
+
trainable_models=args.trainable_models,
|
| 134 |
+
lora_base_model=args.lora_base_model,
|
| 135 |
+
lora_target_modules=args.lora_target_modules,
|
| 136 |
+
lora_rank=args.lora_rank,
|
| 137 |
+
lora_checkpoint=args.lora_checkpoint,
|
| 138 |
+
preset_lora_path=args.preset_lora_path,
|
| 139 |
+
preset_lora_model=args.preset_lora_model,
|
| 140 |
+
use_gradient_checkpointing=args.use_gradient_checkpointing,
|
| 141 |
+
use_gradient_checkpointing_offload=args.use_gradient_checkpointing_offload,
|
| 142 |
+
extra_inputs=args.extra_inputs,
|
| 143 |
+
fp8_models=args.fp8_models,
|
| 144 |
+
offload_models=args.offload_models,
|
| 145 |
+
template_model_id_or_path=args.template_model_id_or_path,
|
| 146 |
+
resume_from_checkpoint=args.resume_from_checkpoint,
|
| 147 |
+
remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
|
| 148 |
+
enable_lora_hot_loading=args.enable_lora_hot_loading,
|
| 149 |
+
task=args.task,
|
| 150 |
+
device="cpu" if args.enable_model_cpu_offload else accelerator.device,
|
| 151 |
+
enable_npu_patch=args.enable_npu_patch
|
| 152 |
+
)
|
| 153 |
+
model_logger = ModelLogger(
|
| 154 |
+
args.output_path,
|
| 155 |
+
remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
|
| 156 |
+
enable_tensorboard_log=args.enable_tensorboard_log,
|
| 157 |
+
enable_swanlab_log=args.enable_swanlab_log,
|
| 158 |
+
swanlab_project=args.swanlab_project,
|
| 159 |
+
enable_wandb_log=args.enable_wandb_log,
|
| 160 |
+
wandb_project=args.wandb_project,
|
| 161 |
+
)
|
| 162 |
+
launcher_map = {
|
| 163 |
+
"sft:data_process": launch_data_process_task,
|
| 164 |
+
"direct_distill:data_process": launch_data_process_task,
|
| 165 |
+
"sft": launch_training_task,
|
| 166 |
+
"sft:train": launch_training_task,
|
| 167 |
+
"direct_distill": launch_training_task,
|
| 168 |
+
"direct_distill:train": launch_training_task,
|
| 169 |
+
"trajectory_imitation": launch_training_task,
|
| 170 |
+
}
|
| 171 |
+
launcher_map[args.task](accelerator, dataset, model, model_logger, args=args)
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/validate_full/Z-Image-Omni-Base.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig
|
| 2 |
+
from diffsynth.core import load_state_dict
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 7 |
+
torch_dtype=torch.bfloat16,
|
| 8 |
+
device="cuda",
|
| 9 |
+
model_configs=[
|
| 10 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="transformer/*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Omni-Base", origin_file_pattern="siglip/model.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 14 |
+
],
|
| 15 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
state_dict = load_state_dict("./models/train/Z-Image-Omni-Base_full/epoch-1.safetensors", torch_dtype=torch.bfloat16)
|
| 19 |
+
pipe.dit.load_state_dict(state_dict)
|
| 20 |
+
prompt = "a dog"
|
| 21 |
+
image = pipe(prompt=prompt, seed=42, rand_device="cuda", num_inference_steps=40, cfg_scale=4)
|
| 22 |
+
image.save("image.jpg")
|
| 23 |
+
|
| 24 |
+
# Edit
|
| 25 |
+
# state_dict = load_state_dict("./models/train/Z-Image-Omni-Base_full_edit/epoch-1.safetensors", torch_dtype=torch.bfloat16)
|
| 26 |
+
# pipe.dit.load_state_dict(state_dict)
|
| 27 |
+
# prompt = "Change the color of the dress in Figure 1 to the color shown in Figure 2."
|
| 28 |
+
# images = [
|
| 29 |
+
# Image.open("data/example_image_dataset/edit/image1.jpg").resize((1024, 1024)),
|
| 30 |
+
# Image.open("data/example_image_dataset/edit/image_color.jpg").resize((1024, 1024)),
|
| 31 |
+
# ]
|
| 32 |
+
# image = pipe(prompt=prompt, seed=42, rand_device="cuda", num_inference_steps=40, cfg_scale=4, edit_image=images)
|
| 33 |
+
# image.save("image.jpg")
|
video_gen_14d/third_party/DiffSynth-Studio/examples/z_image/model_training/validate_full/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffsynth.pipelines.z_image import ZImagePipeline, ModelConfig, ControlNetInput
|
| 2 |
+
from diffsynth import load_state_dict
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 8 |
+
torch_dtype=torch.bfloat16,
|
| 9 |
+
device="cuda",
|
| 10 |
+
model_configs=[
|
| 11 |
+
ModelConfig(model_id="PAI/Z-Image-Turbo-Fun-Controlnet-Union-2.1", origin_file_pattern="Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors"),
|
| 12 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="transformer/*.safetensors"),
|
| 13 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="text_encoder/*.safetensors"),
|
| 14 |
+
ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 15 |
+
],
|
| 16 |
+
tokenizer_config=ModelConfig(model_id="Tongyi-MAI/Z-Image-Turbo", origin_file_pattern="tokenizer/"),
|
| 17 |
+
)
|
| 18 |
+
state_dict = load_state_dict("./models/train/Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps_full/epoch-1.safetensors")
|
| 19 |
+
pipe.controlnet.load_state_dict(state_dict)
|
| 20 |
+
|
| 21 |
+
controlnet_image = Image.open("data/example_image_dataset/upscale/image_1.jpg").resize((1024, 1024))
|
| 22 |
+
prompt = "a dog"
|
| 23 |
+
image = pipe(prompt=prompt, seed=0, height=1024, width=1024, controlnet_inputs=[ControlNetInput(image=controlnet_image, scale=1)])
|
| 24 |
+
image.save("image_tile.jpg")
|