Diffusers documentation

DDPMScheduler

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DDPMScheduler

Jonathan Ho, Ajay Jain, Pieter Abbeel의 Denoising Diffusion Probabilistic Models(DDPM)은 동일한 이름의 diffusion 기반 모델을 제안합니다. 🤗 Diffusers 라이브러리 컨텍스트에서 DDPM은 해당 논문에서 제시한 discrete denoising scheduler와 파이프라인을 모두 가리킵니다.

해당 논문의 초록은 다음과 같습니다:

비평형 열역학의 고려 사항에서 영감을 받은 잠재 변수 모델의 한 종류인 확률적 확산 모델(diffusion probabilistic models)을 사용하여 고품질 이미지 합성 결과를 제시합니다. 우리의 최우수 결과는 확률적 확산 모델과 Langevin 동역학을 갖는 노이즈 제거 점수 매칭(denoising score matching) 사이의 새로운 연결에 따라 설계된 가중치 변분 경계(weighted variational bound)를 사용하여 학습함으로써 얻어졌으며, 우리의 모델은 자기 회귀 디코딩(autoregressive decoding)의 일반화로 해석될 수 있는 점진적 손실 압축 해제(progressive lossy decompression) 스키마를 자연스럽게 허용합니다. 무조건적 CIFAR10 데이터셋에서 Inception score 9.46과 최첨단 FID score 3.17을 달성했습니다. 256x256 LSUN에서는 ProgressiveGAN과 유사한 샘플 품질을 얻었습니다. 구현은 이 https URL에서 사용할 수 있습니다.

DDPMScheduler

클래스 diffusers.DDPMScheduler

< >

( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2', 'sigmoid'] = 'linear'trained_betas: numpy.ndarray | list[float] | None = Nonevariance_type: typing.Literal['fixed_small', 'fixed_small_log', 'fixed_large', 'fixed_large_log', 'learned', 'learned_range'] = 'fixed_small'clip_sample: bool = Trueprediction_type: typing.Literal['epsilon', 'sample', 'v_prediction'] = 'epsilon'thresholding: bool = Falsedynamic_thresholding_ratio: float = 0.995clip_sample_range: float = 1.0sample_max_value: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'leading'steps_offset: int = 0rescale_betas_zero_snr: bool = False )

매개변수

  • 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" 또는 "sigmoid", 기본값은 "linear") — 모델을 단계별로 진행하기 위한 베타 값의 시퀀스로 베타 범위를 매핑하는 베타 스케줄입니다.
  • trained_betas (np.ndarray, 선택 사항) — beta_start와 beta_end를 사용하지 않고 생성자에 직접 전달할 베타 값의 배열입니다.
  • variance_type ("fixed_small", "fixed_small_log", "fixed_large", "fixed_large_log", "learned", 또는 "learned_range", 기본값은 "fixed_small") — denoised sample에 노이즈를 추가할 때 variance를 clip합니다.
  • clip_sample (bool, 기본값 True) — 수치적 안정성을 위해 예측된 샘플을 클리핑합니다.
  • clip_sample_range (float, 기본값 1.0) — 샘플 클리핑의 최대 크기입니다. clip_sample=True일 때만 유효합니다.
  • prediction_type ("epsilon", "sample", or "v_prediction", defaults to "epsilon") — Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process), sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen Video paper).
  • thresholding (bool, 기본값 False) — “동적 임계값 설정” 방법을 사용할지 여부입니다. Stable Diffusion과 같은 잠재 공간 확산 모델에는 적합하지 않습니다.
  • dynamic_thresholding_ratio (float, 기본값 0.995) — 동적 임계값 설정 방법의 비율입니다. thresholding=True일 때만 유효합니다.
  • sample_max_value (float, 기본값 1.0) — 동적 임계값 설정을 위한 임계값입니다. thresholding=True일 때만 유효합니다.
  • timestep_spacing ("linspace", "leading" 또는 "trailing", 기본값은 "leading") — timestep을 스케일링하는 방식입니다. 자세한 내용은 일반적인 확산 노이즈 스케줄 및 샘플 단계는 결함이 있다의 표 2를 참고하세요.
  • steps_offset (int, 기본값 0) — 일부 모델 계열에서 요구하는 대로 추론 단계에 추가되는 오프셋입니다.
  • rescale_betas_zero_snr (bool, 기본값 False) — 베타를 재조정하여 최종 SNR을 0으로 만들지 여부를 지정합니다. 이를 통해 중간 밝기의 샘플로 제한되는 대신 매우 밝고 어두운 샘플을 생성할 수 있습니다. --offset_noise와 느슨하게 관련이 있습니다.

DDPMScheduler는 denoising score matching과 Langevin dynamics sampling 간의 연결을 탐구합니다.

