Skip to content

Commit 687bc27

Browse files
mhh0318sayakpaul
andauthored
add TCD Scheduler (#7174)
* add: support TCD scheduler --------- Co-authored-by: Sayak Paul <[email protected]>
1 parent 6246c70 commit 687bc27

File tree

7 files changed

+918
-0
lines changed

7 files changed

+918
-0
lines changed

docs/source/en/_toctree.yml

+2
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@
418418
title: ScoreSdeVeScheduler
419419
- local: api/schedulers/score_sde_vp
420420
title: ScoreSdeVpScheduler
421+
- local: api/schedulers/tcd
422+
title: TCDScheduler
421423
- local: api/schedulers/unipc
422424
title: UniPCMultistepScheduler
423425
- local: api/schedulers/vq_diffusion

docs/source/en/api/schedulers/tcd.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
# TCDScheduler
14+
15+
[Trajectory Consistency Distillation](https://huggingface.co/papers/2402.19159) by Jianbin Zheng, Minghui Hu, Zhongyi Fan, Chaoyue Wang, Changxing Ding, Dacheng Tao and Tat-Jen Cham introduced a Strategic Stochastic Sampling (Algorithm 4) that is capable of generating good samples in a small number of steps. Distinguishing it as an advanced iteration of the multistep scheduler (Algorithm 1) in the [Consistency Models](https://huggingface.co/papers/2303.01469), Strategic Stochastic Sampling specifically tailored for the trajectory consistency function.
16+
17+
The abstract from the paper is:
18+
19+
*Latent Consistency Model (LCM) extends the Consistency Model to the latent space and leverages the guided consistency distillation technique to achieve impressive performance in accelerating text-to-image synthesis. However, we observed that LCM struggles to generate images with both clarity and detailed intricacy. To address this limitation, we initially delve into and elucidate the underlying causes. Our investigation identifies that the primary issue stems from errors in three distinct areas. Consequently, we introduce Trajectory Consistency Distillation (TCD), which encompasses trajectory consistency function and strategic stochastic sampling. The trajectory consistency function diminishes the distillation errors by broadening the scope of the self-consistency boundary condition and endowing the TCD with the ability to accurately trace the entire trajectory of the Probability Flow ODE. Additionally, strategic stochastic sampling is specifically designed to circumvent the accumulated errors inherent in multi-step consistency sampling, which is meticulously tailored to complement the TCD model. Experiments demonstrate that TCD not only significantly enhances image quality at low NFEs but also yields more detailed results compared to the teacher model at high NFEs.*
20+
21+
The original codebase can be found at [jabir-zheng/TCD](https://github.com/jabir-zheng/TCD).
22+
23+
## TCDScheduler
24+
[[autodoc]] TCDScheduler
25+
26+
27+
## TCDSchedulerOutput
28+
[[autodoc]] schedulers.scheduling_tcd.TCDSchedulerOutput
29+

src/diffusers/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"SASolverScheduler",
161161
"SchedulerMixin",
162162
"ScoreSdeVeScheduler",
163+
"TCDScheduler",
163164
"UnCLIPScheduler",
164165
"UniPCMultistepScheduler",
165166
"VQDiffusionScheduler",
@@ -545,6 +546,7 @@
545546
SASolverScheduler,
546547
SchedulerMixin,
547548
ScoreSdeVeScheduler,
549+
TCDScheduler,
548550
UnCLIPScheduler,
549551
UniPCMultistepScheduler,
550552
VQDiffusionScheduler,

src/diffusers/schedulers/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
_import_structure["scheduling_repaint"] = ["RePaintScheduler"]
6666
_import_structure["scheduling_sasolver"] = ["SASolverScheduler"]
6767
_import_structure["scheduling_sde_ve"] = ["ScoreSdeVeScheduler"]
68+
_import_structure["scheduling_tcd"] = ["TCDScheduler"]
6869
_import_structure["scheduling_unclip"] = ["UnCLIPScheduler"]
6970
_import_structure["scheduling_unipc_multistep"] = ["UniPCMultistepScheduler"]
7071
_import_structure["scheduling_utils"] = ["KarrasDiffusionSchedulers", "SchedulerMixin"]
@@ -159,6 +160,7 @@
159160
from .scheduling_repaint import RePaintScheduler
160161
from .scheduling_sasolver import SASolverScheduler
161162
from .scheduling_sde_ve import ScoreSdeVeScheduler
163+
from .scheduling_tcd import TCDScheduler
162164
from .scheduling_unclip import UnCLIPScheduler
163165
from .scheduling_unipc_multistep import UniPCMultistepScheduler
164166
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin

0 commit comments

Comments
 (0)