Diffusers documentation
EulerDiscreteScheduler
EulerDiscreteScheduler
Euler 스케줄러(Algorithm 2)는 Karras 외의 Elucidating the Design Space of Diffusion-Based Generative Models 논문에서 제시된 것입니다. 이는 20~30단계로 좋은 출력을 생성할 수 있는 빠른 스케줄러입니다. 해당 스케줄러는 Katherine Crowson의 원래 k-diffusion 구현을 기반으로 합니다.
EulerDiscreteScheduler
클래스 diffusers.EulerDiscreteScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneprediction_type: str = 'epsilon'interpolation_type: str = 'linear'use_karras_sigmas: bool | None = Falseuse_exponential_sigmas: bool | None = Falseuse_beta_sigmas: bool | None = Falsesigma_min: float | None = Nonesigma_max: float | None = Nonetimestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'linspace'timestep_type: typing.Literal['discrete', 'continuous'] = 'discrete'steps_offset: int = 0rescale_betas_zero_snr: bool = Falsefinal_sigmas_type: typing.Literal['zero', 'sigma_min'] = 'zero' )
매개변수
- num_train_timesteps (
int, 기본값 1000) — 모델을 학습할 때 사용할 diffusion 단계 수입니다. - beta_start (
float, 기본값 0.0001) — 추론의 시작beta값입니다. - beta_end (
float, 기본값 0.02) — 최종beta값입니다. - beta_schedule (
Literal["linear", "scaled_linear", "squaredcos_cap_v2"], 기본값"linear") — 모델을 스테핑하기 위한 베타 범위에서 베타 시퀀스로의 매핑인 베타 스케줄입니다."linear","scaled_linear", 또는"squaredcos_cap_v2"중 하나를 선택합니다. - trained_betas (
np.ndarray, 선택 사항) —beta_start와beta_end를 우회하여 베타 배열을 생성자에 직접 전달합니다. - prediction_type (
Literal["epsilon", "sample", "v_prediction"], defaults to"epsilon", optional) — 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). - interpolation_type (
Literal["linear", "log_linear"], 기본값"linear", 선택 사항) — 스케줄러의 디노이징 단계에서 중간 시그마를 계산하기 위한 보간 유형입니다."linear"또는"log_linear"중 하나여야 합니다. - 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. - sigma_min (
float, 선택 사항) — 노이즈 스케줄의 최소 sigma 값입니다. 제공되지 않으면 스케줄의 마지막 sigma 값이 기본값으로 사용됩니다. - sigma_max (
float, 선택 사항) — 노이즈 스케줄의 최대 sigma 값입니다. 제공되지 않으면 스케줄의 첫 번째 sigma 값이 기본값으로 사용됩니다. - timestep_spacing (
Literal["linspace", "leading", "trailing"], defaults to"linspace") — The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and Sample Steps are Flawed for more information. - timestep_type (
Literal["discrete", "continuous"], 기본값"discrete") — 사용할 timesteps의 유형입니다."discrete"또는"continuous"를 사용할 수 있습니다. - steps_offset (
int, 기본값 0) — 일부 모델 계열에서 요구하는 추론 단계에 추가되는 오프셋입니다. - rescale_betas_zero_snr (
bool, 기본값False) — 베타를 재조정하여 최종 SNR을 0으로 만들지 여부를 지정합니다. 이를 통해 중간 밝기의 샘플로 제한되는 대신 매우 밝고 어두운 샘플을 생성할 수 있습니다.--offset_noise와 느슨하게 관련이 있습니다. - final_sigmas_type (
Literal["zero", "sigma_min"], 기본값"zero") — 샘플링 과정에서 노이즈 스케줄의 최종sigma값입니다."sigma_min"인 경우, 최종 sigma는 학습 스케줄의 마지막 sigma와 동일합니다."zero"인 경우, 최종 sigma는 0으로 설정됩니다.
Euler 스케줄러.
이 모델은 SchedulerMixin과 ConfigMixin을 상속합니다. 로딩 및 저장과 같은 모든 스케줄러에 대해 라이브러리가 구현하는 일반적 메서드에 대해서는 상위 클래스 문서를 확인하세요.
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: Tensor ) → torch.Tensor
지정된 timesteps의 noise schedule에 따라 원래 샘플에 노이즈를 추가합니다.
get_velocity
< source >( sample: Tensornoise: Tensortimesteps: Tensor ) → torch.Tensor
…
이 메서드는 v-prediction 모델에서 사용되는 속도 예측을 구현하며, 샘플과 노이즈의 선형 결합을 예측합니다.
index_for_timestep
< source >( timestep: typing.Union[float, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
매개변수
- timestep (
float또는torch.Tensor) — 스케줄에서 찾을 timestep 값입니다. - schedule_timesteps (
torch.Tensor, 선택 사항) — 검색할 timestep schedule입니다.None인 경우self.timesteps를 사용합니다.
반환값
int
The index of the timestep in the schedule. For the very first step, returns the second index if multiple matches exist to avoid skipping a sigma when starting mid-schedule (e.g., for image-to-image).
…
scale_model_input
< source >( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
현재 timestep에 따라 denoising 모델 입력을 스케일링해야 하는 스케줄러와의 호환성을 보장합니다. Euler 알고리즘에 맞추기 위해 denoising 모델 입력을 (sigma**2 + 1) ** 0.5로 스케일링합니다.
set_begin_index
< source >( begin_index: int = 0 )
… 스케줄러의 시작 인덱스를 설정합니다. 이 함수는 추론 전에 파이프라인에서 실행해야 합니다.
set_timesteps
< source >( num_inference_steps: int = Nonedevice: typing.Union[str, torch.device] = Nonetimesteps: list[int] | None = Nonesigmas: list[float] | None = None )
매개변수
- num_inference_steps (
int, 선택 사항) — 학습된 모델로 샘플을 생성할 때 사용되는 diffusion 단계 수입니다.None인 경우timesteps또는sigmas를 제공해야 합니다. - device (
str또는torch.device, 선택 사항) — timesteps를 이동할 대상 device입니다.None인 경우 timesteps는 이동되지 않습니다. - timesteps (
list[int], 선택 사항) — 임의의 timesteps 스케줄을 지원하기 위해 사용되는 사용자 지정 timesteps입니다.None인 경우,timestep_spacing속성에 기반하여 timesteps가 생성됩니다.timesteps가 전달되면num_inference_steps와sigmas는None이어야 하며,timestep_spacing속성은 무시됩니다. - sigmas (
list[float], 선택 사항) — 임의의 timesteps 스케줄을 지원하기 위해 사용되는 사용자 정의 sigmas입니다.None인 경우, 관련 스케줄러 속성에 기반하여 timesteps와 sigmas가 생성됩니다.sigmas가 전달되면num_inference_steps와timesteps는None이어야 하며, 사용자 정의 sigmas 스케줄에 기반하여 timesteps가 생성됩니다.
추론 실행 전에 실행할 diffusion chain에 사용할 이산 timesteps를 설정합니다.
단계
< source >( model_output: Tensortimestep: typing.Union[float, torch.Tensor]sample: Tensors_churn: float = 0.0s_tmin: float = 0.0s_tmax: float = infs_noise: float = 1.0generator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → EulerDiscreteSchedulerOutput or tuple
매개변수
- model_output (
torch.Tensor) — 학습된 diffusion 모델의 직접적인 출력입니다. - timestep (
float또는torch.Tensor) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다. - sample (
torch.Tensor) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다. - s_churn (
float, 선택 사항, 기본값0.0) — 샘플링 중에 추가되는 노이즈의 양을 제어하는 확률성 파라미터입니다. 값이 높을수록 무작위성이 증가합니다. - s_tmin (
float, 선택 사항, 기본값0.0) — 확률성을 적용하기 위한 최소 타임스텝 임계값입니다. 이 값보다 큰 타임스텝에만 노이즈가 추가됩니다. - s_tmax (
float, 선택 사항, 기본값inf) — 확률성을 적용하기 위한 최대 타임스텝 임계값입니다. 이 값보다 작은 타임스텝에만 노이즈가 추가됩니다. - s_noise (
float, 선택 사항, 기본값1.0) — 샘플에 추가되는 노이즈의 스케일링 계수입니다. - generator (
torch.Generator, 선택 사항) — 재현 가능한 샘플링을 위한 난수 생성기. - return_dict (
bool, 선택 사항, 기본값True) — EulerDiscreteSchedulerOutput 또는 tuple을 반환할지 여부.
반환값
EulerDiscreteSchedulerOutput 또는 tuple
return_dict가 True인 경우 EulerDiscreteSchedulerOutput이 반환되고, 그렇지 않으면 첫 번째 요소가 샘플 텐서, 두 번째 요소가 예측된 원래 샘플인 튜플이 반환됩니다.
이전 시간 단계의 샘플을 SDE를 역방향으로 적용하여 예측합니다. 이 함수는 학습된 모델의 출력(대부분 예측된 노이즈)으로부터 확산 과정을 전파합니다.
EulerDiscreteSchedulerOutput
class diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteSchedulerOutput
< source >( 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 함수 출력을 위한 출력 클래스입니다.