Spaces:
Configuration error
Configuration error
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +16 -0
- .gitignore +14 -0
- Dataset/data_video.py +452 -0
- Dataset/dummy_datasets.py +106 -0
- Dataset/sakuga_dataset.py +401 -0
- Dataset/sakuga_dataset_auto.py +412 -0
- Dataset/video_dataset.py +333 -0
- Dataset/webds.py +389 -0
- LICENSE +201 -0
- MODEL_LICENSE +71 -0
- README.md +105 -12
- accelerate_config_machine_single.yaml +24 -0
- diffusers/.github/ISSUE_TEMPLATE/bug-report.yml +110 -0
- diffusers/.github/ISSUE_TEMPLATE/config.yml +4 -0
- diffusers/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- diffusers/.github/ISSUE_TEMPLATE/feedback.md +12 -0
- diffusers/.github/ISSUE_TEMPLATE/new-model-addition.yml +31 -0
- diffusers/.github/ISSUE_TEMPLATE/translate.md +29 -0
- diffusers/.github/PULL_REQUEST_TEMPLATE.md +61 -0
- diffusers/.github/actions/setup-miniconda/action.yml +146 -0
- diffusers/.github/workflows/benchmark.yml +67 -0
- diffusers/.github/workflows/build_docker_images.yml +103 -0
- diffusers/.github/workflows/build_documentation.yml +27 -0
- diffusers/.github/workflows/build_pr_documentation.yml +23 -0
- diffusers/.github/workflows/mirror_community_pipeline.yml +102 -0
- diffusers/.github/workflows/nightly_tests.yml +408 -0
- diffusers/.github/workflows/notify_slack_about_release.yml +23 -0
- diffusers/.github/workflows/pr_dependency_test.yml +35 -0
- diffusers/.github/workflows/pr_flax_dependency_test.yml +38 -0
- diffusers/.github/workflows/pr_test_fetcher.yml +177 -0
- diffusers/.github/workflows/pr_test_peft_backend.yml +134 -0
- diffusers/.github/workflows/pr_tests.yml +236 -0
- diffusers/.github/workflows/pr_torch_dependency_test.yml +36 -0
- diffusers/.github/workflows/push_tests.yml +391 -0
- diffusers/.github/workflows/push_tests_fast.yml +126 -0
- diffusers/.github/workflows/push_tests_mps.yml +76 -0
- diffusers/.github/workflows/pypi_publish.yaml +81 -0
- diffusers/.github/workflows/release_tests_fast.yml +389 -0
- diffusers/.github/workflows/run_tests_from_a_pr.yml +74 -0
- diffusers/.github/workflows/ssh-pr-runner.yml +40 -0
- diffusers/.github/workflows/ssh-runner.yml +51 -0
- diffusers/.github/workflows/stale.yml +30 -0
- diffusers/.github/workflows/trufflehog.yml +15 -0
- diffusers/.github/workflows/typos.yml +14 -0
- diffusers/.github/workflows/update_metadata.yml +30 -0
- diffusers/.github/workflows/upload_pr_documentation.yml +16 -0
- diffusers/.gitignore +178 -0
- diffusers/CITATION.cff +52 -0
- diffusers/CODE_OF_CONDUCT.md +130 -0
- diffusers/CONTRIBUTING.md +506 -0
.gitattributes
CHANGED
@@ -33,3 +33,19 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
diffusers/docs/source/en/imgs/access_request.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
diffusers/examples/research_projects/gligen/generated-images-100000-00.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
inference/gradio_composite_demo/example_images/beach.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
inference/gradio_composite_demo/example_images/camping.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
inference/gradio_composite_demo/example_images/street.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
inference/gradio_composite_demo/example_videos/kitten.mp4 filter=lfs diff=lfs merge=lfs -text
|
42 |
+
inference/gradio_composite_demo/example_videos/train_running.mp4 filter=lfs diff=lfs merge=lfs -text
|
43 |
+
tools/caption/assests/CogVLM2-Caption-example.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
tools/caption/assests/cogvlm2-video-example.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
video/showcase_1.mp4 filter=lfs diff=lfs merge=lfs -text
|
46 |
+
video/showcase_2.mp4 filter=lfs diff=lfs merge=lfs -text
|
47 |
+
video/showcase_3.mp4 filter=lfs diff=lfs merge=lfs -text
|
48 |
+
video/text_1.mp4 filter=lfs diff=lfs merge=lfs -text
|
49 |
+
video/text_2.mp4 filter=lfs diff=lfs merge=lfs -text
|
50 |
+
video/text_3.mp4 filter=lfs diff=lfs merge=lfs -text
|
51 |
+
video/video.mp4 filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*__pycache__/
|
2 |
+
samples*/
|
3 |
+
runs/
|
4 |
+
checkpoints/
|
5 |
+
master_ip
|
6 |
+
logs/
|
7 |
+
*.DS_Store
|
8 |
+
.idea
|
9 |
+
output*
|
10 |
+
test/
|
11 |
+
wandb/
|
12 |
+
pretrained_weight/
|
13 |
+
.vscode/
|
14 |
+
Test_Dataset/
|
Dataset/data_video.py
ADDED
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
from functools import partial
|
5 |
+
import math
|
6 |
+
import torchvision.transforms as TT
|
7 |
+
from webds import MetaDistributedWebDataset
|
8 |
+
import random
|
9 |
+
from fractions import Fraction
|
10 |
+
from typing import Union, Optional, Dict, Any, Tuple
|
11 |
+
from torchvision.io.video import av
|
12 |
+
import numpy as np
|
13 |
+
import torch
|
14 |
+
from torchvision.io import _video_opt
|
15 |
+
from torchvision.io.video import _check_av_available, _read_from_stream, _align_audio_frames
|
16 |
+
from torchvision.transforms.functional import center_crop, resize
|
17 |
+
from torchvision.transforms import InterpolationMode
|
18 |
+
import decord
|
19 |
+
from decord import VideoReader
|
20 |
+
from torch.utils.data import Dataset
|
21 |
+
|
22 |
+
|
23 |
+
def read_video(
|
24 |
+
filename: str,
|
25 |
+
start_pts: Union[float, Fraction] = 0,
|
26 |
+
end_pts: Optional[Union[float, Fraction]] = None,
|
27 |
+
pts_unit: str = "pts",
|
28 |
+
output_format: str = "THWC",
|
29 |
+
) -> Tuple[torch.Tensor, torch.Tensor, Dict[str, Any]]:
|
30 |
+
"""
|
31 |
+
Reads a video from a file, returning both the video frames and the audio frames
|
32 |
+
|
33 |
+
Args:
|
34 |
+
filename (str): path to the video file
|
35 |
+
start_pts (int if pts_unit = 'pts', float / Fraction if pts_unit = 'sec', optional):
|
36 |
+
The start presentation time of the video
|
37 |
+
end_pts (int if pts_unit = 'pts', float / Fraction if pts_unit = 'sec', optional):
|
38 |
+
The end presentation time
|
39 |
+
pts_unit (str, optional): unit in which start_pts and end_pts values will be interpreted,
|
40 |
+
either 'pts' or 'sec'. Defaults to 'pts'.
|
41 |
+
output_format (str, optional): The format of the output video tensors. Can be either "THWC" (default) or "TCHW".
|
42 |
+
|
43 |
+
Returns:
|
44 |
+
vframes (Tensor[T, H, W, C] or Tensor[T, C, H, W]): the `T` video frames
|
45 |
+
aframes (Tensor[K, L]): the audio frames, where `K` is the number of channels and `L` is the number of points
|
46 |
+
info (Dict): metadata for the video and audio. Can contain the fields video_fps (float) and audio_fps (int)
|
47 |
+
"""
|
48 |
+
|
49 |
+
output_format = output_format.upper()
|
50 |
+
if output_format not in ("THWC", "TCHW"):
|
51 |
+
raise ValueError(f"output_format should be either 'THWC' or 'TCHW', got {output_format}.")
|
52 |
+
|
53 |
+
_check_av_available()
|
54 |
+
|
55 |
+
if end_pts is None:
|
56 |
+
end_pts = float("inf")
|
57 |
+
|
58 |
+
if end_pts < start_pts:
|
59 |
+
raise ValueError(f"end_pts should be larger than start_pts, got start_pts={start_pts} and end_pts={end_pts}")
|
60 |
+
|
61 |
+
info = {}
|
62 |
+
audio_frames = []
|
63 |
+
audio_timebase = _video_opt.default_timebase
|
64 |
+
|
65 |
+
with av.open(filename, metadata_errors="ignore") as container:
|
66 |
+
if container.streams.audio:
|
67 |
+
audio_timebase = container.streams.audio[0].time_base
|
68 |
+
if container.streams.video:
|
69 |
+
video_frames = _read_from_stream(
|
70 |
+
container,
|
71 |
+
start_pts,
|
72 |
+
end_pts,
|
73 |
+
pts_unit,
|
74 |
+
container.streams.video[0],
|
75 |
+
{"video": 0},
|
76 |
+
)
|
77 |
+
video_fps = container.streams.video[0].average_rate
|
78 |
+
# guard against potentially corrupted files
|
79 |
+
if video_fps is not None:
|
80 |
+
info["video_fps"] = float(video_fps)
|
81 |
+
|
82 |
+
if container.streams.audio:
|
83 |
+
audio_frames = _read_from_stream(
|
84 |
+
container,
|
85 |
+
start_pts,
|
86 |
+
end_pts,
|
87 |
+
pts_unit,
|
88 |
+
container.streams.audio[0],
|
89 |
+
{"audio": 0},
|
90 |
+
)
|
91 |
+
info["audio_fps"] = container.streams.audio[0].rate
|
92 |
+
|
93 |
+
aframes_list = [frame.to_ndarray() for frame in audio_frames]
|
94 |
+
|
95 |
+
vframes = torch.empty((0, 1, 1, 3), dtype=torch.uint8)
|
96 |
+
|
97 |
+
if aframes_list:
|
98 |
+
aframes = np.concatenate(aframes_list, 1)
|
99 |
+
aframes = torch.as_tensor(aframes)
|
100 |
+
if pts_unit == "sec":
|
101 |
+
start_pts = int(math.floor(start_pts * (1 / audio_timebase)))
|
102 |
+
if end_pts != float("inf"):
|
103 |
+
end_pts = int(math.ceil(end_pts * (1 / audio_timebase)))
|
104 |
+
aframes = _align_audio_frames(aframes, audio_frames, start_pts, end_pts)
|
105 |
+
else:
|
106 |
+
aframes = torch.empty((1, 0), dtype=torch.float32)
|
107 |
+
|
108 |
+
if output_format == "TCHW":
|
109 |
+
# [T,H,W,C] --> [T,C,H,W]
|
110 |
+
vframes = vframes.permute(0, 3, 1, 2)
|
111 |
+
|
112 |
+
return vframes, aframes, info
|
113 |
+
|
114 |
+
|
115 |
+
def resize_for_rectangle_crop(arr, image_size, reshape_mode="random"):
|
116 |
+
if arr.shape[3] / arr.shape[2] > image_size[1] / image_size[0]:
|
117 |
+
arr = resize(
|
118 |
+
arr,
|
119 |
+
size=[image_size[0], int(arr.shape[3] * image_size[0] / arr.shape[2])],
|
120 |
+
interpolation=InterpolationMode.BICUBIC,
|
121 |
+
)
|
122 |
+
else:
|
123 |
+
arr = resize(
|
124 |
+
arr,
|
125 |
+
size=[int(arr.shape[2] * image_size[1] / arr.shape[3]), image_size[1]],
|
126 |
+
interpolation=InterpolationMode.BICUBIC,
|
127 |
+
)
|
128 |
+
|
129 |
+
h, w = arr.shape[2], arr.shape[3]
|
130 |
+
arr = arr.squeeze(0)
|
131 |
+
|
132 |
+
delta_h = h - image_size[0]
|
133 |
+
delta_w = w - image_size[1]
|
134 |
+
|
135 |
+
if reshape_mode == "random" or reshape_mode == "none":
|
136 |
+
top = np.random.randint(0, delta_h + 1)
|
137 |
+
left = np.random.randint(0, delta_w + 1)
|
138 |
+
elif reshape_mode == "center":
|
139 |
+
top, left = delta_h // 2, delta_w // 2
|
140 |
+
else:
|
141 |
+
raise NotImplementedError
|
142 |
+
arr = TT.functional.crop(arr, top=top, left=left, height=image_size[0], width=image_size[1])
|
143 |
+
return arr
|
144 |
+
|
145 |
+
|
146 |
+
def pad_last_frame(tensor, num_frames):
|
147 |
+
# T, H, W, C
|
148 |
+
if len(tensor) < num_frames:
|
149 |
+
pad_length = num_frames - len(tensor)
|
150 |
+
# Use the last frame to pad instead of zero
|
151 |
+
last_frame = tensor[-1]
|
152 |
+
pad_tensor = last_frame.unsqueeze(0).expand(pad_length, *tensor.shape[1:])
|
153 |
+
padded_tensor = torch.cat([tensor, pad_tensor], dim=0)
|
154 |
+
return padded_tensor
|
155 |
+
else:
|
156 |
+
return tensor[:num_frames]
|
157 |
+
|
158 |
+
|
159 |
+
def load_video(
|
160 |
+
video_data,
|
161 |
+
sampling="uniform",
|
162 |
+
duration=None,
|
163 |
+
num_frames=4,
|
164 |
+
wanted_fps=None,
|
165 |
+
actual_fps=None,
|
166 |
+
skip_frms_num=0.0,
|
167 |
+
nb_read_frames=None,
|
168 |
+
):
|
169 |
+
decord.bridge.set_bridge("torch")
|
170 |
+
vr = VideoReader(uri=video_data, height=-1, width=-1)
|
171 |
+
if nb_read_frames is not None:
|
172 |
+
ori_vlen = nb_read_frames
|
173 |
+
else:
|
174 |
+
ori_vlen = min(int(duration * actual_fps) - 1, len(vr))
|
175 |
+
|
176 |
+
max_seek = int(ori_vlen - skip_frms_num - num_frames / wanted_fps * actual_fps)
|
177 |
+
start = random.randint(skip_frms_num, max_seek + 1)
|
178 |
+
end = int(start + num_frames / wanted_fps * actual_fps)
|
179 |
+
n_frms = num_frames
|
180 |
+
|
181 |
+
if sampling == "uniform":
|
182 |
+
indices = np.arange(start, end, (end - start) / n_frms).astype(int)
|
183 |
+
else:
|
184 |
+
raise NotImplementedError
|
185 |
+
|
186 |
+
# get_batch -> T, H, W, C
|
187 |
+
temp_frms = vr.get_batch(np.arange(start, end))
|
188 |
+
assert temp_frms is not None
|
189 |
+
tensor_frms = torch.from_numpy(temp_frms) if type(temp_frms) is not torch.Tensor else temp_frms
|
190 |
+
tensor_frms = tensor_frms[torch.tensor((indices - start).tolist())]
|
191 |
+
|
192 |
+
return pad_last_frame(tensor_frms, num_frames)
|
193 |
+
|
194 |
+
|
195 |
+
import threading
|
196 |
+
|
197 |
+
|
198 |
+
def load_video_with_timeout(*args, **kwargs):
|
199 |
+
video_container = {}
|
200 |
+
|
201 |
+
def target_function():
|
202 |
+
video = load_video(*args, **kwargs)
|
203 |
+
video_container["video"] = video
|
204 |
+
|
205 |
+
thread = threading.Thread(target=target_function)
|
206 |
+
thread.start()
|
207 |
+
timeout = 20
|
208 |
+
thread.join(timeout)
|
209 |
+
|
210 |
+
if thread.is_alive():
|
211 |
+
print("Loading video timed out")
|
212 |
+
raise TimeoutError
|
213 |
+
return video_container.get("video", None).contiguous()
|
214 |
+
|
215 |
+
|
216 |
+
def process_video(
|
217 |
+
video_path,
|
218 |
+
image_size=None,
|
219 |
+
duration=None,
|
220 |
+
num_frames=4,
|
221 |
+
wanted_fps=None,
|
222 |
+
actual_fps=None,
|
223 |
+
skip_frms_num=0.0,
|
224 |
+
nb_read_frames=None,
|
225 |
+
):
|
226 |
+
"""
|
227 |
+
video_path: str or io.BytesIO
|
228 |
+
image_size: .
|
229 |
+
duration: preknow the duration to speed up by seeking to sampled start. TODO by_pass if unknown.
|
230 |
+
num_frames: wanted num_frames.
|
231 |
+
wanted_fps: .
|
232 |
+
skip_frms_num: ignore the first and the last xx frames, avoiding transitions.
|
233 |
+
"""
|
234 |
+
|
235 |
+
video = load_video_with_timeout(
|
236 |
+
video_path,
|
237 |
+
duration=duration,
|
238 |
+
num_frames=num_frames,
|
239 |
+
wanted_fps=wanted_fps,
|
240 |
+
actual_fps=actual_fps,
|
241 |
+
skip_frms_num=skip_frms_num,
|
242 |
+
nb_read_frames=nb_read_frames,
|
243 |
+
)
|
244 |
+
|
245 |
+
# --- copy and modify the image process ---
|
246 |
+
video = video.permute(0, 3, 1, 2) # [T, C, H, W]
|
247 |
+
|
248 |
+
# resize
|
249 |
+
if image_size is not None:
|
250 |
+
video = resize_for_rectangle_crop(video, image_size, reshape_mode="center")
|
251 |
+
|
252 |
+
return video
|
253 |
+
|
254 |
+
|
255 |
+
def process_fn_video(src, image_size, fps, num_frames, skip_frms_num=0.0, txt_key="caption"):
|
256 |
+
while True:
|
257 |
+
r = next(src)
|
258 |
+
if "mp4" in r:
|
259 |
+
video_data = r["mp4"]
|
260 |
+
elif "avi" in r:
|
261 |
+
video_data = r["avi"]
|
262 |
+
else:
|
263 |
+
print("No video data found")
|
264 |
+
continue
|
265 |
+
|
266 |
+
if txt_key not in r:
|
267 |
+
txt = ""
|
268 |
+
else:
|
269 |
+
txt = r[txt_key]
|
270 |
+
|
271 |
+
if isinstance(txt, bytes):
|
272 |
+
txt = txt.decode("utf-8")
|
273 |
+
else:
|
274 |
+
txt = str(txt)
|
275 |
+
|
276 |
+
duration = r.get("duration", None)
|
277 |
+
if duration is not None:
|
278 |
+
duration = float(duration)
|
279 |
+
else:
|
280 |
+
continue
|
281 |
+
|
282 |
+
actual_fps = r.get("fps", None)
|
283 |
+
if actual_fps is not None:
|
284 |
+
actual_fps = float(actual_fps)
|
285 |
+
else:
|
286 |
+
continue
|
287 |
+
|
288 |
+
required_frames = num_frames / fps * actual_fps + 2 * skip_frms_num
|
289 |
+
required_duration = num_frames / fps + 2 * skip_frms_num / actual_fps
|
290 |
+
|
291 |
+
if duration is not None and duration < required_duration:
|
292 |
+
continue
|
293 |
+
|
294 |
+
try:
|
295 |
+
frames = process_video(
|
296 |
+
io.BytesIO(video_data),
|
297 |
+
num_frames=num_frames,
|
298 |
+
wanted_fps=fps,
|
299 |
+
image_size=image_size,
|
300 |
+
duration=duration,
|
301 |
+
actual_fps=actual_fps,
|
302 |
+
skip_frms_num=skip_frms_num,
|
303 |
+
)
|
304 |
+
frames = (frames - 127.5) / 127.5
|
305 |
+
except Exception as e:
|
306 |
+
print(e)
|
307 |
+
continue
|
308 |
+
|
309 |
+
item = {
|
310 |
+
"mp4": frames,
|
311 |
+
"txt": txt,
|
312 |
+
"num_frames": num_frames,
|
313 |
+
"fps": fps,
|
314 |
+
}
|
315 |
+
|
316 |
+
yield item
|
317 |
+
|
318 |
+
|
319 |
+
class VideoDataset(MetaDistributedWebDataset):
|
320 |
+
def __init__(
|
321 |
+
self,
|
322 |
+
path,
|
323 |
+
image_size,
|
324 |
+
num_frames,
|
325 |
+
fps,
|
326 |
+
skip_frms_num=0.0,
|
327 |
+
nshards=sys.maxsize,
|
328 |
+
seed=1,
|
329 |
+
meta_names=None,
|
330 |
+
shuffle_buffer=1000,
|
331 |
+
include_dirs=None,
|
332 |
+
txt_key="caption",
|
333 |
+
**kwargs,
|
334 |
+
):
|
335 |
+
if seed == -1:
|
336 |
+
seed = random.randint(0, 1000000)
|
337 |
+
if meta_names is None:
|
338 |
+
meta_names = []
|
339 |
+
|
340 |
+
if path.startswith(";"):
|
341 |
+
path, include_dirs = path.split(";", 1)
|
342 |
+
super().__init__(
|
343 |
+
path,
|
344 |
+
partial(
|
345 |
+
process_fn_video, num_frames=num_frames, image_size=image_size, fps=fps, skip_frms_num=skip_frms_num
|
346 |
+
),
|
347 |
+
seed,
|
348 |
+
meta_names=meta_names,
|
349 |
+
shuffle_buffer=shuffle_buffer,
|
350 |
+
nshards=nshards,
|
351 |
+
include_dirs=include_dirs,
|
352 |
+
)
|
353 |
+
|
354 |
+
@classmethod
|
355 |
+
def create_dataset_function(cls, path, args, **kwargs):
|
356 |
+
return cls(path, **kwargs)
|
357 |
+
|
358 |
+
|
359 |
+
class SFTDataset(Dataset):
|
360 |
+
def __init__(self, data_dir, video_size, fps, max_num_frames, skip_frms_num=3):
|
361 |
+
"""
|
362 |
+
skip_frms_num: ignore the first and the last xx frames, avoiding transitions.
|
363 |
+
"""
|
364 |
+
super(SFTDataset, self).__init__()
|
365 |
+
|
366 |
+
self.video_size = video_size
|
367 |
+
self.fps = fps
|
368 |
+
self.max_num_frames = max_num_frames
|
369 |
+
self.skip_frms_num = skip_frms_num
|
370 |
+
|
371 |
+
self.video_paths = []
|
372 |
+
self.captions = []
|
373 |
+
|
374 |
+
for root, dirnames, filenames in os.walk(data_dir):
|
375 |
+
for filename in filenames:
|
376 |
+
if filename.endswith(".mp4"):
|
377 |
+
video_path = os.path.join(root, filename)
|
378 |
+
self.video_paths.append(video_path)
|
379 |
+
|
380 |
+
caption_path = video_path.replace(".mp4", ".txt").replace("videos", "labels")
|
381 |
+
if os.path.exists(caption_path):
|
382 |
+
caption = open(caption_path, "r").read().splitlines()[0]
|
383 |
+
else:
|
384 |
+
caption = ""
|
385 |
+
self.captions.append(caption)
|
386 |
+
|
387 |
+
def __getitem__(self, index):
|
388 |
+
decord.bridge.set_bridge("torch")
|
389 |
+
|
390 |
+
video_path = self.video_paths[index]
|
391 |
+
vr = VideoReader(uri=video_path, height=-1, width=-1)
|
392 |
+
actual_fps = vr.get_avg_fps()
|
393 |
+
ori_vlen = len(vr)
|
394 |
+
|
395 |
+
if ori_vlen / actual_fps * self.fps > self.max_num_frames:
|
396 |
+
num_frames = self.max_num_frames
|
397 |
+
start = int(self.skip_frms_num)
|
398 |
+
end = int(start + num_frames / self.fps * actual_fps)
|
399 |
+
end_safty = min(int(start + num_frames / self.fps * actual_fps), int(ori_vlen))
|
400 |
+
indices = np.arange(start, end, (end - start) // num_frames).astype(int)
|
401 |
+
temp_frms = vr.get_batch(np.arange(start, end_safty))
|
402 |
+
assert temp_frms is not None
|
403 |
+
tensor_frms = torch.from_numpy(temp_frms) if type(temp_frms) is not torch.Tensor else temp_frms
|
404 |
+
tensor_frms = tensor_frms[torch.tensor((indices - start).tolist())]
|
405 |
+
else:
|
406 |
+
if ori_vlen > self.max_num_frames:
|
407 |
+
num_frames = self.max_num_frames
|
408 |
+
start = int(self.skip_frms_num)
|
409 |
+
end = int(ori_vlen - self.skip_frms_num)
|
410 |
+
indices = np.arange(start, end, max((end - start) // num_frames, 1)).astype(int)
|
411 |
+
temp_frms = vr.get_batch(np.arange(start, end))
|
412 |
+
assert temp_frms is not None
|
413 |
+
tensor_frms = torch.from_numpy(temp_frms) if type(temp_frms) is not torch.Tensor else temp_frms
|
414 |
+
tensor_frms = tensor_frms[torch.tensor((indices - start).tolist())]
|
415 |
+
else:
|
416 |
+
|
417 |
+
def nearest_smaller_4k_plus_1(n):
|
418 |
+
remainder = n % 4
|
419 |
+
if remainder == 0:
|
420 |
+
return n - 3
|
421 |
+
else:
|
422 |
+
return n - remainder + 1
|
423 |
+
|
424 |
+
start = int(self.skip_frms_num)
|
425 |
+
end = int(ori_vlen - self.skip_frms_num)
|
426 |
+
num_frames = nearest_smaller_4k_plus_1(end - start) # 3D VAE requires the number of frames to be 4k+1
|
427 |
+
end = int(start + num_frames)
|
428 |
+
temp_frms = vr.get_batch(np.arange(start, end))
|
429 |
+
assert temp_frms is not None
|
430 |
+
tensor_frms = torch.from_numpy(temp_frms) if type(temp_frms) is not torch.Tensor else temp_frms
|
431 |
+
|
432 |
+
tensor_frms = pad_last_frame(
|
433 |
+
tensor_frms, self.max_num_frames
|
434 |
+
) # the len of indices may be less than num_frames, due to round error
|
435 |
+
tensor_frms = tensor_frms.permute(0, 3, 1, 2) # [T, H, W, C] -> [T, C, H, W]
|
436 |
+
tensor_frms = resize_for_rectangle_crop(tensor_frms, self.video_size, reshape_mode="center")
|
437 |
+
tensor_frms = (tensor_frms - 127.5) / 127.5
|
438 |
+
|
439 |
+
item = {
|
440 |
+
"mp4": tensor_frms,
|
441 |
+
"txt": self.captions[index],
|
442 |
+
"num_frames": num_frames,
|
443 |
+
"fps": self.fps,
|
444 |
+
}
|
445 |
+
return item
|
446 |
+
|
447 |
+
def __len__(self):
|
448 |
+
return len(self.video_paths)
|
449 |
+
|
450 |
+
@classmethod
|
451 |
+
def create_dataset_function(cls, path, args, **kwargs):
|
452 |
+
return cls(data_dir=path, **kwargs)
|
Dataset/dummy_datasets.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
import glob
|
4 |
+
import random
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
import torch
|
9 |
+
from torch.utils.data import Dataset
|
10 |
+
import torchvision
|
11 |
+
import torch.distributed as dist
|
12 |
+
|
13 |
+
from decord import VideoReader
|
14 |
+
|
15 |
+
|
16 |
+
class DummyDataset(Dataset):
|
17 |
+
def __init__(
|
18 |
+
self,
|
19 |
+
# width=1024, height=576,
|
20 |
+
sample_frames=25,
|
21 |
+
base_folder='data/samples/',
|
22 |
+
file_list=None,
|
23 |
+
temporal_sample=None,
|
24 |
+
transform=None,
|
25 |
+
seed=42,
|
26 |
+
):
|
27 |
+
"""
|
28 |
+
Args:
|
29 |
+
num_samples (int): Number of samples in the dataset.
|
30 |
+
channels (int): Number of channels, default is 3 for RGB.
|
31 |
+
"""
|
32 |
+
# Define the path to the folder containing video frames
|
33 |
+
# self.base_folder = 'bdd100k/images/track/mini'
|
34 |
+
self.base_folder = base_folder
|
35 |
+
|
36 |
+
self.file_list = file_list
|
37 |
+
if file_list is None:
|
38 |
+
self.video_lists = glob.glob(os.path.join(self.base_folder, '*.mp4'))
|
39 |
+
else:
|
40 |
+
# read from file_list.txt
|
41 |
+
self.video_lists = []
|
42 |
+
with open(file_list, 'r') as f:
|
43 |
+
for line in f:
|
44 |
+
video_path = line.strip()
|
45 |
+
self.video_lists.append(os.path.join(self.base_folder, video_path))
|
46 |
+
|
47 |
+
self.num_samples = len(self.video_lists)
|
48 |
+
self.channels = 3
|
49 |
+
# self.width = width
|
50 |
+
# self.height = height
|
51 |
+
self.sample_frames = sample_frames
|
52 |
+
self.temporal_sample = temporal_sample
|
53 |
+
self.transform = transform
|
54 |
+
|
55 |
+
self.seed = seed
|
56 |
+
|
57 |
+
def __len__(self):
|
58 |
+
return self.num_samples
|
59 |
+
|
60 |
+
def get_sample(self, idx):
|
61 |
+
"""
|
62 |
+
Args:
|
63 |
+
idx (int): Index of the sample to return.
|
64 |
+
|
65 |
+
Returns:
|
66 |
+
dict: A dictionary containing the 'pixel_values' tensor of shape (16, channels, 320, 512).
|
67 |
+
"""
|
68 |
+
|
69 |
+
# path = random.choice(self.video_lists)
|
70 |
+
path = self.video_lists[idx]
|
71 |
+
|
72 |
+
if self.file_list is not None: # read from pcache
|
73 |
+
with open(path, 'rb') as f:
|
74 |
+
vframes = VideoReader(f)
|
75 |
+
else:
|
76 |
+
vframes, aframes, info = torchvision.io.read_video(filename=path, pts_unit='sec', output_format='TCHW')
|
77 |
+
total_frames = len(vframes)
|
78 |
+
|
79 |
+
# Sampling video frames
|
80 |
+
start_frame_ind, end_frame_ind = self.temporal_sample(total_frames)
|
81 |
+
if not end_frame_ind - start_frame_ind >= self.sample_frames:
|
82 |
+
raise ValueError(f'video {path} does not have enough frames')
|
83 |
+
frame_indice = np.linspace(start_frame_ind, end_frame_ind-1, self.sample_frames, dtype=int)
|
84 |
+
|
85 |
+
if self.file_list is not None: # read from pcache
|
86 |
+
video = torch.from_numpy(vframes.get_batch(frame_indice).asnumpy()).permute(0, 3, 1, 2).contiguous()
|
87 |
+
else:
|
88 |
+
video = vframes[frame_indice]
|
89 |
+
|
90 |
+
# (f c h w)
|
91 |
+
pixel_values = self.transform(video)
|
92 |
+
|
93 |
+
return {'pixel_values': pixel_values}
|
94 |
+
|
95 |
+
def __getitem__(self, idx):
|
96 |
+
# return self.get_sample(idx)
|
97 |
+
|
98 |
+
while(True):
|
99 |
+
try:
|
100 |
+
# idx = np.random.randint(0, len(self.video_lists) - 1)
|
101 |
+
# idx = self.rng.integers(0, len(self.video_lists))
|
102 |
+
item = self.get_sample(idx)
|
103 |
+
return item
|
104 |
+
except:
|
105 |
+
warnings.warn(f'loading {idx} failed, retrying...')
|
106 |
+
idx = np.random.randint(0, len(self.video_lists) - 1)
|
Dataset/sakuga_dataset.py
ADDED
@@ -0,0 +1,401 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datetime import timedelta
|
3 |
+
from pathlib import Path
|
4 |
+
from typing import List, Optional, Tuple, Union
|
5 |
+
from torch.utils.data import DataLoader, Dataset
|
6 |
+
from tqdm.auto import tqdm
|
7 |
+
from torchvision.transforms.functional import center_crop, resize
|
8 |
+
from torchvision.transforms import InterpolationMode
|
9 |
+
import torchvision.transforms as TT
|
10 |
+
import numpy as np
|
11 |
+
import accelerate
|
12 |
+
import torch
|
13 |
+
import pandas as pd
|
14 |
+
from pathlib import PosixPath
|
15 |
+
import os
|
16 |
+
from datetime import datetime
|
17 |
+
|
18 |
+
try:
|
19 |
+
import decord
|
20 |
+
except ImportError:
|
21 |
+
raise ImportError(
|
22 |
+
"The `decord` package is required for loading the video dataset. Install with `pip install decord`"
|
23 |
+
)
|
24 |
+
decord.bridge.set_bridge("torch")
|
25 |
+
|
26 |
+
|
27 |
+
class Sakuga_Dataset(Dataset):
|
28 |
+
def __init__(
|
29 |
+
self,
|
30 |
+
instance_data_root: Optional[str] = None,
|
31 |
+
sketch_data_root: Optional[str] = None,
|
32 |
+
dataset_name: Optional[str] = None,
|
33 |
+
dataset_config_name: Optional[str] = None,
|
34 |
+
caption_column: str = "text",
|
35 |
+
video_column: str = "video",
|
36 |
+
height: int = 480,
|
37 |
+
width: int = 720,
|
38 |
+
video_reshape_mode: str = "center",
|
39 |
+
fps: int = 8,
|
40 |
+
max_num_frames: int = 49,
|
41 |
+
skip_frames_start: int = 0,
|
42 |
+
skip_frames_end: int = 0,
|
43 |
+
cache_dir: Optional[str] = None,
|
44 |
+
id_token: Optional[str] = None,
|
45 |
+
data_information: Optional[str] = None,
|
46 |
+
stage: Optional[str] = "1",
|
47 |
+
) -> None:
|
48 |
+
super().__init__()
|
49 |
+
|
50 |
+
self.instance_data_root = Path(instance_data_root) if instance_data_root is not None else None
|
51 |
+
self.sketch_data_root = Path(sketch_data_root) if sketch_data_root is not None else None
|
52 |
+
self.dataset_name = dataset_name
|
53 |
+
self.dataset_config_name = dataset_config_name
|
54 |
+
self.caption_column = caption_column
|
55 |
+
self.video_column = video_column
|
56 |
+
self.height = height
|
57 |
+
self.width = width
|
58 |
+
self.video_reshape_mode = video_reshape_mode
|
59 |
+
self.fps = fps
|
60 |
+
self.max_num_frames = max_num_frames
|
61 |
+
self.skip_frames_start = skip_frames_start
|
62 |
+
self.skip_frames_end = skip_frames_end
|
63 |
+
self.cache_dir = cache_dir
|
64 |
+
self.id_token = id_token or ""
|
65 |
+
self.stage=stage
|
66 |
+
|
67 |
+
'''
|
68 |
+
if dataset_name is not None:
|
69 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_hub()
|
70 |
+
else:
|
71 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_local_path()
|
72 |
+
'''
|
73 |
+
|
74 |
+
self.data_information=pd.read_parquet(data_information)
|
75 |
+
self.num_instance_videos = self.data_information.shape[0]
|
76 |
+
|
77 |
+
|
78 |
+
#self.detector = LineartDetector('cpu')
|
79 |
+
#TODO: here just point the cuda maybe have some problem
|
80 |
+
|
81 |
+
#we put the preprocess_data() in the get_item function
|
82 |
+
#self.instance_videos = self._preprocess_data()
|
83 |
+
#here, how to make it in the get_item?
|
84 |
+
|
85 |
+
def __len__(self):
|
86 |
+
return self.num_instance_videos
|
87 |
+
|
88 |
+
def encode_video(self, video,vae,device):
|
89 |
+
|
90 |
+
|
91 |
+
#vae,device
|
92 |
+
video = video.to(device, dtype=vae.dtype).unsqueeze(0)
|
93 |
+
video = video.permute(0, 2, 1, 3, 4) # [B, C, F, H, W]
|
94 |
+
image = video[:, :, :1].clone()
|
95 |
+
|
96 |
+
latent_dist = vae.encode(video).latent_dist
|
97 |
+
|
98 |
+
image_noise_sigma = torch.normal(mean=-3.0, std=0.5, size=(1,), device=image.device)
|
99 |
+
image_noise_sigma = torch.exp(image_noise_sigma).to(dtype=image.dtype)
|
100 |
+
noisy_image = torch.randn_like(image) * image_noise_sigma[:, None, None, None, None]
|
101 |
+
image_latent_dist = vae.encode(noisy_image).latent_dist
|
102 |
+
|
103 |
+
return latent_dist, image_latent_dist
|
104 |
+
|
105 |
+
def read_video(self,video_path):
|
106 |
+
filename=PosixPath(video_path)
|
107 |
+
|
108 |
+
#this part have some wrong things
|
109 |
+
try:
|
110 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
111 |
+
video_num_frames = len(video_reader)
|
112 |
+
|
113 |
+
#需不需要这里强制一下从第10帧开始?
|
114 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
115 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
116 |
+
if end_frame <= start_frame:
|
117 |
+
frames = video_reader.get_batch([start_frame])
|
118 |
+
elif end_frame - start_frame <= self.max_num_frames:
|
119 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
120 |
+
else:
|
121 |
+
#this has problem
|
122 |
+
#indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
123 |
+
indices=list(range(start_frame,self.max_num_frames))
|
124 |
+
frames = video_reader.get_batch(indices)
|
125 |
+
|
126 |
+
# Ensure that we don't go over the limit
|
127 |
+
frames = frames[: self.max_num_frames]
|
128 |
+
selected_num_frames = frames.shape[0]
|
129 |
+
|
130 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
131 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
132 |
+
if remainder != 0:
|
133 |
+
frames = frames[:-remainder]
|
134 |
+
selected_num_frames = frames.shape[0]
|
135 |
+
|
136 |
+
assert (selected_num_frames - 1) % 4 == 0
|
137 |
+
|
138 |
+
# Training transforms
|
139 |
+
|
140 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
141 |
+
#print("frame",frames.shape)
|
142 |
+
frames = self._resize_for_rectangle_crop(frames)
|
143 |
+
final_frames = frames.contiguous()
|
144 |
+
if final_frames.dim()==3:
|
145 |
+
final_frames=final_frames.unsqueeze(0)
|
146 |
+
return final_frames
|
147 |
+
except:
|
148 |
+
return None
|
149 |
+
|
150 |
+
|
151 |
+
|
152 |
+
def __getitem__(self, index):
|
153 |
+
|
154 |
+
#output_video=self.encode_video(video,vae,device)
|
155 |
+
#_encode_instance_video=self.encode_video(self.instance_prompts[index],device=)
|
156 |
+
|
157 |
+
#处理selfinstance_videos
|
158 |
+
|
159 |
+
folder_path=os.path.join(self.instance_data_root, str(self.data_information.iloc[index]['identifier_video']))
|
160 |
+
|
161 |
+
#sketch_path=os.path.join(self.sketch_data_root, str(self.data_information.iloc[index]['identifier_video']))
|
162 |
+
#注意这里的sketch存的是[0,255]的信息,不需要1-了,但是之后可能还是要变成2值的操作,得看一下如何2值化
|
163 |
+
|
164 |
+
|
165 |
+
#这里寻找id号的过程有点问题,不太对
|
166 |
+
#这个identifier是不是就是对应的片段名称?是的,identifier后面的对应的就是sence_number
|
167 |
+
#indices = self.data_information.index[self.data_information['identifier_video'] == self.data_information.iloc[index]['identifier_video']].tolist()
|
168 |
+
|
169 |
+
# video_name=self.data_information.iloc[index]['identifier_video']
|
170 |
+
# sence_number=self.data_information.iloc[index]["identifier"].split(":")[1]
|
171 |
+
# data_name=f"{video_name}-Scene-{int(sence_number):03d}.mp4"
|
172 |
+
|
173 |
+
|
174 |
+
frames=self.data_information.iloc[index]["start_frame"]
|
175 |
+
video_name=self.data_information.iloc[index]["identifier"].split(':')[0]
|
176 |
+
#print(frames)
|
177 |
+
|
178 |
+
data_path_1=f'{video_name}-Scene-{frames}.mp4'
|
179 |
+
data_path_2=f'{video_name}-Scene-{frames+1}.mp4'
|
180 |
+
data_path_3=f'{video_name}-Scene-{frames-1}.mp4'
|
181 |
+
fd1=os.path.join(folder_path,data_path_1)
|
182 |
+
#sketch_fd1=os.path.join(sketch_path,data_path_1)
|
183 |
+
fd2=os.path.join(folder_path,data_path_2)
|
184 |
+
#sketch_fd2=os.path.join(sketch_path,data_path_2)
|
185 |
+
fd3=os.path.join(folder_path,data_path_3)
|
186 |
+
#sketch_fd3=os.path.join(sketch_path,data_path_2)
|
187 |
+
|
188 |
+
#print(fd1)
|
189 |
+
|
190 |
+
if os.path.exists(fd1):
|
191 |
+
file_path=fd1
|
192 |
+
elif os.path.exists(fd2):
|
193 |
+
file_path=fd2
|
194 |
+
elif os.path.exists(fd3):
|
195 |
+
file_path=fd3
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
prompt=self.data_information.iloc[index]["text_description"]
|
200 |
+
|
201 |
+
final_frames=self.read_video(PosixPath(file_path))
|
202 |
+
#final_sketch_frames=self.read_video(PosixPath(sketch_file_path))
|
203 |
+
final_sketch_frames=None
|
204 |
+
|
205 |
+
|
206 |
+
|
207 |
+
instance_prompt = prompt + self.id_token
|
208 |
+
|
209 |
+
return {
|
210 |
+
"instance_prompt": instance_prompt,
|
211 |
+
"instance_video": final_frames,
|
212 |
+
"file_path":file_path,
|
213 |
+
"sketch_video": final_sketch_frames,
|
214 |
+
"instance_image": None,
|
215 |
+
#"instance_sketch": final_sketch,
|
216 |
+
}
|
217 |
+
|
218 |
+
def _load_dataset_from_hub(self):
|
219 |
+
try:
|
220 |
+
from datasets import load_dataset
|
221 |
+
except ImportError:
|
222 |
+
raise ImportError(
|
223 |
+
"You are trying to load your data using the datasets library. If you wish to train using custom "
|
224 |
+
"captions please install the datasets library: `pip install datasets`. If you wish to load a "
|
225 |
+
"local folder containing images only, specify --instance_data_root instead."
|
226 |
+
)
|
227 |
+
|
228 |
+
# Downloading and loading a dataset from the hub. See more about loading custom images at
|
229 |
+
# https://huggingface.co/docs/datasets/v2.0.0/en/dataset_script
|
230 |
+
dataset = load_dataset(
|
231 |
+
self.dataset_name,
|
232 |
+
self.dataset_config_name,
|
233 |
+
cache_dir=self.cache_dir,
|
234 |
+
)
|
235 |
+
column_names = dataset["train"].column_names
|
236 |
+
|
237 |
+
if self.video_column is None:
|
238 |
+
video_column = column_names[0]
|
239 |
+
#logger.info(f"`video_column` defaulting to {video_column}")
|
240 |
+
print(f"`video_column` defaulting to {video_column}")
|
241 |
+
else:
|
242 |
+
video_column = self.video_column
|
243 |
+
if video_column not in column_names:
|
244 |
+
raise ValueError(
|
245 |
+
f"`--video_column` value '{video_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
246 |
+
)
|
247 |
+
|
248 |
+
if self.caption_column is None:
|
249 |
+
caption_column = column_names[1]
|
250 |
+
#logger.info(f"`caption_column` defaulting to {caption_column}")
|
251 |
+
print(f"`caption_column` defaulting to {caption_column}")
|
252 |
+
else:
|
253 |
+
caption_column = self.caption_column
|
254 |
+
if self.caption_column not in column_names:
|
255 |
+
raise ValueError(
|
256 |
+
f"`--caption_column` value '{self.caption_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
257 |
+
)
|
258 |
+
|
259 |
+
instance_prompts = dataset["train"][caption_column]
|
260 |
+
instance_videos = [Path(self.instance_data_root, filepath) for filepath in dataset["train"][video_column]]
|
261 |
+
|
262 |
+
return instance_prompts, instance_videos
|
263 |
+
|
264 |
+
def _load_dataset_from_local_path(self):
|
265 |
+
if not self.instance_data_root.exists():
|
266 |
+
raise ValueError("Instance videos root folder does not exist")
|
267 |
+
|
268 |
+
prompt_path = self.instance_data_root.joinpath(self.caption_column)
|
269 |
+
video_path = self.instance_data_root.joinpath(self.video_column)
|
270 |
+
|
271 |
+
if not prompt_path.exists() or not prompt_path.is_file():
|
272 |
+
raise ValueError(
|
273 |
+
"Expected `--caption_column` to be path to a file in `--instance_data_root` containing line-separated text prompts."
|
274 |
+
)
|
275 |
+
if not video_path.exists() or not video_path.is_file():
|
276 |
+
raise ValueError(
|
277 |
+
"Expected `--video_column` to be path to a file in `--instance_data_root` containing line-separated paths to video data in the same directory."
|
278 |
+
)
|
279 |
+
|
280 |
+
with open(prompt_path, "r", encoding="utf-8") as file:
|
281 |
+
instance_prompts = [line.strip() for line in file.readlines() if len(line.strip()) > 0]
|
282 |
+
with open(video_path, "r", encoding="utf-8") as file:
|
283 |
+
instance_videos = [
|
284 |
+
self.instance_data_root.joinpath(line.strip()) for line in file.readlines() if len(line.strip()) > 0
|
285 |
+
]
|
286 |
+
|
287 |
+
if any(not path.is_file() for path in instance_videos):
|
288 |
+
raise ValueError(
|
289 |
+
"Expected '--video_column' to be a path to a file in `--instance_data_root` containing line-separated paths to video data but found atleast one path that is not a valid file."
|
290 |
+
)
|
291 |
+
|
292 |
+
return instance_prompts, instance_videos
|
293 |
+
|
294 |
+
def _resize_for_rectangle_crop(self, arr):
|
295 |
+
image_size = self.height, self.width
|
296 |
+
reshape_mode = self.video_reshape_mode
|
297 |
+
if arr.shape[3] / arr.shape[2] > image_size[1] / image_size[0]:
|
298 |
+
arr = resize(
|
299 |
+
arr,
|
300 |
+
size=[image_size[0], int(arr.shape[3] * image_size[0] / arr.shape[2])],
|
301 |
+
interpolation=InterpolationMode.BICUBIC,
|
302 |
+
)
|
303 |
+
else:
|
304 |
+
arr = resize(
|
305 |
+
arr,
|
306 |
+
size=[int(arr.shape[2] * image_size[1] / arr.shape[3]), image_size[1]],
|
307 |
+
interpolation=InterpolationMode.BICUBIC,
|
308 |
+
)
|
309 |
+
|
310 |
+
h, w = arr.shape[2], arr.shape[3]
|
311 |
+
arr = arr.squeeze(0)
|
312 |
+
|
313 |
+
delta_h = h - image_size[0]
|
314 |
+
delta_w = w - image_size[1]
|
315 |
+
|
316 |
+
if reshape_mode == "random" or reshape_mode == "none":
|
317 |
+
top = np.random.randint(0, delta_h + 1)
|
318 |
+
left = np.random.randint(0, delta_w + 1)
|
319 |
+
elif reshape_mode == "center":
|
320 |
+
top, left = delta_h // 2, delta_w // 2
|
321 |
+
else:
|
322 |
+
raise NotImplementedError
|
323 |
+
arr = TT.functional.crop(arr, top=top, left=left, height=image_size[0], width=image_size[1])
|
324 |
+
return arr
|
325 |
+
|
326 |
+
|
327 |
+
# here process the all data, we should make these processed in the get_item or other position
|
328 |
+
|
329 |
+
def _preprocess_data(self):
|
330 |
+
|
331 |
+
|
332 |
+
decord.bridge.set_bridge("torch")
|
333 |
+
|
334 |
+
progress_dataset_bar = tqdm(
|
335 |
+
range(0, len(self.instance_video_paths)),
|
336 |
+
desc="Loading progress resize and crop videos",
|
337 |
+
)
|
338 |
+
|
339 |
+
videos = []
|
340 |
+
|
341 |
+
for filename in self.instance_video_paths:
|
342 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
343 |
+
video_num_frames = len(video_reader)
|
344 |
+
|
345 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
346 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
347 |
+
if end_frame <= start_frame:
|
348 |
+
frames = video_reader.get_batch([start_frame])
|
349 |
+
elif end_frame - start_frame <= self.max_num_frames:
|
350 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
351 |
+
else:
|
352 |
+
indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
353 |
+
frames = video_reader.get_batch(indices)
|
354 |
+
|
355 |
+
# Ensure that we don't go over the limit
|
356 |
+
frames = frames[: self.max_num_frames]
|
357 |
+
selected_num_frames = frames.shape[0]
|
358 |
+
|
359 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
360 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
361 |
+
if remainder != 0:
|
362 |
+
frames = frames[:-remainder]
|
363 |
+
selected_num_frames = frames.shape[0]
|
364 |
+
|
365 |
+
assert (selected_num_frames - 1) % 4 == 0
|
366 |
+
|
367 |
+
# Training transforms
|
368 |
+
|
369 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
370 |
+
progress_dataset_bar.set_description(
|
371 |
+
f"Loading progress Resizing video from {frames.shape[2]}x{frames.shape[3]} to {self.height}x{self.width}"
|
372 |
+
)
|
373 |
+
frames = self._resize_for_rectangle_crop(frames) #here the tensor should be processed to right size
|
374 |
+
|
375 |
+
frames = (frames - 127.5) / 127.5
|
376 |
+
videos.append(frames.contiguous()) # [F, C, H, W]
|
377 |
+
progress_dataset_bar.update(1)
|
378 |
+
|
379 |
+
progress_dataset_bar.close()
|
380 |
+
|
381 |
+
return videos
|
382 |
+
|
383 |
+
|
384 |
+
|
385 |
+
|
386 |
+
if __name__=="__main__":
|
387 |
+
train_dataset = Sakuga_Dataset(
|
388 |
+
instance_data_root='',
|
389 |
+
height= 480,
|
390 |
+
width= 720,
|
391 |
+
video_reshape_mode="center",
|
392 |
+
fps=8,
|
393 |
+
max_num_frames=49,
|
394 |
+
skip_frames_start=0,
|
395 |
+
skip_frames_end=0,
|
396 |
+
cache_dir="~/.cache",
|
397 |
+
id_token="",
|
398 |
+
data_information="../../../Datasets/SakugaDataset/parquet/fliter_59_aesthetic_precise.parquet"
|
399 |
+
)
|
400 |
+
data=train_dataset.__getitem__(0)
|
401 |
+
print(data["instance_video"].shape)
|
Dataset/sakuga_dataset_auto.py
ADDED
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datetime import timedelta
|
3 |
+
from pathlib import Path
|
4 |
+
from typing import List, Optional, Tuple, Union
|
5 |
+
from torch.utils.data import DataLoader, Dataset
|
6 |
+
from tqdm.auto import tqdm
|
7 |
+
from torchvision.transforms.functional import center_crop, resize
|
8 |
+
from torchvision.transforms import InterpolationMode
|
9 |
+
import torchvision.transforms as TT
|
10 |
+
import numpy as np
|
11 |
+
import accelerate
|
12 |
+
import torch
|
13 |
+
import pandas as pd
|
14 |
+
from pathlib import PosixPath
|
15 |
+
import os
|
16 |
+
from datetime import datetime
|
17 |
+
import random
|
18 |
+
|
19 |
+
try:
|
20 |
+
import decord
|
21 |
+
except ImportError:
|
22 |
+
raise ImportError(
|
23 |
+
"The `decord` package is required for loading the video dataset. Install with `pip install decord`"
|
24 |
+
)
|
25 |
+
decord.bridge.set_bridge("torch")
|
26 |
+
|
27 |
+
|
28 |
+
class Sakuga_Dataset_auto(Dataset):
|
29 |
+
def __init__(
|
30 |
+
self,
|
31 |
+
instance_data_root: Optional[str] = None,
|
32 |
+
sketch_data_root: Optional[str] = None,
|
33 |
+
dataset_name: Optional[str] = None,
|
34 |
+
dataset_config_name: Optional[str] = None,
|
35 |
+
caption_column: str = "text",
|
36 |
+
video_column: str = "video",
|
37 |
+
height: int = 480,
|
38 |
+
width: int = 720,
|
39 |
+
video_reshape_mode: str = "center",
|
40 |
+
fps: int = 8,
|
41 |
+
max_num_frames: int = 49,
|
42 |
+
skip_frames_start: int = 0,
|
43 |
+
skip_frames_end: int = 0,
|
44 |
+
cache_dir: Optional[str] = None,
|
45 |
+
id_token: Optional[str] = None,
|
46 |
+
data_information: Optional[str] = None,
|
47 |
+
stage: Optional[str] = "1",
|
48 |
+
) -> None:
|
49 |
+
super().__init__()
|
50 |
+
|
51 |
+
self.instance_data_root = Path(instance_data_root) if instance_data_root is not None else None
|
52 |
+
self.sketch_data_root = Path(sketch_data_root) if sketch_data_root is not None else None
|
53 |
+
self.dataset_name = dataset_name
|
54 |
+
self.dataset_config_name = dataset_config_name
|
55 |
+
self.caption_column = caption_column
|
56 |
+
self.video_column = video_column
|
57 |
+
self.height = height
|
58 |
+
self.width = width
|
59 |
+
self.video_reshape_mode = video_reshape_mode
|
60 |
+
self.fps = fps
|
61 |
+
self.max_num_frames = max_num_frames
|
62 |
+
self.skip_frames_start = skip_frames_start
|
63 |
+
self.skip_frames_end = skip_frames_end
|
64 |
+
self.cache_dir = cache_dir
|
65 |
+
self.id_token = id_token or ""
|
66 |
+
self.stage=stage
|
67 |
+
|
68 |
+
'''
|
69 |
+
if dataset_name is not None:
|
70 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_hub()
|
71 |
+
else:
|
72 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_local_path()
|
73 |
+
'''
|
74 |
+
|
75 |
+
self.data_information=pd.read_parquet(data_information)
|
76 |
+
self.num_instance_videos = self.data_information.shape[0]
|
77 |
+
|
78 |
+
|
79 |
+
#self.detector = LineartDetector('cpu')
|
80 |
+
#TODO: here just point the cuda maybe have some problem
|
81 |
+
|
82 |
+
#we put the preprocess_data() in the get_item function
|
83 |
+
#self.instance_videos = self._preprocess_data()
|
84 |
+
#here, how to make it in the get_item?
|
85 |
+
|
86 |
+
def __len__(self):
|
87 |
+
return self.num_instance_videos
|
88 |
+
|
89 |
+
def encode_video(self, video,vae,device):
|
90 |
+
|
91 |
+
|
92 |
+
#vae,device
|
93 |
+
video = video.to(device, dtype=vae.dtype).unsqueeze(0)
|
94 |
+
video = video.permute(0, 2, 1, 3, 4) # [B, C, F, H, W]
|
95 |
+
image = video[:, :, :1].clone()
|
96 |
+
|
97 |
+
latent_dist = vae.encode(video).latent_dist
|
98 |
+
|
99 |
+
image_noise_sigma = torch.normal(mean=-3.0, std=0.5, size=(1,), device=image.device)
|
100 |
+
image_noise_sigma = torch.exp(image_noise_sigma).to(dtype=image.dtype)
|
101 |
+
noisy_image = torch.randn_like(image) * image_noise_sigma[:, None, None, None, None]
|
102 |
+
image_latent_dist = vae.encode(noisy_image).latent_dist
|
103 |
+
|
104 |
+
return latent_dist, image_latent_dist
|
105 |
+
|
106 |
+
def read_video(self,video_path):
|
107 |
+
filename=PosixPath(video_path)
|
108 |
+
|
109 |
+
#this part have some wrong things
|
110 |
+
try:
|
111 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
112 |
+
video_num_frames = len(video_reader)
|
113 |
+
|
114 |
+
#需不需要这里强制一下从第10帧开始?
|
115 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
116 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
117 |
+
# if end_frame <= start_frame:
|
118 |
+
# frames = video_reader.get_batch([start_frame])
|
119 |
+
if end_frame - start_frame <= self.max_num_frames:
|
120 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
121 |
+
else:
|
122 |
+
#this has problem
|
123 |
+
#indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
124 |
+
|
125 |
+
|
126 |
+
indices=list(range(start_frame,self.max_num_frames))
|
127 |
+
frames = video_reader.get_batch(indices)
|
128 |
+
|
129 |
+
|
130 |
+
s = random.randint(0, self.max_num_frames - 241)
|
131 |
+
d=s+241
|
132 |
+
|
133 |
+
frames = frames[s: d+1]
|
134 |
+
selected_num_frames = frames.shape[0]
|
135 |
+
|
136 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
137 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
138 |
+
if remainder != 0:
|
139 |
+
frames = frames[:-remainder]
|
140 |
+
selected_num_frames = frames.shape[0]
|
141 |
+
|
142 |
+
assert (selected_num_frames - 1) % 4 == 0
|
143 |
+
|
144 |
+
# Training transforms
|
145 |
+
|
146 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
147 |
+
#print("frame",frames.shape)
|
148 |
+
|
149 |
+
frames = self._resize_for_rectangle_crop(frames)
|
150 |
+
final_frames = frames.contiguous()
|
151 |
+
if final_frames.dim()==3:
|
152 |
+
final_frames=final_frames.unsqueeze(0)
|
153 |
+
|
154 |
+
#print("here",final_frames.shape)
|
155 |
+
memory_video=final_frames[0:-81].permute(0,2,3,1).contiguous()
|
156 |
+
reward_video=final_frames[-81:].permute(0,2,3,1).contiguous()
|
157 |
+
#print("here",memory_video.shape)
|
158 |
+
return final_frames,memory_video,reward_video
|
159 |
+
except:
|
160 |
+
return None
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
def __getitem__(self, index):
|
165 |
+
|
166 |
+
#output_video=self.encode_video(video,vae,device)
|
167 |
+
#_encode_instance_video=self.encode_video(self.instance_prompts[index],device=)
|
168 |
+
|
169 |
+
#处理selfinstance_videos
|
170 |
+
|
171 |
+
folder_path=os.path.join(self.instance_data_root, str(self.data_information.iloc[index]['identifier_video']))
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
+
frames=self.data_information.iloc[index]["start_frame"]
|
176 |
+
video_name=self.data_information.iloc[index]["identifier"].split(':')[0]
|
177 |
+
|
178 |
+
|
179 |
+
data_path_1=f'{video_name}-Scene-{frames}.mp4'
|
180 |
+
data_path_2=f'{video_name}-Scene-{frames+1}.mp4'
|
181 |
+
data_path_3=f'{video_name}-Scene-{frames-1}.mp4'
|
182 |
+
|
183 |
+
|
184 |
+
fd1=os.path.join(folder_path,data_path_1)
|
185 |
+
|
186 |
+
fd2=os.path.join(folder_path,data_path_2)
|
187 |
+
|
188 |
+
fd3=os.path.join(folder_path,data_path_3)
|
189 |
+
|
190 |
+
|
191 |
+
|
192 |
+
|
193 |
+
if os.path.exists(fd1):
|
194 |
+
file_path=fd1
|
195 |
+
elif os.path.exists(fd2):
|
196 |
+
file_path=fd2
|
197 |
+
elif os.path.exists(fd3):
|
198 |
+
file_path=fd3
|
199 |
+
|
200 |
+
|
201 |
+
|
202 |
+
|
203 |
+
prompt=self.data_information.iloc[index]["text_description"]
|
204 |
+
|
205 |
+
final_frames,memory_video,reward_video=self.read_video(PosixPath(file_path))
|
206 |
+
global_frame=final_frames[0]
|
207 |
+
final_frames=final_frames[-81:]
|
208 |
+
|
209 |
+
final_sketch_frames=None
|
210 |
+
|
211 |
+
|
212 |
+
|
213 |
+
memory_video_choice= random.choices([0, 1], weights=[0.6, 0.4], k=1)[0]
|
214 |
+
|
215 |
+
|
216 |
+
instance_prompt = prompt + self.id_token
|
217 |
+
|
218 |
+
return {
|
219 |
+
"instance_prompt": instance_prompt,
|
220 |
+
"instance_video": final_frames,
|
221 |
+
"file_path":file_path,
|
222 |
+
"sketch_video": final_sketch_frames,
|
223 |
+
"instance_image": global_frame,
|
224 |
+
"memory_video":memory_video,
|
225 |
+
"reward_video":reward_video,
|
226 |
+
#"instance_sketch": final_sketch,
|
227 |
+
}
|
228 |
+
|
229 |
+
def _load_dataset_from_hub(self):
|
230 |
+
try:
|
231 |
+
from datasets import load_dataset
|
232 |
+
except ImportError:
|
233 |
+
raise ImportError(
|
234 |
+
"You are trying to load your data using the datasets library. If you wish to train using custom "
|
235 |
+
"captions please install the datasets library: `pip install datasets`. If you wish to load a "
|
236 |
+
"local folder containing images only, specify --instance_data_root instead."
|
237 |
+
)
|
238 |
+
|
239 |
+
# Downloading and loading a dataset from the hub. See more about loading custom images at
|
240 |
+
# https://huggingface.co/docs/datasets/v2.0.0/en/dataset_script
|
241 |
+
dataset = load_dataset(
|
242 |
+
self.dataset_name,
|
243 |
+
self.dataset_config_name,
|
244 |
+
cache_dir=self.cache_dir,
|
245 |
+
)
|
246 |
+
column_names = dataset["train"].column_names
|
247 |
+
|
248 |
+
if self.video_column is None:
|
249 |
+
video_column = column_names[0]
|
250 |
+
#logger.info(f"`video_column` defaulting to {video_column}")
|
251 |
+
print(f"`video_column` defaulting to {video_column}")
|
252 |
+
else:
|
253 |
+
video_column = self.video_column
|
254 |
+
if video_column not in column_names:
|
255 |
+
raise ValueError(
|
256 |
+
f"`--video_column` value '{video_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
257 |
+
)
|
258 |
+
|
259 |
+
if self.caption_column is None:
|
260 |
+
caption_column = column_names[1]
|
261 |
+
#logger.info(f"`caption_column` defaulting to {caption_column}")
|
262 |
+
print(f"`caption_column` defaulting to {caption_column}")
|
263 |
+
else:
|
264 |
+
caption_column = self.caption_column
|
265 |
+
if self.caption_column not in column_names:
|
266 |
+
raise ValueError(
|
267 |
+
f"`--caption_column` value '{self.caption_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
268 |
+
)
|
269 |
+
|
270 |
+
instance_prompts = dataset["train"][caption_column]
|
271 |
+
instance_videos = [Path(self.instance_data_root, filepath) for filepath in dataset["train"][video_column]]
|
272 |
+
|
273 |
+
return instance_prompts, instance_videos
|
274 |
+
|
275 |
+
def _load_dataset_from_local_path(self):
|
276 |
+
if not self.instance_data_root.exists():
|
277 |
+
raise ValueError("Instance videos root folder does not exist")
|
278 |
+
|
279 |
+
prompt_path = self.instance_data_root.joinpath(self.caption_column)
|
280 |
+
video_path = self.instance_data_root.joinpath(self.video_column)
|
281 |
+
|
282 |
+
if not prompt_path.exists() or not prompt_path.is_file():
|
283 |
+
raise ValueError(
|
284 |
+
"Expected `--caption_column` to be path to a file in `--instance_data_root` containing line-separated text prompts."
|
285 |
+
)
|
286 |
+
if not video_path.exists() or not video_path.is_file():
|
287 |
+
raise ValueError(
|
288 |
+
"Expected `--video_column` to be path to a file in `--instance_data_root` containing line-separated paths to video data in the same directory."
|
289 |
+
)
|
290 |
+
|
291 |
+
with open(prompt_path, "r", encoding="utf-8") as file:
|
292 |
+
instance_prompts = [line.strip() for line in file.readlines() if len(line.strip()) > 0]
|
293 |
+
with open(video_path, "r", encoding="utf-8") as file:
|
294 |
+
instance_videos = [
|
295 |
+
self.instance_data_root.joinpath(line.strip()) for line in file.readlines() if len(line.strip()) > 0
|
296 |
+
]
|
297 |
+
|
298 |
+
if any(not path.is_file() for path in instance_videos):
|
299 |
+
raise ValueError(
|
300 |
+
"Expected '--video_column' to be a path to a file in `--instance_data_root` containing line-separated paths to video data but found atleast one path that is not a valid file."
|
301 |
+
)
|
302 |
+
|
303 |
+
return instance_prompts, instance_videos
|
304 |
+
|
305 |
+
def _resize_for_rectangle_crop(self, arr):
|
306 |
+
image_size = self.height, self.width
|
307 |
+
reshape_mode = self.video_reshape_mode
|
308 |
+
if arr.shape[3] / arr.shape[2] > image_size[1] / image_size[0]:
|
309 |
+
arr = resize(
|
310 |
+
arr,
|
311 |
+
size=[image_size[0], int(arr.shape[3] * image_size[0] / arr.shape[2])],
|
312 |
+
interpolation=InterpolationMode.BICUBIC,
|
313 |
+
)
|
314 |
+
else:
|
315 |
+
arr = resize(
|
316 |
+
arr,
|
317 |
+
size=[int(arr.shape[2] * image_size[1] / arr.shape[3]), image_size[1]],
|
318 |
+
interpolation=InterpolationMode.BICUBIC,
|
319 |
+
)
|
320 |
+
|
321 |
+
h, w = arr.shape[2], arr.shape[3]
|
322 |
+
arr = arr.squeeze(0)
|
323 |
+
|
324 |
+
delta_h = h - image_size[0]
|
325 |
+
delta_w = w - image_size[1]
|
326 |
+
|
327 |
+
if reshape_mode == "random" or reshape_mode == "none":
|
328 |
+
top = np.random.randint(0, delta_h + 1)
|
329 |
+
left = np.random.randint(0, delta_w + 1)
|
330 |
+
elif reshape_mode == "center":
|
331 |
+
top, left = delta_h // 2, delta_w // 2
|
332 |
+
else:
|
333 |
+
raise NotImplementedError
|
334 |
+
arr = TT.functional.crop(arr, top=top, left=left, height=image_size[0], width=image_size[1])
|
335 |
+
return arr
|
336 |
+
|
337 |
+
|
338 |
+
# here process the all data, we should make these processed in the get_item or other position
|
339 |
+
|
340 |
+
def _preprocess_data(self):
|
341 |
+
|
342 |
+
|
343 |
+
decord.bridge.set_bridge("torch")
|
344 |
+
|
345 |
+
progress_dataset_bar = tqdm(
|
346 |
+
range(0, len(self.instance_video_paths)),
|
347 |
+
desc="Loading progress resize and crop videos",
|
348 |
+
)
|
349 |
+
|
350 |
+
videos = []
|
351 |
+
|
352 |
+
for filename in self.instance_video_paths:
|
353 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
354 |
+
video_num_frames = len(video_reader)
|
355 |
+
|
356 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
357 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
358 |
+
if end_frame <= start_frame:
|
359 |
+
frames = video_reader.get_batch([start_frame])
|
360 |
+
elif end_frame - start_frame <= self.max_num_frames:
|
361 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
362 |
+
else:
|
363 |
+
indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
364 |
+
frames = video_reader.get_batch(indices)
|
365 |
+
|
366 |
+
# Ensure that we don't go over the limit
|
367 |
+
frames = frames[: self.max_num_frames]
|
368 |
+
selected_num_frames = frames.shape[0]
|
369 |
+
|
370 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
371 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
372 |
+
if remainder != 0:
|
373 |
+
frames = frames[:-remainder]
|
374 |
+
selected_num_frames = frames.shape[0]
|
375 |
+
|
376 |
+
assert (selected_num_frames - 1) % 4 == 0
|
377 |
+
|
378 |
+
# Training transforms
|
379 |
+
|
380 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
381 |
+
progress_dataset_bar.set_description(
|
382 |
+
f"Loading progress Resizing video from {frames.shape[2]}x{frames.shape[3]} to {self.height}x{self.width}"
|
383 |
+
)
|
384 |
+
frames = self._resize_for_rectangle_crop(frames) #here the tensor should be processed to right size
|
385 |
+
|
386 |
+
frames = (frames - 127.5) / 127.5
|
387 |
+
videos.append(frames.contiguous()) # [F, C, H, W]
|
388 |
+
progress_dataset_bar.update(1)
|
389 |
+
|
390 |
+
progress_dataset_bar.close()
|
391 |
+
|
392 |
+
return videos
|
393 |
+
|
394 |
+
|
395 |
+
|
396 |
+
|
397 |
+
if __name__=="__main__":
|
398 |
+
train_dataset = Sakuga_Dataset_auto(
|
399 |
+
instance_data_root='',
|
400 |
+
height= 480,
|
401 |
+
width= 720,
|
402 |
+
video_reshape_mode="center",
|
403 |
+
fps=8,
|
404 |
+
max_num_frames=49,
|
405 |
+
skip_frames_start=0,
|
406 |
+
skip_frames_end=0,
|
407 |
+
cache_dir="~/.cache",
|
408 |
+
id_token="",
|
409 |
+
data_information="../../../Datasets/SakugaDataset/parquet/fliter_59_aesthetic_precise.parquet"
|
410 |
+
)
|
411 |
+
data=train_dataset.__getitem__(0)
|
412 |
+
print(data["instance_video"].shape)
|
Dataset/video_dataset.py
ADDED
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datetime import timedelta
|
3 |
+
from pathlib import Path
|
4 |
+
from typing import List, Optional, Tuple, Union
|
5 |
+
from torch.utils.data import DataLoader, Dataset
|
6 |
+
from tqdm.auto import tqdm
|
7 |
+
from lineart_extractor.annotator.lineart import LineartDetector
|
8 |
+
from torchvision.transforms.functional import center_crop, resize
|
9 |
+
from torchvision.transforms import InterpolationMode
|
10 |
+
import torchvision.transforms as TT
|
11 |
+
import numpy as np
|
12 |
+
import accelerate
|
13 |
+
import torch
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
try:
|
18 |
+
import decord
|
19 |
+
except ImportError:
|
20 |
+
raise ImportError(
|
21 |
+
"The `decord` package is required for loading the video dataset. Install with `pip install decord`"
|
22 |
+
)
|
23 |
+
decord.bridge.set_bridge("torch")
|
24 |
+
|
25 |
+
|
26 |
+
class VideoDataset(Dataset):
|
27 |
+
def __init__(
|
28 |
+
self,
|
29 |
+
instance_data_root: Optional[str] = None,
|
30 |
+
dataset_name: Optional[str] = None,
|
31 |
+
dataset_config_name: Optional[str] = None,
|
32 |
+
caption_column: str = "text",
|
33 |
+
video_column: str = "video",
|
34 |
+
height: int = 480,
|
35 |
+
width: int = 720,
|
36 |
+
video_reshape_mode: str = "center",
|
37 |
+
fps: int = 8,
|
38 |
+
max_num_frames: int = 49,
|
39 |
+
skip_frames_start: int = 0,
|
40 |
+
skip_frames_end: int = 0,
|
41 |
+
cache_dir: Optional[str] = None,
|
42 |
+
id_token: Optional[str] = None,
|
43 |
+
) -> None:
|
44 |
+
super().__init__()
|
45 |
+
|
46 |
+
self.instance_data_root = Path(instance_data_root) if instance_data_root is not None else None
|
47 |
+
self.dataset_name = dataset_name
|
48 |
+
self.dataset_config_name = dataset_config_name
|
49 |
+
self.caption_column = caption_column
|
50 |
+
self.video_column = video_column
|
51 |
+
self.height = height
|
52 |
+
self.width = width
|
53 |
+
self.video_reshape_mode = video_reshape_mode
|
54 |
+
self.fps = fps
|
55 |
+
self.max_num_frames = max_num_frames
|
56 |
+
self.skip_frames_start = skip_frames_start
|
57 |
+
self.skip_frames_end = skip_frames_end
|
58 |
+
self.cache_dir = cache_dir
|
59 |
+
self.id_token = id_token or ""
|
60 |
+
|
61 |
+
if dataset_name is not None:
|
62 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_hub()
|
63 |
+
else:
|
64 |
+
self.instance_prompts, self.instance_video_paths = self._load_dataset_from_local_path()
|
65 |
+
|
66 |
+
self.instance_prompts = [self.id_token + prompt for prompt in self.instance_prompts]
|
67 |
+
|
68 |
+
self.num_instance_videos = len(self.instance_video_paths)
|
69 |
+
if self.num_instance_videos != len(self.instance_prompts):
|
70 |
+
raise ValueError(
|
71 |
+
f"Expected length of instance prompts and videos to be the same but found {len(self.instance_prompts)=} and {len(self.instance_video_paths)=}. Please ensure that the number of caption prompts and videos match in your dataset."
|
72 |
+
)
|
73 |
+
#self.detector = LineartDetector('cpu')
|
74 |
+
#TODO: here just point the cuda maybe have some problem
|
75 |
+
|
76 |
+
#we put the preprocess_data() in the get_item function
|
77 |
+
#self.instance_videos = self._preprocess_data()
|
78 |
+
#here, how to make it in the get_item?
|
79 |
+
|
80 |
+
def __len__(self):
|
81 |
+
return self.num_instance_videos
|
82 |
+
|
83 |
+
def encode_video(self, video,vae,device):
|
84 |
+
|
85 |
+
#vae,device
|
86 |
+
video = video.to(device, dtype=vae.dtype).unsqueeze(0)
|
87 |
+
video = video.permute(0, 2, 1, 3, 4) # [B, C, F, H, W]
|
88 |
+
image = video[:, :, :1].clone()
|
89 |
+
|
90 |
+
latent_dist = vae.encode(video).latent_dist
|
91 |
+
|
92 |
+
image_noise_sigma = torch.normal(mean=-3.0, std=0.5, size=(1,), device=image.device)
|
93 |
+
image_noise_sigma = torch.exp(image_noise_sigma).to(dtype=image.dtype)
|
94 |
+
noisy_image = torch.randn_like(image) * image_noise_sigma[:, None, None, None, None]
|
95 |
+
image_latent_dist = vae.encode(noisy_image).latent_dist
|
96 |
+
|
97 |
+
return latent_dist, image_latent_dist
|
98 |
+
|
99 |
+
def __getitem__(self, index):
|
100 |
+
|
101 |
+
#output_video=self.encode_video(video,vae,device)
|
102 |
+
#_encode_instance_video=self.encode_video(self.instance_prompts[index],device=)
|
103 |
+
|
104 |
+
#处理selfinstance_videos
|
105 |
+
|
106 |
+
|
107 |
+
filename = self.instance_video_paths[index]
|
108 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
109 |
+
video_num_frames = len(video_reader)
|
110 |
+
|
111 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
112 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
113 |
+
if end_frame <= start_frame:
|
114 |
+
frames = video_reader.get_batch([start_frame])
|
115 |
+
elif end_frame - start_frame <= self.max_num_frames:
|
116 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
117 |
+
else:
|
118 |
+
indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
119 |
+
frames = video_reader.get_batch(indices)
|
120 |
+
|
121 |
+
# Ensure that we don't go over the limit
|
122 |
+
frames = frames[: self.max_num_frames]
|
123 |
+
selected_num_frames = frames.shape[0]
|
124 |
+
|
125 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
126 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
127 |
+
if remainder != 0:
|
128 |
+
frames = frames[:-remainder]
|
129 |
+
selected_num_frames = frames.shape[0]
|
130 |
+
|
131 |
+
assert (selected_num_frames - 1) % 4 == 0
|
132 |
+
|
133 |
+
# Training transforms
|
134 |
+
|
135 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
136 |
+
frames = self._resize_for_rectangle_crop(frames)
|
137 |
+
final_frames = frames.contiguous()
|
138 |
+
|
139 |
+
# [F, C, H, W]
|
140 |
+
# with torch.no_grad():
|
141 |
+
# sketch = self.detector(final_frames,coarse=False)
|
142 |
+
# #sketch应该被增加成三通道的,方便后续的处理
|
143 |
+
|
144 |
+
# sketch=sketch.repeat(1,3,1,1)
|
145 |
+
# sketch = (sketch - 0.5) / 0.5
|
146 |
+
# final_sketch=sketch.contiguous()
|
147 |
+
|
148 |
+
|
149 |
+
#print("Frames is contiguous after arithmetic operations:", final_frames.is_contiguous())
|
150 |
+
|
151 |
+
# for i in range(selected_num_frames):
|
152 |
+
# np_img = np.array(Image.open(img_path).convert('RGB').resize((720,480)))
|
153 |
+
# with torch.no_grad():
|
154 |
+
# sketch = detector(np_img, coarse=False)
|
155 |
+
|
156 |
+
# sketch = (sketch - 127.5) / 127.5
|
157 |
+
# sketch = sketch.permute(0, 3, 1, 2) # [F, C, H, W]
|
158 |
+
# sketch = self._resize_for_rectangle_crop(sketch)
|
159 |
+
# final_sketch=final_sketch.contiguous() # [F, C, H, W]
|
160 |
+
#here is tensor framse
|
161 |
+
|
162 |
+
return {
|
163 |
+
"instance_prompt": self.instance_prompts[index],
|
164 |
+
"instance_video": final_frames,
|
165 |
+
#"instance_sketch": final_sketch,
|
166 |
+
}
|
167 |
+
|
168 |
+
def _load_dataset_from_hub(self):
|
169 |
+
try:
|
170 |
+
from datasets import load_dataset
|
171 |
+
except ImportError:
|
172 |
+
raise ImportError(
|
173 |
+
"You are trying to load your data using the datasets library. If you wish to train using custom "
|
174 |
+
"captions please install the datasets library: `pip install datasets`. If you wish to load a "
|
175 |
+
"local folder containing images only, specify --instance_data_root instead."
|
176 |
+
)
|
177 |
+
|
178 |
+
# Downloading and loading a dataset from the hub. See more about loading custom images at
|
179 |
+
# https://huggingface.co/docs/datasets/v2.0.0/en/dataset_script
|
180 |
+
dataset = load_dataset(
|
181 |
+
self.dataset_name,
|
182 |
+
self.dataset_config_name,
|
183 |
+
cache_dir=self.cache_dir,
|
184 |
+
)
|
185 |
+
column_names = dataset["train"].column_names
|
186 |
+
|
187 |
+
if self.video_column is None:
|
188 |
+
video_column = column_names[0]
|
189 |
+
#logger.info(f"`video_column` defaulting to {video_column}")
|
190 |
+
print(f"`video_column` defaulting to {video_column}")
|
191 |
+
else:
|
192 |
+
video_column = self.video_column
|
193 |
+
if video_column not in column_names:
|
194 |
+
raise ValueError(
|
195 |
+
f"`--video_column` value '{video_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
196 |
+
)
|
197 |
+
|
198 |
+
if self.caption_column is None:
|
199 |
+
caption_column = column_names[1]
|
200 |
+
#logger.info(f"`caption_column` defaulting to {caption_column}")
|
201 |
+
print(f"`caption_column` defaulting to {caption_column}")
|
202 |
+
else:
|
203 |
+
caption_column = self.caption_column
|
204 |
+
if self.caption_column not in column_names:
|
205 |
+
raise ValueError(
|
206 |
+
f"`--caption_column` value '{self.caption_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
|
207 |
+
)
|
208 |
+
|
209 |
+
instance_prompts = dataset["train"][caption_column]
|
210 |
+
instance_videos = [Path(self.instance_data_root, filepath) for filepath in dataset["train"][video_column]]
|
211 |
+
|
212 |
+
return instance_prompts, instance_videos
|
213 |
+
|
214 |
+
def _load_dataset_from_local_path(self):
|
215 |
+
if not self.instance_data_root.exists():
|
216 |
+
raise ValueError("Instance videos root folder does not exist")
|
217 |
+
|
218 |
+
prompt_path = self.instance_data_root.joinpath(self.caption_column)
|
219 |
+
video_path = self.instance_data_root.joinpath(self.video_column)
|
220 |
+
|
221 |
+
if not prompt_path.exists() or not prompt_path.is_file():
|
222 |
+
raise ValueError(
|
223 |
+
"Expected `--caption_column` to be path to a file in `--instance_data_root` containing line-separated text prompts."
|
224 |
+
)
|
225 |
+
if not video_path.exists() or not video_path.is_file():
|
226 |
+
raise ValueError(
|
227 |
+
"Expected `--video_column` to be path to a file in `--instance_data_root` containing line-separated paths to video data in the same directory."
|
228 |
+
)
|
229 |
+
|
230 |
+
with open(prompt_path, "r", encoding="utf-8") as file:
|
231 |
+
instance_prompts = [line.strip() for line in file.readlines() if len(line.strip()) > 0]
|
232 |
+
with open(video_path, "r", encoding="utf-8") as file:
|
233 |
+
instance_videos = [
|
234 |
+
self.instance_data_root.joinpath(line.strip()) for line in file.readlines() if len(line.strip()) > 0
|
235 |
+
]
|
236 |
+
|
237 |
+
if any(not path.is_file() for path in instance_videos):
|
238 |
+
raise ValueError(
|
239 |
+
"Expected '--video_column' to be a path to a file in `--instance_data_root` containing line-separated paths to video data but found atleast one path that is not a valid file."
|
240 |
+
)
|
241 |
+
|
242 |
+
return instance_prompts, instance_videos
|
243 |
+
|
244 |
+
def _resize_for_rectangle_crop(self, arr):
|
245 |
+
image_size = self.height, self.width
|
246 |
+
reshape_mode = self.video_reshape_mode
|
247 |
+
if arr.shape[3] / arr.shape[2] > image_size[1] / image_size[0]:
|
248 |
+
arr = resize(
|
249 |
+
arr,
|
250 |
+
size=[image_size[0], int(arr.shape[3] * image_size[0] / arr.shape[2])],
|
251 |
+
interpolation=InterpolationMode.BICUBIC,
|
252 |
+
)
|
253 |
+
else:
|
254 |
+
arr = resize(
|
255 |
+
arr,
|
256 |
+
size=[int(arr.shape[2] * image_size[1] / arr.shape[3]), image_size[1]],
|
257 |
+
interpolation=InterpolationMode.BICUBIC,
|
258 |
+
)
|
259 |
+
|
260 |
+
h, w = arr.shape[2], arr.shape[3]
|
261 |
+
arr = arr.squeeze(0)
|
262 |
+
|
263 |
+
delta_h = h - image_size[0]
|
264 |
+
delta_w = w - image_size[1]
|
265 |
+
|
266 |
+
if reshape_mode == "random" or reshape_mode == "none":
|
267 |
+
top = np.random.randint(0, delta_h + 1)
|
268 |
+
left = np.random.randint(0, delta_w + 1)
|
269 |
+
elif reshape_mode == "center":
|
270 |
+
top, left = delta_h // 2, delta_w // 2
|
271 |
+
else:
|
272 |
+
raise NotImplementedError
|
273 |
+
arr = TT.functional.crop(arr, top=top, left=left, height=image_size[0], width=image_size[1])
|
274 |
+
return arr
|
275 |
+
|
276 |
+
|
277 |
+
# here process the all data, we should make these processed in the get_item or other position
|
278 |
+
|
279 |
+
def _preprocess_data(self):
|
280 |
+
|
281 |
+
|
282 |
+
decord.bridge.set_bridge("torch")
|
283 |
+
|
284 |
+
progress_dataset_bar = tqdm(
|
285 |
+
range(0, len(self.instance_video_paths)),
|
286 |
+
desc="Loading progress resize and crop videos",
|
287 |
+
)
|
288 |
+
|
289 |
+
videos = []
|
290 |
+
|
291 |
+
for filename in self.instance_video_paths:
|
292 |
+
video_reader = decord.VideoReader(uri=filename.as_posix())
|
293 |
+
video_num_frames = len(video_reader)
|
294 |
+
|
295 |
+
start_frame = min(self.skip_frames_start, video_num_frames)
|
296 |
+
end_frame = max(0, video_num_frames - self.skip_frames_end)
|
297 |
+
if end_frame <= start_frame:
|
298 |
+
frames = video_reader.get_batch([start_frame])
|
299 |
+
elif end_frame - start_frame <= self.max_num_frames:
|
300 |
+
frames = video_reader.get_batch(list(range(start_frame, end_frame)))
|
301 |
+
else:
|
302 |
+
indices = list(range(start_frame, end_frame, (end_frame - start_frame) // self.max_num_frames))
|
303 |
+
frames = video_reader.get_batch(indices)
|
304 |
+
|
305 |
+
# Ensure that we don't go over the limit
|
306 |
+
frames = frames[: self.max_num_frames]
|
307 |
+
selected_num_frames = frames.shape[0]
|
308 |
+
|
309 |
+
# Choose first (4k + 1) frames as this is how many is required by the VAE
|
310 |
+
remainder = (3 + (selected_num_frames % 4)) % 4
|
311 |
+
if remainder != 0:
|
312 |
+
frames = frames[:-remainder]
|
313 |
+
selected_num_frames = frames.shape[0]
|
314 |
+
|
315 |
+
assert (selected_num_frames - 1) % 4 == 0
|
316 |
+
|
317 |
+
# Training transforms
|
318 |
+
|
319 |
+
frames = frames.permute(0, 3, 1, 2) # [F, C, H, W]
|
320 |
+
progress_dataset_bar.set_description(
|
321 |
+
f"Loading progress Resizing video from {frames.shape[2]}x{frames.shape[3]} to {self.height}x{self.width}"
|
322 |
+
)
|
323 |
+
frames = self._resize_for_rectangle_crop(frames) #here the tensor should be processed to right size
|
324 |
+
|
325 |
+
frames = (frames - 127.5) / 127.5
|
326 |
+
videos.append(frames.contiguous()) # [F, C, H, W]
|
327 |
+
progress_dataset_bar.update(1)
|
328 |
+
|
329 |
+
progress_dataset_bar.close()
|
330 |
+
|
331 |
+
return videos
|
332 |
+
|
333 |
+
|
Dataset/webds.py
ADDED
@@ -0,0 +1,389 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import io
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import json
|
6 |
+
import tarfile
|
7 |
+
from functools import partial
|
8 |
+
|
9 |
+
import webdataset as wds
|
10 |
+
from webdataset import ResampledShards, DataPipeline, tarfile_to_samples
|
11 |
+
from webdataset.filters import pipelinefilter
|
12 |
+
from webdataset.tariterators import url_opener, group_by_keys
|
13 |
+
from webdataset.handlers import reraise_exception
|
14 |
+
from webdataset.gopen import gopen_schemes, gopen
|
15 |
+
|
16 |
+
|
17 |
+
def pytorch_worker_info(group=None): # sourcery skip: use-contextlib-suppress
|
18 |
+
"""Return node and worker info for PyTorch and some distributed environments."""
|
19 |
+
rank = 0
|
20 |
+
world_size = 1
|
21 |
+
worker = 0
|
22 |
+
num_workers = 1
|
23 |
+
try:
|
24 |
+
import torch.distributed
|
25 |
+
|
26 |
+
if torch.distributed.is_available() and torch.distributed.is_initialized():
|
27 |
+
group = group or torch.distributed.group.WORLD
|
28 |
+
rank = torch.distributed.get_rank(group=group)
|
29 |
+
world_size = torch.distributed.get_world_size(group=group)
|
30 |
+
except ModuleNotFoundError:
|
31 |
+
pass
|
32 |
+
try:
|
33 |
+
import torch.utils.data
|
34 |
+
|
35 |
+
worker_info = torch.utils.data.get_worker_info()
|
36 |
+
if worker_info is not None:
|
37 |
+
worker = worker_info.id
|
38 |
+
num_workers = worker_info.num_workers
|
39 |
+
except ModuleNotFoundError:
|
40 |
+
pass
|
41 |
+
|
42 |
+
return rank, world_size, worker, num_workers
|
43 |
+
|
44 |
+
|
45 |
+
def pytorch_worker_seed(group=None):
|
46 |
+
"""Compute a distinct, deterministic RNG seed for each worker and node."""
|
47 |
+
rank, world_size, worker, num_workers = pytorch_worker_info(group=group)
|
48 |
+
return rank * 1000 + worker
|
49 |
+
|
50 |
+
|
51 |
+
def worker_seed_sat(group=None, seed=0):
|
52 |
+
return pytorch_worker_seed(group=group) + seed * 23
|
53 |
+
|
54 |
+
|
55 |
+
class ConfiguredResampledShards(ResampledShards):
|
56 |
+
def __init__(self, urls, seed, nshards=sys.maxsize, deterministic=True):
|
57 |
+
from sat.helpers import print_rank0
|
58 |
+
|
59 |
+
try:
|
60 |
+
from megatron.core.parallel_state import get_data_parallel_group
|
61 |
+
|
62 |
+
group = get_data_parallel_group()
|
63 |
+
print_rank0("Using megatron data parallel group.")
|
64 |
+
except:
|
65 |
+
from sat.mpu import get_data_parallel_group
|
66 |
+
|
67 |
+
try:
|
68 |
+
group = get_data_parallel_group()
|
69 |
+
print_rank0("Using sat data parallel group.")
|
70 |
+
except AssertionError:
|
71 |
+
group = None
|
72 |
+
print_rank0("No data parallel group is specified!")
|
73 |
+
worker_seed_sat_this = partial(worker_seed_sat, group=group, seed=seed)
|
74 |
+
super().__init__(urls, nshards, worker_seed_sat_this, deterministic)
|
75 |
+
|
76 |
+
|
77 |
+
class SimpleDistributedWebDataset(DataPipeline):
|
78 |
+
def __init__(self, path, process_fn, seed, *, shuffle_buffer=1000):
|
79 |
+
# set shuffle_buffer = 1 to disable it, model-parallel will be different due to shuffle
|
80 |
+
try:
|
81 |
+
from sat.mpu import get_model_parallel_world_size
|
82 |
+
|
83 |
+
if get_model_parallel_world_size() > 1:
|
84 |
+
shuffle_buffer = 1
|
85 |
+
except Exception:
|
86 |
+
pass
|
87 |
+
super().__init__(
|
88 |
+
ConfiguredResampledShards(path, seed), # Lots of shards are recommended, or not evenly
|
89 |
+
tarfile_to_samples(),
|
90 |
+
wds.shuffle(shuffle_buffer),
|
91 |
+
process_fn,
|
92 |
+
)
|
93 |
+
|
94 |
+
|
95 |
+
def tar_file_iterator_with_meta(
|
96 |
+
fileobj, meta_names, skip_meta=r"__[^/]*__($|/)", suffix=None, handler=reraise_exception, meta_stream=None
|
97 |
+
):
|
98 |
+
"""Iterate over tar file, yielding filename, content pairs for the given tar stream.
|
99 |
+
|
100 |
+
:param fileobj: byte stream suitable for tarfile
|
101 |
+
:param meta_names: key of different items in meta file
|
102 |
+
:param skip_meta: regexp for keys that are skipped entirely (Default value = r"__[^/]*__($|/)")
|
103 |
+
|
104 |
+
"""
|
105 |
+
stream = tarfile.open(fileobj=fileobj, mode="r|*")
|
106 |
+
data_dir, filename = fileobj.name.rsplit("/", 1)
|
107 |
+
meta_data = {} # {id: {meta_name: meta_value, meta_name2: meta_value2, ...}}
|
108 |
+
|
109 |
+
if meta_stream is None:
|
110 |
+
meta_file_name = filename.split(".")[0] + ".meta.jsonl"
|
111 |
+
meta_path = os.path.join(data_dir, meta_file_name)
|
112 |
+
if os.path.exists(meta_path):
|
113 |
+
meta_stream = open(meta_path, "r")
|
114 |
+
else:
|
115 |
+
meta_file_name = meta_stream.name
|
116 |
+
|
117 |
+
if meta_stream is not None:
|
118 |
+
for lineno, line in enumerate(meta_stream):
|
119 |
+
meta_list = []
|
120 |
+
try:
|
121 |
+
meta_list.append(json.loads(line))
|
122 |
+
except Exception as exn:
|
123 |
+
from sat.helpers import print_rank0
|
124 |
+
|
125 |
+
print_rank0(f"Error in loading jsonl {meta_file_name}, lineno {lineno}: {line}", level="DEBUG")
|
126 |
+
continue
|
127 |
+
for item in meta_list:
|
128 |
+
if not item["key"] in meta_data:
|
129 |
+
meta_data[item["key"]] = {}
|
130 |
+
for meta_name in meta_names:
|
131 |
+
if meta_name in item:
|
132 |
+
meta_data[item["key"]][meta_name] = item[meta_name]
|
133 |
+
meta_stream.close()
|
134 |
+
|
135 |
+
try:
|
136 |
+
for tarinfo in stream:
|
137 |
+
fname = tarinfo.name
|
138 |
+
try:
|
139 |
+
if not tarinfo.isreg():
|
140 |
+
continue
|
141 |
+
if fname is None:
|
142 |
+
continue
|
143 |
+
if "/" not in fname and fname.startswith("__") and fname.endswith("__"):
|
144 |
+
# skipping metadata for now
|
145 |
+
continue
|
146 |
+
if skip_meta is not None and re.match(skip_meta, fname):
|
147 |
+
continue
|
148 |
+
if fname.endswith(".txt") and suffix is not None:
|
149 |
+
data = (stream.extractfile(tarinfo).read().decode() + suffix).encode()
|
150 |
+
else:
|
151 |
+
data = stream.extractfile(tarinfo).read()
|
152 |
+
result = dict(fname=fname, data=data)
|
153 |
+
yield result
|
154 |
+
|
155 |
+
if fname.endswith(".id"):
|
156 |
+
fid = fname.split(".")[0]
|
157 |
+
if "-$#%@&" in fid:
|
158 |
+
sfid = fid.split("-$#%@&")[0]
|
159 |
+
else:
|
160 |
+
sfid = fid
|
161 |
+
meta_data_fid = meta_data.get(sfid, {})
|
162 |
+
for meta_name in meta_names:
|
163 |
+
meta_fname = fid + "." + meta_name
|
164 |
+
meta = meta_data_fid.get(meta_name, None)
|
165 |
+
yield dict(fname=meta_fname, data=meta)
|
166 |
+
stream.members = []
|
167 |
+
except Exception as exn:
|
168 |
+
if hasattr(exn, "args") and len(exn.args) > 0:
|
169 |
+
exn.args = (exn.args[0] + " @ " + str(fileobj),) + exn.args[1:]
|
170 |
+
if handler(exn):
|
171 |
+
continue
|
172 |
+
else:
|
173 |
+
break
|
174 |
+
except Exception as exn:
|
175 |
+
print(exn)
|
176 |
+
del stream
|
177 |
+
|
178 |
+
|
179 |
+
def tar_file_expander_with_meta(data, meta_names, handler=reraise_exception):
|
180 |
+
"""Expand a stream of open tar files into a stream of tar file contents.
|
181 |
+
|
182 |
+
This returns an iterator over (filename, file_contents).
|
183 |
+
"""
|
184 |
+
for source in data:
|
185 |
+
url = source["url"]
|
186 |
+
try:
|
187 |
+
assert isinstance(source, dict)
|
188 |
+
assert "stream" in source
|
189 |
+
for sample in tar_file_iterator_with_meta(source["stream"], meta_names, meta_stream=source["meta_stream"]):
|
190 |
+
assert isinstance(sample, dict) and "data" in sample and "fname" in sample
|
191 |
+
sample["__url__"] = url
|
192 |
+
yield sample
|
193 |
+
except Exception as exn:
|
194 |
+
exn.args = exn.args + (source.get("stream"), source.get("url"))
|
195 |
+
if handler(exn):
|
196 |
+
continue
|
197 |
+
else:
|
198 |
+
break
|
199 |
+
|
200 |
+
|
201 |
+
def url_opener(
|
202 |
+
data,
|
203 |
+
handler,
|
204 |
+
**kw,
|
205 |
+
):
|
206 |
+
"""Open URLs and yield a stream of url+stream pairs.
|
207 |
+
|
208 |
+
Args:
|
209 |
+
data: iterator over dict(url=...)
|
210 |
+
handler: exception handler.
|
211 |
+
kw: keyword arguments for gopen.gopen.
|
212 |
+
|
213 |
+
Yields:
|
214 |
+
a stream of url+stream pairs.
|
215 |
+
"""
|
216 |
+
for sample in data:
|
217 |
+
assert isinstance(sample, dict), sample
|
218 |
+
assert "url" in sample
|
219 |
+
url = sample["url"]
|
220 |
+
try:
|
221 |
+
stream = gopen(url, **kw)
|
222 |
+
if hasattr(stream, "meta_stream"):
|
223 |
+
meta_stream = stream.meta_stream
|
224 |
+
del stream.meta_stream
|
225 |
+
else:
|
226 |
+
meta_stream = None
|
227 |
+
sample.update(stream=stream, meta_stream=meta_stream)
|
228 |
+
yield sample
|
229 |
+
except Exception as exn:
|
230 |
+
exn.args = exn.args + (url,)
|
231 |
+
if handler(exn):
|
232 |
+
continue
|
233 |
+
else:
|
234 |
+
break
|
235 |
+
|
236 |
+
|
237 |
+
def tarfile_samples_with_meta(src, meta_names, handler=reraise_exception):
|
238 |
+
streams = url_opener(src, handler=handler)
|
239 |
+
files = tar_file_expander_with_meta(streams, meta_names, handler)
|
240 |
+
samples = group_by_keys(files, handler=handler)
|
241 |
+
return samples
|
242 |
+
|
243 |
+
|
244 |
+
class MetaDistributedWebDataset(DataPipeline):
|
245 |
+
"""WebDataset with meta information files
|
246 |
+
Extra Format:
|
247 |
+
in webdataset (tar), for each sample there is a '.id';
|
248 |
+
for each tar file, there is a '.meta.jsonl' file with the same name;
|
249 |
+
The '.meta.jsonl' file contains lines of json objects, each with a 'key' field to match '.id'.
|
250 |
+
"""
|
251 |
+
|
252 |
+
def __init__(
|
253 |
+
self, path, process_fn, seed, *, meta_names=[], nshards=sys.maxsize, shuffle_buffer=1000, include_dirs=None
|
254 |
+
):
|
255 |
+
# os.environ['WDS_SHOW_SEED'] = '1'
|
256 |
+
import torch
|
257 |
+
|
258 |
+
if torch.distributed.get_rank() == 0:
|
259 |
+
if include_dirs is not None: # /webdatasets/A,/webdatasets/C
|
260 |
+
other_paths = []
|
261 |
+
include_dirs = include_dirs.split(",")
|
262 |
+
for include_dir in include_dirs:
|
263 |
+
if "*" in include_dir:
|
264 |
+
include_dir, n = include_dir.split("*")
|
265 |
+
n = int(n)
|
266 |
+
else:
|
267 |
+
n = 1
|
268 |
+
for cur_dir, dirs, files in os.walk(include_dir):
|
269 |
+
for f in files:
|
270 |
+
if f.endswith("tar") and os.path.getsize(os.path.join(cur_dir, f)) > 0:
|
271 |
+
# other_paths.append(os.path.join(cur_dir,f))
|
272 |
+
other_paths.extend([os.path.join(cur_dir, f)] * n)
|
273 |
+
# print(f'Adding dataset paths {",".join(other_paths)}')
|
274 |
+
from braceexpand import braceexpand
|
275 |
+
|
276 |
+
if len(path) > 0: # not ""
|
277 |
+
path = list(braceexpand(path)) + other_paths
|
278 |
+
else:
|
279 |
+
path = other_paths
|
280 |
+
path = [path]
|
281 |
+
else:
|
282 |
+
path = [
|
283 |
+
None,
|
284 |
+
]
|
285 |
+
torch.distributed.broadcast_object_list(path, src=0)
|
286 |
+
path = path[0]
|
287 |
+
|
288 |
+
tarfile_samples = partial(tarfile_samples_with_meta, meta_names=meta_names)
|
289 |
+
tarfile_to_samples = pipelinefilter(tarfile_samples)
|
290 |
+
|
291 |
+
# if model parallel, shuffle_buffer should be 1 to disable shuffling
|
292 |
+
try:
|
293 |
+
from sat.mpu import get_model_parallel_world_size
|
294 |
+
|
295 |
+
if get_model_parallel_world_size() > 1:
|
296 |
+
shuffle_buffer = 1
|
297 |
+
except Exception:
|
298 |
+
pass
|
299 |
+
|
300 |
+
super().__init__(
|
301 |
+
ConfiguredResampledShards(path, seed, nshards=nshards),
|
302 |
+
tarfile_to_samples(),
|
303 |
+
wds.shuffle(shuffle_buffer),
|
304 |
+
process_fn,
|
305 |
+
)
|
306 |
+
|
307 |
+
|
308 |
+
# rclone support
|
309 |
+
from webdataset.gopen import Pipe
|
310 |
+
|
311 |
+
|
312 |
+
def gopen_rclone(url, mode="rb", bufsize=1024 * 1024 * 32):
|
313 |
+
"""Open a URL with `curl`.
|
314 |
+
|
315 |
+
:param url: rclone url, e.g. data:bucket1/foo.tar. data should be configured.
|
316 |
+
:param mode: file mode
|
317 |
+
:param bufsize: buffer size
|
318 |
+
"""
|
319 |
+
url = url.replace("rclone://", "")
|
320 |
+
if mode[0] == "r":
|
321 |
+
cmd = f"rclone cat '{url}'"
|
322 |
+
return Pipe(
|
323 |
+
cmd,
|
324 |
+
mode=mode,
|
325 |
+
shell=True,
|
326 |
+
bufsize=bufsize,
|
327 |
+
ignore_status=[141, 23],
|
328 |
+
) # skipcq: BAN-B604
|
329 |
+
elif mode[0] == "w":
|
330 |
+
cmd = f"rclone cp - '{url}'"
|
331 |
+
return Pipe(
|
332 |
+
cmd,
|
333 |
+
mode=mode,
|
334 |
+
shell=True,
|
335 |
+
bufsize=bufsize,
|
336 |
+
ignore_status=[141, 26],
|
337 |
+
) # skipcq: BAN-B604
|
338 |
+
else:
|
339 |
+
raise ValueError(f"{mode}: unknown mode")
|
340 |
+
|
341 |
+
|
342 |
+
def gopen_boto3(url, mode="rb", bufsize=8192 * 2):
|
343 |
+
"""Open a URL with boto3 API.
|
344 |
+
|
345 |
+
:param url: boto3 url, e.g. boto3://bucket1/foo.tar. data should be configured.
|
346 |
+
:param mode: file mode
|
347 |
+
:param bufsize: buffer size
|
348 |
+
"""
|
349 |
+
import boto3
|
350 |
+
|
351 |
+
# boto3.set_stream_logger('botocore', level='DEBUG')
|
352 |
+
if url.startswith("boto3://"):
|
353 |
+
url = url.replace("boto3://", "")
|
354 |
+
need_meta = False
|
355 |
+
else:
|
356 |
+
url = url.replace("metaboto3://", "")
|
357 |
+
need_meta = True
|
358 |
+
endpoint_url = os.environ.get("S3_ENDPOINT_URL", None)
|
359 |
+
access_key = os.environ.get("S3_ACCESS_KEY_ID", None)
|
360 |
+
secret_key = os.environ.get("S3_SECRET_ACCESS_KEY", None)
|
361 |
+
|
362 |
+
if mode[0] == "r":
|
363 |
+
s3_client = boto3.client(
|
364 |
+
"s3", endpoint_url=endpoint_url, aws_access_key_id=access_key, aws_secret_access_key=secret_key
|
365 |
+
)
|
366 |
+
bucket, key = url.split("/", 1)
|
367 |
+
|
368 |
+
if need_meta:
|
369 |
+
# download a meta json
|
370 |
+
meta_file_key = key.split(".")[0] + ".meta.jsonl"
|
371 |
+
meta_stream = io.BytesIO()
|
372 |
+
s3_client.download_fileobj(bucket, meta_file_key, meta_stream)
|
373 |
+
meta_stream.seek(0)
|
374 |
+
meta_stream.name = meta_file_key
|
375 |
+
else:
|
376 |
+
meta_stream = None
|
377 |
+
|
378 |
+
# data tar stream
|
379 |
+
response = s3_client.get_object(Bucket=bucket, Key=key) # Range optional
|
380 |
+
response["Body"].name = key # actually not used
|
381 |
+
response["Body"].meta_stream = meta_stream
|
382 |
+
return response["Body"]
|
383 |
+
else:
|
384 |
+
raise ValueError(f"{mode}: unknown mode")
|
385 |
+
|
386 |
+
|
387 |
+
gopen_schemes["rclone"] = gopen_rclone
|
388 |
+
gopen_schemes["boto3"] = gopen_boto3
|
389 |
+
gopen_schemes["metaboto3"] = gopen_boto3
|
LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright 2024 CogVideo Model Team @ Zhipu AI
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
MODEL_LICENSE
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The CogVideoX License
|
2 |
+
|
3 |
+
1. Definitions
|
4 |
+
|
5 |
+
“Licensor” means the CogVideoX Model Team that distributes its Software.
|
6 |
+
|
7 |
+
“Software” means the CogVideoX model parameters made available under this license.
|
8 |
+
|
9 |
+
2. License Grant
|
10 |
+
|
11 |
+
Under the terms and conditions of this license, the licensor hereby grants you a non-exclusive, worldwide, non-transferable, non-sublicensable, revocable, royalty-free copyright license. The intellectual property rights of the generated content belong to the user to the extent permitted by applicable local laws.
|
12 |
+
This license allows you to freely use all open-source models in this repository for academic research. Users who wish to use the models for commercial purposes must register and obtain a basic commercial license in https://open.bigmodel.cn/mla/form .
|
13 |
+
Users who have registered and obtained the basic commercial license can use the models for commercial activities for free, but must comply with all terms and conditions of this license. Additionally, the number of service users (visits) for your commercial activities must not exceed 1 million visits per month.
|
14 |
+
If the number of service users (visits) for your commercial activities exceeds 1 million visits per month, you need to contact our business team to obtain more commercial licenses.
|
15 |
+
The above copyright statement and this license statement should be included in all copies or significant portions of this software.
|
16 |
+
|
17 |
+
3. Restriction
|
18 |
+
|
19 |
+
You will not use, copy, modify, merge, publish, distribute, reproduce, or create derivative works of the Software, in whole or in part, for any military, or illegal purposes.
|
20 |
+
|
21 |
+
You will not use the Software for any act that may undermine China's national security and national unity, harm the public interest of society, or infringe upon the rights and interests of human beings.
|
22 |
+
|
23 |
+
4. Disclaimer
|
24 |
+
|
25 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
|
27 |
+
5. Limitation of Liability
|
28 |
+
|
29 |
+
EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL THEORY, WHETHER BASED IN TORT, NEGLIGENCE, CONTRACT, LIABILITY, OR OTHERWISE WILL ANY LICENSOR BE LIABLE TO YOU FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES, OR ANY OTHER COMMERCIAL LOSSES, EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
30 |
+
|
31 |
+
6. Dispute Resolution
|
32 |
+
|
33 |
+
This license shall be governed and construed in accordance with the laws of People’s Republic of China. Any dispute arising from or in connection with this License shall be submitted to Haidian District People's Court in Beijing.
|
34 |
+
|
35 |
+
Note that the license is subject to update to a more comprehensive version. For any questions related to the license and copyright, please contact us at [email protected].
|
36 |
+
|
37 |
+
1. 定义
|
38 |
+
|
39 |
+
“许可方”是指分发其软件的 CogVideoX 模型团队。
|
40 |
+
|
41 |
+
“软件”是指根据本许可提供的 CogVideoX 模型参数。
|
42 |
+
|
43 |
+
2. 许可授予
|
44 |
+
|
45 |
+
根据本许可的条款和条件,许可方特此授予您非排他性、全球性、不可转让、不可再许可、可撤销、免版税的版权许可。生成内容的知识产权所属,可根据适用当地法律的规定,在法律允许的范围内由用户享有生成内容的知识产权或其他权利。
|
46 |
+
本许可允许您免费使用本仓库中的所有开源模型进行学术研究。对于希望将模型用于商业目的的用户,需在 https://open.bigmodel.cn/mla/form 完成登记并获得基础商用授权。
|
47 |
+
|
48 |
+
经过登记并获得基础商用授权的用户可以免费使用本模型进行商业活动,但必须遵守本许可的所有条款和条件。
|
49 |
+
在本许可证下,您的商业活动的服务用户数量(访问量)不得超过100万人次访问 / 每月。如果超过,您需要与我们的商业团队联系以获得更多的商业许可。
|
50 |
+
上述版权声明和本许可声明应包含在本软件的所有副本或重要部分中。
|
51 |
+
|
52 |
+
3.限制
|
53 |
+
|
54 |
+
您不得出于任何军事或非法目的使用、复制、修改、合并、发布、分发、复制或创建本软件的全部或部分衍生作品。
|
55 |
+
|
56 |
+
您不得利用本软件从事任何危害国家安全和国家统一、危害社会公共利益、侵犯人身权益的行为。
|
57 |
+
|
58 |
+
4.免责声明
|
59 |
+
|
60 |
+
本软件“按原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和非侵权性的保证。
|
61 |
+
在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为还是其他方面,由软件或软件的使用或其他交易引起、由软件引起或与之相关 软件。
|
62 |
+
|
63 |
+
5. 责任限制
|
64 |
+
|
65 |
+
除适用��律禁止的范围外,在任何情况下且根据任何法律理论,无论是基于侵权行为、疏忽、合同、责任或其他原因,任何许可方均不对您承担任何直接、间接、特殊、偶然、示范性、 或间接损害,或任何其他商业损失,即使许可人已被告知此类损害的可能性。
|
66 |
+
|
67 |
+
6.争议解决
|
68 |
+
|
69 |
+
本许可受中华人民共和国法律管辖并按其解释。 因本许可引起的或与本许可有关的任何争议应提交北京市海淀区人民法院。
|
70 |
+
|
71 |
+
请注意,许可证可能会更新到更全面的版本。 有关许可和版权的任何问题,请通过 [email protected] 与我们联系。
|
README.md
CHANGED
@@ -1,12 +1,105 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# LongAnimation: Long Animation Generation with Dynamic Global-Local Memory
|
2 |
+
<a href="https://cn-makers.github.io/long_animation_web/"><img src="https://img.shields.io/static/v1?label=Project&message=Website&color=blue"></a>
|
3 |
+
<a href="https://arxiv.org/pdf/2507.01945"><img src="https://img.shields.io/badge/arXiv-2057.01945-b31b1b.svg"></a>
|
4 |
+
<a href="https://www.apache.org/licenses/LICENSE-2.0.txt"><img src="https://img.shields.io/badge/License-Apache-yellow"></a>
|
5 |
+
|
6 |
+
|
7 |
+
https://github.com/user-attachments/assets/a3866f82-b07a-41ae-9673-2a24f7c78af4
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
> <a href="https://cn-makers.github.io/long_animation_web/">**LongAnimation: Long Animation Generation with Dynamic Global-Local Memory**</a>
|
12 |
+
>
|
13 |
+
|
14 |
+
[Nan Chen](https://openreview.net/profile?id=~Nan_Chen13)<sup>1</sup>, [Mengqi Huang](https://corleone-huang.github.io/)<sup>1</sup>, [Yihao Meng](https://yihao-meng.github.io/)<sup>2</sup>, [Zhendong Mao](https://faculty.ustc.edu.cn/maozhendong/en/index.htm)<sup>†,1</sup><br>
|
15 |
+
<sup>1</sup>USTC <sup>2</sup>HKUST <sup>†</sup>corresponding author
|
16 |
+
|
17 |
+
> Existing studies are limited to short-term colorization by fusing overlapping features to achieve smooth transitions, which fails to maintain long-term color consistency. In this study, we propose a dynamic global-local paradigm to achieve ideal long-term color consistency by dynamically extracting global color-consistent features relevant to the current generation.
|
18 |
+
</p>
|
19 |
+
|
20 |
+
🎉🎉 Our paper, “LongAnimation: Long Animation Generation with Dynamic Global-Local Memory” accepted by ICCV 2025!
|
21 |
+
**Strongly recommend seeing our [demo page](https://cn-makers.github.io/long_animation_web/).**
|
22 |
+
|
23 |
+
|
24 |
+
## Showcase
|
25 |
+
|
26 |
+
https://github.com/user-attachments/assets/8d225a9e-6e27-42bd-9638-5f4e4cb4dbf7
|
27 |
+
|
28 |
+
https://github.com/user-attachments/assets/0fee3eed-8a38-4382-bbe6-21c0cf2371e9
|
29 |
+
|
30 |
+
https://github.com/user-attachments/assets/7d87e63a-f5e6-46ba-bb1b-d457ceb0b1d8
|
31 |
+
|
32 |
+
|
33 |
+
## Creative usage
|
34 |
+
### Text-guided Background Generation
|
35 |
+
https://github.com/user-attachments/assets/68a5d0fb-f767-4fc8-aed6-cd798301484f
|
36 |
+
|
37 |
+
https://github.com/user-attachments/assets/7cba4d5b-b793-474d-9da4-34892853b240
|
38 |
+
|
39 |
+
https://github.com/user-attachments/assets/6787349b-6a3e-4ed1-8a6a-efc1643a4e92
|
40 |
+
<div style="text-align:center; margin-top: -50px; margin-bottom: 70px;font-size: 18px; letter-spacing: 0.2px;">
|
41 |
+
<em>A boy and a girl in different environment.</em>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
|
45 |
+
## TODO List
|
46 |
+
|
47 |
+
- [x] Release the paper and demo page. Visit [https://cn-makers.github.io/long_animation_web/](https://cn-makers.github.io/long_animation_web/)
|
48 |
+
- [x] Release the code.
|
49 |
+
|
50 |
+
|
51 |
+
## Requirements
|
52 |
+
The training is conducted on 6 A100 GPUs (80GB VRAM), the inference is tested on 1 A100 GPU.
|
53 |
+
## Setup
|
54 |
+
```
|
55 |
+
git clone https://github.com/CN-makers/LongAnimation
|
56 |
+
cd LongAnimation
|
57 |
+
```
|
58 |
+
|
59 |
+
## Environment
|
60 |
+
All the tests are conducted in Linux. We suggest running our code in Linux. To set up our environment in Linux, please run:
|
61 |
+
```
|
62 |
+
conda create -n LongAnimation python=3.10 -y
|
63 |
+
conda activate LongAnimation
|
64 |
+
|
65 |
+
bash install.sh
|
66 |
+
```
|
67 |
+
|
68 |
+
|
69 |
+
## Checkpoints
|
70 |
+
1. please download the pre-trained CogVideoX-1.5 I2V checkpoints from [here](https://huggingface.co/THUDM/CogVideoX1.5-5B-I2V), and put the whole folder under `pretrained_weight`, it should look like `./pretrained_weights/CogVideoX1.5-5B-I2V`
|
71 |
+
|
72 |
+
2. please download the pre-trained long video understanding model Video-XL checkpoints from [here](https://huggingface.co/sy1998/Video_XL/tree/main), and put the whole folder under `pretrained_weight`, it should look like `./pretrained_weights/videoxl`
|
73 |
+
|
74 |
+
3. please download the checkpoint for our SketchDiT and DGLM model from [here](https://huggingface.co/CNcreator0331/LongAnimation/tree/main), and put the whole folder as `./pretrained_weights/longanimation`.
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
## Generate Your Animation!
|
81 |
+
To colorize the target lineart sequence with a specific character design, you can run the following command:
|
82 |
+
```
|
83 |
+
bash long_animation_inference.sh
|
84 |
+
```
|
85 |
+
|
86 |
+
|
87 |
+
We provide some test cases in `test_json` folder. You can also try our model with your own data. You can change the lineart sequence and corresponding character design in the script `Long_animation_inference.sh`.
|
88 |
+
|
89 |
+
During the official training and testing, the --height and --weight we used were 576 and 1024 respectively. Additionally, the model can also be compatible with resolutions of 768 in length and 1360 in width respectively.
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
## Citation:
|
94 |
+
Don't forget to cite this source if it proves useful in your research!
|
95 |
+
```
|
96 |
+
@misc{chen2025longanimationlonganimationgeneration,
|
97 |
+
title={LongAnimation: Long Animation Generation with Dynamic Global-Local Memory},
|
98 |
+
author={Nan Chen and Mengqi Huang and Yihao Meng and Zhendong Mao},
|
99 |
+
year={2025},
|
100 |
+
eprint={2507.01945},
|
101 |
+
archivePrefix={arXiv},
|
102 |
+
primaryClass={cs.CV},
|
103 |
+
url={https://arxiv.org/abs/2507.01945},
|
104 |
+
}
|
105 |
+
```
|
accelerate_config_machine_single.yaml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
compute_environment: LOCAL_MACHINE
|
2 |
+
debug: false
|
3 |
+
deepspeed_config:
|
4 |
+
gradient_accumulation_steps: 1
|
5 |
+
gradient_clipping: 1.0
|
6 |
+
offload_optimizer_device: none
|
7 |
+
offload_param_device: none
|
8 |
+
zero3_init_flag: false
|
9 |
+
zero_stage: 2
|
10 |
+
distributed_type: DEEPSPEED
|
11 |
+
downcast_bf16: 'no'
|
12 |
+
enable_cpu_affinity: false
|
13 |
+
machine_rank: 0
|
14 |
+
main_training_function: main
|
15 |
+
dynamo_backend: 'no'
|
16 |
+
mixed_precision: 'no'
|
17 |
+
num_machines: 1
|
18 |
+
num_processes: 4
|
19 |
+
rdzv_backend: static
|
20 |
+
same_network: true
|
21 |
+
tpu_env: []
|
22 |
+
tpu_use_cluster: false
|
23 |
+
tpu_use_sudo: false
|
24 |
+
use_cpu: false
|
diffusers/.github/ISSUE_TEMPLATE/bug-report.yml
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "\U0001F41B Bug Report"
|
2 |
+
description: Report a bug on Diffusers
|
3 |
+
labels: [ "bug" ]
|
4 |
+
body:
|
5 |
+
- type: markdown
|
6 |
+
attributes:
|
7 |
+
value: |
|
8 |
+
Thanks a lot for taking the time to file this issue 🤗.
|
9 |
+
Issues do not only help to improve the library, but also publicly document common problems, questions, workflows for the whole community!
|
10 |
+
Thus, issues are of the same importance as pull requests when contributing to this library ❤️.
|
11 |
+
In order to make your issue as **useful for the community as possible**, let's try to stick to some simple guidelines:
|
12 |
+
- 1. Please try to be as precise and concise as possible.
|
13 |
+
*Give your issue a fitting title. Assume that someone which very limited knowledge of Diffusers can understand your issue. Add links to the source code, documentation other issues, pull requests etc...*
|
14 |
+
- 2. If your issue is about something not working, **always** provide a reproducible code snippet. The reader should be able to reproduce your issue by **only copy-pasting your code snippet into a Python shell**.
|
15 |
+
*The community cannot solve your issue if it cannot reproduce it. If your bug is related to training, add your training script and make everything needed to train public. Otherwise, just add a simple Python code snippet.*
|
16 |
+
- 3. Add the **minimum** amount of code / context that is needed to understand, reproduce your issue.
|
17 |
+
*Make the life of maintainers easy. `diffusers` is getting many issues every day. Make sure your issue is about one bug and one bug only. Make sure you add only the context, code needed to understand your issues - nothing more. Generally, every issue is a way of documenting this library, try to make it a good documentation entry.*
|
18 |
+
- 4. For issues related to community pipelines (i.e., the pipelines located in the `examples/community` folder), please tag the author of the pipeline in your issue thread as those pipelines are not maintained.
|
19 |
+
- type: markdown
|
20 |
+
attributes:
|
21 |
+
value: |
|
22 |
+
For more in-detail information on how to write good issues you can have a look [here](https://huggingface.co/course/chapter8/5?fw=pt).
|
23 |
+
- type: textarea
|
24 |
+
id: bug-description
|
25 |
+
attributes:
|
26 |
+
label: Describe the bug
|
27 |
+
description: A clear and concise description of what the bug is. If you intend to submit a pull request for this issue, tell us in the description. Thanks!
|
28 |
+
placeholder: Bug description
|
29 |
+
validations:
|
30 |
+
required: true
|
31 |
+
- type: textarea
|
32 |
+
id: reproduction
|
33 |
+
attributes:
|
34 |
+
label: Reproduction
|
35 |
+
description: Please provide a minimal reproducible code which we can copy/paste and reproduce the issue.
|
36 |
+
placeholder: Reproduction
|
37 |
+
validations:
|
38 |
+
required: true
|
39 |
+
- type: textarea
|
40 |
+
id: logs
|
41 |
+
attributes:
|
42 |
+
label: Logs
|
43 |
+
description: "Please include the Python logs if you can."
|
44 |
+
render: shell
|
45 |
+
- type: textarea
|
46 |
+
id: system-info
|
47 |
+
attributes:
|
48 |
+
label: System Info
|
49 |
+
description: Please share your system info with us. You can run the command `diffusers-cli env` and copy-paste its output below.
|
50 |
+
placeholder: Diffusers version, platform, Python version, ...
|
51 |
+
validations:
|
52 |
+
required: true
|
53 |
+
- type: textarea
|
54 |
+
id: who-can-help
|
55 |
+
attributes:
|
56 |
+
label: Who can help?
|
57 |
+
description: |
|
58 |
+
Your issue will be replied to more quickly if you can figure out the right person to tag with @.
|
59 |
+
If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
|
60 |
+
|
61 |
+
All issues are read by one of the core maintainers, so if you don't know who to tag, just leave this blank and
|
62 |
+
a core maintainer will ping the right person.
|
63 |
+
|
64 |
+
Please tag a maximum of 2 people.
|
65 |
+
|
66 |
+
Questions on DiffusionPipeline (Saving, Loading, From pretrained, ...): @sayakpaul @DN6
|
67 |
+
|
68 |
+
Questions on pipelines:
|
69 |
+
- Stable Diffusion @yiyixuxu @asomoza
|
70 |
+
- Stable Diffusion XL @yiyixuxu @sayakpaul @DN6
|
71 |
+
- Stable Diffusion 3: @yiyixuxu @sayakpaul @DN6 @asomoza
|
72 |
+
- Kandinsky @yiyixuxu
|
73 |
+
- ControlNet @sayakpaul @yiyixuxu @DN6
|
74 |
+
- T2I Adapter @sayakpaul @yiyixuxu @DN6
|
75 |
+
- IF @DN6
|
76 |
+
- Text-to-Video / Video-to-Video @DN6 @a-r-r-o-w
|
77 |
+
- Wuerstchen @DN6
|
78 |
+
- Other: @yiyixuxu @DN6
|
79 |
+
- Improving generation quality: @asomoza
|
80 |
+
|
81 |
+
Questions on models:
|
82 |
+
- UNet @DN6 @yiyixuxu @sayakpaul
|
83 |
+
- VAE @sayakpaul @DN6 @yiyixuxu
|
84 |
+
- Transformers/Attention @DN6 @yiyixuxu @sayakpaul
|
85 |
+
|
86 |
+
Questions on single file checkpoints: @DN6
|
87 |
+
|
88 |
+
Questions on Schedulers: @yiyixuxu
|
89 |
+
|
90 |
+
Questions on LoRA: @sayakpaul
|
91 |
+
|
92 |
+
Questions on Textual Inversion: @sayakpaul
|
93 |
+
|
94 |
+
Questions on Training:
|
95 |
+
- DreamBooth @sayakpaul
|
96 |
+
- Text-to-Image Fine-tuning @sayakpaul
|
97 |
+
- Textual Inversion @sayakpaul
|
98 |
+
- ControlNet @sayakpaul
|
99 |
+
|
100 |
+
Questions on Tests: @DN6 @sayakpaul @yiyixuxu
|
101 |
+
|
102 |
+
Questions on Documentation: @stevhliu
|
103 |
+
|
104 |
+
Questions on JAX- and MPS-related things: @pcuenca
|
105 |
+
|
106 |
+
Questions on audio pipelines: @sanchit-gandhi
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
placeholder: "@Username ..."
|
diffusers/.github/ISSUE_TEMPLATE/config.yml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
contact_links:
|
2 |
+
- name: Questions / Discussions
|
3 |
+
url: https://github.com/huggingface/diffusers/discussions
|
4 |
+
about: General usage questions and community discussions
|
diffusers/.github/ISSUE_TEMPLATE/feature_request.md
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: "\U0001F680 Feature Request"
|
3 |
+
about: Suggest an idea for this project
|
4 |
+
title: ''
|
5 |
+
labels: ''
|
6 |
+
assignees: ''
|
7 |
+
|
8 |
+
---
|
9 |
+
|
10 |
+
**Is your feature request related to a problem? Please describe.**
|
11 |
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...].
|
12 |
+
|
13 |
+
**Describe the solution you'd like.**
|
14 |
+
A clear and concise description of what you want to happen.
|
15 |
+
|
16 |
+
**Describe alternatives you've considered.**
|
17 |
+
A clear and concise description of any alternative solutions or features you've considered.
|
18 |
+
|
19 |
+
**Additional context.**
|
20 |
+
Add any other context or screenshots about the feature request here.
|
diffusers/.github/ISSUE_TEMPLATE/feedback.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: "💬 Feedback about API Design"
|
3 |
+
about: Give feedback about the current API design
|
4 |
+
title: ''
|
5 |
+
labels: ''
|
6 |
+
assignees: ''
|
7 |
+
|
8 |
+
---
|
9 |
+
|
10 |
+
**What API design would you like to have changed or added to the library? Why?**
|
11 |
+
|
12 |
+
**What use case would this enable or better enable? Can you give us a code example?**
|
diffusers/.github/ISSUE_TEMPLATE/new-model-addition.yml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "\U0001F31F New Model/Pipeline/Scheduler Addition"
|
2 |
+
description: Submit a proposal/request to implement a new diffusion model/pipeline/scheduler
|
3 |
+
labels: [ "New model/pipeline/scheduler" ]
|
4 |
+
|
5 |
+
body:
|
6 |
+
- type: textarea
|
7 |
+
id: description-request
|
8 |
+
validations:
|
9 |
+
required: true
|
10 |
+
attributes:
|
11 |
+
label: Model/Pipeline/Scheduler description
|
12 |
+
description: |
|
13 |
+
Put any and all important information relative to the model/pipeline/scheduler
|
14 |
+
|
15 |
+
- type: checkboxes
|
16 |
+
id: information-tasks
|
17 |
+
attributes:
|
18 |
+
label: Open source status
|
19 |
+
description: |
|
20 |
+
Please note that if the model implementation isn't available or if the weights aren't open-source, we are less likely to implement it in `diffusers`.
|
21 |
+
options:
|
22 |
+
- label: "The model implementation is available."
|
23 |
+
- label: "The model weights are available (Only relevant if addition is not a scheduler)."
|
24 |
+
|
25 |
+
- type: textarea
|
26 |
+
id: additional-info
|
27 |
+
attributes:
|
28 |
+
label: Provide useful links for the implementation
|
29 |
+
description: |
|
30 |
+
Please provide information regarding the implementation, the weights, and the authors.
|
31 |
+
Please mention the authors by @gh-username if you're aware of their usernames.
|
diffusers/.github/ISSUE_TEMPLATE/translate.md
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
name: 🌐 Translating a New Language?
|
3 |
+
about: Start a new translation effort in your language
|
4 |
+
title: '[<languageCode>] Translating docs to <languageName>'
|
5 |
+
labels: WIP
|
6 |
+
assignees: ''
|
7 |
+
|
8 |
+
---
|
9 |
+
|
10 |
+
<!--
|
11 |
+
Note: Please search to see if an issue already exists for the language you are trying to translate.
|
12 |
+
-->
|
13 |
+
|
14 |
+
Hi!
|
15 |
+
|
16 |
+
Let's bring the documentation to all the <languageName>-speaking community 🌐.
|
17 |
+
|
18 |
+
Who would want to translate? Please follow the 🤗 [TRANSLATING guide](https://github.com/huggingface/diffusers/blob/main/docs/TRANSLATING.md). Here is a list of the files ready for translation. Let us know in this issue if you'd like to translate any, and we'll add your name to the list.
|
19 |
+
|
20 |
+
Some notes:
|
21 |
+
|
22 |
+
* Please translate using an informal tone (imagine you are talking with a friend about Diffusers 🤗).
|
23 |
+
* Please translate in a gender-neutral way.
|
24 |
+
* Add your translations to the folder called `<languageCode>` inside the [source folder](https://github.com/huggingface/diffusers/tree/main/docs/source).
|
25 |
+
* Register your translation in `<languageCode>/_toctree.yml`; please follow the order of the [English version](https://github.com/huggingface/diffusers/blob/main/docs/source/en/_toctree.yml).
|
26 |
+
* Once you're finished, open a pull request and tag this issue by including #issue-number in the description, where issue-number is the number of this issue. Please ping @stevhliu for review.
|
27 |
+
* 🙋 If you'd like others to help you with the translation, you can also post in the 🤗 [forums](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63).
|
28 |
+
|
29 |
+
Thank you so much for your help! 🤗
|
diffusers/.github/PULL_REQUEST_TEMPLATE.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# What does this PR do?
|
2 |
+
|
3 |
+
<!--
|
4 |
+
Congratulations! You've made it this far! You're not quite done yet though.
|
5 |
+
|
6 |
+
Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.
|
7 |
+
|
8 |
+
Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.
|
9 |
+
|
10 |
+
Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
|
11 |
+
-->
|
12 |
+
|
13 |
+
<!-- Remove if not applicable -->
|
14 |
+
|
15 |
+
Fixes # (issue)
|
16 |
+
|
17 |
+
|
18 |
+
## Before submitting
|
19 |
+
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
|
20 |
+
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md)?
|
21 |
+
- [ ] Did you read our [philosophy doc](https://github.com/huggingface/diffusers/blob/main/PHILOSOPHY.md) (important for complex PRs)?
|
22 |
+
- [ ] Was this discussed/approved via a GitHub issue or the [forum](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63)? Please add a link to it if that's the case.
|
23 |
+
- [ ] Did you make sure to update the documentation with your changes? Here are the
|
24 |
+
[documentation guidelines](https://github.com/huggingface/diffusers/tree/main/docs), and
|
25 |
+
[here are tips on formatting docstrings](https://github.com/huggingface/diffusers/tree/main/docs#writing-source-documentation).
|
26 |
+
- [ ] Did you write any new necessary tests?
|
27 |
+
|
28 |
+
|
29 |
+
## Who can review?
|
30 |
+
|
31 |
+
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
|
32 |
+
members/contributors who may be interested in your PR.
|
33 |
+
|
34 |
+
<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @.
|
35 |
+
|
36 |
+
If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
|
37 |
+
Please tag fewer than 3 people.
|
38 |
+
|
39 |
+
Core library:
|
40 |
+
|
41 |
+
- Schedulers: @yiyixuxu
|
42 |
+
- Pipelines and pipeline callbacks: @yiyixuxu and @asomoza
|
43 |
+
- Training examples: @sayakpaul
|
44 |
+
- Docs: @stevhliu and @sayakpaul
|
45 |
+
- JAX and MPS: @pcuenca
|
46 |
+
- Audio: @sanchit-gandhi
|
47 |
+
- General functionalities: @sayakpaul @yiyixuxu @DN6
|
48 |
+
|
49 |
+
Integrations:
|
50 |
+
|
51 |
+
- deepspeed: HF Trainer/Accelerate: @SunMarc
|
52 |
+
- PEFT: @sayakpaul @BenjaminBossan
|
53 |
+
|
54 |
+
HF projects:
|
55 |
+
|
56 |
+
- accelerate: [different repo](https://github.com/huggingface/accelerate)
|
57 |
+
- datasets: [different repo](https://github.com/huggingface/datasets)
|
58 |
+
- transformers: [different repo](https://github.com/huggingface/transformers)
|
59 |
+
- safetensors: [different repo](https://github.com/huggingface/safetensors)
|
60 |
+
|
61 |
+
-->
|
diffusers/.github/actions/setup-miniconda/action.yml
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Set up conda environment for testing
|
2 |
+
|
3 |
+
description: Sets up miniconda in your ${RUNNER_TEMP} environment and gives you the ${CONDA_RUN} environment variable so you don't have to worry about polluting non-empeheral runners anymore
|
4 |
+
|
5 |
+
inputs:
|
6 |
+
python-version:
|
7 |
+
description: If set to any value, don't use sudo to clean the workspace
|
8 |
+
required: false
|
9 |
+
type: string
|
10 |
+
default: "3.9"
|
11 |
+
miniconda-version:
|
12 |
+
description: Miniconda version to install
|
13 |
+
required: false
|
14 |
+
type: string
|
15 |
+
default: "4.12.0"
|
16 |
+
environment-file:
|
17 |
+
description: Environment file to install dependencies from
|
18 |
+
required: false
|
19 |
+
type: string
|
20 |
+
default: ""
|
21 |
+
|
22 |
+
runs:
|
23 |
+
using: composite
|
24 |
+
steps:
|
25 |
+
# Use the same trick from https://github.com/marketplace/actions/setup-miniconda
|
26 |
+
# to refresh the cache daily. This is kind of optional though
|
27 |
+
- name: Get date
|
28 |
+
id: get-date
|
29 |
+
shell: bash
|
30 |
+
run: echo "today=$(/bin/date -u '+%Y%m%d')d" >> $GITHUB_OUTPUT
|
31 |
+
- name: Setup miniconda cache
|
32 |
+
id: miniconda-cache
|
33 |
+
uses: actions/cache@v2
|
34 |
+
with:
|
35 |
+
path: ${{ runner.temp }}/miniconda
|
36 |
+
key: miniconda-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
|
37 |
+
- name: Install miniconda (${{ inputs.miniconda-version }})
|
38 |
+
if: steps.miniconda-cache.outputs.cache-hit != 'true'
|
39 |
+
env:
|
40 |
+
MINICONDA_VERSION: ${{ inputs.miniconda-version }}
|
41 |
+
shell: bash -l {0}
|
42 |
+
run: |
|
43 |
+
MINICONDA_INSTALL_PATH="${RUNNER_TEMP}/miniconda"
|
44 |
+
mkdir -p "${MINICONDA_INSTALL_PATH}"
|
45 |
+
case ${RUNNER_OS}-${RUNNER_ARCH} in
|
46 |
+
Linux-X64)
|
47 |
+
MINICONDA_ARCH="Linux-x86_64"
|
48 |
+
;;
|
49 |
+
macOS-ARM64)
|
50 |
+
MINICONDA_ARCH="MacOSX-arm64"
|
51 |
+
;;
|
52 |
+
macOS-X64)
|
53 |
+
MINICONDA_ARCH="MacOSX-x86_64"
|
54 |
+
;;
|
55 |
+
*)
|
56 |
+
echo "::error::Platform ${RUNNER_OS}-${RUNNER_ARCH} currently unsupported using this action"
|
57 |
+
exit 1
|
58 |
+
;;
|
59 |
+
esac
|
60 |
+
MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-py39_${MINICONDA_VERSION}-${MINICONDA_ARCH}.sh"
|
61 |
+
curl -fsSL "${MINICONDA_URL}" -o "${MINICONDA_INSTALL_PATH}/miniconda.sh"
|
62 |
+
bash "${MINICONDA_INSTALL_PATH}/miniconda.sh" -b -u -p "${MINICONDA_INSTALL_PATH}"
|
63 |
+
rm -rf "${MINICONDA_INSTALL_PATH}/miniconda.sh"
|
64 |
+
- name: Update GitHub path to include miniconda install
|
65 |
+
shell: bash
|
66 |
+
run: |
|
67 |
+
MINICONDA_INSTALL_PATH="${RUNNER_TEMP}/miniconda"
|
68 |
+
echo "${MINICONDA_INSTALL_PATH}/bin" >> $GITHUB_PATH
|
69 |
+
- name: Setup miniconda env cache (with env file)
|
70 |
+
id: miniconda-env-cache-env-file
|
71 |
+
if: ${{ runner.os }} == 'macOS' && ${{ inputs.environment-file }} != ''
|
72 |
+
uses: actions/cache@v2
|
73 |
+
with:
|
74 |
+
path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
|
75 |
+
key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles(inputs.environment-file) }}
|
76 |
+
- name: Setup miniconda env cache (without env file)
|
77 |
+
id: miniconda-env-cache
|
78 |
+
if: ${{ runner.os }} == 'macOS' && ${{ inputs.environment-file }} == ''
|
79 |
+
uses: actions/cache@v2
|
80 |
+
with:
|
81 |
+
path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
|
82 |
+
key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
|
83 |
+
- name: Setup conda environment with python (v${{ inputs.python-version }})
|
84 |
+
if: steps.miniconda-env-cache-env-file.outputs.cache-hit != 'true' && steps.miniconda-env-cache.outputs.cache-hit != 'true'
|
85 |
+
shell: bash
|
86 |
+
env:
|
87 |
+
PYTHON_VERSION: ${{ inputs.python-version }}
|
88 |
+
ENV_FILE: ${{ inputs.environment-file }}
|
89 |
+
run: |
|
90 |
+
CONDA_BASE_ENV="${RUNNER_TEMP}/conda-python-${PYTHON_VERSION}"
|
91 |
+
ENV_FILE_FLAG=""
|
92 |
+
if [[ -f "${ENV_FILE}" ]]; then
|
93 |
+
ENV_FILE_FLAG="--file ${ENV_FILE}"
|
94 |
+
elif [[ -n "${ENV_FILE}" ]]; then
|
95 |
+
echo "::warning::Specified env file (${ENV_FILE}) not found, not going to include it"
|
96 |
+
fi
|
97 |
+
conda create \
|
98 |
+
--yes \
|
99 |
+
--prefix "${CONDA_BASE_ENV}" \
|
100 |
+
"python=${PYTHON_VERSION}" \
|
101 |
+
${ENV_FILE_FLAG} \
|
102 |
+
cmake=3.22 \
|
103 |
+
conda-build=3.21 \
|
104 |
+
ninja=1.10 \
|
105 |
+
pkg-config=0.29 \
|
106 |
+
wheel=0.37
|
107 |
+
- name: Clone the base conda environment and update GitHub env
|
108 |
+
shell: bash
|
109 |
+
env:
|
110 |
+
PYTHON_VERSION: ${{ inputs.python-version }}
|
111 |
+
CONDA_BASE_ENV: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
|
112 |
+
run: |
|
113 |
+
CONDA_ENV="${RUNNER_TEMP}/conda_environment_${GITHUB_RUN_ID}"
|
114 |
+
conda create \
|
115 |
+
--yes \
|
116 |
+
--prefix "${CONDA_ENV}" \
|
117 |
+
--clone "${CONDA_BASE_ENV}"
|
118 |
+
# TODO: conda-build could not be cloned because it hardcodes the path, so it
|
119 |
+
# could not be cached
|
120 |
+
conda install --yes -p ${CONDA_ENV} conda-build=3.21
|
121 |
+
echo "CONDA_ENV=${CONDA_ENV}" >> "${GITHUB_ENV}"
|
122 |
+
echo "CONDA_RUN=conda run -p ${CONDA_ENV} --no-capture-output" >> "${GITHUB_ENV}"
|
123 |
+
echo "CONDA_BUILD=conda run -p ${CONDA_ENV} conda-build" >> "${GITHUB_ENV}"
|
124 |
+
echo "CONDA_INSTALL=conda install -p ${CONDA_ENV}" >> "${GITHUB_ENV}"
|
125 |
+
- name: Get disk space usage and throw an error for low disk space
|
126 |
+
shell: bash
|
127 |
+
run: |
|
128 |
+
echo "Print the available disk space for manual inspection"
|
129 |
+
df -h
|
130 |
+
# Set the minimum requirement space to 4GB
|
131 |
+
MINIMUM_AVAILABLE_SPACE_IN_GB=4
|
132 |
+
MINIMUM_AVAILABLE_SPACE_IN_KB=$(($MINIMUM_AVAILABLE_SPACE_IN_GB * 1024 * 1024))
|
133 |
+
# Use KB to avoid floating point warning like 3.1GB
|
134 |
+
df -k | tr -s ' ' | cut -d' ' -f 4,9 | while read -r LINE;
|
135 |
+
do
|
136 |
+
AVAIL=$(echo $LINE | cut -f1 -d' ')
|
137 |
+
MOUNT=$(echo $LINE | cut -f2 -d' ')
|
138 |
+
if [ "$MOUNT" = "/" ]; then
|
139 |
+
if [ "$AVAIL" -lt "$MINIMUM_AVAILABLE_SPACE_IN_KB" ]; then
|
140 |
+
echo "There is only ${AVAIL}KB free space left in $MOUNT, which is less than the minimum requirement of ${MINIMUM_AVAILABLE_SPACE_IN_KB}KB. Please help create an issue to PyTorch Release Engineering via https://github.com/pytorch/test-infra/issues and provide the link to the workflow run."
|
141 |
+
exit 1;
|
142 |
+
else
|
143 |
+
echo "There is ${AVAIL}KB free space left in $MOUNT, continue"
|
144 |
+
fi
|
145 |
+
fi
|
146 |
+
done
|
diffusers/.github/workflows/benchmark.yml
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Benchmarking tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
schedule:
|
6 |
+
- cron: "30 1 1,15 * *" # every 2 weeks on the 1st and the 15th of every month at 1:30 AM
|
7 |
+
|
8 |
+
env:
|
9 |
+
DIFFUSERS_IS_CI: yes
|
10 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
11 |
+
HF_HOME: /mnt/cache
|
12 |
+
OMP_NUM_THREADS: 8
|
13 |
+
MKL_NUM_THREADS: 8
|
14 |
+
|
15 |
+
jobs:
|
16 |
+
torch_pipelines_cuda_benchmark_tests:
|
17 |
+
env:
|
18 |
+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_BENCHMARK }}
|
19 |
+
name: Torch Core Pipelines CUDA Benchmarking Tests
|
20 |
+
strategy:
|
21 |
+
fail-fast: false
|
22 |
+
max-parallel: 1
|
23 |
+
runs-on:
|
24 |
+
group: aws-g6-4xlarge-plus
|
25 |
+
container:
|
26 |
+
image: diffusers/diffusers-pytorch-compile-cuda
|
27 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
28 |
+
steps:
|
29 |
+
- name: Checkout diffusers
|
30 |
+
uses: actions/checkout@v3
|
31 |
+
with:
|
32 |
+
fetch-depth: 2
|
33 |
+
- name: NVIDIA-SMI
|
34 |
+
run: |
|
35 |
+
nvidia-smi
|
36 |
+
- name: Install dependencies
|
37 |
+
run: |
|
38 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
39 |
+
python -m uv pip install -e [quality,test]
|
40 |
+
python -m uv pip install pandas peft
|
41 |
+
- name: Environment
|
42 |
+
run: |
|
43 |
+
python utils/print_env.py
|
44 |
+
- name: Diffusers Benchmarking
|
45 |
+
env:
|
46 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_BOT_TOKEN }}
|
47 |
+
BASE_PATH: benchmark_outputs
|
48 |
+
run: |
|
49 |
+
export TOTAL_GPU_MEMORY=$(python -c "import torch; print(torch.cuda.get_device_properties(0).total_memory / (1024**3))")
|
50 |
+
cd benchmarks && mkdir ${BASE_PATH} && python run_all.py && python push_results.py
|
51 |
+
|
52 |
+
- name: Test suite reports artifacts
|
53 |
+
if: ${{ always() }}
|
54 |
+
uses: actions/upload-artifact@v4
|
55 |
+
with:
|
56 |
+
name: benchmark_test_reports
|
57 |
+
path: benchmarks/benchmark_outputs
|
58 |
+
|
59 |
+
- name: Report success status
|
60 |
+
if: ${{ success() }}
|
61 |
+
run: |
|
62 |
+
pip install requests && python utils/notify_benchmarking_status.py --status=success
|
63 |
+
|
64 |
+
- name: Report failure status
|
65 |
+
if: ${{ failure() }}
|
66 |
+
run: |
|
67 |
+
pip install requests && python utils/notify_benchmarking_status.py --status=failure
|
diffusers/.github/workflows/build_docker_images.yml
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Test, build, and push Docker images
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request: # During PRs, we just check if the changes Dockerfiles can be successfully built
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "docker/**"
|
9 |
+
workflow_dispatch:
|
10 |
+
schedule:
|
11 |
+
- cron: "0 0 * * *" # every day at midnight
|
12 |
+
|
13 |
+
concurrency:
|
14 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
15 |
+
cancel-in-progress: true
|
16 |
+
|
17 |
+
env:
|
18 |
+
REGISTRY: diffusers
|
19 |
+
CI_SLACK_CHANNEL: ${{ secrets.CI_DOCKER_CHANNEL }}
|
20 |
+
|
21 |
+
jobs:
|
22 |
+
test-build-docker-images:
|
23 |
+
runs-on:
|
24 |
+
group: aws-general-8-plus
|
25 |
+
if: github.event_name == 'pull_request'
|
26 |
+
steps:
|
27 |
+
- name: Set up Docker Buildx
|
28 |
+
uses: docker/setup-buildx-action@v1
|
29 |
+
|
30 |
+
- name: Check out code
|
31 |
+
uses: actions/checkout@v3
|
32 |
+
|
33 |
+
- name: Find Changed Dockerfiles
|
34 |
+
id: file_changes
|
35 |
+
uses: jitterbit/get-changed-files@v1
|
36 |
+
with:
|
37 |
+
format: 'space-delimited'
|
38 |
+
token: ${{ secrets.GITHUB_TOKEN }}
|
39 |
+
|
40 |
+
- name: Build Changed Docker Images
|
41 |
+
run: |
|
42 |
+
CHANGED_FILES="${{ steps.file_changes.outputs.all }}"
|
43 |
+
for FILE in $CHANGED_FILES; do
|
44 |
+
if [[ "$FILE" == docker/*Dockerfile ]]; then
|
45 |
+
DOCKER_PATH="${FILE%/Dockerfile}"
|
46 |
+
DOCKER_TAG=$(basename "$DOCKER_PATH")
|
47 |
+
echo "Building Docker image for $DOCKER_TAG"
|
48 |
+
docker build -t "$DOCKER_TAG" "$DOCKER_PATH"
|
49 |
+
fi
|
50 |
+
done
|
51 |
+
if: steps.file_changes.outputs.all != ''
|
52 |
+
|
53 |
+
build-and-push-docker-images:
|
54 |
+
runs-on:
|
55 |
+
group: aws-general-8-plus
|
56 |
+
if: github.event_name != 'pull_request'
|
57 |
+
|
58 |
+
permissions:
|
59 |
+
contents: read
|
60 |
+
packages: write
|
61 |
+
|
62 |
+
strategy:
|
63 |
+
fail-fast: false
|
64 |
+
matrix:
|
65 |
+
image-name:
|
66 |
+
- diffusers-pytorch-cpu
|
67 |
+
- diffusers-pytorch-cuda
|
68 |
+
- diffusers-pytorch-compile-cuda
|
69 |
+
- diffusers-pytorch-xformers-cuda
|
70 |
+
- diffusers-flax-cpu
|
71 |
+
- diffusers-flax-tpu
|
72 |
+
- diffusers-onnxruntime-cpu
|
73 |
+
- diffusers-onnxruntime-cuda
|
74 |
+
- diffusers-doc-builder
|
75 |
+
|
76 |
+
steps:
|
77 |
+
- name: Checkout repository
|
78 |
+
uses: actions/checkout@v3
|
79 |
+
- name: Set up Docker Buildx
|
80 |
+
uses: docker/setup-buildx-action@v1
|
81 |
+
- name: Login to Docker Hub
|
82 |
+
uses: docker/login-action@v2
|
83 |
+
with:
|
84 |
+
username: ${{ env.REGISTRY }}
|
85 |
+
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
86 |
+
- name: Build and push
|
87 |
+
uses: docker/build-push-action@v3
|
88 |
+
with:
|
89 |
+
no-cache: true
|
90 |
+
context: ./docker/${{ matrix.image-name }}
|
91 |
+
push: true
|
92 |
+
tags: ${{ env.REGISTRY }}/${{ matrix.image-name }}:latest
|
93 |
+
|
94 |
+
- name: Post to a Slack channel
|
95 |
+
id: slack
|
96 |
+
uses: huggingface/hf-workflows/.github/actions/post-slack@main
|
97 |
+
with:
|
98 |
+
# Slack channel id, channel name, or user id to post message.
|
99 |
+
# See also: https://api.slack.com/methods/chat.postMessage#channels
|
100 |
+
slack_channel: ${{ env.CI_SLACK_CHANNEL }}
|
101 |
+
title: "🤗 Results of the ${{ matrix.image-name }} Docker Image build"
|
102 |
+
status: ${{ job.status }}
|
103 |
+
slack_token: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
|
diffusers/.github/workflows/build_documentation.yml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Build documentation
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
- doc-builder*
|
8 |
+
- v*-release
|
9 |
+
- v*-patch
|
10 |
+
paths:
|
11 |
+
- "src/diffusers/**.py"
|
12 |
+
- "examples/**"
|
13 |
+
- "docs/**"
|
14 |
+
|
15 |
+
jobs:
|
16 |
+
build:
|
17 |
+
uses: huggingface/doc-builder/.github/workflows/build_main_documentation.yml@main
|
18 |
+
with:
|
19 |
+
commit_sha: ${{ github.sha }}
|
20 |
+
install_libgl1: true
|
21 |
+
package: diffusers
|
22 |
+
notebook_folder: diffusers_doc
|
23 |
+
languages: en ko zh ja pt
|
24 |
+
custom_container: diffusers/diffusers-doc-builder
|
25 |
+
secrets:
|
26 |
+
token: ${{ secrets.HUGGINGFACE_PUSH }}
|
27 |
+
hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }}
|
diffusers/.github/workflows/build_pr_documentation.yml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Build PR Documentation
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
paths:
|
6 |
+
- "src/diffusers/**.py"
|
7 |
+
- "examples/**"
|
8 |
+
- "docs/**"
|
9 |
+
|
10 |
+
concurrency:
|
11 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
12 |
+
cancel-in-progress: true
|
13 |
+
|
14 |
+
jobs:
|
15 |
+
build:
|
16 |
+
uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main
|
17 |
+
with:
|
18 |
+
commit_sha: ${{ github.event.pull_request.head.sha }}
|
19 |
+
pr_number: ${{ github.event.number }}
|
20 |
+
install_libgl1: true
|
21 |
+
package: diffusers
|
22 |
+
languages: en ko zh ja pt
|
23 |
+
custom_container: diffusers/diffusers-doc-builder
|
diffusers/.github/workflows/mirror_community_pipeline.yml
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Mirror Community Pipeline
|
2 |
+
|
3 |
+
on:
|
4 |
+
# Push changes on the main branch
|
5 |
+
push:
|
6 |
+
branches:
|
7 |
+
- main
|
8 |
+
paths:
|
9 |
+
- 'examples/community/**.py'
|
10 |
+
|
11 |
+
# And on tag creation (e.g. `v0.28.1`)
|
12 |
+
tags:
|
13 |
+
- '*'
|
14 |
+
|
15 |
+
# Manual trigger with ref input
|
16 |
+
workflow_dispatch:
|
17 |
+
inputs:
|
18 |
+
ref:
|
19 |
+
description: "Either 'main' or a tag ref"
|
20 |
+
required: true
|
21 |
+
default: 'main'
|
22 |
+
|
23 |
+
jobs:
|
24 |
+
mirror_community_pipeline:
|
25 |
+
env:
|
26 |
+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_COMMUNITY_MIRROR }}
|
27 |
+
|
28 |
+
runs-on: ubuntu-22.04
|
29 |
+
steps:
|
30 |
+
# Checkout to correct ref
|
31 |
+
# If workflow dispatch
|
32 |
+
# If ref is 'main', set:
|
33 |
+
# CHECKOUT_REF=refs/heads/main
|
34 |
+
# PATH_IN_REPO=main
|
35 |
+
# Else it must be a tag. Set:
|
36 |
+
# CHECKOUT_REF=refs/tags/{tag}
|
37 |
+
# PATH_IN_REPO={tag}
|
38 |
+
# If not workflow dispatch
|
39 |
+
# If ref is 'refs/heads/main' => set 'main'
|
40 |
+
# Else it must be a tag => set {tag}
|
41 |
+
- name: Set checkout_ref and path_in_repo
|
42 |
+
run: |
|
43 |
+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
44 |
+
if [ -z "${{ github.event.inputs.ref }}" ]; then
|
45 |
+
echo "Error: Missing ref input"
|
46 |
+
exit 1
|
47 |
+
elif [ "${{ github.event.inputs.ref }}" == "main" ]; then
|
48 |
+
echo "CHECKOUT_REF=refs/heads/main" >> $GITHUB_ENV
|
49 |
+
echo "PATH_IN_REPO=main" >> $GITHUB_ENV
|
50 |
+
else
|
51 |
+
echo "CHECKOUT_REF=refs/tags/${{ github.event.inputs.ref }}" >> $GITHUB_ENV
|
52 |
+
echo "PATH_IN_REPO=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
|
53 |
+
fi
|
54 |
+
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
55 |
+
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV
|
56 |
+
echo "PATH_IN_REPO=main" >> $GITHUB_ENV
|
57 |
+
else
|
58 |
+
# e.g. refs/tags/v0.28.1 -> v0.28.1
|
59 |
+
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV
|
60 |
+
echo "PATH_IN_REPO=$(echo ${{ github.ref }} | sed 's/^refs\/tags\///')" >> $GITHUB_ENV
|
61 |
+
fi
|
62 |
+
- name: Print env vars
|
63 |
+
run: |
|
64 |
+
echo "CHECKOUT_REF: ${{ env.CHECKOUT_REF }}"
|
65 |
+
echo "PATH_IN_REPO: ${{ env.PATH_IN_REPO }}"
|
66 |
+
- uses: actions/checkout@v3
|
67 |
+
with:
|
68 |
+
ref: ${{ env.CHECKOUT_REF }}
|
69 |
+
|
70 |
+
# Setup + install dependencies
|
71 |
+
- name: Set up Python
|
72 |
+
uses: actions/setup-python@v4
|
73 |
+
with:
|
74 |
+
python-version: "3.10"
|
75 |
+
- name: Install dependencies
|
76 |
+
run: |
|
77 |
+
python -m pip install --upgrade pip
|
78 |
+
pip install --upgrade huggingface_hub
|
79 |
+
|
80 |
+
# Check secret is set
|
81 |
+
- name: whoami
|
82 |
+
run: huggingface-cli whoami
|
83 |
+
env:
|
84 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN_MIRROR_COMMUNITY_PIPELINES }}
|
85 |
+
|
86 |
+
# Push to HF! (under subfolder based on checkout ref)
|
87 |
+
# https://huggingface.co/datasets/diffusers/community-pipelines-mirror
|
88 |
+
- name: Mirror community pipeline to HF
|
89 |
+
run: huggingface-cli upload diffusers/community-pipelines-mirror ./examples/community ${PATH_IN_REPO} --repo-type dataset
|
90 |
+
env:
|
91 |
+
PATH_IN_REPO: ${{ env.PATH_IN_REPO }}
|
92 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN_MIRROR_COMMUNITY_PIPELINES }}
|
93 |
+
|
94 |
+
- name: Report success status
|
95 |
+
if: ${{ success() }}
|
96 |
+
run: |
|
97 |
+
pip install requests && python utils/notify_community_pipelines_mirror.py --status=success
|
98 |
+
|
99 |
+
- name: Report failure status
|
100 |
+
if: ${{ failure() }}
|
101 |
+
run: |
|
102 |
+
pip install requests && python utils/notify_community_pipelines_mirror.py --status=failure
|
diffusers/.github/workflows/nightly_tests.yml
ADDED
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Nightly and release tests on main/release branch
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
schedule:
|
6 |
+
- cron: "0 0 * * *" # every day at midnight
|
7 |
+
|
8 |
+
env:
|
9 |
+
DIFFUSERS_IS_CI: yes
|
10 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
11 |
+
OMP_NUM_THREADS: 8
|
12 |
+
MKL_NUM_THREADS: 8
|
13 |
+
PYTEST_TIMEOUT: 600
|
14 |
+
RUN_SLOW: yes
|
15 |
+
RUN_NIGHTLY: yes
|
16 |
+
PIPELINE_USAGE_CUTOFF: 5000
|
17 |
+
SLACK_API_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
|
18 |
+
|
19 |
+
jobs:
|
20 |
+
setup_torch_cuda_pipeline_matrix:
|
21 |
+
name: Setup Torch Pipelines CUDA Slow Tests Matrix
|
22 |
+
runs-on:
|
23 |
+
group: aws-general-8-plus
|
24 |
+
container:
|
25 |
+
image: diffusers/diffusers-pytorch-cpu
|
26 |
+
outputs:
|
27 |
+
pipeline_test_matrix: ${{ steps.fetch_pipeline_matrix.outputs.pipeline_test_matrix }}
|
28 |
+
steps:
|
29 |
+
- name: Checkout diffusers
|
30 |
+
uses: actions/checkout@v3
|
31 |
+
with:
|
32 |
+
fetch-depth: 2
|
33 |
+
- name: Install dependencies
|
34 |
+
run: |
|
35 |
+
pip install -e .[test]
|
36 |
+
pip install huggingface_hub
|
37 |
+
- name: Fetch Pipeline Matrix
|
38 |
+
id: fetch_pipeline_matrix
|
39 |
+
run: |
|
40 |
+
matrix=$(python utils/fetch_torch_cuda_pipeline_test_matrix.py)
|
41 |
+
echo $matrix
|
42 |
+
echo "pipeline_test_matrix=$matrix" >> $GITHUB_OUTPUT
|
43 |
+
|
44 |
+
- name: Pipeline Tests Artifacts
|
45 |
+
if: ${{ always() }}
|
46 |
+
uses: actions/upload-artifact@v4
|
47 |
+
with:
|
48 |
+
name: test-pipelines.json
|
49 |
+
path: reports
|
50 |
+
|
51 |
+
run_nightly_tests_for_torch_pipelines:
|
52 |
+
name: Nightly Torch Pipelines CUDA Tests
|
53 |
+
needs: setup_torch_cuda_pipeline_matrix
|
54 |
+
strategy:
|
55 |
+
fail-fast: false
|
56 |
+
max-parallel: 8
|
57 |
+
matrix:
|
58 |
+
module: ${{ fromJson(needs.setup_torch_cuda_pipeline_matrix.outputs.pipeline_test_matrix) }}
|
59 |
+
runs-on:
|
60 |
+
group: aws-g4dn-2xlarge
|
61 |
+
container:
|
62 |
+
image: diffusers/diffusers-pytorch-cuda
|
63 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
64 |
+
steps:
|
65 |
+
- name: Checkout diffusers
|
66 |
+
uses: actions/checkout@v3
|
67 |
+
with:
|
68 |
+
fetch-depth: 2
|
69 |
+
- name: NVIDIA-SMI
|
70 |
+
run: nvidia-smi
|
71 |
+
- name: Install dependencies
|
72 |
+
run: |
|
73 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
74 |
+
python -m uv pip install -e [quality,test]
|
75 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
76 |
+
python -m uv pip install pytest-reportlog
|
77 |
+
- name: Environment
|
78 |
+
run: |
|
79 |
+
python utils/print_env.py
|
80 |
+
- name: Pipeline CUDA Test
|
81 |
+
env:
|
82 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
|
83 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
84 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
85 |
+
run: |
|
86 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
87 |
+
-s -v -k "not Flax and not Onnx" \
|
88 |
+
--make-reports=tests_pipeline_${{ matrix.module }}_cuda \
|
89 |
+
--report-log=tests_pipeline_${{ matrix.module }}_cuda.log \
|
90 |
+
tests/pipelines/${{ matrix.module }}
|
91 |
+
- name: Failure short reports
|
92 |
+
if: ${{ failure() }}
|
93 |
+
run: |
|
94 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_stats.txt
|
95 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_failures_short.txt
|
96 |
+
- name: Test suite reports artifacts
|
97 |
+
if: ${{ always() }}
|
98 |
+
uses: actions/upload-artifact@v4
|
99 |
+
with:
|
100 |
+
name: pipeline_${{ matrix.module }}_test_reports
|
101 |
+
path: reports
|
102 |
+
- name: Generate Report and Notify Channel
|
103 |
+
if: always()
|
104 |
+
run: |
|
105 |
+
pip install slack_sdk tabulate
|
106 |
+
python utils/log_reports.py >> $GITHUB_STEP_SUMMARY
|
107 |
+
|
108 |
+
run_nightly_tests_for_other_torch_modules:
|
109 |
+
name: Nightly Torch CUDA Tests
|
110 |
+
runs-on:
|
111 |
+
group: aws-g4dn-2xlarge
|
112 |
+
container:
|
113 |
+
image: diffusers/diffusers-pytorch-cuda
|
114 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
115 |
+
defaults:
|
116 |
+
run:
|
117 |
+
shell: bash
|
118 |
+
strategy:
|
119 |
+
fail-fast: false
|
120 |
+
max-parallel: 2
|
121 |
+
matrix:
|
122 |
+
module: [models, schedulers, lora, others, single_file, examples]
|
123 |
+
steps:
|
124 |
+
- name: Checkout diffusers
|
125 |
+
uses: actions/checkout@v3
|
126 |
+
with:
|
127 |
+
fetch-depth: 2
|
128 |
+
|
129 |
+
- name: Install dependencies
|
130 |
+
run: |
|
131 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
132 |
+
python -m uv pip install -e [quality,test]
|
133 |
+
python -m uv pip install peft@git+https://github.com/huggingface/peft.git
|
134 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
135 |
+
python -m uv pip install pytest-reportlog
|
136 |
+
- name: Environment
|
137 |
+
run: python utils/print_env.py
|
138 |
+
|
139 |
+
- name: Run nightly PyTorch CUDA tests for non-pipeline modules
|
140 |
+
if: ${{ matrix.module != 'examples'}}
|
141 |
+
env:
|
142 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
|
143 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
144 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
145 |
+
run: |
|
146 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
147 |
+
-s -v -k "not Flax and not Onnx" \
|
148 |
+
--make-reports=tests_torch_${{ matrix.module }}_cuda \
|
149 |
+
--report-log=tests_torch_${{ matrix.module }}_cuda.log \
|
150 |
+
tests/${{ matrix.module }}
|
151 |
+
|
152 |
+
- name: Run nightly example tests with Torch
|
153 |
+
if: ${{ matrix.module == 'examples' }}
|
154 |
+
env:
|
155 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
|
156 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
157 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
158 |
+
run: |
|
159 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
160 |
+
-s -v --make-reports=examples_torch_cuda \
|
161 |
+
--report-log=examples_torch_cuda.log \
|
162 |
+
examples/
|
163 |
+
|
164 |
+
- name: Failure short reports
|
165 |
+
if: ${{ failure() }}
|
166 |
+
run: |
|
167 |
+
cat reports/tests_torch_${{ matrix.module }}_cuda_stats.txt
|
168 |
+
cat reports/tests_torch_${{ matrix.module }}_cuda_failures_short.txt
|
169 |
+
|
170 |
+
- name: Test suite reports artifacts
|
171 |
+
if: ${{ always() }}
|
172 |
+
uses: actions/upload-artifact@v4
|
173 |
+
with:
|
174 |
+
name: torch_${{ matrix.module }}_cuda_test_reports
|
175 |
+
path: reports
|
176 |
+
|
177 |
+
- name: Generate Report and Notify Channel
|
178 |
+
if: always()
|
179 |
+
run: |
|
180 |
+
pip install slack_sdk tabulate
|
181 |
+
python utils/log_reports.py >> $GITHUB_STEP_SUMMARY
|
182 |
+
|
183 |
+
run_flax_tpu_tests:
|
184 |
+
name: Nightly Flax TPU Tests
|
185 |
+
runs-on: docker-tpu
|
186 |
+
if: github.event_name == 'schedule'
|
187 |
+
|
188 |
+
container:
|
189 |
+
image: diffusers/diffusers-flax-tpu
|
190 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/ --privileged
|
191 |
+
defaults:
|
192 |
+
run:
|
193 |
+
shell: bash
|
194 |
+
steps:
|
195 |
+
- name: Checkout diffusers
|
196 |
+
uses: actions/checkout@v3
|
197 |
+
with:
|
198 |
+
fetch-depth: 2
|
199 |
+
|
200 |
+
- name: Install dependencies
|
201 |
+
run: |
|
202 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
203 |
+
python -m uv pip install -e [quality,test]
|
204 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
205 |
+
python -m uv pip install pytest-reportlog
|
206 |
+
|
207 |
+
- name: Environment
|
208 |
+
run: python utils/print_env.py
|
209 |
+
|
210 |
+
- name: Run nightly Flax TPU tests
|
211 |
+
env:
|
212 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
|
213 |
+
run: |
|
214 |
+
python -m pytest -n 0 \
|
215 |
+
-s -v -k "Flax" \
|
216 |
+
--make-reports=tests_flax_tpu \
|
217 |
+
--report-log=tests_flax_tpu.log \
|
218 |
+
tests/
|
219 |
+
|
220 |
+
- name: Failure short reports
|
221 |
+
if: ${{ failure() }}
|
222 |
+
run: |
|
223 |
+
cat reports/tests_flax_tpu_stats.txt
|
224 |
+
cat reports/tests_flax_tpu_failures_short.txt
|
225 |
+
|
226 |
+
- name: Test suite reports artifacts
|
227 |
+
if: ${{ always() }}
|
228 |
+
uses: actions/upload-artifact@v4
|
229 |
+
with:
|
230 |
+
name: flax_tpu_test_reports
|
231 |
+
path: reports
|
232 |
+
|
233 |
+
- name: Generate Report and Notify Channel
|
234 |
+
if: always()
|
235 |
+
run: |
|
236 |
+
pip install slack_sdk tabulate
|
237 |
+
python utils/log_reports.py >> $GITHUB_STEP_SUMMARY
|
238 |
+
|
239 |
+
run_nightly_onnx_tests:
|
240 |
+
name: Nightly ONNXRuntime CUDA tests on Ubuntu
|
241 |
+
runs-on:
|
242 |
+
group: aws-g4dn-2xlarge
|
243 |
+
container:
|
244 |
+
image: diffusers/diffusers-onnxruntime-cuda
|
245 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
246 |
+
|
247 |
+
steps:
|
248 |
+
- name: Checkout diffusers
|
249 |
+
uses: actions/checkout@v3
|
250 |
+
with:
|
251 |
+
fetch-depth: 2
|
252 |
+
|
253 |
+
- name: NVIDIA-SMI
|
254 |
+
run: nvidia-smi
|
255 |
+
|
256 |
+
- name: Install dependencies
|
257 |
+
run: |
|
258 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
259 |
+
python -m uv pip install -e [quality,test]
|
260 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
261 |
+
python -m uv pip install pytest-reportlog
|
262 |
+
- name: Environment
|
263 |
+
run: python utils/print_env.py
|
264 |
+
|
265 |
+
- name: Run Nightly ONNXRuntime CUDA tests
|
266 |
+
env:
|
267 |
+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
|
268 |
+
run: |
|
269 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
270 |
+
-s -v -k "Onnx" \
|
271 |
+
--make-reports=tests_onnx_cuda \
|
272 |
+
--report-log=tests_onnx_cuda.log \
|
273 |
+
tests/
|
274 |
+
|
275 |
+
- name: Failure short reports
|
276 |
+
if: ${{ failure() }}
|
277 |
+
run: |
|
278 |
+
cat reports/tests_onnx_cuda_stats.txt
|
279 |
+
cat reports/tests_onnx_cuda_failures_short.txt
|
280 |
+
|
281 |
+
- name: Test suite reports artifacts
|
282 |
+
if: ${{ always() }}
|
283 |
+
uses: actions/upload-artifact@v4
|
284 |
+
with:
|
285 |
+
name: tests_onnx_cuda_reports
|
286 |
+
path: reports
|
287 |
+
|
288 |
+
- name: Generate Report and Notify Channel
|
289 |
+
if: always()
|
290 |
+
run: |
|
291 |
+
pip install slack_sdk tabulate
|
292 |
+
python utils/log_reports.py >> $GITHUB_STEP_SUMMARY
|
293 |
+
|
294 |
+
# M1 runner currently not well supported
|
295 |
+
# TODO: (Dhruv) add these back when we setup better testing for Apple Silicon
|
296 |
+
# run_nightly_tests_apple_m1:
|
297 |
+
# name: Nightly PyTorch MPS tests on MacOS
|
298 |
+
# runs-on: [ self-hosted, apple-m1 ]
|
299 |
+
# if: github.event_name == 'schedule'
|
300 |
+
#
|
301 |
+
# steps:
|
302 |
+
# - name: Checkout diffusers
|
303 |
+
# uses: actions/checkout@v3
|
304 |
+
# with:
|
305 |
+
# fetch-depth: 2
|
306 |
+
#
|
307 |
+
# - name: Clean checkout
|
308 |
+
# shell: arch -arch arm64 bash {0}
|
309 |
+
# run: |
|
310 |
+
# git clean -fxd
|
311 |
+
# - name: Setup miniconda
|
312 |
+
# uses: ./.github/actions/setup-miniconda
|
313 |
+
# with:
|
314 |
+
# python-version: 3.9
|
315 |
+
#
|
316 |
+
# - name: Install dependencies
|
317 |
+
# shell: arch -arch arm64 bash {0}
|
318 |
+
# run: |
|
319 |
+
# ${CONDA_RUN} python -m pip install --upgrade pip uv
|
320 |
+
# ${CONDA_RUN} python -m uv pip install -e [quality,test]
|
321 |
+
# ${CONDA_RUN} python -m uv pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
|
322 |
+
# ${CONDA_RUN} python -m uv pip install accelerate@git+https://github.com/huggingface/accelerate
|
323 |
+
# ${CONDA_RUN} python -m uv pip install pytest-reportlog
|
324 |
+
# - name: Environment
|
325 |
+
# shell: arch -arch arm64 bash {0}
|
326 |
+
# run: |
|
327 |
+
# ${CONDA_RUN} python utils/print_env.py
|
328 |
+
# - name: Run nightly PyTorch tests on M1 (MPS)
|
329 |
+
# shell: arch -arch arm64 bash {0}
|
330 |
+
# env:
|
331 |
+
# HF_HOME: /System/Volumes/Data/mnt/cache
|
332 |
+
# HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
333 |
+
# run: |
|
334 |
+
# ${CONDA_RUN} python -m pytest -n 1 -s -v --make-reports=tests_torch_mps \
|
335 |
+
# --report-log=tests_torch_mps.log \
|
336 |
+
# tests/
|
337 |
+
# - name: Failure short reports
|
338 |
+
# if: ${{ failure() }}
|
339 |
+
# run: cat reports/tests_torch_mps_failures_short.txt
|
340 |
+
#
|
341 |
+
# - name: Test suite reports artifacts
|
342 |
+
# if: ${{ always() }}
|
343 |
+
# uses: actions/upload-artifact@v4
|
344 |
+
# with:
|
345 |
+
# name: torch_mps_test_reports
|
346 |
+
# path: reports
|
347 |
+
#
|
348 |
+
# - name: Generate Report and Notify Channel
|
349 |
+
# if: always()
|
350 |
+
# run: |
|
351 |
+
# pip install slack_sdk tabulate
|
352 |
+
# python utils/log_reports.py >> $GITHUB_STEP_SUMMARY run_nightly_tests_apple_m1:
|
353 |
+
# name: Nightly PyTorch MPS tests on MacOS
|
354 |
+
# runs-on: [ self-hosted, apple-m1 ]
|
355 |
+
# if: github.event_name == 'schedule'
|
356 |
+
#
|
357 |
+
# steps:
|
358 |
+
# - name: Checkout diffusers
|
359 |
+
# uses: actions/checkout@v3
|
360 |
+
# with:
|
361 |
+
# fetch-depth: 2
|
362 |
+
#
|
363 |
+
# - name: Clean checkout
|
364 |
+
# shell: arch -arch arm64 bash {0}
|
365 |
+
# run: |
|
366 |
+
# git clean -fxd
|
367 |
+
# - name: Setup miniconda
|
368 |
+
# uses: ./.github/actions/setup-miniconda
|
369 |
+
# with:
|
370 |
+
# python-version: 3.9
|
371 |
+
#
|
372 |
+
# - name: Install dependencies
|
373 |
+
# shell: arch -arch arm64 bash {0}
|
374 |
+
# run: |
|
375 |
+
# ${CONDA_RUN} python -m pip install --upgrade pip uv
|
376 |
+
# ${CONDA_RUN} python -m uv pip install -e [quality,test]
|
377 |
+
# ${CONDA_RUN} python -m uv pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
|
378 |
+
# ${CONDA_RUN} python -m uv pip install accelerate@git+https://github.com/huggingface/accelerate
|
379 |
+
# ${CONDA_RUN} python -m uv pip install pytest-reportlog
|
380 |
+
# - name: Environment
|
381 |
+
# shell: arch -arch arm64 bash {0}
|
382 |
+
# run: |
|
383 |
+
# ${CONDA_RUN} python utils/print_env.py
|
384 |
+
# - name: Run nightly PyTorch tests on M1 (MPS)
|
385 |
+
# shell: arch -arch arm64 bash {0}
|
386 |
+
# env:
|
387 |
+
# HF_HOME: /System/Volumes/Data/mnt/cache
|
388 |
+
# HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
389 |
+
# run: |
|
390 |
+
# ${CONDA_RUN} python -m pytest -n 1 -s -v --make-reports=tests_torch_mps \
|
391 |
+
# --report-log=tests_torch_mps.log \
|
392 |
+
# tests/
|
393 |
+
# - name: Failure short reports
|
394 |
+
# if: ${{ failure() }}
|
395 |
+
# run: cat reports/tests_torch_mps_failures_short.txt
|
396 |
+
#
|
397 |
+
# - name: Test suite reports artifacts
|
398 |
+
# if: ${{ always() }}
|
399 |
+
# uses: actions/upload-artifact@v4
|
400 |
+
# with:
|
401 |
+
# name: torch_mps_test_reports
|
402 |
+
# path: reports
|
403 |
+
#
|
404 |
+
# - name: Generate Report and Notify Channel
|
405 |
+
# if: always()
|
406 |
+
# run: |
|
407 |
+
# pip install slack_sdk tabulate
|
408 |
+
# python utils/log_reports.py >> $GITHUB_STEP_SUMMARY
|
diffusers/.github/workflows/notify_slack_about_release.yml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Notify Slack about a release
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
release:
|
6 |
+
types: [published]
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-22.04
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- uses: actions/checkout@v3
|
14 |
+
|
15 |
+
- name: Setup Python
|
16 |
+
uses: actions/setup-python@v4
|
17 |
+
with:
|
18 |
+
python-version: '3.8'
|
19 |
+
|
20 |
+
- name: Notify Slack about the release
|
21 |
+
env:
|
22 |
+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
23 |
+
run: pip install requests && python utils/notify_slack_about_release.py
|
diffusers/.github/workflows/pr_dependency_test.yml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run dependency tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
push:
|
10 |
+
branches:
|
11 |
+
- main
|
12 |
+
|
13 |
+
concurrency:
|
14 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
15 |
+
cancel-in-progress: true
|
16 |
+
|
17 |
+
jobs:
|
18 |
+
check_dependencies:
|
19 |
+
runs-on: ubuntu-22.04
|
20 |
+
steps:
|
21 |
+
- uses: actions/checkout@v3
|
22 |
+
- name: Set up Python
|
23 |
+
uses: actions/setup-python@v4
|
24 |
+
with:
|
25 |
+
python-version: "3.8"
|
26 |
+
- name: Install dependencies
|
27 |
+
run: |
|
28 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
29 |
+
python -m pip install --upgrade pip uv
|
30 |
+
python -m uv pip install -e .
|
31 |
+
python -m uv pip install pytest
|
32 |
+
- name: Check for soft dependencies
|
33 |
+
run: |
|
34 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
35 |
+
pytest tests/others/test_dependencies.py
|
diffusers/.github/workflows/pr_flax_dependency_test.yml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Flax dependency tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
push:
|
10 |
+
branches:
|
11 |
+
- main
|
12 |
+
|
13 |
+
concurrency:
|
14 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
15 |
+
cancel-in-progress: true
|
16 |
+
|
17 |
+
jobs:
|
18 |
+
check_flax_dependencies:
|
19 |
+
runs-on: ubuntu-22.04
|
20 |
+
steps:
|
21 |
+
- uses: actions/checkout@v3
|
22 |
+
- name: Set up Python
|
23 |
+
uses: actions/setup-python@v4
|
24 |
+
with:
|
25 |
+
python-version: "3.8"
|
26 |
+
- name: Install dependencies
|
27 |
+
run: |
|
28 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
29 |
+
python -m pip install --upgrade pip uv
|
30 |
+
python -m uv pip install -e .
|
31 |
+
python -m uv pip install "jax[cpu]>=0.2.16,!=0.3.2"
|
32 |
+
python -m uv pip install "flax>=0.4.1"
|
33 |
+
python -m uv pip install "jaxlib>=0.1.65"
|
34 |
+
python -m uv pip install pytest
|
35 |
+
- name: Check for soft dependencies
|
36 |
+
run: |
|
37 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
38 |
+
pytest tests/others/test_dependencies.py
|
diffusers/.github/workflows/pr_test_fetcher.yml
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast tests for PRs - Test Fetcher
|
2 |
+
|
3 |
+
on: workflow_dispatch
|
4 |
+
|
5 |
+
env:
|
6 |
+
DIFFUSERS_IS_CI: yes
|
7 |
+
OMP_NUM_THREADS: 4
|
8 |
+
MKL_NUM_THREADS: 4
|
9 |
+
PYTEST_TIMEOUT: 60
|
10 |
+
|
11 |
+
concurrency:
|
12 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
13 |
+
cancel-in-progress: true
|
14 |
+
|
15 |
+
jobs:
|
16 |
+
setup_pr_tests:
|
17 |
+
name: Setup PR Tests
|
18 |
+
runs-on:
|
19 |
+
group: aws-general-8-plus
|
20 |
+
container:
|
21 |
+
image: diffusers/diffusers-pytorch-cpu
|
22 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
23 |
+
defaults:
|
24 |
+
run:
|
25 |
+
shell: bash
|
26 |
+
outputs:
|
27 |
+
matrix: ${{ steps.set_matrix.outputs.matrix }}
|
28 |
+
test_map: ${{ steps.set_matrix.outputs.test_map }}
|
29 |
+
steps:
|
30 |
+
- name: Checkout diffusers
|
31 |
+
uses: actions/checkout@v3
|
32 |
+
with:
|
33 |
+
fetch-depth: 0
|
34 |
+
- name: Install dependencies
|
35 |
+
run: |
|
36 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
37 |
+
python -m uv pip install -e [quality,test]
|
38 |
+
- name: Environment
|
39 |
+
run: |
|
40 |
+
python utils/print_env.py
|
41 |
+
echo $(git --version)
|
42 |
+
- name: Fetch Tests
|
43 |
+
run: |
|
44 |
+
python utils/tests_fetcher.py | tee test_preparation.txt
|
45 |
+
- name: Report fetched tests
|
46 |
+
uses: actions/upload-artifact@v3
|
47 |
+
with:
|
48 |
+
name: test_fetched
|
49 |
+
path: test_preparation.txt
|
50 |
+
- id: set_matrix
|
51 |
+
name: Create Test Matrix
|
52 |
+
# The `keys` is used as GitHub actions matrix for jobs, i.e. `models`, `pipelines`, etc.
|
53 |
+
# The `test_map` is used to get the actual identified test files under each key.
|
54 |
+
# If no test to run (so no `test_map.json` file), create a dummy map (empty matrix will fail)
|
55 |
+
run: |
|
56 |
+
if [ -f test_map.json ]; then
|
57 |
+
keys=$(python3 -c 'import json; fp = open("test_map.json"); test_map = json.load(fp); fp.close(); d = list(test_map.keys()); print(json.dumps(d))')
|
58 |
+
test_map=$(python3 -c 'import json; fp = open("test_map.json"); test_map = json.load(fp); fp.close(); print(json.dumps(test_map))')
|
59 |
+
else
|
60 |
+
keys=$(python3 -c 'keys = ["dummy"]; print(keys)')
|
61 |
+
test_map=$(python3 -c 'test_map = {"dummy": []}; print(test_map)')
|
62 |
+
fi
|
63 |
+
echo $keys
|
64 |
+
echo $test_map
|
65 |
+
echo "matrix=$keys" >> $GITHUB_OUTPUT
|
66 |
+
echo "test_map=$test_map" >> $GITHUB_OUTPUT
|
67 |
+
|
68 |
+
run_pr_tests:
|
69 |
+
name: Run PR Tests
|
70 |
+
needs: setup_pr_tests
|
71 |
+
if: contains(fromJson(needs.setup_pr_tests.outputs.matrix), 'dummy') != true
|
72 |
+
strategy:
|
73 |
+
fail-fast: false
|
74 |
+
max-parallel: 2
|
75 |
+
matrix:
|
76 |
+
modules: ${{ fromJson(needs.setup_pr_tests.outputs.matrix) }}
|
77 |
+
runs-on:
|
78 |
+
group: aws-general-8-plus
|
79 |
+
container:
|
80 |
+
image: diffusers/diffusers-pytorch-cpu
|
81 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
82 |
+
defaults:
|
83 |
+
run:
|
84 |
+
shell: bash
|
85 |
+
steps:
|
86 |
+
- name: Checkout diffusers
|
87 |
+
uses: actions/checkout@v3
|
88 |
+
with:
|
89 |
+
fetch-depth: 2
|
90 |
+
|
91 |
+
- name: Install dependencies
|
92 |
+
run: |
|
93 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
94 |
+
python -m pip install -e [quality,test]
|
95 |
+
python -m pip install accelerate
|
96 |
+
|
97 |
+
- name: Environment
|
98 |
+
run: |
|
99 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
100 |
+
python utils/print_env.py
|
101 |
+
|
102 |
+
- name: Run all selected tests on CPU
|
103 |
+
run: |
|
104 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
105 |
+
python -m pytest -n 2 --dist=loadfile -v --make-reports=${{ matrix.modules }}_tests_cpu ${{ fromJson(needs.setup_pr_tests.outputs.test_map)[matrix.modules] }}
|
106 |
+
|
107 |
+
- name: Failure short reports
|
108 |
+
if: ${{ failure() }}
|
109 |
+
continue-on-error: true
|
110 |
+
run: |
|
111 |
+
cat reports/${{ matrix.modules }}_tests_cpu_stats.txt
|
112 |
+
cat reports/${{ matrix.modules }}_tests_cpu_failures_short.txt
|
113 |
+
|
114 |
+
- name: Test suite reports artifacts
|
115 |
+
if: ${{ always() }}
|
116 |
+
uses: actions/upload-artifact@v3
|
117 |
+
with:
|
118 |
+
name: ${{ matrix.modules }}_test_reports
|
119 |
+
path: reports
|
120 |
+
|
121 |
+
run_staging_tests:
|
122 |
+
strategy:
|
123 |
+
fail-fast: false
|
124 |
+
matrix:
|
125 |
+
config:
|
126 |
+
- name: Hub tests for models, schedulers, and pipelines
|
127 |
+
framework: hub_tests_pytorch
|
128 |
+
runner: aws-general-8-plus
|
129 |
+
image: diffusers/diffusers-pytorch-cpu
|
130 |
+
report: torch_hub
|
131 |
+
|
132 |
+
name: ${{ matrix.config.name }}
|
133 |
+
runs-on:
|
134 |
+
group: ${{ matrix.config.runner }}
|
135 |
+
container:
|
136 |
+
image: ${{ matrix.config.image }}
|
137 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
138 |
+
|
139 |
+
defaults:
|
140 |
+
run:
|
141 |
+
shell: bash
|
142 |
+
|
143 |
+
steps:
|
144 |
+
- name: Checkout diffusers
|
145 |
+
uses: actions/checkout@v3
|
146 |
+
with:
|
147 |
+
fetch-depth: 2
|
148 |
+
|
149 |
+
- name: Install dependencies
|
150 |
+
run: |
|
151 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
152 |
+
python -m pip install -e [quality,test]
|
153 |
+
|
154 |
+
- name: Environment
|
155 |
+
run: |
|
156 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
157 |
+
python utils/print_env.py
|
158 |
+
|
159 |
+
- name: Run Hub tests for models, schedulers, and pipelines on a staging env
|
160 |
+
if: ${{ matrix.config.framework == 'hub_tests_pytorch' }}
|
161 |
+
run: |
|
162 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
163 |
+
HUGGINGFACE_CO_STAGING=true python -m pytest \
|
164 |
+
-m "is_staging_test" \
|
165 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
166 |
+
tests
|
167 |
+
|
168 |
+
- name: Failure short reports
|
169 |
+
if: ${{ failure() }}
|
170 |
+
run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
|
171 |
+
|
172 |
+
- name: Test suite reports artifacts
|
173 |
+
if: ${{ always() }}
|
174 |
+
uses: actions/upload-artifact@v4
|
175 |
+
with:
|
176 |
+
name: pr_${{ matrix.config.report }}_test_reports
|
177 |
+
path: reports
|
diffusers/.github/workflows/pr_test_peft_backend.yml
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast tests for PRs - PEFT backend
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
- "tests/**.py"
|
10 |
+
|
11 |
+
concurrency:
|
12 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
13 |
+
cancel-in-progress: true
|
14 |
+
|
15 |
+
env:
|
16 |
+
DIFFUSERS_IS_CI: yes
|
17 |
+
OMP_NUM_THREADS: 4
|
18 |
+
MKL_NUM_THREADS: 4
|
19 |
+
PYTEST_TIMEOUT: 60
|
20 |
+
|
21 |
+
jobs:
|
22 |
+
check_code_quality:
|
23 |
+
runs-on: ubuntu-22.04
|
24 |
+
steps:
|
25 |
+
- uses: actions/checkout@v3
|
26 |
+
- name: Set up Python
|
27 |
+
uses: actions/setup-python@v4
|
28 |
+
with:
|
29 |
+
python-version: "3.8"
|
30 |
+
- name: Install dependencies
|
31 |
+
run: |
|
32 |
+
python -m pip install --upgrade pip
|
33 |
+
pip install .[quality]
|
34 |
+
- name: Check quality
|
35 |
+
run: make quality
|
36 |
+
- name: Check if failure
|
37 |
+
if: ${{ failure() }}
|
38 |
+
run: |
|
39 |
+
echo "Quality check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make style && make quality'" >> $GITHUB_STEP_SUMMARY
|
40 |
+
|
41 |
+
check_repository_consistency:
|
42 |
+
needs: check_code_quality
|
43 |
+
runs-on: ubuntu-22.04
|
44 |
+
steps:
|
45 |
+
- uses: actions/checkout@v3
|
46 |
+
- name: Set up Python
|
47 |
+
uses: actions/setup-python@v4
|
48 |
+
with:
|
49 |
+
python-version: "3.8"
|
50 |
+
- name: Install dependencies
|
51 |
+
run: |
|
52 |
+
python -m pip install --upgrade pip
|
53 |
+
pip install .[quality]
|
54 |
+
- name: Check repo consistency
|
55 |
+
run: |
|
56 |
+
python utils/check_copies.py
|
57 |
+
python utils/check_dummies.py
|
58 |
+
make deps_table_check_updated
|
59 |
+
- name: Check if failure
|
60 |
+
if: ${{ failure() }}
|
61 |
+
run: |
|
62 |
+
echo "Repo consistency check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make fix-copies'" >> $GITHUB_STEP_SUMMARY
|
63 |
+
|
64 |
+
run_fast_tests:
|
65 |
+
needs: [check_code_quality, check_repository_consistency]
|
66 |
+
strategy:
|
67 |
+
fail-fast: false
|
68 |
+
matrix:
|
69 |
+
lib-versions: ["main", "latest"]
|
70 |
+
|
71 |
+
|
72 |
+
name: LoRA - ${{ matrix.lib-versions }}
|
73 |
+
|
74 |
+
runs-on:
|
75 |
+
group: aws-general-8-plus
|
76 |
+
|
77 |
+
container:
|
78 |
+
image: diffusers/diffusers-pytorch-cpu
|
79 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
80 |
+
|
81 |
+
defaults:
|
82 |
+
run:
|
83 |
+
shell: bash
|
84 |
+
|
85 |
+
steps:
|
86 |
+
- name: Checkout diffusers
|
87 |
+
uses: actions/checkout@v3
|
88 |
+
with:
|
89 |
+
fetch-depth: 2
|
90 |
+
|
91 |
+
- name: Install dependencies
|
92 |
+
run: |
|
93 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
94 |
+
python -m uv pip install -e [quality,test]
|
95 |
+
# TODO (sayakpaul, DN6): revisit `--no-deps`
|
96 |
+
if [ "${{ matrix.lib-versions }}" == "main" ]; then
|
97 |
+
python -m pip install -U peft@git+https://github.com/huggingface/peft.git --no-deps
|
98 |
+
python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps
|
99 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git --no-deps
|
100 |
+
else
|
101 |
+
python -m uv pip install -U peft --no-deps
|
102 |
+
python -m uv pip install -U transformers accelerate --no-deps
|
103 |
+
fi
|
104 |
+
|
105 |
+
- name: Environment
|
106 |
+
run: |
|
107 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
108 |
+
python utils/print_env.py
|
109 |
+
|
110 |
+
- name: Run fast PyTorch LoRA CPU tests with PEFT backend
|
111 |
+
run: |
|
112 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
113 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
114 |
+
-s -v \
|
115 |
+
--make-reports=tests_${{ matrix.lib-versions }} \
|
116 |
+
tests/lora/
|
117 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
118 |
+
-s -v \
|
119 |
+
--make-reports=tests_models_lora_${{ matrix.lib-versions }} \
|
120 |
+
tests/models/ -k "lora"
|
121 |
+
|
122 |
+
|
123 |
+
- name: Failure short reports
|
124 |
+
if: ${{ failure() }}
|
125 |
+
run: |
|
126 |
+
cat reports/tests_${{ matrix.lib-versions }}_failures_short.txt
|
127 |
+
cat reports/tests_models_lora_${{ matrix.lib-versions }}_failures_short.txt
|
128 |
+
|
129 |
+
- name: Test suite reports artifacts
|
130 |
+
if: ${{ always() }}
|
131 |
+
uses: actions/upload-artifact@v4
|
132 |
+
with:
|
133 |
+
name: pr_${{ matrix.lib-versions }}_test_reports
|
134 |
+
path: reports
|
diffusers/.github/workflows/pr_tests.yml
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast tests for PRs
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
- "benchmarks/**.py"
|
10 |
+
- "examples/**.py"
|
11 |
+
- "scripts/**.py"
|
12 |
+
- "tests/**.py"
|
13 |
+
- ".github/**.yml"
|
14 |
+
- "utils/**.py"
|
15 |
+
push:
|
16 |
+
branches:
|
17 |
+
- ci-*
|
18 |
+
|
19 |
+
concurrency:
|
20 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
21 |
+
cancel-in-progress: true
|
22 |
+
|
23 |
+
env:
|
24 |
+
DIFFUSERS_IS_CI: yes
|
25 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
26 |
+
OMP_NUM_THREADS: 4
|
27 |
+
MKL_NUM_THREADS: 4
|
28 |
+
PYTEST_TIMEOUT: 60
|
29 |
+
|
30 |
+
jobs:
|
31 |
+
check_code_quality:
|
32 |
+
runs-on: ubuntu-22.04
|
33 |
+
steps:
|
34 |
+
- uses: actions/checkout@v3
|
35 |
+
- name: Set up Python
|
36 |
+
uses: actions/setup-python@v4
|
37 |
+
with:
|
38 |
+
python-version: "3.8"
|
39 |
+
- name: Install dependencies
|
40 |
+
run: |
|
41 |
+
python -m pip install --upgrade pip
|
42 |
+
pip install .[quality]
|
43 |
+
- name: Check quality
|
44 |
+
run: make quality
|
45 |
+
- name: Check if failure
|
46 |
+
if: ${{ failure() }}
|
47 |
+
run: |
|
48 |
+
echo "Quality check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make style && make quality'" >> $GITHUB_STEP_SUMMARY
|
49 |
+
|
50 |
+
check_repository_consistency:
|
51 |
+
needs: check_code_quality
|
52 |
+
runs-on: ubuntu-22.04
|
53 |
+
steps:
|
54 |
+
- uses: actions/checkout@v3
|
55 |
+
- name: Set up Python
|
56 |
+
uses: actions/setup-python@v4
|
57 |
+
with:
|
58 |
+
python-version: "3.8"
|
59 |
+
- name: Install dependencies
|
60 |
+
run: |
|
61 |
+
python -m pip install --upgrade pip
|
62 |
+
pip install .[quality]
|
63 |
+
- name: Check repo consistency
|
64 |
+
run: |
|
65 |
+
python utils/check_copies.py
|
66 |
+
python utils/check_dummies.py
|
67 |
+
make deps_table_check_updated
|
68 |
+
- name: Check if failure
|
69 |
+
if: ${{ failure() }}
|
70 |
+
run: |
|
71 |
+
echo "Repo consistency check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make fix-copies'" >> $GITHUB_STEP_SUMMARY
|
72 |
+
|
73 |
+
run_fast_tests:
|
74 |
+
needs: [check_code_quality, check_repository_consistency]
|
75 |
+
strategy:
|
76 |
+
fail-fast: false
|
77 |
+
matrix:
|
78 |
+
config:
|
79 |
+
- name: Fast PyTorch Pipeline CPU tests
|
80 |
+
framework: pytorch_pipelines
|
81 |
+
runner: aws-highmemory-32-plus
|
82 |
+
image: diffusers/diffusers-pytorch-cpu
|
83 |
+
report: torch_cpu_pipelines
|
84 |
+
- name: Fast PyTorch Models & Schedulers CPU tests
|
85 |
+
framework: pytorch_models
|
86 |
+
runner: aws-general-8-plus
|
87 |
+
image: diffusers/diffusers-pytorch-cpu
|
88 |
+
report: torch_cpu_models_schedulers
|
89 |
+
- name: Fast Flax CPU tests
|
90 |
+
framework: flax
|
91 |
+
runner: aws-general-8-plus
|
92 |
+
image: diffusers/diffusers-flax-cpu
|
93 |
+
report: flax_cpu
|
94 |
+
- name: PyTorch Example CPU tests
|
95 |
+
framework: pytorch_examples
|
96 |
+
runner: aws-general-8-plus
|
97 |
+
image: diffusers/diffusers-pytorch-cpu
|
98 |
+
report: torch_example_cpu
|
99 |
+
|
100 |
+
name: ${{ matrix.config.name }}
|
101 |
+
|
102 |
+
runs-on:
|
103 |
+
group: ${{ matrix.config.runner }}
|
104 |
+
|
105 |
+
container:
|
106 |
+
image: ${{ matrix.config.image }}
|
107 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
108 |
+
|
109 |
+
defaults:
|
110 |
+
run:
|
111 |
+
shell: bash
|
112 |
+
|
113 |
+
steps:
|
114 |
+
- name: Checkout diffusers
|
115 |
+
uses: actions/checkout@v3
|
116 |
+
with:
|
117 |
+
fetch-depth: 2
|
118 |
+
|
119 |
+
- name: Install dependencies
|
120 |
+
run: |
|
121 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
122 |
+
python -m uv pip install -e [quality,test]
|
123 |
+
python -m uv pip install accelerate
|
124 |
+
|
125 |
+
- name: Environment
|
126 |
+
run: |
|
127 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
128 |
+
python utils/print_env.py
|
129 |
+
|
130 |
+
- name: Run fast PyTorch Pipeline CPU tests
|
131 |
+
if: ${{ matrix.config.framework == 'pytorch_pipelines' }}
|
132 |
+
run: |
|
133 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
134 |
+
python -m pytest -n 8 --max-worker-restart=0 --dist=loadfile \
|
135 |
+
-s -v -k "not Flax and not Onnx" \
|
136 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
137 |
+
tests/pipelines
|
138 |
+
|
139 |
+
- name: Run fast PyTorch Model Scheduler CPU tests
|
140 |
+
if: ${{ matrix.config.framework == 'pytorch_models' }}
|
141 |
+
run: |
|
142 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
143 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
144 |
+
-s -v -k "not Flax and not Onnx and not Dependency" \
|
145 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
146 |
+
tests/models tests/schedulers tests/others
|
147 |
+
|
148 |
+
- name: Run fast Flax TPU tests
|
149 |
+
if: ${{ matrix.config.framework == 'flax' }}
|
150 |
+
run: |
|
151 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
152 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
153 |
+
-s -v -k "Flax" \
|
154 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
155 |
+
tests
|
156 |
+
|
157 |
+
- name: Run example PyTorch CPU tests
|
158 |
+
if: ${{ matrix.config.framework == 'pytorch_examples' }}
|
159 |
+
run: |
|
160 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
161 |
+
python -m uv pip install peft timm
|
162 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
163 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
164 |
+
examples
|
165 |
+
|
166 |
+
- name: Failure short reports
|
167 |
+
if: ${{ failure() }}
|
168 |
+
run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
|
169 |
+
|
170 |
+
- name: Test suite reports artifacts
|
171 |
+
if: ${{ always() }}
|
172 |
+
uses: actions/upload-artifact@v4
|
173 |
+
with:
|
174 |
+
name: pr_${{ matrix.config.framework }}_${{ matrix.config.report }}_test_reports
|
175 |
+
path: reports
|
176 |
+
|
177 |
+
run_staging_tests:
|
178 |
+
needs: [check_code_quality, check_repository_consistency]
|
179 |
+
strategy:
|
180 |
+
fail-fast: false
|
181 |
+
matrix:
|
182 |
+
config:
|
183 |
+
- name: Hub tests for models, schedulers, and pipelines
|
184 |
+
framework: hub_tests_pytorch
|
185 |
+
runner:
|
186 |
+
group: aws-general-8-plus
|
187 |
+
image: diffusers/diffusers-pytorch-cpu
|
188 |
+
report: torch_hub
|
189 |
+
|
190 |
+
name: ${{ matrix.config.name }}
|
191 |
+
|
192 |
+
runs-on: ${{ matrix.config.runner }}
|
193 |
+
|
194 |
+
container:
|
195 |
+
image: ${{ matrix.config.image }}
|
196 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
197 |
+
|
198 |
+
defaults:
|
199 |
+
run:
|
200 |
+
shell: bash
|
201 |
+
|
202 |
+
steps:
|
203 |
+
- name: Checkout diffusers
|
204 |
+
uses: actions/checkout@v3
|
205 |
+
with:
|
206 |
+
fetch-depth: 2
|
207 |
+
|
208 |
+
- name: Install dependencies
|
209 |
+
run: |
|
210 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
211 |
+
python -m uv pip install -e [quality,test]
|
212 |
+
|
213 |
+
- name: Environment
|
214 |
+
run: |
|
215 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
216 |
+
python utils/print_env.py
|
217 |
+
|
218 |
+
- name: Run Hub tests for models, schedulers, and pipelines on a staging env
|
219 |
+
if: ${{ matrix.config.framework == 'hub_tests_pytorch' }}
|
220 |
+
run: |
|
221 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
222 |
+
HUGGINGFACE_CO_STAGING=true python -m pytest \
|
223 |
+
-m "is_staging_test" \
|
224 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
225 |
+
tests
|
226 |
+
|
227 |
+
- name: Failure short reports
|
228 |
+
if: ${{ failure() }}
|
229 |
+
run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
|
230 |
+
|
231 |
+
- name: Test suite reports artifacts
|
232 |
+
if: ${{ always() }}
|
233 |
+
uses: actions/upload-artifact@v4
|
234 |
+
with:
|
235 |
+
name: pr_${{ matrix.config.report }}_test_reports
|
236 |
+
path: reports
|
diffusers/.github/workflows/pr_torch_dependency_test.yml
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Torch dependency tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
push:
|
10 |
+
branches:
|
11 |
+
- main
|
12 |
+
|
13 |
+
concurrency:
|
14 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
15 |
+
cancel-in-progress: true
|
16 |
+
|
17 |
+
jobs:
|
18 |
+
check_torch_dependencies:
|
19 |
+
runs-on: ubuntu-22.04
|
20 |
+
steps:
|
21 |
+
- uses: actions/checkout@v3
|
22 |
+
- name: Set up Python
|
23 |
+
uses: actions/setup-python@v4
|
24 |
+
with:
|
25 |
+
python-version: "3.8"
|
26 |
+
- name: Install dependencies
|
27 |
+
run: |
|
28 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
29 |
+
python -m pip install --upgrade pip uv
|
30 |
+
python -m uv pip install -e .
|
31 |
+
python -m uv pip install torch torchvision torchaudio
|
32 |
+
python -m uv pip install pytest
|
33 |
+
- name: Check for soft dependencies
|
34 |
+
run: |
|
35 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
36 |
+
pytest tests/others/test_dependencies.py
|
diffusers/.github/workflows/push_tests.yml
ADDED
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast GPU Tests on main
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
push:
|
6 |
+
branches:
|
7 |
+
- main
|
8 |
+
paths:
|
9 |
+
- "src/diffusers/**.py"
|
10 |
+
- "examples/**.py"
|
11 |
+
- "tests/**.py"
|
12 |
+
|
13 |
+
env:
|
14 |
+
DIFFUSERS_IS_CI: yes
|
15 |
+
OMP_NUM_THREADS: 8
|
16 |
+
MKL_NUM_THREADS: 8
|
17 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
18 |
+
PYTEST_TIMEOUT: 600
|
19 |
+
PIPELINE_USAGE_CUTOFF: 50000
|
20 |
+
|
21 |
+
jobs:
|
22 |
+
setup_torch_cuda_pipeline_matrix:
|
23 |
+
name: Setup Torch Pipelines CUDA Slow Tests Matrix
|
24 |
+
runs-on:
|
25 |
+
group: aws-general-8-plus
|
26 |
+
container:
|
27 |
+
image: diffusers/diffusers-pytorch-cpu
|
28 |
+
outputs:
|
29 |
+
pipeline_test_matrix: ${{ steps.fetch_pipeline_matrix.outputs.pipeline_test_matrix }}
|
30 |
+
steps:
|
31 |
+
- name: Checkout diffusers
|
32 |
+
uses: actions/checkout@v3
|
33 |
+
with:
|
34 |
+
fetch-depth: 2
|
35 |
+
- name: Install dependencies
|
36 |
+
run: |
|
37 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
38 |
+
python -m uv pip install -e [quality,test]
|
39 |
+
- name: Environment
|
40 |
+
run: |
|
41 |
+
python utils/print_env.py
|
42 |
+
- name: Fetch Pipeline Matrix
|
43 |
+
id: fetch_pipeline_matrix
|
44 |
+
run: |
|
45 |
+
matrix=$(python utils/fetch_torch_cuda_pipeline_test_matrix.py)
|
46 |
+
echo $matrix
|
47 |
+
echo "pipeline_test_matrix=$matrix" >> $GITHUB_OUTPUT
|
48 |
+
- name: Pipeline Tests Artifacts
|
49 |
+
if: ${{ always() }}
|
50 |
+
uses: actions/upload-artifact@v4
|
51 |
+
with:
|
52 |
+
name: test-pipelines.json
|
53 |
+
path: reports
|
54 |
+
|
55 |
+
torch_pipelines_cuda_tests:
|
56 |
+
name: Torch Pipelines CUDA Tests
|
57 |
+
needs: setup_torch_cuda_pipeline_matrix
|
58 |
+
strategy:
|
59 |
+
fail-fast: false
|
60 |
+
max-parallel: 8
|
61 |
+
matrix:
|
62 |
+
module: ${{ fromJson(needs.setup_torch_cuda_pipeline_matrix.outputs.pipeline_test_matrix) }}
|
63 |
+
runs-on:
|
64 |
+
group: aws-g4dn-2xlarge
|
65 |
+
container:
|
66 |
+
image: diffusers/diffusers-pytorch-cuda
|
67 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
68 |
+
steps:
|
69 |
+
- name: Checkout diffusers
|
70 |
+
uses: actions/checkout@v3
|
71 |
+
with:
|
72 |
+
fetch-depth: 2
|
73 |
+
- name: NVIDIA-SMI
|
74 |
+
run: |
|
75 |
+
nvidia-smi
|
76 |
+
- name: Install dependencies
|
77 |
+
run: |
|
78 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
79 |
+
python -m uv pip install -e [quality,test]
|
80 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
81 |
+
- name: Environment
|
82 |
+
run: |
|
83 |
+
python utils/print_env.py
|
84 |
+
- name: Slow PyTorch CUDA checkpoint tests on Ubuntu
|
85 |
+
env:
|
86 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
87 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
88 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
89 |
+
run: |
|
90 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
91 |
+
-s -v -k "not Flax and not Onnx" \
|
92 |
+
--make-reports=tests_pipeline_${{ matrix.module }}_cuda \
|
93 |
+
tests/pipelines/${{ matrix.module }}
|
94 |
+
- name: Failure short reports
|
95 |
+
if: ${{ failure() }}
|
96 |
+
run: |
|
97 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_stats.txt
|
98 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_failures_short.txt
|
99 |
+
- name: Test suite reports artifacts
|
100 |
+
if: ${{ always() }}
|
101 |
+
uses: actions/upload-artifact@v4
|
102 |
+
with:
|
103 |
+
name: pipeline_${{ matrix.module }}_test_reports
|
104 |
+
path: reports
|
105 |
+
|
106 |
+
torch_cuda_tests:
|
107 |
+
name: Torch CUDA Tests
|
108 |
+
runs-on:
|
109 |
+
group: aws-g4dn-2xlarge
|
110 |
+
container:
|
111 |
+
image: diffusers/diffusers-pytorch-cuda
|
112 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
113 |
+
defaults:
|
114 |
+
run:
|
115 |
+
shell: bash
|
116 |
+
strategy:
|
117 |
+
fail-fast: false
|
118 |
+
max-parallel: 2
|
119 |
+
matrix:
|
120 |
+
module: [models, schedulers, lora, others, single_file]
|
121 |
+
steps:
|
122 |
+
- name: Checkout diffusers
|
123 |
+
uses: actions/checkout@v3
|
124 |
+
with:
|
125 |
+
fetch-depth: 2
|
126 |
+
|
127 |
+
- name: Install dependencies
|
128 |
+
run: |
|
129 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
130 |
+
python -m uv pip install -e [quality,test]
|
131 |
+
python -m uv pip install peft@git+https://github.com/huggingface/peft.git
|
132 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
133 |
+
|
134 |
+
- name: Environment
|
135 |
+
run: |
|
136 |
+
python utils/print_env.py
|
137 |
+
|
138 |
+
- name: Run PyTorch CUDA tests
|
139 |
+
env:
|
140 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
141 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
142 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
143 |
+
run: |
|
144 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
145 |
+
-s -v -k "not Flax and not Onnx" \
|
146 |
+
--make-reports=tests_torch_cuda_${{ matrix.module }} \
|
147 |
+
tests/${{ matrix.module }}
|
148 |
+
|
149 |
+
- name: Failure short reports
|
150 |
+
if: ${{ failure() }}
|
151 |
+
run: |
|
152 |
+
cat reports/tests_torch_cuda_${{ matrix.module }}_stats.txt
|
153 |
+
cat reports/tests_torch_cuda_${{ matrix.module }}_failures_short.txt
|
154 |
+
|
155 |
+
- name: Test suite reports artifacts
|
156 |
+
if: ${{ always() }}
|
157 |
+
uses: actions/upload-artifact@v4
|
158 |
+
with:
|
159 |
+
name: torch_cuda_test_reports_${{ matrix.module }}
|
160 |
+
path: reports
|
161 |
+
|
162 |
+
flax_tpu_tests:
|
163 |
+
name: Flax TPU Tests
|
164 |
+
runs-on: docker-tpu
|
165 |
+
container:
|
166 |
+
image: diffusers/diffusers-flax-tpu
|
167 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ --privileged
|
168 |
+
defaults:
|
169 |
+
run:
|
170 |
+
shell: bash
|
171 |
+
steps:
|
172 |
+
- name: Checkout diffusers
|
173 |
+
uses: actions/checkout@v3
|
174 |
+
with:
|
175 |
+
fetch-depth: 2
|
176 |
+
|
177 |
+
- name: Install dependencies
|
178 |
+
run: |
|
179 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
180 |
+
python -m uv pip install -e [quality,test]
|
181 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
182 |
+
|
183 |
+
- name: Environment
|
184 |
+
run: |
|
185 |
+
python utils/print_env.py
|
186 |
+
|
187 |
+
- name: Run slow Flax TPU tests
|
188 |
+
env:
|
189 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
190 |
+
run: |
|
191 |
+
python -m pytest -n 0 \
|
192 |
+
-s -v -k "Flax" \
|
193 |
+
--make-reports=tests_flax_tpu \
|
194 |
+
tests/
|
195 |
+
|
196 |
+
- name: Failure short reports
|
197 |
+
if: ${{ failure() }}
|
198 |
+
run: |
|
199 |
+
cat reports/tests_flax_tpu_stats.txt
|
200 |
+
cat reports/tests_flax_tpu_failures_short.txt
|
201 |
+
|
202 |
+
- name: Test suite reports artifacts
|
203 |
+
if: ${{ always() }}
|
204 |
+
uses: actions/upload-artifact@v4
|
205 |
+
with:
|
206 |
+
name: flax_tpu_test_reports
|
207 |
+
path: reports
|
208 |
+
|
209 |
+
onnx_cuda_tests:
|
210 |
+
name: ONNX CUDA Tests
|
211 |
+
runs-on:
|
212 |
+
group: aws-g4dn-2xlarge
|
213 |
+
container:
|
214 |
+
image: diffusers/diffusers-onnxruntime-cuda
|
215 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ --gpus 0
|
216 |
+
defaults:
|
217 |
+
run:
|
218 |
+
shell: bash
|
219 |
+
steps:
|
220 |
+
- name: Checkout diffusers
|
221 |
+
uses: actions/checkout@v3
|
222 |
+
with:
|
223 |
+
fetch-depth: 2
|
224 |
+
|
225 |
+
- name: Install dependencies
|
226 |
+
run: |
|
227 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
228 |
+
python -m uv pip install -e [quality,test]
|
229 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
230 |
+
|
231 |
+
- name: Environment
|
232 |
+
run: |
|
233 |
+
python utils/print_env.py
|
234 |
+
|
235 |
+
- name: Run slow ONNXRuntime CUDA tests
|
236 |
+
env:
|
237 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
238 |
+
run: |
|
239 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
240 |
+
-s -v -k "Onnx" \
|
241 |
+
--make-reports=tests_onnx_cuda \
|
242 |
+
tests/
|
243 |
+
|
244 |
+
- name: Failure short reports
|
245 |
+
if: ${{ failure() }}
|
246 |
+
run: |
|
247 |
+
cat reports/tests_onnx_cuda_stats.txt
|
248 |
+
cat reports/tests_onnx_cuda_failures_short.txt
|
249 |
+
|
250 |
+
- name: Test suite reports artifacts
|
251 |
+
if: ${{ always() }}
|
252 |
+
uses: actions/upload-artifact@v4
|
253 |
+
with:
|
254 |
+
name: onnx_cuda_test_reports
|
255 |
+
path: reports
|
256 |
+
|
257 |
+
run_torch_compile_tests:
|
258 |
+
name: PyTorch Compile CUDA tests
|
259 |
+
|
260 |
+
runs-on:
|
261 |
+
group: aws-g4dn-2xlarge
|
262 |
+
|
263 |
+
container:
|
264 |
+
image: diffusers/diffusers-pytorch-compile-cuda
|
265 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
266 |
+
|
267 |
+
steps:
|
268 |
+
- name: Checkout diffusers
|
269 |
+
uses: actions/checkout@v3
|
270 |
+
with:
|
271 |
+
fetch-depth: 2
|
272 |
+
|
273 |
+
- name: NVIDIA-SMI
|
274 |
+
run: |
|
275 |
+
nvidia-smi
|
276 |
+
- name: Install dependencies
|
277 |
+
run: |
|
278 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
279 |
+
python -m uv pip install -e [quality,test,training]
|
280 |
+
- name: Environment
|
281 |
+
run: |
|
282 |
+
python utils/print_env.py
|
283 |
+
- name: Run example tests on GPU
|
284 |
+
env:
|
285 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
286 |
+
RUN_COMPILE: yes
|
287 |
+
run: |
|
288 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "compile" --make-reports=tests_torch_compile_cuda tests/
|
289 |
+
- name: Failure short reports
|
290 |
+
if: ${{ failure() }}
|
291 |
+
run: cat reports/tests_torch_compile_cuda_failures_short.txt
|
292 |
+
|
293 |
+
- name: Test suite reports artifacts
|
294 |
+
if: ${{ always() }}
|
295 |
+
uses: actions/upload-artifact@v4
|
296 |
+
with:
|
297 |
+
name: torch_compile_test_reports
|
298 |
+
path: reports
|
299 |
+
|
300 |
+
run_xformers_tests:
|
301 |
+
name: PyTorch xformers CUDA tests
|
302 |
+
|
303 |
+
runs-on:
|
304 |
+
group: aws-g4dn-2xlarge
|
305 |
+
|
306 |
+
container:
|
307 |
+
image: diffusers/diffusers-pytorch-xformers-cuda
|
308 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
309 |
+
|
310 |
+
steps:
|
311 |
+
- name: Checkout diffusers
|
312 |
+
uses: actions/checkout@v3
|
313 |
+
with:
|
314 |
+
fetch-depth: 2
|
315 |
+
|
316 |
+
- name: NVIDIA-SMI
|
317 |
+
run: |
|
318 |
+
nvidia-smi
|
319 |
+
- name: Install dependencies
|
320 |
+
run: |
|
321 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
322 |
+
python -m uv pip install -e [quality,test,training]
|
323 |
+
- name: Environment
|
324 |
+
run: |
|
325 |
+
python utils/print_env.py
|
326 |
+
- name: Run example tests on GPU
|
327 |
+
env:
|
328 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
329 |
+
run: |
|
330 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "xformers" --make-reports=tests_torch_xformers_cuda tests/
|
331 |
+
- name: Failure short reports
|
332 |
+
if: ${{ failure() }}
|
333 |
+
run: cat reports/tests_torch_xformers_cuda_failures_short.txt
|
334 |
+
|
335 |
+
- name: Test suite reports artifacts
|
336 |
+
if: ${{ always() }}
|
337 |
+
uses: actions/upload-artifact@v4
|
338 |
+
with:
|
339 |
+
name: torch_xformers_test_reports
|
340 |
+
path: reports
|
341 |
+
|
342 |
+
run_examples_tests:
|
343 |
+
name: Examples PyTorch CUDA tests on Ubuntu
|
344 |
+
|
345 |
+
runs-on:
|
346 |
+
group: aws-g4dn-2xlarge
|
347 |
+
|
348 |
+
container:
|
349 |
+
image: diffusers/diffusers-pytorch-cuda
|
350 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
351 |
+
|
352 |
+
steps:
|
353 |
+
- name: Checkout diffusers
|
354 |
+
uses: actions/checkout@v3
|
355 |
+
with:
|
356 |
+
fetch-depth: 2
|
357 |
+
|
358 |
+
- name: NVIDIA-SMI
|
359 |
+
run: |
|
360 |
+
nvidia-smi
|
361 |
+
|
362 |
+
- name: Install dependencies
|
363 |
+
run: |
|
364 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
365 |
+
python -m uv pip install -e [quality,test,training]
|
366 |
+
|
367 |
+
- name: Environment
|
368 |
+
run: |
|
369 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
370 |
+
python utils/print_env.py
|
371 |
+
|
372 |
+
- name: Run example tests on GPU
|
373 |
+
env:
|
374 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
375 |
+
run: |
|
376 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
377 |
+
python -m uv pip install timm
|
378 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v --make-reports=examples_torch_cuda examples/
|
379 |
+
|
380 |
+
- name: Failure short reports
|
381 |
+
if: ${{ failure() }}
|
382 |
+
run: |
|
383 |
+
cat reports/examples_torch_cuda_stats.txt
|
384 |
+
cat reports/examples_torch_cuda_failures_short.txt
|
385 |
+
|
386 |
+
- name: Test suite reports artifacts
|
387 |
+
if: ${{ always() }}
|
388 |
+
uses: actions/upload-artifact@v4
|
389 |
+
with:
|
390 |
+
name: examples_test_reports
|
391 |
+
path: reports
|
diffusers/.github/workflows/push_tests_fast.yml
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast tests on main
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
- "examples/**.py"
|
10 |
+
- "tests/**.py"
|
11 |
+
|
12 |
+
concurrency:
|
13 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
14 |
+
cancel-in-progress: true
|
15 |
+
|
16 |
+
env:
|
17 |
+
DIFFUSERS_IS_CI: yes
|
18 |
+
HF_HOME: /mnt/cache
|
19 |
+
OMP_NUM_THREADS: 8
|
20 |
+
MKL_NUM_THREADS: 8
|
21 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
22 |
+
PYTEST_TIMEOUT: 600
|
23 |
+
RUN_SLOW: no
|
24 |
+
|
25 |
+
jobs:
|
26 |
+
run_fast_tests:
|
27 |
+
strategy:
|
28 |
+
fail-fast: false
|
29 |
+
matrix:
|
30 |
+
config:
|
31 |
+
- name: Fast PyTorch CPU tests on Ubuntu
|
32 |
+
framework: pytorch
|
33 |
+
runner: aws-general-8-plus
|
34 |
+
image: diffusers/diffusers-pytorch-cpu
|
35 |
+
report: torch_cpu
|
36 |
+
- name: Fast Flax CPU tests on Ubuntu
|
37 |
+
framework: flax
|
38 |
+
runner: aws-general-8-plus
|
39 |
+
image: diffusers/diffusers-flax-cpu
|
40 |
+
report: flax_cpu
|
41 |
+
- name: Fast ONNXRuntime CPU tests on Ubuntu
|
42 |
+
framework: onnxruntime
|
43 |
+
runner: aws-general-8-plus
|
44 |
+
image: diffusers/diffusers-onnxruntime-cpu
|
45 |
+
report: onnx_cpu
|
46 |
+
- name: PyTorch Example CPU tests on Ubuntu
|
47 |
+
framework: pytorch_examples
|
48 |
+
runner: aws-general-8-plus
|
49 |
+
image: diffusers/diffusers-pytorch-cpu
|
50 |
+
report: torch_example_cpu
|
51 |
+
|
52 |
+
name: ${{ matrix.config.name }}
|
53 |
+
|
54 |
+
runs-on:
|
55 |
+
group: ${{ matrix.config.runner }}
|
56 |
+
|
57 |
+
container:
|
58 |
+
image: ${{ matrix.config.image }}
|
59 |
+
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
|
60 |
+
|
61 |
+
defaults:
|
62 |
+
run:
|
63 |
+
shell: bash
|
64 |
+
|
65 |
+
steps:
|
66 |
+
- name: Checkout diffusers
|
67 |
+
uses: actions/checkout@v3
|
68 |
+
with:
|
69 |
+
fetch-depth: 2
|
70 |
+
|
71 |
+
- name: Install dependencies
|
72 |
+
run: |
|
73 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
74 |
+
python -m uv pip install -e [quality,test]
|
75 |
+
|
76 |
+
- name: Environment
|
77 |
+
run: |
|
78 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
79 |
+
python utils/print_env.py
|
80 |
+
|
81 |
+
- name: Run fast PyTorch CPU tests
|
82 |
+
if: ${{ matrix.config.framework == 'pytorch' }}
|
83 |
+
run: |
|
84 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
85 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
86 |
+
-s -v -k "not Flax and not Onnx" \
|
87 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
88 |
+
tests/
|
89 |
+
|
90 |
+
- name: Run fast Flax TPU tests
|
91 |
+
if: ${{ matrix.config.framework == 'flax' }}
|
92 |
+
run: |
|
93 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
94 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
95 |
+
-s -v -k "Flax" \
|
96 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
97 |
+
tests/
|
98 |
+
|
99 |
+
- name: Run fast ONNXRuntime CPU tests
|
100 |
+
if: ${{ matrix.config.framework == 'onnxruntime' }}
|
101 |
+
run: |
|
102 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
103 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
104 |
+
-s -v -k "Onnx" \
|
105 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
106 |
+
tests/
|
107 |
+
|
108 |
+
- name: Run example PyTorch CPU tests
|
109 |
+
if: ${{ matrix.config.framework == 'pytorch_examples' }}
|
110 |
+
run: |
|
111 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
112 |
+
python -m uv pip install peft timm
|
113 |
+
python -m pytest -n 4 --max-worker-restart=0 --dist=loadfile \
|
114 |
+
--make-reports=tests_${{ matrix.config.report }} \
|
115 |
+
examples
|
116 |
+
|
117 |
+
- name: Failure short reports
|
118 |
+
if: ${{ failure() }}
|
119 |
+
run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
|
120 |
+
|
121 |
+
- name: Test suite reports artifacts
|
122 |
+
if: ${{ always() }}
|
123 |
+
uses: actions/upload-artifact@v4
|
124 |
+
with:
|
125 |
+
name: pr_${{ matrix.config.report }}_test_reports
|
126 |
+
path: reports
|
diffusers/.github/workflows/push_tests_mps.yml
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Fast mps tests on main
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
paths:
|
8 |
+
- "src/diffusers/**.py"
|
9 |
+
- "tests/**.py"
|
10 |
+
|
11 |
+
env:
|
12 |
+
DIFFUSERS_IS_CI: yes
|
13 |
+
HF_HOME: /mnt/cache
|
14 |
+
OMP_NUM_THREADS: 8
|
15 |
+
MKL_NUM_THREADS: 8
|
16 |
+
HF_HUB_ENABLE_HF_TRANSFER: 1
|
17 |
+
PYTEST_TIMEOUT: 600
|
18 |
+
RUN_SLOW: no
|
19 |
+
|
20 |
+
concurrency:
|
21 |
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
22 |
+
cancel-in-progress: true
|
23 |
+
|
24 |
+
jobs:
|
25 |
+
run_fast_tests_apple_m1:
|
26 |
+
name: Fast PyTorch MPS tests on MacOS
|
27 |
+
runs-on: macos-13-xlarge
|
28 |
+
|
29 |
+
steps:
|
30 |
+
- name: Checkout diffusers
|
31 |
+
uses: actions/checkout@v3
|
32 |
+
with:
|
33 |
+
fetch-depth: 2
|
34 |
+
|
35 |
+
- name: Clean checkout
|
36 |
+
shell: arch -arch arm64 bash {0}
|
37 |
+
run: |
|
38 |
+
git clean -fxd
|
39 |
+
|
40 |
+
- name: Setup miniconda
|
41 |
+
uses: ./.github/actions/setup-miniconda
|
42 |
+
with:
|
43 |
+
python-version: 3.9
|
44 |
+
|
45 |
+
- name: Install dependencies
|
46 |
+
shell: arch -arch arm64 bash {0}
|
47 |
+
run: |
|
48 |
+
${CONDA_RUN} python -m pip install --upgrade pip uv
|
49 |
+
${CONDA_RUN} python -m uv pip install -e [quality,test]
|
50 |
+
${CONDA_RUN} python -m uv pip install torch torchvision torchaudio
|
51 |
+
${CONDA_RUN} python -m uv pip install accelerate@git+https://github.com/huggingface/accelerate.git
|
52 |
+
${CONDA_RUN} python -m uv pip install transformers --upgrade
|
53 |
+
|
54 |
+
- name: Environment
|
55 |
+
shell: arch -arch arm64 bash {0}
|
56 |
+
run: |
|
57 |
+
${CONDA_RUN} python utils/print_env.py
|
58 |
+
|
59 |
+
- name: Run fast PyTorch tests on M1 (MPS)
|
60 |
+
shell: arch -arch arm64 bash {0}
|
61 |
+
env:
|
62 |
+
HF_HOME: /System/Volumes/Data/mnt/cache
|
63 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
64 |
+
run: |
|
65 |
+
${CONDA_RUN} python -m pytest -n 0 -s -v --make-reports=tests_torch_mps tests/
|
66 |
+
|
67 |
+
- name: Failure short reports
|
68 |
+
if: ${{ failure() }}
|
69 |
+
run: cat reports/tests_torch_mps_failures_short.txt
|
70 |
+
|
71 |
+
- name: Test suite reports artifacts
|
72 |
+
if: ${{ always() }}
|
73 |
+
uses: actions/upload-artifact@v4
|
74 |
+
with:
|
75 |
+
name: pr_torch_mps_test_reports
|
76 |
+
path: reports
|
diffusers/.github/workflows/pypi_publish.yaml
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Adapted from https://blog.deepjyoti30.dev/pypi-release-github-action
|
2 |
+
|
3 |
+
name: PyPI release
|
4 |
+
|
5 |
+
on:
|
6 |
+
workflow_dispatch:
|
7 |
+
push:
|
8 |
+
tags:
|
9 |
+
- "*"
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
find-and-checkout-latest-branch:
|
13 |
+
runs-on: ubuntu-22.04
|
14 |
+
outputs:
|
15 |
+
latest_branch: ${{ steps.set_latest_branch.outputs.latest_branch }}
|
16 |
+
steps:
|
17 |
+
- name: Checkout Repo
|
18 |
+
uses: actions/checkout@v3
|
19 |
+
|
20 |
+
- name: Set up Python
|
21 |
+
uses: actions/setup-python@v4
|
22 |
+
with:
|
23 |
+
python-version: '3.8'
|
24 |
+
|
25 |
+
- name: Fetch latest branch
|
26 |
+
id: fetch_latest_branch
|
27 |
+
run: |
|
28 |
+
pip install -U requests packaging
|
29 |
+
LATEST_BRANCH=$(python utils/fetch_latest_release_branch.py)
|
30 |
+
echo "Latest branch: $LATEST_BRANCH"
|
31 |
+
echo "latest_branch=$LATEST_BRANCH" >> $GITHUB_ENV
|
32 |
+
|
33 |
+
- name: Set latest branch output
|
34 |
+
id: set_latest_branch
|
35 |
+
run: echo "::set-output name=latest_branch::${{ env.latest_branch }}"
|
36 |
+
|
37 |
+
release:
|
38 |
+
needs: find-and-checkout-latest-branch
|
39 |
+
runs-on: ubuntu-22.04
|
40 |
+
|
41 |
+
steps:
|
42 |
+
- name: Checkout Repo
|
43 |
+
uses: actions/checkout@v3
|
44 |
+
with:
|
45 |
+
ref: ${{ needs.find-and-checkout-latest-branch.outputs.latest_branch }}
|
46 |
+
|
47 |
+
- name: Setup Python
|
48 |
+
uses: actions/setup-python@v4
|
49 |
+
with:
|
50 |
+
python-version: "3.8"
|
51 |
+
|
52 |
+
- name: Install dependencies
|
53 |
+
run: |
|
54 |
+
python -m pip install --upgrade pip
|
55 |
+
pip install -U setuptools wheel twine
|
56 |
+
pip install -U torch --index-url https://download.pytorch.org/whl/cpu
|
57 |
+
pip install -U transformers
|
58 |
+
|
59 |
+
- name: Build the dist files
|
60 |
+
run: python setup.py bdist_wheel && python setup.py sdist
|
61 |
+
|
62 |
+
- name: Publish to the test PyPI
|
63 |
+
env:
|
64 |
+
TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }}
|
65 |
+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }}
|
66 |
+
run: twine upload dist/* -r pypitest --repository-url=https://test.pypi.org/legacy/
|
67 |
+
|
68 |
+
- name: Test installing diffusers and importing
|
69 |
+
run: |
|
70 |
+
pip install diffusers && pip uninstall diffusers -y
|
71 |
+
pip install -i https://testpypi.python.org/pypi diffusers
|
72 |
+
python -c "from diffusers import __version__; print(__version__)"
|
73 |
+
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('fusing/unet-ldm-dummy-update'); pipe()"
|
74 |
+
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe', safety_checker=None); pipe('ah suh du')"
|
75 |
+
python -c "from diffusers import *"
|
76 |
+
|
77 |
+
- name: Publish to PyPI
|
78 |
+
env:
|
79 |
+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
80 |
+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
81 |
+
run: twine upload dist/* -r pypi
|
diffusers/.github/workflows/release_tests_fast.yml
ADDED
@@ -0,0 +1,389 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Duplicate workflow to push_tests.yml that is meant to run on release/patch branches as a final check
|
2 |
+
# Creating a duplicate workflow here is simpler than adding complex path/branch parsing logic to push_tests.yml
|
3 |
+
# Needs to be updated if push_tests.yml updated
|
4 |
+
name: (Release) Fast GPU Tests on main
|
5 |
+
|
6 |
+
on:
|
7 |
+
push:
|
8 |
+
branches:
|
9 |
+
- "v*.*.*-release"
|
10 |
+
- "v*.*.*-patch"
|
11 |
+
|
12 |
+
env:
|
13 |
+
DIFFUSERS_IS_CI: yes
|
14 |
+
OMP_NUM_THREADS: 8
|
15 |
+
MKL_NUM_THREADS: 8
|
16 |
+
PYTEST_TIMEOUT: 600
|
17 |
+
PIPELINE_USAGE_CUTOFF: 50000
|
18 |
+
|
19 |
+
jobs:
|
20 |
+
setup_torch_cuda_pipeline_matrix:
|
21 |
+
name: Setup Torch Pipelines CUDA Slow Tests Matrix
|
22 |
+
runs-on:
|
23 |
+
group: aws-general-8-plus
|
24 |
+
container:
|
25 |
+
image: diffusers/diffusers-pytorch-cpu
|
26 |
+
outputs:
|
27 |
+
pipeline_test_matrix: ${{ steps.fetch_pipeline_matrix.outputs.pipeline_test_matrix }}
|
28 |
+
steps:
|
29 |
+
- name: Checkout diffusers
|
30 |
+
uses: actions/checkout@v3
|
31 |
+
with:
|
32 |
+
fetch-depth: 2
|
33 |
+
- name: Install dependencies
|
34 |
+
run: |
|
35 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
36 |
+
python -m uv pip install -e [quality,test]
|
37 |
+
- name: Environment
|
38 |
+
run: |
|
39 |
+
python utils/print_env.py
|
40 |
+
- name: Fetch Pipeline Matrix
|
41 |
+
id: fetch_pipeline_matrix
|
42 |
+
run: |
|
43 |
+
matrix=$(python utils/fetch_torch_cuda_pipeline_test_matrix.py)
|
44 |
+
echo $matrix
|
45 |
+
echo "pipeline_test_matrix=$matrix" >> $GITHUB_OUTPUT
|
46 |
+
- name: Pipeline Tests Artifacts
|
47 |
+
if: ${{ always() }}
|
48 |
+
uses: actions/upload-artifact@v4
|
49 |
+
with:
|
50 |
+
name: test-pipelines.json
|
51 |
+
path: reports
|
52 |
+
|
53 |
+
torch_pipelines_cuda_tests:
|
54 |
+
name: Torch Pipelines CUDA Tests
|
55 |
+
needs: setup_torch_cuda_pipeline_matrix
|
56 |
+
strategy:
|
57 |
+
fail-fast: false
|
58 |
+
max-parallel: 8
|
59 |
+
matrix:
|
60 |
+
module: ${{ fromJson(needs.setup_torch_cuda_pipeline_matrix.outputs.pipeline_test_matrix) }}
|
61 |
+
runs-on:
|
62 |
+
group: aws-g4dn-2xlarge
|
63 |
+
container:
|
64 |
+
image: diffusers/diffusers-pytorch-cuda
|
65 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
66 |
+
steps:
|
67 |
+
- name: Checkout diffusers
|
68 |
+
uses: actions/checkout@v3
|
69 |
+
with:
|
70 |
+
fetch-depth: 2
|
71 |
+
- name: NVIDIA-SMI
|
72 |
+
run: |
|
73 |
+
nvidia-smi
|
74 |
+
- name: Install dependencies
|
75 |
+
run: |
|
76 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
77 |
+
python -m uv pip install -e [quality,test]
|
78 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
79 |
+
- name: Environment
|
80 |
+
run: |
|
81 |
+
python utils/print_env.py
|
82 |
+
- name: Slow PyTorch CUDA checkpoint tests on Ubuntu
|
83 |
+
env:
|
84 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
85 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
86 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
87 |
+
run: |
|
88 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
89 |
+
-s -v -k "not Flax and not Onnx" \
|
90 |
+
--make-reports=tests_pipeline_${{ matrix.module }}_cuda \
|
91 |
+
tests/pipelines/${{ matrix.module }}
|
92 |
+
- name: Failure short reports
|
93 |
+
if: ${{ failure() }}
|
94 |
+
run: |
|
95 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_stats.txt
|
96 |
+
cat reports/tests_pipeline_${{ matrix.module }}_cuda_failures_short.txt
|
97 |
+
- name: Test suite reports artifacts
|
98 |
+
if: ${{ always() }}
|
99 |
+
uses: actions/upload-artifact@v4
|
100 |
+
with:
|
101 |
+
name: pipeline_${{ matrix.module }}_test_reports
|
102 |
+
path: reports
|
103 |
+
|
104 |
+
torch_cuda_tests:
|
105 |
+
name: Torch CUDA Tests
|
106 |
+
runs-on:
|
107 |
+
group: aws-g4dn-2xlarge
|
108 |
+
container:
|
109 |
+
image: diffusers/diffusers-pytorch-cuda
|
110 |
+
options: --shm-size "16gb" --ipc host --gpus 0
|
111 |
+
defaults:
|
112 |
+
run:
|
113 |
+
shell: bash
|
114 |
+
strategy:
|
115 |
+
fail-fast: false
|
116 |
+
max-parallel: 2
|
117 |
+
matrix:
|
118 |
+
module: [models, schedulers, lora, others, single_file]
|
119 |
+
steps:
|
120 |
+
- name: Checkout diffusers
|
121 |
+
uses: actions/checkout@v3
|
122 |
+
with:
|
123 |
+
fetch-depth: 2
|
124 |
+
|
125 |
+
- name: Install dependencies
|
126 |
+
run: |
|
127 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
128 |
+
python -m uv pip install -e [quality,test]
|
129 |
+
python -m uv pip install peft@git+https://github.com/huggingface/peft.git
|
130 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
131 |
+
|
132 |
+
- name: Environment
|
133 |
+
run: |
|
134 |
+
python utils/print_env.py
|
135 |
+
|
136 |
+
- name: Run PyTorch CUDA tests
|
137 |
+
env:
|
138 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
139 |
+
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
|
140 |
+
CUBLAS_WORKSPACE_CONFIG: :16:8
|
141 |
+
run: |
|
142 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
143 |
+
-s -v -k "not Flax and not Onnx" \
|
144 |
+
--make-reports=tests_torch_${{ matrix.module }}_cuda \
|
145 |
+
tests/${{ matrix.module }}
|
146 |
+
|
147 |
+
- name: Failure short reports
|
148 |
+
if: ${{ failure() }}
|
149 |
+
run: |
|
150 |
+
cat reports/tests_torch_${{ matrix.module }}_cuda_stats.txt
|
151 |
+
cat reports/tests_torch_${{ matrix.module }}_cuda_failures_short.txt
|
152 |
+
|
153 |
+
- name: Test suite reports artifacts
|
154 |
+
if: ${{ always() }}
|
155 |
+
uses: actions/upload-artifact@v4
|
156 |
+
with:
|
157 |
+
name: torch_cuda_${{ matrix.module }}_test_reports
|
158 |
+
path: reports
|
159 |
+
|
160 |
+
flax_tpu_tests:
|
161 |
+
name: Flax TPU Tests
|
162 |
+
runs-on: docker-tpu
|
163 |
+
container:
|
164 |
+
image: diffusers/diffusers-flax-tpu
|
165 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ --privileged
|
166 |
+
defaults:
|
167 |
+
run:
|
168 |
+
shell: bash
|
169 |
+
steps:
|
170 |
+
- name: Checkout diffusers
|
171 |
+
uses: actions/checkout@v3
|
172 |
+
with:
|
173 |
+
fetch-depth: 2
|
174 |
+
|
175 |
+
- name: Install dependencies
|
176 |
+
run: |
|
177 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
178 |
+
python -m uv pip install -e [quality,test]
|
179 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
180 |
+
|
181 |
+
- name: Environment
|
182 |
+
run: |
|
183 |
+
python utils/print_env.py
|
184 |
+
|
185 |
+
- name: Run slow Flax TPU tests
|
186 |
+
env:
|
187 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
188 |
+
run: |
|
189 |
+
python -m pytest -n 0 \
|
190 |
+
-s -v -k "Flax" \
|
191 |
+
--make-reports=tests_flax_tpu \
|
192 |
+
tests/
|
193 |
+
|
194 |
+
- name: Failure short reports
|
195 |
+
if: ${{ failure() }}
|
196 |
+
run: |
|
197 |
+
cat reports/tests_flax_tpu_stats.txt
|
198 |
+
cat reports/tests_flax_tpu_failures_short.txt
|
199 |
+
|
200 |
+
- name: Test suite reports artifacts
|
201 |
+
if: ${{ always() }}
|
202 |
+
uses: actions/upload-artifact@v4
|
203 |
+
with:
|
204 |
+
name: flax_tpu_test_reports
|
205 |
+
path: reports
|
206 |
+
|
207 |
+
onnx_cuda_tests:
|
208 |
+
name: ONNX CUDA Tests
|
209 |
+
runs-on:
|
210 |
+
group: aws-g4dn-2xlarge
|
211 |
+
container:
|
212 |
+
image: diffusers/diffusers-onnxruntime-cuda
|
213 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ --gpus 0
|
214 |
+
defaults:
|
215 |
+
run:
|
216 |
+
shell: bash
|
217 |
+
steps:
|
218 |
+
- name: Checkout diffusers
|
219 |
+
uses: actions/checkout@v3
|
220 |
+
with:
|
221 |
+
fetch-depth: 2
|
222 |
+
|
223 |
+
- name: Install dependencies
|
224 |
+
run: |
|
225 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
226 |
+
python -m uv pip install -e [quality,test]
|
227 |
+
pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
|
228 |
+
|
229 |
+
- name: Environment
|
230 |
+
run: |
|
231 |
+
python utils/print_env.py
|
232 |
+
|
233 |
+
- name: Run slow ONNXRuntime CUDA tests
|
234 |
+
env:
|
235 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
236 |
+
run: |
|
237 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
|
238 |
+
-s -v -k "Onnx" \
|
239 |
+
--make-reports=tests_onnx_cuda \
|
240 |
+
tests/
|
241 |
+
|
242 |
+
- name: Failure short reports
|
243 |
+
if: ${{ failure() }}
|
244 |
+
run: |
|
245 |
+
cat reports/tests_onnx_cuda_stats.txt
|
246 |
+
cat reports/tests_onnx_cuda_failures_short.txt
|
247 |
+
|
248 |
+
- name: Test suite reports artifacts
|
249 |
+
if: ${{ always() }}
|
250 |
+
uses: actions/upload-artifact@v4
|
251 |
+
with:
|
252 |
+
name: onnx_cuda_test_reports
|
253 |
+
path: reports
|
254 |
+
|
255 |
+
run_torch_compile_tests:
|
256 |
+
name: PyTorch Compile CUDA tests
|
257 |
+
|
258 |
+
runs-on:
|
259 |
+
group: aws-g4dn-2xlarge
|
260 |
+
|
261 |
+
container:
|
262 |
+
image: diffusers/diffusers-pytorch-compile-cuda
|
263 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
264 |
+
|
265 |
+
steps:
|
266 |
+
- name: Checkout diffusers
|
267 |
+
uses: actions/checkout@v3
|
268 |
+
with:
|
269 |
+
fetch-depth: 2
|
270 |
+
|
271 |
+
- name: NVIDIA-SMI
|
272 |
+
run: |
|
273 |
+
nvidia-smi
|
274 |
+
- name: Install dependencies
|
275 |
+
run: |
|
276 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
277 |
+
python -m uv pip install -e [quality,test,training]
|
278 |
+
- name: Environment
|
279 |
+
run: |
|
280 |
+
python utils/print_env.py
|
281 |
+
- name: Run example tests on GPU
|
282 |
+
env:
|
283 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
284 |
+
RUN_COMPILE: yes
|
285 |
+
run: |
|
286 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "compile" --make-reports=tests_torch_compile_cuda tests/
|
287 |
+
- name: Failure short reports
|
288 |
+
if: ${{ failure() }}
|
289 |
+
run: cat reports/tests_torch_compile_cuda_failures_short.txt
|
290 |
+
|
291 |
+
- name: Test suite reports artifacts
|
292 |
+
if: ${{ always() }}
|
293 |
+
uses: actions/upload-artifact@v4
|
294 |
+
with:
|
295 |
+
name: torch_compile_test_reports
|
296 |
+
path: reports
|
297 |
+
|
298 |
+
run_xformers_tests:
|
299 |
+
name: PyTorch xformers CUDA tests
|
300 |
+
|
301 |
+
runs-on:
|
302 |
+
group: aws-g4dn-2xlarge
|
303 |
+
|
304 |
+
container:
|
305 |
+
image: diffusers/diffusers-pytorch-xformers-cuda
|
306 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
307 |
+
|
308 |
+
steps:
|
309 |
+
- name: Checkout diffusers
|
310 |
+
uses: actions/checkout@v3
|
311 |
+
with:
|
312 |
+
fetch-depth: 2
|
313 |
+
|
314 |
+
- name: NVIDIA-SMI
|
315 |
+
run: |
|
316 |
+
nvidia-smi
|
317 |
+
- name: Install dependencies
|
318 |
+
run: |
|
319 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
320 |
+
python -m uv pip install -e [quality,test,training]
|
321 |
+
- name: Environment
|
322 |
+
run: |
|
323 |
+
python utils/print_env.py
|
324 |
+
- name: Run example tests on GPU
|
325 |
+
env:
|
326 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
327 |
+
run: |
|
328 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "xformers" --make-reports=tests_torch_xformers_cuda tests/
|
329 |
+
- name: Failure short reports
|
330 |
+
if: ${{ failure() }}
|
331 |
+
run: cat reports/tests_torch_xformers_cuda_failures_short.txt
|
332 |
+
|
333 |
+
- name: Test suite reports artifacts
|
334 |
+
if: ${{ always() }}
|
335 |
+
uses: actions/upload-artifact@v4
|
336 |
+
with:
|
337 |
+
name: torch_xformers_test_reports
|
338 |
+
path: reports
|
339 |
+
|
340 |
+
run_examples_tests:
|
341 |
+
name: Examples PyTorch CUDA tests on Ubuntu
|
342 |
+
|
343 |
+
runs-on:
|
344 |
+
group: aws-g4dn-2xlarge
|
345 |
+
|
346 |
+
container:
|
347 |
+
image: diffusers/diffusers-pytorch-cuda
|
348 |
+
options: --gpus 0 --shm-size "16gb" --ipc host
|
349 |
+
|
350 |
+
steps:
|
351 |
+
- name: Checkout diffusers
|
352 |
+
uses: actions/checkout@v3
|
353 |
+
with:
|
354 |
+
fetch-depth: 2
|
355 |
+
|
356 |
+
- name: NVIDIA-SMI
|
357 |
+
run: |
|
358 |
+
nvidia-smi
|
359 |
+
|
360 |
+
- name: Install dependencies
|
361 |
+
run: |
|
362 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
363 |
+
python -m uv pip install -e [quality,test,training]
|
364 |
+
|
365 |
+
- name: Environment
|
366 |
+
run: |
|
367 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
368 |
+
python utils/print_env.py
|
369 |
+
|
370 |
+
- name: Run example tests on GPU
|
371 |
+
env:
|
372 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
373 |
+
run: |
|
374 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
375 |
+
python -m uv pip install timm
|
376 |
+
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v --make-reports=examples_torch_cuda examples/
|
377 |
+
|
378 |
+
- name: Failure short reports
|
379 |
+
if: ${{ failure() }}
|
380 |
+
run: |
|
381 |
+
cat reports/examples_torch_cuda_stats.txt
|
382 |
+
cat reports/examples_torch_cuda_failures_short.txt
|
383 |
+
|
384 |
+
- name: Test suite reports artifacts
|
385 |
+
if: ${{ always() }}
|
386 |
+
uses: actions/upload-artifact@v4
|
387 |
+
with:
|
388 |
+
name: examples_test_reports
|
389 |
+
path: reports
|
diffusers/.github/workflows/run_tests_from_a_pr.yml
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Check running SLOW tests from a PR (only GPU)
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
docker_image:
|
7 |
+
default: 'diffusers/diffusers-pytorch-cuda'
|
8 |
+
description: 'Name of the Docker image'
|
9 |
+
required: true
|
10 |
+
branch:
|
11 |
+
description: 'PR Branch to test on'
|
12 |
+
required: true
|
13 |
+
test:
|
14 |
+
description: 'Tests to run (e.g.: `tests/models`).'
|
15 |
+
required: true
|
16 |
+
|
17 |
+
env:
|
18 |
+
DIFFUSERS_IS_CI: yes
|
19 |
+
IS_GITHUB_CI: "1"
|
20 |
+
HF_HOME: /mnt/cache
|
21 |
+
OMP_NUM_THREADS: 8
|
22 |
+
MKL_NUM_THREADS: 8
|
23 |
+
PYTEST_TIMEOUT: 600
|
24 |
+
RUN_SLOW: yes
|
25 |
+
|
26 |
+
jobs:
|
27 |
+
run_tests:
|
28 |
+
name: "Run a test on our runner from a PR"
|
29 |
+
runs-on:
|
30 |
+
group: aws-g4dn-2xlarge
|
31 |
+
container:
|
32 |
+
image: ${{ github.event.inputs.docker_image }}
|
33 |
+
options: --gpus 0 --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
|
34 |
+
|
35 |
+
steps:
|
36 |
+
- name: Validate test files input
|
37 |
+
id: validate_test_files
|
38 |
+
env:
|
39 |
+
PY_TEST: ${{ github.event.inputs.test }}
|
40 |
+
run: |
|
41 |
+
if [[ ! "$PY_TEST" =~ ^tests/ ]]; then
|
42 |
+
echo "Error: The input string must start with 'tests/'."
|
43 |
+
exit 1
|
44 |
+
fi
|
45 |
+
|
46 |
+
if [[ ! "$PY_TEST" =~ ^tests/(models|pipelines) ]]; then
|
47 |
+
echo "Error: The input string must contain either 'models' or 'pipelines' after 'tests/'."
|
48 |
+
exit 1
|
49 |
+
fi
|
50 |
+
|
51 |
+
if [[ "$PY_TEST" == *";"* ]]; then
|
52 |
+
echo "Error: The input string must not contain ';'."
|
53 |
+
exit 1
|
54 |
+
fi
|
55 |
+
echo "$PY_TEST"
|
56 |
+
|
57 |
+
- name: Checkout PR branch
|
58 |
+
uses: actions/checkout@v4
|
59 |
+
with:
|
60 |
+
ref: ${{ github.event.inputs.branch }}
|
61 |
+
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
62 |
+
|
63 |
+
|
64 |
+
- name: Install pytest
|
65 |
+
run: |
|
66 |
+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
|
67 |
+
python -m uv pip install -e [quality,test]
|
68 |
+
python -m uv pip install peft
|
69 |
+
|
70 |
+
- name: Run tests
|
71 |
+
env:
|
72 |
+
PY_TEST: ${{ github.event.inputs.test }}
|
73 |
+
run: |
|
74 |
+
pytest "$PY_TEST"
|
diffusers/.github/workflows/ssh-pr-runner.yml
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: SSH into PR runners
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
docker_image:
|
7 |
+
description: 'Name of the Docker image'
|
8 |
+
required: true
|
9 |
+
|
10 |
+
env:
|
11 |
+
IS_GITHUB_CI: "1"
|
12 |
+
HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }}
|
13 |
+
HF_HOME: /mnt/cache
|
14 |
+
DIFFUSERS_IS_CI: yes
|
15 |
+
OMP_NUM_THREADS: 8
|
16 |
+
MKL_NUM_THREADS: 8
|
17 |
+
RUN_SLOW: yes
|
18 |
+
|
19 |
+
jobs:
|
20 |
+
ssh_runner:
|
21 |
+
name: "SSH"
|
22 |
+
runs-on:
|
23 |
+
group: aws-highmemory-32-plus
|
24 |
+
container:
|
25 |
+
image: ${{ github.event.inputs.docker_image }}
|
26 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface/diffusers:/mnt/cache/ --privileged
|
27 |
+
|
28 |
+
steps:
|
29 |
+
- name: Checkout diffusers
|
30 |
+
uses: actions/checkout@v3
|
31 |
+
with:
|
32 |
+
fetch-depth: 2
|
33 |
+
|
34 |
+
- name: Tailscale # In order to be able to SSH when a test fails
|
35 |
+
uses: huggingface/tailscale-action@main
|
36 |
+
with:
|
37 |
+
authkey: ${{ secrets.TAILSCALE_SSH_AUTHKEY }}
|
38 |
+
slackChannel: ${{ secrets.SLACK_CIFEEDBACK_CHANNEL }}
|
39 |
+
slackToken: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
|
40 |
+
waitForSSH: true
|
diffusers/.github/workflows/ssh-runner.yml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: SSH into GPU runners
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
runner_type:
|
7 |
+
description: 'Type of runner to test (aws-g6-4xlarge-plus: a10 or aws-g4dn-2xlarge: t4)'
|
8 |
+
type: choice
|
9 |
+
required: true
|
10 |
+
options:
|
11 |
+
- aws-g6-4xlarge-plus
|
12 |
+
- aws-g4dn-2xlarge
|
13 |
+
docker_image:
|
14 |
+
description: 'Name of the Docker image'
|
15 |
+
required: true
|
16 |
+
|
17 |
+
env:
|
18 |
+
IS_GITHUB_CI: "1"
|
19 |
+
HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }}
|
20 |
+
HF_HOME: /mnt/cache
|
21 |
+
DIFFUSERS_IS_CI: yes
|
22 |
+
OMP_NUM_THREADS: 8
|
23 |
+
MKL_NUM_THREADS: 8
|
24 |
+
RUN_SLOW: yes
|
25 |
+
|
26 |
+
jobs:
|
27 |
+
ssh_runner:
|
28 |
+
name: "SSH"
|
29 |
+
runs-on:
|
30 |
+
group: "${{ github.event.inputs.runner_type }}"
|
31 |
+
container:
|
32 |
+
image: ${{ github.event.inputs.docker_image }}
|
33 |
+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface/diffusers:/mnt/cache/ --gpus 0 --privileged
|
34 |
+
|
35 |
+
steps:
|
36 |
+
- name: Checkout diffusers
|
37 |
+
uses: actions/checkout@v3
|
38 |
+
with:
|
39 |
+
fetch-depth: 2
|
40 |
+
|
41 |
+
- name: NVIDIA-SMI
|
42 |
+
run: |
|
43 |
+
nvidia-smi
|
44 |
+
|
45 |
+
- name: Tailscale # In order to be able to SSH when a test fails
|
46 |
+
uses: huggingface/tailscale-action@main
|
47 |
+
with:
|
48 |
+
authkey: ${{ secrets.TAILSCALE_SSH_AUTHKEY }}
|
49 |
+
slackChannel: ${{ secrets.SLACK_CIFEEDBACK_CHANNEL }}
|
50 |
+
slackToken: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
|
51 |
+
waitForSSH: true
|
diffusers/.github/workflows/stale.yml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Stale Bot
|
2 |
+
|
3 |
+
on:
|
4 |
+
schedule:
|
5 |
+
- cron: "0 15 * * *"
|
6 |
+
|
7 |
+
jobs:
|
8 |
+
close_stale_issues:
|
9 |
+
name: Close Stale Issues
|
10 |
+
if: github.repository == 'huggingface/diffusers'
|
11 |
+
runs-on: ubuntu-22.04
|
12 |
+
permissions:
|
13 |
+
issues: write
|
14 |
+
pull-requests: write
|
15 |
+
env:
|
16 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
17 |
+
steps:
|
18 |
+
- uses: actions/checkout@v2
|
19 |
+
|
20 |
+
- name: Setup Python
|
21 |
+
uses: actions/setup-python@v1
|
22 |
+
with:
|
23 |
+
python-version: 3.8
|
24 |
+
|
25 |
+
- name: Install requirements
|
26 |
+
run: |
|
27 |
+
pip install PyGithub
|
28 |
+
- name: Close stale issues
|
29 |
+
run: |
|
30 |
+
python utils/stale.py
|
diffusers/.github/workflows/trufflehog.yml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
on:
|
2 |
+
push:
|
3 |
+
|
4 |
+
name: Secret Leaks
|
5 |
+
|
6 |
+
jobs:
|
7 |
+
trufflehog:
|
8 |
+
runs-on: ubuntu-22.04
|
9 |
+
steps:
|
10 |
+
- name: Checkout code
|
11 |
+
uses: actions/checkout@v4
|
12 |
+
with:
|
13 |
+
fetch-depth: 0
|
14 |
+
- name: Secret Scanning
|
15 |
+
uses: trufflesecurity/trufflehog@main
|
diffusers/.github/workflows/typos.yml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Check typos
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
|
6 |
+
jobs:
|
7 |
+
build:
|
8 |
+
runs-on: ubuntu-22.04
|
9 |
+
|
10 |
+
steps:
|
11 |
+
- uses: actions/checkout@v3
|
12 |
+
|
13 |
+
- name: typos-action
|
14 |
+
uses: crate-ci/[email protected]
|
diffusers/.github/workflows/update_metadata.yml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Update Diffusers metadata
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
push:
|
6 |
+
branches:
|
7 |
+
- main
|
8 |
+
- update_diffusers_metadata*
|
9 |
+
|
10 |
+
jobs:
|
11 |
+
update_metadata:
|
12 |
+
runs-on: ubuntu-22.04
|
13 |
+
defaults:
|
14 |
+
run:
|
15 |
+
shell: bash -l {0}
|
16 |
+
|
17 |
+
steps:
|
18 |
+
- uses: actions/checkout@v3
|
19 |
+
|
20 |
+
- name: Setup environment
|
21 |
+
run: |
|
22 |
+
pip install --upgrade pip
|
23 |
+
pip install datasets pandas
|
24 |
+
pip install .[torch]
|
25 |
+
|
26 |
+
- name: Update metadata
|
27 |
+
env:
|
28 |
+
HF_TOKEN: ${{ secrets.SAYAK_HF_TOKEN }}
|
29 |
+
run: |
|
30 |
+
python utils/update_metadata.py --commit_sha ${{ github.sha }}
|
diffusers/.github/workflows/upload_pr_documentation.yml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Upload PR Documentation
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_run:
|
5 |
+
workflows: ["Build PR Documentation"]
|
6 |
+
types:
|
7 |
+
- completed
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
build:
|
11 |
+
uses: huggingface/doc-builder/.github/workflows/upload_pr_documentation.yml@main
|
12 |
+
with:
|
13 |
+
package_name: diffusers
|
14 |
+
secrets:
|
15 |
+
hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }}
|
16 |
+
comment_bot_token: ${{ secrets.COMMENT_BOT_TOKEN }}
|
diffusers/.gitignore
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Initially taken from GitHub's Python gitignore file
|
2 |
+
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
*.py[cod]
|
6 |
+
*$py.class
|
7 |
+
|
8 |
+
# C extensions
|
9 |
+
*.so
|
10 |
+
|
11 |
+
# tests and logs
|
12 |
+
tests/fixtures/cached_*_text.txt
|
13 |
+
logs/
|
14 |
+
lightning_logs/
|
15 |
+
lang_code_data/
|
16 |
+
|
17 |
+
# Distribution / packaging
|
18 |
+
.Python
|
19 |
+
build/
|
20 |
+
develop-eggs/
|
21 |
+
dist/
|
22 |
+
downloads/
|
23 |
+
eggs/
|
24 |
+
.eggs/
|
25 |
+
lib/
|
26 |
+
lib64/
|
27 |
+
parts/
|
28 |
+
sdist/
|
29 |
+
var/
|
30 |
+
wheels/
|
31 |
+
*.egg-info/
|
32 |
+
.installed.cfg
|
33 |
+
*.egg
|
34 |
+
MANIFEST
|
35 |
+
|
36 |
+
# PyInstaller
|
37 |
+
# Usually these files are written by a Python script from a template
|
38 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
39 |
+
*.manifest
|
40 |
+
*.spec
|
41 |
+
|
42 |
+
# Installer logs
|
43 |
+
pip-log.txt
|
44 |
+
pip-delete-this-directory.txt
|
45 |
+
|
46 |
+
# Unit test / coverage reports
|
47 |
+
htmlcov/
|
48 |
+
.tox/
|
49 |
+
.nox/
|
50 |
+
.coverage
|
51 |
+
.coverage.*
|
52 |
+
.cache
|
53 |
+
nosetests.xml
|
54 |
+
coverage.xml
|
55 |
+
*.cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
|
59 |
+
# Translations
|
60 |
+
*.mo
|
61 |
+
*.pot
|
62 |
+
|
63 |
+
# Django stuff:
|
64 |
+
*.log
|
65 |
+
local_settings.py
|
66 |
+
db.sqlite3
|
67 |
+
|
68 |
+
# Flask stuff:
|
69 |
+
instance/
|
70 |
+
.webassets-cache
|
71 |
+
|
72 |
+
# Scrapy stuff:
|
73 |
+
.scrapy
|
74 |
+
|
75 |
+
# Sphinx documentation
|
76 |
+
docs/_build/
|
77 |
+
|
78 |
+
# PyBuilder
|
79 |
+
target/
|
80 |
+
|
81 |
+
# Jupyter Notebook
|
82 |
+
.ipynb_checkpoints
|
83 |
+
|
84 |
+
# IPython
|
85 |
+
profile_default/
|
86 |
+
ipython_config.py
|
87 |
+
|
88 |
+
# pyenv
|
89 |
+
.python-version
|
90 |
+
|
91 |
+
# celery beat schedule file
|
92 |
+
celerybeat-schedule
|
93 |
+
|
94 |
+
# SageMath parsed files
|
95 |
+
*.sage.py
|
96 |
+
|
97 |
+
# Environments
|
98 |
+
.env
|
99 |
+
.venv
|
100 |
+
env/
|
101 |
+
venv/
|
102 |
+
ENV/
|
103 |
+
env.bak/
|
104 |
+
venv.bak/
|
105 |
+
|
106 |
+
# Spyder project settings
|
107 |
+
.spyderproject
|
108 |
+
.spyproject
|
109 |
+
|
110 |
+
# Rope project settings
|
111 |
+
.ropeproject
|
112 |
+
|
113 |
+
# mkdocs documentation
|
114 |
+
/site
|
115 |
+
|
116 |
+
# mypy
|
117 |
+
.mypy_cache/
|
118 |
+
.dmypy.json
|
119 |
+
dmypy.json
|
120 |
+
|
121 |
+
# Pyre type checker
|
122 |
+
.pyre/
|
123 |
+
|
124 |
+
# vscode
|
125 |
+
.vs
|
126 |
+
.vscode
|
127 |
+
|
128 |
+
# Pycharm
|
129 |
+
.idea
|
130 |
+
|
131 |
+
# TF code
|
132 |
+
tensorflow_code
|
133 |
+
|
134 |
+
# Models
|
135 |
+
proc_data
|
136 |
+
|
137 |
+
# examples
|
138 |
+
runs
|
139 |
+
/runs_old
|
140 |
+
/wandb
|
141 |
+
/examples/runs
|
142 |
+
/examples/**/*.args
|
143 |
+
/examples/rag/sweep
|
144 |
+
|
145 |
+
# data
|
146 |
+
/data
|
147 |
+
serialization_dir
|
148 |
+
|
149 |
+
# emacs
|
150 |
+
*.*~
|
151 |
+
debug.env
|
152 |
+
|
153 |
+
# vim
|
154 |
+
.*.swp
|
155 |
+
|
156 |
+
# ctags
|
157 |
+
tags
|
158 |
+
|
159 |
+
# pre-commit
|
160 |
+
.pre-commit*
|
161 |
+
|
162 |
+
# .lock
|
163 |
+
*.lock
|
164 |
+
|
165 |
+
# DS_Store (MacOS)
|
166 |
+
.DS_Store
|
167 |
+
|
168 |
+
# RL pipelines may produce mp4 outputs
|
169 |
+
*.mp4
|
170 |
+
|
171 |
+
# dependencies
|
172 |
+
/transformers
|
173 |
+
|
174 |
+
# ruff
|
175 |
+
.ruff_cache
|
176 |
+
|
177 |
+
# wandb
|
178 |
+
wandb
|
diffusers/CITATION.cff
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
cff-version: 1.2.0
|
2 |
+
title: 'Diffusers: State-of-the-art diffusion models'
|
3 |
+
message: >-
|
4 |
+
If you use this software, please cite it using the
|
5 |
+
metadata from this file.
|
6 |
+
type: software
|
7 |
+
authors:
|
8 |
+
- given-names: Patrick
|
9 |
+
family-names: von Platen
|
10 |
+
- given-names: Suraj
|
11 |
+
family-names: Patil
|
12 |
+
- given-names: Anton
|
13 |
+
family-names: Lozhkov
|
14 |
+
- given-names: Pedro
|
15 |
+
family-names: Cuenca
|
16 |
+
- given-names: Nathan
|
17 |
+
family-names: Lambert
|
18 |
+
- given-names: Kashif
|
19 |
+
family-names: Rasul
|
20 |
+
- given-names: Mishig
|
21 |
+
family-names: Davaadorj
|
22 |
+
- given-names: Dhruv
|
23 |
+
family-names: Nair
|
24 |
+
- given-names: Sayak
|
25 |
+
family-names: Paul
|
26 |
+
- given-names: Steven
|
27 |
+
family-names: Liu
|
28 |
+
- given-names: William
|
29 |
+
family-names: Berman
|
30 |
+
- given-names: Yiyi
|
31 |
+
family-names: Xu
|
32 |
+
- given-names: Thomas
|
33 |
+
family-names: Wolf
|
34 |
+
repository-code: 'https://github.com/huggingface/diffusers'
|
35 |
+
abstract: >-
|
36 |
+
Diffusers provides pretrained diffusion models across
|
37 |
+
multiple modalities, such as vision and audio, and serves
|
38 |
+
as a modular toolbox for inference and training of
|
39 |
+
diffusion models.
|
40 |
+
keywords:
|
41 |
+
- deep-learning
|
42 |
+
- pytorch
|
43 |
+
- image-generation
|
44 |
+
- hacktoberfest
|
45 |
+
- diffusion
|
46 |
+
- text2image
|
47 |
+
- image2image
|
48 |
+
- score-based-generative-modeling
|
49 |
+
- stable-diffusion
|
50 |
+
- stable-diffusion-diffusers
|
51 |
+
license: Apache-2.0
|
52 |
+
version: 0.12.1
|
diffusers/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Contributor Covenant Code of Conduct
|
3 |
+
|
4 |
+
## Our Pledge
|
5 |
+
|
6 |
+
We as members, contributors, and leaders pledge to make participation in our
|
7 |
+
community a harassment-free experience for everyone, regardless of age, body
|
8 |
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9 |
+
identity and expression, level of experience, education, socio-economic status,
|
10 |
+
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
11 |
+
and orientation.
|
12 |
+
|
13 |
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14 |
+
diverse, inclusive, and healthy community.
|
15 |
+
|
16 |
+
## Our Standards
|
17 |
+
|
18 |
+
Examples of behavior that contributes to a positive environment for our
|
19 |
+
community include:
|
20 |
+
|
21 |
+
* Demonstrating empathy and kindness toward other people
|
22 |
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23 |
+
* Giving and gracefully accepting constructive feedback
|
24 |
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25 |
+
and learning from the experience
|
26 |
+
* Focusing on what is best not just for us as individuals, but for the
|
27 |
+
overall Diffusers community
|
28 |
+
|
29 |
+
Examples of unacceptable behavior include:
|
30 |
+
|
31 |
+
* The use of sexualized language or imagery, and sexual attention or
|
32 |
+
advances of any kind
|
33 |
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
34 |
+
* Public or private harassment
|
35 |
+
* Publishing others' private information, such as a physical or email
|
36 |
+
address, without their explicit permission
|
37 |
+
* Spamming issues or PRs with links to projects unrelated to this library
|
38 |
+
* Other conduct which could reasonably be considered inappropriate in a
|
39 |
+
professional setting
|
40 |
+
|
41 |
+
## Enforcement Responsibilities
|
42 |
+
|
43 |
+
Community leaders are responsible for clarifying and enforcing our standards of
|
44 |
+
acceptable behavior and will take appropriate and fair corrective action in
|
45 |
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
46 |
+
or harmful.
|
47 |
+
|
48 |
+
Community leaders have the right and responsibility to remove, edit, or reject
|
49 |
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
50 |
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
51 |
+
decisions when appropriate.
|
52 |
+
|
53 |
+
## Scope
|
54 |
+
|
55 |
+
This Code of Conduct applies within all community spaces, and also applies when
|
56 |
+
an individual is officially representing the community in public spaces.
|
57 |
+
Examples of representing our community include using an official e-mail address,
|
58 |
+
posting via an official social media account, or acting as an appointed
|
59 |
+
representative at an online or offline event.
|
60 |
+
|
61 |
+
## Enforcement
|
62 |
+
|
63 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
64 |
+
reported to the community leaders responsible for enforcement at
|
65 | |
66 |
+
All complaints will be reviewed and investigated promptly and fairly.
|
67 |
+
|
68 |
+
All community leaders are obligated to respect the privacy and security of the
|
69 |
+
reporter of any incident.
|
70 |
+
|
71 |
+
## Enforcement Guidelines
|
72 |
+
|
73 |
+
Community leaders will follow these Community Impact Guidelines in determining
|
74 |
+
the consequences for any action they deem in violation of this Code of Conduct:
|
75 |
+
|
76 |
+
### 1. Correction
|
77 |
+
|
78 |
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
79 |
+
unprofessional or unwelcome in the community.
|
80 |
+
|
81 |
+
**Consequence**: A private, written warning from community leaders, providing
|
82 |
+
clarity around the nature of the violation and an explanation of why the
|
83 |
+
behavior was inappropriate. A public apology may be requested.
|
84 |
+
|
85 |
+
### 2. Warning
|
86 |
+
|
87 |
+
**Community Impact**: A violation through a single incident or series
|
88 |
+
of actions.
|
89 |
+
|
90 |
+
**Consequence**: A warning with consequences for continued behavior. No
|
91 |
+
interaction with the people involved, including unsolicited interaction with
|
92 |
+
those enforcing the Code of Conduct, for a specified period of time. This
|
93 |
+
includes avoiding interactions in community spaces as well as external channels
|
94 |
+
like social media. Violating these terms may lead to a temporary or
|
95 |
+
permanent ban.
|
96 |
+
|
97 |
+
### 3. Temporary Ban
|
98 |
+
|
99 |
+
**Community Impact**: A serious violation of community standards, including
|
100 |
+
sustained inappropriate behavior.
|
101 |
+
|
102 |
+
**Consequence**: A temporary ban from any sort of interaction or public
|
103 |
+
communication with the community for a specified period of time. No public or
|
104 |
+
private interaction with the people involved, including unsolicited interaction
|
105 |
+
with those enforcing the Code of Conduct, is allowed during this period.
|
106 |
+
Violating these terms may lead to a permanent ban.
|
107 |
+
|
108 |
+
### 4. Permanent Ban
|
109 |
+
|
110 |
+
**Community Impact**: Demonstrating a pattern of violation of community
|
111 |
+
standards, including sustained inappropriate behavior, harassment of an
|
112 |
+
individual, or aggression toward or disparagement of classes of individuals.
|
113 |
+
|
114 |
+
**Consequence**: A permanent ban from any sort of public interaction within
|
115 |
+
the community.
|
116 |
+
|
117 |
+
## Attribution
|
118 |
+
|
119 |
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
120 |
+
version 2.1, available at
|
121 |
+
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
|
122 |
+
|
123 |
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
124 |
+
enforcement ladder](https://github.com/mozilla/diversity).
|
125 |
+
|
126 |
+
[homepage]: https://www.contributor-covenant.org
|
127 |
+
|
128 |
+
For answers to common questions about this code of conduct, see the FAQ at
|
129 |
+
https://www.contributor-covenant.org/faq. Translations are available at
|
130 |
+
https://www.contributor-covenant.org/translations.
|
diffusers/CONTRIBUTING.md
ADDED
@@ -0,0 +1,506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
2 |
+
|
3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
4 |
+
the License. You may obtain a copy of the License at
|
5 |
+
|
6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
7 |
+
|
8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
10 |
+
specific language governing permissions and limitations under the License.
|
11 |
+
-->
|
12 |
+
|
13 |
+
# How to contribute to Diffusers 🧨
|
14 |
+
|
15 |
+
We ❤️ contributions from the open-source community! Everyone is welcome, and all types of participation –not just code– are valued and appreciated. Answering questions, helping others, reaching out, and improving the documentation are all immensely valuable to the community, so don't be afraid and get involved if you're up for it!
|
16 |
+
|
17 |
+
Everyone is encouraged to start by saying 👋 in our public Discord channel. We discuss the latest trends in diffusion models, ask questions, show off personal projects, help each other with contributions, or just hang out ☕. <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=Discord&logoColor=white"></a>
|
18 |
+
|
19 |
+
Whichever way you choose to contribute, we strive to be part of an open, welcoming, and kind community. Please, read our [code of conduct](https://github.com/huggingface/diffusers/blob/main/CODE_OF_CONDUCT.md) and be mindful to respect it during your interactions. We also recommend you become familiar with the [ethical guidelines](https://huggingface.co/docs/diffusers/conceptual/ethical_guidelines) that guide our project and ask you to adhere to the same principles of transparency and responsibility.
|
20 |
+
|
21 |
+
We enormously value feedback from the community, so please do not be afraid to speak up if you believe you have valuable feedback that can help improve the library - every message, comment, issue, and pull request (PR) is read and considered.
|
22 |
+
|
23 |
+
## Overview
|
24 |
+
|
25 |
+
You can contribute in many ways ranging from answering questions on issues to adding new diffusion models to
|
26 |
+
the core library.
|
27 |
+
|
28 |
+
In the following, we give an overview of different ways to contribute, ranked by difficulty in ascending order. All of them are valuable to the community.
|
29 |
+
|
30 |
+
* 1. Asking and answering questions on [the Diffusers discussion forum](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers) or on [Discord](https://discord.gg/G7tWnz98XR).
|
31 |
+
* 2. Opening new issues on [the GitHub Issues tab](https://github.com/huggingface/diffusers/issues/new/choose).
|
32 |
+
* 3. Answering issues on [the GitHub Issues tab](https://github.com/huggingface/diffusers/issues).
|
33 |
+
* 4. Fix a simple issue, marked by the "Good first issue" label, see [here](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22).
|
34 |
+
* 5. Contribute to the [documentation](https://github.com/huggingface/diffusers/tree/main/docs/source).
|
35 |
+
* 6. Contribute a [Community Pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3Acommunity-examples).
|
36 |
+
* 7. Contribute to the [examples](https://github.com/huggingface/diffusers/tree/main/examples).
|
37 |
+
* 8. Fix a more difficult issue, marked by the "Good second issue" label, see [here](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+second+issue%22).
|
38 |
+
* 9. Add a new pipeline, model, or scheduler, see ["New Pipeline/Model"](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22) and ["New scheduler"](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22) issues. For this contribution, please have a look at [Design Philosophy](https://github.com/huggingface/diffusers/blob/main/PHILOSOPHY.md).
|
39 |
+
|
40 |
+
As said before, **all contributions are valuable to the community**.
|
41 |
+
In the following, we will explain each contribution a bit more in detail.
|
42 |
+
|
43 |
+
For all contributions 4-9, you will need to open a PR. It is explained in detail how to do so in [Opening a pull request](#how-to-open-a-pr).
|
44 |
+
|
45 |
+
### 1. Asking and answering questions on the Diffusers discussion forum or on the Diffusers Discord
|
46 |
+
|
47 |
+
Any question or comment related to the Diffusers library can be asked on the [discussion forum](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/) or on [Discord](https://discord.gg/G7tWnz98XR). Such questions and comments include (but are not limited to):
|
48 |
+
- Reports of training or inference experiments in an attempt to share knowledge
|
49 |
+
- Presentation of personal projects
|
50 |
+
- Questions to non-official training examples
|
51 |
+
- Project proposals
|
52 |
+
- General feedback
|
53 |
+
- Paper summaries
|
54 |
+
- Asking for help on personal projects that build on top of the Diffusers library
|
55 |
+
- General questions
|
56 |
+
- Ethical questions regarding diffusion models
|
57 |
+
- ...
|
58 |
+
|
59 |
+
Every question that is asked on the forum or on Discord actively encourages the community to publicly
|
60 |
+
share knowledge and might very well help a beginner in the future who has the same question you're
|
61 |
+
having. Please do pose any questions you might have.
|
62 |
+
In the same spirit, you are of immense help to the community by answering such questions because this way you are publicly documenting knowledge for everybody to learn from.
|
63 |
+
|
64 |
+
**Please** keep in mind that the more effort you put into asking or answering a question, the higher
|
65 |
+
the quality of the publicly documented knowledge. In the same way, well-posed and well-answered questions create a high-quality knowledge database accessible to everybody, while badly posed questions or answers reduce the overall quality of the public knowledge database.
|
66 |
+
In short, a high quality question or answer is *precise*, *concise*, *relevant*, *easy-to-understand*, *accessible*, and *well-formatted/well-posed*. For more information, please have a look through the [How to write a good issue](#how-to-write-a-good-issue) section.
|
67 |
+
|
68 |
+
**NOTE about channels**:
|
69 |
+
[*The forum*](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63) is much better indexed by search engines, such as Google. Posts are ranked by popularity rather than chronologically. Hence, it's easier to look up questions and answers that we posted some time ago.
|
70 |
+
In addition, questions and answers posted in the forum can easily be linked to.
|
71 |
+
In contrast, *Discord* has a chat-like format that invites fast back-and-forth communication.
|
72 |
+
While it will most likely take less time for you to get an answer to your question on Discord, your
|
73 |
+
question won't be visible anymore over time. Also, it's much harder to find information that was posted a while back on Discord. We therefore strongly recommend using the forum for high-quality questions and answers in an attempt to create long-lasting knowledge for the community. If discussions on Discord lead to very interesting answers and conclusions, we recommend posting the results on the forum to make the information more available for future readers.
|
74 |
+
|
75 |
+
### 2. Opening new issues on the GitHub issues tab
|
76 |
+
|
77 |
+
The 🧨 Diffusers library is robust and reliable thanks to the users who notify us of
|
78 |
+
the problems they encounter. So thank you for reporting an issue.
|
79 |
+
|
80 |
+
Remember, GitHub issues are reserved for technical questions directly related to the Diffusers library, bug reports, feature requests, or feedback on the library design.
|
81 |
+
|
82 |
+
In a nutshell, this means that everything that is **not** related to the **code of the Diffusers library** (including the documentation) should **not** be asked on GitHub, but rather on either the [forum](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63) or [Discord](https://discord.gg/G7tWnz98XR).
|
83 |
+
|
84 |
+
**Please consider the following guidelines when opening a new issue**:
|
85 |
+
- Make sure you have searched whether your issue has already been asked before (use the search bar on GitHub under Issues).
|
86 |
+
- Please never report a new issue on another (related) issue. If another issue is highly related, please
|
87 |
+
open a new issue nevertheless and link to the related issue.
|
88 |
+
- Make sure your issue is written in English. Please use one of the great, free online translation services, such as [DeepL](https://www.deepl.com/translator) to translate from your native language to English if you are not comfortable in English.
|
89 |
+
- Check whether your issue might be solved by updating to the newest Diffusers version. Before posting your issue, please make sure that `python -c "import diffusers; print(diffusers.__version__)"` is higher or matches the latest Diffusers version.
|
90 |
+
- Remember that the more effort you put into opening a new issue, the higher the quality of your answer will be and the better the overall quality of the Diffusers issues.
|
91 |
+
|
92 |
+
New issues usually include the following.
|
93 |
+
|
94 |
+
#### 2.1. Reproducible, minimal bug reports
|
95 |
+
|
96 |
+
A bug report should always have a reproducible code snippet and be as minimal and concise as possible.
|
97 |
+
This means in more detail:
|
98 |
+
- Narrow the bug down as much as you can, **do not just dump your whole code file**.
|
99 |
+
- Format your code.
|
100 |
+
- Do not include any external libraries except for Diffusers depending on them.
|
101 |
+
- **Always** provide all necessary information about your environment; for this, you can run: `diffusers-cli env` in your shell and copy-paste the displayed information to the issue.
|
102 |
+
- Explain the issue. If the reader doesn't know what the issue is and why it is an issue, she cannot solve it.
|
103 |
+
- **Always** make sure the reader can reproduce your issue with as little effort as possible. If your code snippet cannot be run because of missing libraries or undefined variables, the reader cannot help you. Make sure your reproducible code snippet is as minimal as possible and can be copy-pasted into a simple Python shell.
|
104 |
+
- If in order to reproduce your issue a model and/or dataset is required, make sure the reader has access to that model or dataset. You can always upload your model or dataset to the [Hub](https://huggingface.co) to make it easily downloadable. Try to keep your model and dataset as small as possible, to make the reproduction of your issue as effortless as possible.
|
105 |
+
|
106 |
+
For more information, please have a look through the [How to write a good issue](#how-to-write-a-good-issue) section.
|
107 |
+
|
108 |
+
You can open a bug report [here](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=bug&projects=&template=bug-report.yml).
|
109 |
+
|
110 |
+
#### 2.2. Feature requests
|
111 |
+
|
112 |
+
A world-class feature request addresses the following points:
|
113 |
+
|
114 |
+
1. Motivation first:
|
115 |
+
* Is it related to a problem/frustration with the library? If so, please explain
|
116 |
+
why. Providing a code snippet that demonstrates the problem is best.
|
117 |
+
* Is it related to something you would need for a project? We'd love to hear
|
118 |
+
about it!
|
119 |
+
* Is it something you worked on and think could benefit the community?
|
120 |
+
Awesome! Tell us what problem it solved for you.
|
121 |
+
2. Write a *full paragraph* describing the feature;
|
122 |
+
3. Provide a **code snippet** that demonstrates its future use;
|
123 |
+
4. In case this is related to a paper, please attach a link;
|
124 |
+
5. Attach any additional information (drawings, screenshots, etc.) you think may help.
|
125 |
+
|
126 |
+
You can open a feature request [here](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feature_request.md&title=).
|
127 |
+
|
128 |
+
#### 2.3 Feedback
|
129 |
+
|
130 |
+
Feedback about the library design and why it is good or not good helps the core maintainers immensely to build a user-friendly library. To understand the philosophy behind the current design philosophy, please have a look [here](https://huggingface.co/docs/diffusers/conceptual/philosophy). If you feel like a certain design choice does not fit with the current design philosophy, please explain why and how it should be changed. If a certain design choice follows the design philosophy too much, hence restricting use cases, explain why and how it should be changed.
|
131 |
+
If a certain design choice is very useful for you, please also leave a note as this is great feedback for future design decisions.
|
132 |
+
|
133 |
+
You can open an issue about feedback [here](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=).
|
134 |
+
|
135 |
+
#### 2.4 Technical questions
|
136 |
+
|
137 |
+
Technical questions are mainly about why certain code of the library was written in a certain way, or what a certain part of the code does. Please make sure to link to the code in question and please provide detail on
|
138 |
+
why this part of the code is difficult to understand.
|
139 |
+
|
140 |
+
You can open an issue about a technical question [here](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=bug&template=bug-report.yml).
|
141 |
+
|
142 |
+
#### 2.5 Proposal to add a new model, scheduler, or pipeline
|
143 |
+
|
144 |
+
If the diffusion model community released a new model, pipeline, or scheduler that you would like to see in the Diffusers library, please provide the following information:
|
145 |
+
|
146 |
+
* Short description of the diffusion pipeline, model, or scheduler and link to the paper or public release.
|
147 |
+
* Link to any of its open-source implementation.
|
148 |
+
* Link to the model weights if they are available.
|
149 |
+
|
150 |
+
If you are willing to contribute to the model yourself, let us know so we can best guide you. Also, don't forget
|
151 |
+
to tag the original author of the component (model, scheduler, pipeline, etc.) by GitHub handle if you can find it.
|
152 |
+
|
153 |
+
You can open a request for a model/pipeline/scheduler [here](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=New+model%2Fpipeline%2Fscheduler&template=new-model-addition.yml).
|
154 |
+
|
155 |
+
### 3. Answering issues on the GitHub issues tab
|
156 |
+
|
157 |
+
Answering issues on GitHub might require some technical knowledge of Diffusers, but we encourage everybody to give it a try even if you are not 100% certain that your answer is correct.
|
158 |
+
Some tips to give a high-quality answer to an issue:
|
159 |
+
- Be as concise and minimal as possible.
|
160 |
+
- Stay on topic. An answer to the issue should concern the issue and only the issue.
|
161 |
+
- Provide links to code, papers, or other sources that prove or encourage your point.
|
162 |
+
- Answer in code. If a simple code snippet is the answer to the issue or shows how the issue can be solved, please provide a fully reproducible code snippet.
|
163 |
+
|
164 |
+
Also, many issues tend to be simply off-topic, duplicates of other issues, or irrelevant. It is of great
|
165 |
+
help to the maintainers if you can answer such issues, encouraging the author of the issue to be
|
166 |
+
more precise, provide the link to a duplicated issue or redirect them to [the forum](https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63) or [Discord](https://discord.gg/G7tWnz98XR).
|
167 |
+
|
168 |
+
If you have verified that the issued bug report is correct and requires a correction in the source code,
|
169 |
+
please have a look at the next sections.
|
170 |
+
|
171 |
+
For all of the following contributions, you will need to open a PR. It is explained in detail how to do so in the [Opening a pull request](#how-to-open-a-pr) section.
|
172 |
+
|
173 |
+
### 4. Fixing a "Good first issue"
|
174 |
+
|
175 |
+
*Good first issues* are marked by the [Good first issue](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) label. Usually, the issue already
|
176 |
+
explains how a potential solution should look so that it is easier to fix.
|
177 |
+
If the issue hasn't been closed and you would like to try to fix this issue, you can just leave a message "I would like to try this issue.". There are usually three scenarios:
|
178 |
+
- a.) The issue description already proposes a fix. In this case and if the solution makes sense to you, you can open a PR or draft PR to fix it.
|
179 |
+
- b.) The issue description does not propose a fix. In this case, you can ask what a proposed fix could look like and someone from the Diffusers team should answer shortly. If you have a good idea of how to fix it, feel free to directly open a PR.
|
180 |
+
- c.) There is already an open PR to fix the issue, but the issue hasn't been closed yet. If the PR has gone stale, you can simply open a new PR and link to the stale PR. PRs often go stale if the original contributor who wanted to fix the issue suddenly cannot find the time anymore to proceed. This often happens in open-source and is very normal. In this case, the community will be very happy if you give it a new try and leverage the knowledge of the existing PR. If there is already a PR and it is active, you can help the author by giving suggestions, reviewing the PR or even asking whether you can contribute to the PR.
|
181 |
+
|
182 |
+
|
183 |
+
### 5. Contribute to the documentation
|
184 |
+
|
185 |
+
A good library **always** has good documentation! The official documentation is often one of the first points of contact for new users of the library, and therefore contributing to the documentation is a **highly
|
186 |
+
valuable contribution**.
|
187 |
+
|
188 |
+
Contributing to the library can have many forms:
|
189 |
+
|
190 |
+
- Correcting spelling or grammatical errors.
|
191 |
+
- Correct incorrect formatting of the docstring. If you see that the official documentation is weirdly displayed or a link is broken, we are very happy if you take some time to correct it.
|
192 |
+
- Correct the shape or dimensions of a docstring input or output tensor.
|
193 |
+
- Clarify documentation that is hard to understand or incorrect.
|
194 |
+
- Update outdated code examples.
|
195 |
+
- Translating the documentation to another language.
|
196 |
+
|
197 |
+
Anything displayed on [the official Diffusers doc page](https://huggingface.co/docs/diffusers/index) is part of the official documentation and can be corrected, adjusted in the respective [documentation source](https://github.com/huggingface/diffusers/tree/main/docs/source).
|
198 |
+
|
199 |
+
Please have a look at [this page](https://github.com/huggingface/diffusers/tree/main/docs) on how to verify changes made to the documentation locally.
|
200 |
+
|
201 |
+
|
202 |
+
### 6. Contribute a community pipeline
|
203 |
+
|
204 |
+
[Pipelines](https://huggingface.co/docs/diffusers/api/pipelines/overview) are usually the first point of contact between the Diffusers library and the user.
|
205 |
+
Pipelines are examples of how to use Diffusers [models](https://huggingface.co/docs/diffusers/api/models/overview) and [schedulers](https://huggingface.co/docs/diffusers/api/schedulers/overview).
|
206 |
+
We support two types of pipelines:
|
207 |
+
|
208 |
+
- Official Pipelines
|
209 |
+
- Community Pipelines
|
210 |
+
|
211 |
+
Both official and community pipelines follow the same design and consist of the same type of components.
|
212 |
+
|
213 |
+
Official pipelines are tested and maintained by the core maintainers of Diffusers. Their code
|
214 |
+
resides in [src/diffusers/pipelines](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines).
|
215 |
+
In contrast, community pipelines are contributed and maintained purely by the **community** and are **not** tested.
|
216 |
+
They reside in [examples/community](https://github.com/huggingface/diffusers/tree/main/examples/community) and while they can be accessed via the [PyPI diffusers package](https://pypi.org/project/diffusers/), their code is not part of the PyPI distribution.
|
217 |
+
|
218 |
+
The reason for the distinction is that the core maintainers of the Diffusers library cannot maintain and test all
|
219 |
+
possible ways diffusion models can be used for inference, but some of them may be of interest to the community.
|
220 |
+
Officially released diffusion pipelines,
|
221 |
+
such as Stable Diffusion are added to the core src/diffusers/pipelines package which ensures
|
222 |
+
high quality of maintenance, no backward-breaking code changes, and testing.
|
223 |
+
More bleeding edge pipelines should be added as community pipelines. If usage for a community pipeline is high, the pipeline can be moved to the official pipelines upon request from the community. This is one of the ways we strive to be a community-driven library.
|
224 |
+
|
225 |
+
To add a community pipeline, one should add a <name-of-the-community>.py file to [examples/community](https://github.com/huggingface/diffusers/tree/main/examples/community) and adapt the [examples/community/README.md](https://github.com/huggingface/diffusers/tree/main/examples/community/README.md) to include an example of the new pipeline.
|
226 |
+
|
227 |
+
An example can be seen [here](https://github.com/huggingface/diffusers/pull/2400).
|
228 |
+
|
229 |
+
Community pipeline PRs are only checked at a superficial level and ideally they should be maintained by their original authors.
|
230 |
+
|
231 |
+
Contributing a community pipeline is a great way to understand how Diffusers models and schedulers work. Having contributed a community pipeline is usually the first stepping stone to contributing an official pipeline to the
|
232 |
+
core package.
|
233 |
+
|
234 |
+
### 7. Contribute to training examples
|
235 |
+
|
236 |
+
Diffusers examples are a collection of training scripts that reside in [examples](https://github.com/huggingface/diffusers/tree/main/examples).
|
237 |
+
|
238 |
+
We support two types of training examples:
|
239 |
+
|
240 |
+
- Official training examples
|
241 |
+
- Research training examples
|
242 |
+
|
243 |
+
Research training examples are located in [examples/research_projects](https://github.com/huggingface/diffusers/tree/main/examples/research_projects) whereas official training examples include all folders under [examples](https://github.com/huggingface/diffusers/tree/main/examples) except the `research_projects` and `community` folders.
|
244 |
+
The official training examples are maintained by the Diffusers' core maintainers whereas the research training examples are maintained by the community.
|
245 |
+
This is because of the same reasons put forward in [6. Contribute a community pipeline](#6-contribute-a-community-pipeline) for official pipelines vs. community pipelines: It is not feasible for the core maintainers to maintain all possible training methods for diffusion models.
|
246 |
+
If the Diffusers core maintainers and the community consider a certain training paradigm to be too experimental or not popular enough, the corresponding training code should be put in the `research_projects` folder and maintained by the author.
|
247 |
+
|
248 |
+
Both official training and research examples consist of a directory that contains one or more training scripts, a `requirements.txt` file, and a `README.md` file. In order for the user to make use of the
|
249 |
+
training examples, it is required to clone the repository:
|
250 |
+
|
251 |
+
```bash
|
252 |
+
git clone https://github.com/huggingface/diffusers
|
253 |
+
```
|
254 |
+
|
255 |
+
as well as to install all additional dependencies required for training:
|
256 |
+
|
257 |
+
```bash
|
258 |
+
cd diffusers
|
259 |
+
pip install -r examples/<your-example-folder>/requirements.txt
|
260 |
+
```
|
261 |
+
|
262 |
+
Therefore when adding an example, the `requirements.txt` file shall define all pip dependencies required for your training example so that once all those are installed, the user can run the example's training script. See, for example, the [DreamBooth `requirements.txt` file](https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/requirements.txt).
|
263 |
+
|
264 |
+
Training examples of the Diffusers library should adhere to the following philosophy:
|
265 |
+
- All the code necessary to run the examples should be found in a single Python file.
|
266 |
+
- One should be able to run the example from the command line with `python <your-example>.py --args`.
|
267 |
+
- Examples should be kept simple and serve as **an example** on how to use Diffusers for training. The purpose of example scripts is **not** to create state-of-the-art diffusion models, but rather to reproduce known training schemes without adding too much custom logic. As a byproduct of this point, our examples also strive to serve as good educational materials.
|
268 |
+
|
269 |
+
To contribute an example, it is highly recommended to look at already existing examples such as [dreambooth](https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth.py) to get an idea of how they should look like.
|
270 |
+
We strongly advise contributors to make use of the [Accelerate library](https://github.com/huggingface/accelerate) as it's tightly integrated
|
271 |
+
with Diffusers.
|
272 |
+
Once an example script works, please make sure to add a comprehensive `README.md` that states how to use the example exactly. This README should include:
|
273 |
+
- An example command on how to run the example script as shown [here e.g.](https://github.com/huggingface/diffusers/tree/main/examples/dreambooth#running-locally-with-pytorch).
|
274 |
+
- A link to some training results (logs, models, ...) that show what the user can expect as shown [here e.g.](https://api.wandb.ai/report/patrickvonplaten/xm6cd5q5).
|
275 |
+
- If you are adding a non-official/research training example, **please don't forget** to add a sentence that you are maintaining this training example which includes your git handle as shown [here](https://github.com/huggingface/diffusers/tree/main/examples/research_projects/intel_opts#diffusers-examples-with-intel-optimizations).
|
276 |
+
|
277 |
+
If you are contributing to the official training examples, please also make sure to add a test to [examples/test_examples.py](https://github.com/huggingface/diffusers/blob/main/examples/test_examples.py). This is not necessary for non-official training examples.
|
278 |
+
|
279 |
+
### 8. Fixing a "Good second issue"
|
280 |
+
|
281 |
+
*Good second issues* are marked by the [Good second issue](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+second+issue%22) label. Good second issues are
|
282 |
+
usually more complicated to solve than [Good first issues](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22).
|
283 |
+
The issue description usually gives less guidance on how to fix the issue and requires
|
284 |
+
a decent understanding of the library by the interested contributor.
|
285 |
+
If you are interested in tackling a good second issue, feel free to open a PR to fix it and link the PR to the issue. If you see that a PR has already been opened for this issue but did not get merged, have a look to understand why it wasn't merged and try to open an improved PR.
|
286 |
+
Good second issues are usually more difficult to get merged compared to good first issues, so don't hesitate to ask for help from the core maintainers. If your PR is almost finished the core maintainers can also jump into your PR and commit to it in order to get it merged.
|
287 |
+
|
288 |
+
### 9. Adding pipelines, models, schedulers
|
289 |
+
|
290 |
+
Pipelines, models, and schedulers are the most important pieces of the Diffusers library.
|
291 |
+
They provide easy access to state-of-the-art diffusion technologies and thus allow the community to
|
292 |
+
build powerful generative AI applications.
|
293 |
+
|
294 |
+
By adding a new model, pipeline, or scheduler you might enable a new powerful use case for any of the user interfaces relying on Diffusers which can be of immense value for the whole generative AI ecosystem.
|
295 |
+
|
296 |
+
Diffusers has a couple of open feature requests for all three components - feel free to gloss over them
|
297 |
+
if you don't know yet what specific component you would like to add:
|
298 |
+
- [Model or pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22)
|
299 |
+
- [Scheduler](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22)
|
300 |
+
|
301 |
+
Before adding any of the three components, it is strongly recommended that you give the [Philosophy guide](https://github.com/huggingface/diffusers/blob/main/PHILOSOPHY.md) a read to better understand the design of any of the three components. Please be aware that
|
302 |
+
we cannot merge model, scheduler, or pipeline additions that strongly diverge from our design philosophy
|
303 |
+
as it will lead to API inconsistencies. If you fundamentally disagree with a design choice, please
|
304 |
+
open a [Feedback issue](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=) instead so that it can be discussed whether a certain design
|
305 |
+
pattern/design choice shall be changed everywhere in the library and whether we shall update our design philosophy. Consistency across the library is very important for us.
|
306 |
+
|
307 |
+
Please make sure to add links to the original codebase/paper to the PR and ideally also ping the
|
308 |
+
original author directly on the PR so that they can follow the progress and potentially help with questions.
|
309 |
+
|
310 |
+
If you are unsure or stuck in the PR, don't hesitate to leave a message to ask for a first review or help.
|
311 |
+
|
312 |
+
## How to write a good issue
|
313 |
+
|
314 |
+
**The better your issue is written, the higher the chances that it will be quickly resolved.**
|
315 |
+
|
316 |
+
1. Make sure that you've used the correct template for your issue. You can pick between *Bug Report*, *Feature Request*, *Feedback about API Design*, *New model/pipeline/scheduler addition*, *Forum*, or a blank issue. Make sure to pick the correct one when opening [a new issue](https://github.com/huggingface/diffusers/issues/new/choose).
|
317 |
+
2. **Be precise**: Give your issue a fitting title. Try to formulate your issue description as simple as possible. The more precise you are when submitting an issue, the less time it takes to understand the issue and potentially solve it. Make sure to open an issue for one issue only and not for multiple issues. If you found multiple issues, simply open multiple issues. If your issue is a bug, try to be as precise as possible about what bug it is - you should not just write "Error in diffusers".
|
318 |
+
3. **Reproducibility**: No reproducible code snippet == no solution. If you encounter a bug, maintainers **have to be able to reproduce** it. Make sure that you include a code snippet that can be copy-pasted into a Python interpreter to reproduce the issue. Make sure that your code snippet works, *i.e.* that there are no missing imports or missing links to images, ... Your issue should contain an error message **and** a code snippet that can be copy-pasted without any changes to reproduce the exact same error message. If your issue is using local model weights or local data that cannot be accessed by the reader, the issue cannot be solved. If you cannot share your data or model, try to make a dummy model or dummy data.
|
319 |
+
4. **Minimalistic**: Try to help the reader as much as you can to understand the issue as quickly as possible by staying as concise as possible. Remove all code / all information that is irrelevant to the issue. If you have found a bug, try to create the easiest code example you can to demonstrate your issue, do not just dump your whole workflow into the issue as soon as you have found a bug. E.g., if you train a model and get an error at some point during the training, you should first try to understand what part of the training code is responsible for the error and try to reproduce it with a couple of lines. Try to use dummy data instead of full datasets.
|
320 |
+
5. Add links. If you are referring to a certain naming, method, or model make sure to provide a link so that the reader can better understand what you mean. If you are referring to a specific PR or issue, make sure to link it to your issue. Do not assume that the reader knows what you are talking about. The more links you add to your issue the better.
|
321 |
+
6. Formatting. Make sure to nicely format your issue by formatting code into Python code syntax, and error messages into normal code syntax. See the [official GitHub formatting docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for more information.
|
322 |
+
7. Think of your issue not as a ticket to be solved, but rather as a beautiful entry to a well-written encyclopedia. Every added issue is a contribution to publicly available knowledge. By adding a nicely written issue you not only make it easier for maintainers to solve your issue, but you are helping the whole community to better understand a certain aspect of the library.
|
323 |
+
|
324 |
+
## How to write a good PR
|
325 |
+
|
326 |
+
1. Be a chameleon. Understand existing design patterns and syntax and make sure your code additions flow seamlessly into the existing code base. Pull requests that significantly diverge from existing design patterns or user interfaces will not be merged.
|
327 |
+
2. Be laser focused. A pull request should solve one problem and one problem only. Make sure to not fall into the trap of "also fixing another problem while we're adding it". It is much more difficult to review pull requests that solve multiple, unrelated problems at once.
|
328 |
+
3. If helpful, try to add a code snippet that displays an example of how your addition can be used.
|
329 |
+
4. The title of your pull request should be a summary of its contribution.
|
330 |
+
5. If your pull request addresses an issue, please mention the issue number in
|
331 |
+
the pull request description to make sure they are linked (and people
|
332 |
+
consulting the issue know you are working on it);
|
333 |
+
6. To indicate a work in progress please prefix the title with `[WIP]`. These
|
334 |
+
are useful to avoid duplicated work, and to differentiate it from PRs ready
|
335 |
+
to be merged;
|
336 |
+
7. Try to formulate and format your text as explained in [How to write a good issue](#how-to-write-a-good-issue).
|
337 |
+
8. Make sure existing tests pass;
|
338 |
+
9. Add high-coverage tests. No quality testing = no merge.
|
339 |
+
- If you are adding new `@slow` tests, make sure they pass using
|
340 |
+
`RUN_SLOW=1 python -m pytest tests/test_my_new_model.py`.
|
341 |
+
CircleCI does not run the slow tests, but GitHub Actions does every night!
|
342 |
+
10. All public methods must have informative docstrings that work nicely with markdown. See [`pipeline_latent_diffusion.py`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py) for an example.
|
343 |
+
11. Due to the rapidly growing repository, it is important to make sure that no files that would significantly weigh down the repository are added. This includes images, videos, and other non-text files. We prefer to leverage a hf.co hosted `dataset` like
|
344 |
+
[`hf-internal-testing`](https://huggingface.co/hf-internal-testing) or [huggingface/documentation-images](https://huggingface.co/datasets/huggingface/documentation-images) to place these files.
|
345 |
+
If an external contribution, feel free to add the images to your PR and ask a Hugging Face member to migrate your images
|
346 |
+
to this dataset.
|
347 |
+
|
348 |
+
## How to open a PR
|
349 |
+
|
350 |
+
Before writing code, we strongly advise you to search through the existing PRs or
|
351 |
+
issues to make sure that nobody is already working on the same thing. If you are
|
352 |
+
unsure, it is always a good idea to open an issue to get some feedback.
|
353 |
+
|
354 |
+
You will need basic `git` proficiency to be able to contribute to
|
355 |
+
🧨 Diffusers. `git` is not the easiest tool to use but it has the greatest
|
356 |
+
manual. Type `git --help` in a shell and enjoy. If you prefer books, [Pro
|
357 |
+
Git](https://git-scm.com/book/en/v2) is a very good reference.
|
358 |
+
|
359 |
+
Follow these steps to start contributing ([supported Python versions](https://github.com/huggingface/diffusers/blob/42f25d601a910dceadaee6c44345896b4cfa9928/setup.py#L270)):
|
360 |
+
|
361 |
+
1. Fork the [repository](https://github.com/huggingface/diffusers) by
|
362 |
+
clicking on the 'Fork' button on the repository's page. This creates a copy of the code
|
363 |
+
under your GitHub user account.
|
364 |
+
|
365 |
+
2. Clone your fork to your local disk, and add the base repository as a remote:
|
366 |
+
|
367 |
+
```bash
|
368 |
+
$ git clone [email protected]:<your GitHub handle>/diffusers.git
|
369 |
+
$ cd diffusers
|
370 |
+
$ git remote add upstream https://github.com/huggingface/diffusers.git
|
371 |
+
```
|
372 |
+
|
373 |
+
3. Create a new branch to hold your development changes:
|
374 |
+
|
375 |
+
```bash
|
376 |
+
$ git checkout -b a-descriptive-name-for-my-changes
|
377 |
+
```
|
378 |
+
|
379 |
+
**Do not** work on the `main` branch.
|
380 |
+
|
381 |
+
4. Set up a development environment by running the following command in a virtual environment:
|
382 |
+
|
383 |
+
```bash
|
384 |
+
$ pip install -e ".[dev]"
|
385 |
+
```
|
386 |
+
|
387 |
+
If you have already cloned the repo, you might need to `git pull` to get the most recent changes in the
|
388 |
+
library.
|
389 |
+
|
390 |
+
5. Develop the features on your branch.
|
391 |
+
|
392 |
+
As you work on the features, you should make sure that the test suite
|
393 |
+
passes. You should run the tests impacted by your changes like this:
|
394 |
+
|
395 |
+
```bash
|
396 |
+
$ pytest tests/<TEST_TO_RUN>.py
|
397 |
+
```
|
398 |
+
|
399 |
+
Before you run the tests, please make sure you install the dependencies required for testing. You can do so
|
400 |
+
with this command:
|
401 |
+
|
402 |
+
```bash
|
403 |
+
$ pip install -e ".[test]"
|
404 |
+
```
|
405 |
+
|
406 |
+
You can also run the full test suite with the following command, but it takes
|
407 |
+
a beefy machine to produce a result in a decent amount of time now that
|
408 |
+
Diffusers has grown a lot. Here is the command for it:
|
409 |
+
|
410 |
+
```bash
|
411 |
+
$ make test
|
412 |
+
```
|
413 |
+
|
414 |
+
🧨 Diffusers relies on `ruff` and `isort` to format its source code
|
415 |
+
consistently. After you make changes, apply automatic style corrections and code verifications
|
416 |
+
that can't be automated in one go with:
|
417 |
+
|
418 |
+
```bash
|
419 |
+
$ make style
|
420 |
+
```
|
421 |
+
|
422 |
+
🧨 Diffusers also uses `ruff` and a few custom scripts to check for coding mistakes. Quality
|
423 |
+
control runs in CI, however, you can also run the same checks with:
|
424 |
+
|
425 |
+
```bash
|
426 |
+
$ make quality
|
427 |
+
```
|
428 |
+
|
429 |
+
Once you're happy with your changes, add changed files using `git add` and
|
430 |
+
make a commit with `git commit` to record your changes locally:
|
431 |
+
|
432 |
+
```bash
|
433 |
+
$ git add modified_file.py
|
434 |
+
$ git commit -m "A descriptive message about your changes."
|
435 |
+
```
|
436 |
+
|
437 |
+
It is a good idea to sync your copy of the code with the original
|
438 |
+
repository regularly. This way you can quickly account for changes:
|
439 |
+
|
440 |
+
```bash
|
441 |
+
$ git pull upstream main
|
442 |
+
```
|
443 |
+
|
444 |
+
Push the changes to your account using:
|
445 |
+
|
446 |
+
```bash
|
447 |
+
$ git push -u origin a-descriptive-name-for-my-changes
|
448 |
+
```
|
449 |
+
|
450 |
+
6. Once you are satisfied, go to the
|
451 |
+
webpage of your fork on GitHub. Click on 'Pull request' to send your changes
|
452 |
+
to the project maintainers for review.
|
453 |
+
|
454 |
+
7. It's ok if maintainers ask you for changes. It happens to core contributors
|
455 |
+
too! So everyone can see the changes in the Pull request, work in your local
|
456 |
+
branch and push the changes to your fork. They will automatically appear in
|
457 |
+
the pull request.
|
458 |
+
|
459 |
+
### Tests
|
460 |
+
|
461 |
+
An extensive test suite is included to test the library behavior and several examples. Library tests can be found in
|
462 |
+
the [tests folder](https://github.com/huggingface/diffusers/tree/main/tests).
|
463 |
+
|
464 |
+
We like `pytest` and `pytest-xdist` because it's faster. From the root of the
|
465 |
+
repository, here's how to run tests with `pytest` for the library:
|
466 |
+
|
467 |
+
```bash
|
468 |
+
$ python -m pytest -n auto --dist=loadfile -s -v ./tests/
|
469 |
+
```
|
470 |
+
|
471 |
+
In fact, that's how `make test` is implemented!
|
472 |
+
|
473 |
+
You can specify a smaller set of tests in order to test only the feature
|
474 |
+
you're working on.
|
475 |
+
|
476 |
+
By default, slow tests are skipped. Set the `RUN_SLOW` environment variable to
|
477 |
+
`yes` to run them. This will download many gigabytes of models — make sure you
|
478 |
+
have enough disk space and a good Internet connection, or a lot of patience!
|
479 |
+
|
480 |
+
```bash
|
481 |
+
$ RUN_SLOW=yes python -m pytest -n auto --dist=loadfile -s -v ./tests/
|
482 |
+
```
|
483 |
+
|
484 |
+
`unittest` is fully supported, here's how to run tests with it:
|
485 |
+
|
486 |
+
```bash
|
487 |
+
$ python -m unittest discover -s tests -t . -v
|
488 |
+
$ python -m unittest discover -s examples -t examples -v
|
489 |
+
```
|
490 |
+
|
491 |
+
### Syncing forked main with upstream (HuggingFace) main
|
492 |
+
|
493 |
+
To avoid pinging the upstream repository which adds reference notes to each upstream PR and sends unnecessary notifications to the developers involved in these PRs,
|
494 |
+
when syncing the main branch of a forked repository, please, follow these steps:
|
495 |
+
1. When possible, avoid syncing with the upstream using a branch and PR on the forked repository. Instead, merge directly into the forked main.
|
496 |
+
2. If a PR is absolutely necessary, use the following steps after checking out your branch:
|
497 |
+
```bash
|
498 |
+
$ git checkout -b your-branch-for-syncing
|
499 |
+
$ git pull --squash --no-commit upstream main
|
500 |
+
$ git commit -m '<your message without GitHub references>'
|
501 |
+
$ git push --set-upstream origin your-branch-for-syncing
|
502 |
+
```
|
503 |
+
|
504 |
+
### Style guide
|
505 |
+
|
506 |
+
For documentation strings, 🧨 Diffusers follows the [Google style](https://google.github.io/styleguide/pyguide.html).
|