이 모델은 SchedulerMixin과 ConfigMixin을 상속합니다. 로딩 및 저장과 같은 모든 스케줄러에 대해 라이브러리가 구현하는 일반적 메서드에 대해서는 상위 클래스 문서를 확인하세요.

add_noise

< >

( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor

매개변수

  • original_samples (torch.Tensor) — 노이즈가 추가될 원래 샘플입니다.
  • noise (torch.Tensor) — 샘플에 추가할 노이즈입니다.
  • timesteps (torch.IntTensor) — 각 샘플의 노이즈 수준을 나타내는 timesteps.

반환값

torch.Tensor

노이즈가 포함된 샘플.

각 timestep의 노이즈 크기에 따라 원래 샘플에 노이즈를 추가합니다(이것은 forward diffusion process입니다).

get_velocity

< >

( sample: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor

매개변수

  • sample (torch.Tensor) — 입력 샘플입니다.
  • noise (torch.Tensor) — 노이즈 텐서입니다.
  • timesteps (torch.IntTensor) — 속도 계산에 사용되는 timesteps입니다.

반환값

torch.Tensor

계산된 속도.

속도 공식에 따라 샘플과 노이즈로부터 속도 예측을 계산합니다.

이전 시간 단계

< >

( timestep: int ) → int or torch.Tensor

매개변수

  • timestep (int) — 현재 timestep입니다.

반환값

int 또는 torch.Tensor

이전 시간 단계(timestep).

확산 체인의 이전 시간 단계를 계산합니다.

scale_model_input

< >

( sample: Tensortimestep: int | None = None ) → torch.Tensor

매개변수

  • sample (torch.Tensor) — 입력 샘플입니다.
  • timestep (int, 선택 사항) — 확산 체인에서의 현재 timestep입니다.

반환값

torch.Tensor

스케일된 입력 샘플.

현재 timestep에 따라 denoising 모델 입력을 scale해야 하는 scheduler와의 호환성을 보장합니다.

set_timesteps

< >

( num_inference_steps: int = Nonedevice: typing.Union[str, torch.device] = Nonetimesteps: list[int] | None = None )

매개변수

  • num_inference_steps (int, 선택 사항) — 학습된 모델로 샘플을 생성할 때 사용되는 diffusion 단계 수입니다. 이 값을 사용하는 경우 timesteps은 None이어야 합니다.
  • device (str 또는 torch.device, 선택 사항) — timesteps를 이동할 대상 device입니다. None인 경우 timesteps는 이동되지 않습니다.
  • timesteps (list[int], 선택 사항) — timesteps 사이의 간격을 자유롭게 지정하기 위해 사용하는 사용자 정의 timesteps입니다. None인 경우, timesteps 사이에 동일한 간격을 두는 기본 전략이 사용됩니다. timesteps가 전달되면 num_inference_steps는 None이어야 합니다.

추론 실행 전에 실행할 diffusion chain에 사용할 이산 timesteps를 설정합니다.

단계

< >

( model_output: Tensortimestep: intsample: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → DDPMSchedulerOutput or tuple

매개변수

  • model_output (torch.Tensor) — 학습된 diffusion 모델의 직접적인 출력입니다.
  • timestep (int) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다.
  • sample (torch.Tensor) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다.
  • generator (torch.Generator, 선택 사항) — 난수 생성기입니다.
  • return_dict (bool, 기본값 True) — tuple 대신 DDPMSchedulerOutput를 반환할지 여부.

반환값

DDPMSchedulerOutput 또는 tuple

return_dict가 True인 경우 DDPMSchedulerOutput이 반환되고, 그렇지 않으면 첫 번째 요소가 샘플 텐서인 튜플이 반환됩니다.

이전 시간 단계의 샘플을 SDE를 역방향으로 적용하여 예측합니다. 이 함수는 학습된 모델의 출력(대부분 예측된 노이즈)으로부터 확산 과정을 전파합니다.

DDPMSchedulerOutput

class diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput

< >

( prev_sample: Tensorpred_original_sample: typing.Optional[torch.Tensor] = None )

매개변수

  • prev_sample (이미지의 경우 torch.Tensor, shape (batch_size, num_channels, height, width)) — 이전 timestep의 계산된 샘플 (x_{t-1}). prev_sample은 denoising 루프에서 다음 모델 입력으로 사용해야 합니다.
  • pred_original_sample (torch.Tensor, 이미지인 경우 shape (batch_size, num_channels, height, width)) — 현재 timestep의 모델 출력에 기반한 예측된 디노이즈 샘플 (x_{0}). pred_original_sample은 진행 상황 미리보기 또는 가이던스에 사용할 수 있습니다.

스케줄러의 step 함수 출력을 위한 출력 클래스입니다.

Update on GitHub