Diffusers documentation
EulerAncestralDiscreteScheduler
EulerAncestralDiscreteScheduler
Euler method 스텝을 사용하는 ancestral sampling 기반 스케줄러입니다. 이는 20~30개의 스텝으로 좋은 출력을 생성할 수 있는 빠른 스케줄러입니다. 해당 스케줄러는 Katherine Crowson의 원래 k-diffusion 구현을 기반으로 합니다.
EulerAncestralDiscreteScheduler
class diffusers.EulerAncestralDiscreteScheduler
< 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'timestep_spacing: str = 'linspace'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", 기본값은"linear") — 모델의 스테핑을 위한 베타 범위에서 베타 시퀀스로의 매핑인 베타 스케줄입니다.linear,scaled_linear, 또는squaredcos_cap_v2중 하나를 선택합니다. - trained_betas (
np.ndarray, 선택 사항) —beta_start와beta_end를 우회하여 베타 배열을 생성자에 직접 전달합니다. - prediction_type (
"epsilon","sample", or"v_prediction", defaults to"epsilon", optional) — 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 (
"linspace","leading", 또는"trailing", 기본값은"linspace") — timestep을 스케일링하는 방법입니다. 자세한 내용은 공통 확산 노이즈 스케줄과 샘플 단계는 결함이 있다의 Table 2를 참고하세요. - steps_offset (
int, 기본값 0) — 일부 모델 계열에서 요구하는 추론 단계에 추가되는 오프셋입니다. - rescale_betas_zero_snr (
bool, 기본값False) — 베타를 재조정하여 최종 SNR을 0으로 만들지 여부를 지정합니다. 이를 통해 중간 밝기의 샘플로 제한되는 대신 매우 밝고 어두운 샘플을 생성할 수 있습니다.--offset_noise와 느슨하게 관련이 있습니다.
Euler method 단계가 포함된 Ancestral sampling.
이 모델은 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 모델 입력을 스케일링해야 하는 스케줄러와의 호환성을 보장합니다. Euler 알고리즘에 맞추기 위해 denoising 모델 입력을 (sigma**2 + 1) ** 0.5로 스케일링합니다.
set_begin_index
< source >( begin_index: int = 0 )
… 스케줄러의 시작 인덱스를 설정합니다. 이 함수는 추론 전에 파이프라인에서 실행해야 합니다.
set_timesteps
< source >( num_inference_steps: intdevice: typing.Union[str, torch.device] = None )
추론 실행 전에 실행할 diffusion chain에 사용할 이산 timesteps를 설정합니다.
단계
< source >( model_output: Tensortimestep: typing.Union[float, torch.Tensor]sample: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → EulerAncestralDiscreteSchedulerOutput or tuple
매개변수
- model_output (
torch.Tensor) — 학습된 diffusion 모델의 직접적인 출력입니다. - timestep (
float또는torch.Tensor) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다. - sample (
torch.Tensor) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다. - generator (
torch.Generator, 선택 사항) — 난수 생성기입니다. - return_dict (
bool, 기본값True) — EulerAncestralDiscreteSchedulerOutput 또는 tuple을 반환할지 여부.
반환값
return_dict가 True인 경우
EulerAncestralDiscreteSchedulerOutput이 반환되고,
그렇지 않으면 첫 번째 요소가 샘플 텐서인 튜플이 반환됩니다.
이전 시간 단계의 샘플을 SDE를 역방향으로 적용하여 예측합니다. 이 함수는 학습된 모델의 출력(대부분 예측된 노이즈)으로부터 확산 과정을 전파합니다.
EulerAncestralDiscreteSchedulerOutput
class diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteSchedulerOutput
< 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 함수 출력을 위한 출력 클래스입니다.