Diffusers documentation
KDPM2AncestralDiscreteScheduler
KDPM2AncestralDiscreteScheduler
The KDPM2DiscreteScheduler with ancestral sampling is inspired by the Elucidating the Design Space of Diffusion-Based Generative Models paper, and the scheduler is ported from and created by Katherine Crowson.
원본 코드베이스는 crowsonkb/k-diffusion에서 찾을 수 있습니다.
KDPM2AncestralDiscreteScheduler
class diffusers.KDPM2AncestralDiscreteScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.00085beta_end: float = 0.012beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneuse_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseprediction_type: str = 'epsilon'timestep_spacing: str = 'linspace'steps_offset: int = 0 )
매개변수
- num_train_timesteps (
int, 기본값 1000) — 모델을 학습할 때 사용할 diffusion 단계 수입니다. - beta_start (
float, 기본값 0.00085) — 추론의 시작beta값입니다. - beta_end (
float, 기본값 0.012) — 최종beta값입니다. - beta_schedule (
str, 기본값"linear") — 모델을 스테핑하기 위한 베타 범위에서 베타 시퀀스로의 매핑인 베타 스케줄입니다.linear또는scaled_linear중 하나를 선택합니다. - trained_betas (
np.ndarray또는list[float], 선택 사항) —beta_start와beta_end를 우회하여 베타 배열을 생성자에 직접 전달합니다. - use_karras_sigmas (
bool, 기본값False) — 샘플링 과정에서 노이즈 스케줄의 단계 크기에 Karras sigmas를 사용할지 여부입니다.True인 경우, sigmas는 노이즈 레벨 {σi}의 시퀀스에 따라 결정됩니다. - use_exponential_sigmas (
bool, 기본값False) — 샘플링 과정에서 노이즈 스케줄의 스텝 크기에 지수 시그마를 사용할지 여부. - use_beta_sigmas (
bool, 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. - prediction_type (
str, defaults to"epsilon") — Prediction type of the scheduler function; can beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample) orv_prediction` (see section 2.4 of Imagen Video paper). - timestep_spacing (
str, 기본값"linspace") — timestep을 스케일링하는 방식입니다. 자세한 내용은 공통 확산 노이즈 스케줄 및 샘플 스텝은 결함이 있습니다의 표 2를 참조하십시오. - steps_offset (
int, 기본값 0) — 일부 모델 계열에서 요구하는 추론 단계에 추가되는 오프셋입니다.
ancestral sampling을 사용하는 KDPM2DiscreteScheduler는 Elucidating the Design Space of Diffusion-Based Generative Models 논문에서 제시된 DPMSolver2와 Algorithm 2에서 영감을 받았습니다.
이 모델은 SchedulerMixin과 ConfigMixin을 상속합니다. 로딩 및 저장과 같은 모든 스케줄러에 대해 라이브러리가 구현하는 일반적 메서드에 대해서는 상위 클래스 문서를 확인하세요.
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: Tensor ) → torch.Tensor
지정된 timesteps의 noise schedule에 따라 원래 샘플에 노이즈를 추가합니다.
index_for_timestep
< source >( timestep: typing.Union[float, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
…
scale_model_input
< source >( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → 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, NoneType] = Nonenum_train_timesteps: int | None = None )
추론 실행 전에 실행할 diffusion chain에 사용할 이산 timesteps를 설정합니다.
단계
< source >( model_output: typing.Union[torch.Tensor, numpy.ndarray]timestep: typing.Union[float, torch.Tensor]sample: typing.Union[torch.Tensor, numpy.ndarray]generator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True )
매개변수
- model_output (
torch.Tensor또는np.ndarray) — 학습된 diffusion 모델의 직접적인 출력입니다. - timestep (
float또는torch.Tensor) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다. - sample (
torch.Tensor또는np.ndarray) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다. - generator (
torch.Generator, 선택 사항) — 난수 생성기입니다. - return_dict (
bool, 기본값True) —KDPM2AncestralDiscreteSchedulerOutput또는 tuple을 반환할지 여부.
이전 시간 단계의 샘플을 SDE를 역방향으로 적용하여 예측합니다. 이 함수는 학습된 모델의 출력(대부분 예측된 노이즈)으로부터 확산 과정을 전파합니다.
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
스케줄러의 step 함수 출력을 위한 베이스 클래스.