Diffusers documentation
DEISMultistepScheduler
DEISMultistepScheduler
Diffusion Exponential Integrator Sampler(DEIS)은 Qinsheng Zhang와 Yongxin Chen이 Fast Sampling of Diffusion Models with Exponential Integrator에서 제안했습니다. DEISMultistepScheduler는 diffusion ordinary differential equations(ODE)를 위한 고속 고차 solver입니다.
이 구현은 DEIS 논문에서 원래 사용된 선형 t 공간이 아닌 log-rho 공간에서 다항식 피팅 공식을 수정합니다. 이 수정은 수치적 솔버에 의존하지 않고 지수형 멀티스텝 업데이트에 대해 닫힌 형식의 계수를 제공합니다.
해당 논문의 초록은 다음과 같습니다:
지난 몇 년간 Diffusion models~(DMs)은 생성 모델링 작업에서 높은 충실도의 샘플을 생성하는 데 큰 성공을 거두었습니다. DM의 주요 한계는 학습된 diffusion process에 도달하기 위해 일반적으로 수백에서 수천 개의 시간 이산화 단계가 필요한 것으로 악명 높은 느린 샘플링 절차입니다. 우리의 목표는 샘플 품질을 유지하면서 훨씬 적은 단계 수로 DM에 대한 빠른 샘플링 방법을 개발하는 것입니다. 이를 위해 DM의 샘플링 절차를 체계적으로 분석하고 샘플 품질에 영향을 미치는 주요 요인을 식별했으며, 그중 이산화 방법이 가장 중요합니다. 학습된 diffusion process를 면밀히 검토하여, 우리는 Diffusion Exponential Integrator Sampler~(DEIS)를 제안합니다. 이는 상미분방정식(ODE)의 이산화를 위해 설계된 Exponential Integrator에 기반하며, 학습된 diffusion process의 반선형(semilinear) 구조를 활용하여 이산화 오류를 줄입니다. 제안된 방법은 모든 DM에 적용할 수 있으며, 최대 10단계로 높은 충실도의 샘플을 생성할 수 있습니다. 우리의 실험에서, CIFAR10에서 50k 이미지를 생성하는 데 A6000 GPU 하나당 약 3분이 소요되었습니다. 또한, 사전 학습된 DM을 직접 사용하여 score function evaluation~(NFE) 수가 제한된 경우, 예를 들어 CIFAR10에서 10 NFE로 4.17 FID, 15 NFE만으로 3.37 FID 및 9.74 IS를 달성하여 최첨단(state-of-the-art) 샘플링 성능을 달성했습니다. 코드는 이 https URL에서 사용할 수 있습니다.
팁
solver_order은 2 또는 3으로 설정하는 것이 권장되며, solver_order=1은 DDIMScheduler와 동일합니다.
Imagen의 동적 임계값 설정(dynamic thresholding)을 지원하며, 픽셀 공간 확산 모델의 경우 thresholding=True를 설정하여 동적 임계값 설정을 사용할 수 있습니다.
DEISMultistepScheduler
클래스 diffusers.DEISMultistepScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2'] = 'linear'trained_betas: numpy.ndarray | list[float] | None = Nonesolver_order: int = 2prediction_type: typing.Literal['epsilon', 'sample', 'v_prediction', 'flow_prediction'] = 'epsilon'thresholding: bool = Falsedynamic_thresholding_ratio: float = 0.995sample_max_value: float = 1.0algorithm_type: typing.Literal['deis'] = 'deis'solver_type: typing.Literal['logrho'] = 'logrho'lower_order_final: bool = Trueuse_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseuse_flow_sigmas: bool = Falseflow_shift: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'linspace'steps_offset: int = 0use_dynamic_shifting: bool = Falsetime_shift_type: typing.Literal['exponential'] = 'exponential' )
매개변수
- num_train_timesteps (
int, 기본값1000) — 모델을 학습할 때 사용할 diffusion 단계 수입니다. - beta_start (
float, 기본값0.0001) — 추론의 시작beta값입니다. - beta_end (
float, 기본값0.02) — 최종beta값입니다. - beta_schedule (
"linear","scaled_linear", 또는"squaredcos_cap_v2", 기본값은"linear") — 모델의 스테핑을 위한 베타 범위에서 베타 시퀀스로의 매핑인 베타 스케줄입니다.linear,scaled_linear, 또는squaredcos_cap_v2중 하나를 선택합니다. - trained_betas (
np.ndarray또는list[float], 선택 사항) —beta_start와beta_end를 우회하여 베타 배열을 생성자에 직접 전달합니다. - solver_order (
int, 기본값2) —1또는2또는3일 수 있는 DEIS order입니다. guided sampling에는solver_order=2를, unconditional sampling에는solver_order=3를 사용하는 것이 권장됩니다. - prediction_type (
"epsilon","sample","v_prediction", or"flow_prediction", defaults to"epsilon") — Prediction type of the scheduler function; can beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample),v_prediction(see section 2.4 of [Imagen Video](https://huggingface.co/papers/2210.02303) paper), orflow_prediction`. - thresholding (
bool, 기본값False) — “동적 임계값 설정” 방법을 사용할지 여부입니다. Stable Diffusion과 같은 잠재 공간 확산 모델에는 적합하지 않습니다. - dynamic_thresholding_ratio (
float, 기본값0.995) — 동적 임계값 설정 방법의 비율입니다.thresholding=True일 때만 유효합니다. - sample_max_value (
float, 기본값1.0) — 동적 임계값 설정을 위한 임계값입니다.thresholding=True일 때만 유효합니다. - algorithm_type (
"deis", 기본값"deis") — 솔버에 사용할 알고리즘 유형입니다. - solver_type (
"logrho", 기본값"logrho") — DEIS의 Solver type입니다. - lower_order_final (
bool, 기본값True) — 마지막 단계에서 저차수 솔버를 사용할지 여부. 추론 단계가 15 미만인 경우에만 유효합니다. - use_karras_sigmas (
bool, 선택 사항, 기본값False) — 샘플링 과정에서 노이즈 스케줄의 단계 크기에 Karras sigmas를 사용할지 여부입니다.True인 경우, sigmas는 노이즈 레벨 {σi}의 시퀀스에 따라 결정됩니다. - use_exponential_sigmas (
bool, 선택 사항, 기본값False) — 샘플링 과정에서 노이즈 스케줄의 스텝 크기에 지수 시그마를 사용할지 여부입니다. - use_beta_sigmas (
bool, optional, defaults toFalse) — Whether to use beta sigmas for step sizes in the noise schedule during the sampling process. Refer to Beta Sampling is All You Need for more information. - use_flow_sigmas (
bool, 선택 사항, 기본값False) — 샘플링 과정에서 노이즈 스케줄의 스텝 크기에 flow sigmas를 사용할지 여부입니다. - flow_shift (
float, 선택 사항, 기본값1.0) — Flow 기반 모델의 flow shift 매개변수입니다. - timestep_spacing (
"linspace","leading", 또는"trailing", 기본값은"linspace") — timestep을 스케일링하는 방법입니다. 자세한 내용은 공통 확산 노이즈 스케줄과 샘플 단계는 결함이 있다의 Table 2를 참고하세요. - steps_offset (
int, 기본값0) — 일부 모델 계열에서 요구하는 대로 추론 단계에 추가되는 오프셋입니다. - use_dynamic_shifting (
bool, 기본값False) — 노이즈 스케줄에 동적 시프트를 사용할지 여부입니다. - time_shift_type (
"exponential", 기본값"exponential") — 적용할 시간 시프트의 유형입니다.
DEISMultistepScheduler는 확산 상미분방정식(ODE)을 위한 고속 고차 솔버입니다.
이 모델은 SchedulerMixin과 ConfigMixin을 상속합니다. 로딩 및 저장과 같은 모든 스케줄러에 대해 라이브러리가 구현하는 일반적 메서드에 대해서는 상위 클래스 문서를 확인하세요.
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
지정된 timesteps의 noise schedule에 따라 원래 샘플에 노이즈를 추가합니다.
convert_model_output
< source >( model_output: Tensor*argssample: Tensor = None**kwargs ) → torch.Tensor
DEIS 알고리즘이 필요로 하는 해당 유형으로 모델 출력을 변환합니다.
deis_first_order_update
< source >( model_output: Tensor*argssample: Tensor = None**kwargs ) → torch.Tensor
1차 DEIS의 한 단계(DDIM과 동일).
index_for_timestep
< source >( timestep: typing.Union[int, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
schedule에서 주어진 timestep에 해당하는 인덱스를 찾습니다.
multistep_deis_second_order_update
< source >( model_output_list: list*argssample: Tensor = None**kwargs ) → torch.Tensor
2차 다단계 DEIS의 한 단계.
multistep_deis_third_order_update
< source >( model_output_list: list*argssample: Tensor = None**kwargs ) → torch.Tensor
3차 다단계 DEIS의 한 단계.
scale_model_input
< source >( sample: Tensor*args**kwargs ) → torch.Tensor
현재 timestep에 따라 denoising 모델 입력을 scale해야 하는 scheduler와의 호환성을 보장합니다.
set_begin_index
< source >( begin_index: int = 0 )
… 스케줄러의 시작 인덱스를 설정합니다. 이 함수는 추론 전에 파이프라인에서 실행해야 합니다.
set_timesteps
< source >( num_inference_steps: intdevice: typing.Union[str, torch.device] = Nonemu: float | None = None )
추론 실행 전에 실행할 diffusion chain에 사용할 이산 timesteps를 설정합니다.
단계
< source >( model_output: Tensortimestep: typing.Union[int, torch.Tensor]sample: Tensorreturn_dict: bool = True ) → SchedulerOutput or tuple
매개변수
- model_output (
torch.Tensor) — 학습된 diffusion 모델의 직접적인 출력입니다. - timestep (
int또는torch.Tensor) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다. - sample (
torch.Tensor) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다. - return_dict (
bool, 기본값True) —tuple대신 SchedulerOutput를 반환할지 여부.
반환값
SchedulerOutput 또는 tuple
return_dict가 True인 경우 SchedulerOutput이 반환되고, 그렇지 않으면 첫 번째 요소가 샘플 텐서인 튜플이 반환됩니다.
이전 시간 단계의 샘플을 SDE를 역방향으로 적용하여 예측합니다. 이 함수는 샘플을 멀티스텝 DEIS로 전파합니다.
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
스케줄러의 step 함수 출력을 위한 베이스 클래스.