Diffusers documentation

HeunDiscreteScheduler

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

HeunDiscreteScheduler

Heun 스케줄러(Algorithm 1)는 Karras 외의 Elucidating the Design Space of Diffusion-Based Generative Models 논문에서 가져온 것입니다. 이 스케줄러는 k-diffusion 라이브러리에서 이식되었으며 Katherine Crowson이 작성했습니다.

HeunDiscreteScheduler

class diffusers.HeunDiscreteScheduler

< >

( num_train_timesteps: int = 1000beta_start: float = 0.00085beta_end: float = 0.012beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneprediction_type: str = 'epsilon'use_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseclip_sample: bool = Falseclip_sample_range: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'linspace'steps_offset: int = 0 )

매개변수

  • 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", 또는 "exp", 기본값은 "linear") — 모델을 스테핑하기 위한 베타 범위에서 베타 시퀀스로의 매핑인 베타 스케줄입니다. linear, scaled_linear, squaredcos_cap_v2, 또는 exp 중 하나를 선택합니다.
  • 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 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).
  • clip_sample (bool, 기본값 True) — 수치적 안정성을 위해 예측된 샘플을 클리핑합니다.
  • clip_sample_range (float, 기본값 1.0) — 샘플 클리핑의 최대 크기입니다. clip_sample=True일 때만 유효합니다.
  • use_karras_sigmas (bool, 선택 사항, 기본값 False) — 샘플링 과정에서 노이즈 스케줄의 단계 크기에 Karras sigmas를 사용할지 여부입니다. True인 경우, sigmas는 노이즈 레벨 {σi}의 시퀀스에 따라 결정됩니다.
  • use_exponential_sigmas (bool, 선택 사항, 기본값 False) — 샘플링 과정에서 노이즈 스케줄의 스텝 크기에 지수 시그마를 사용할지 여부입니다.
  • use_beta_sigmas (bool, optional, defaults to False) — 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.
  • timestep_spacing ("linspace", "leading", 또는 "trailing", 기본값은 "linspace") — timestep을 스케일링하는 방법입니다. 자세한 내용은 공통 확산 노이즈 스케줄과 샘플 단계는 결함이 있다의 Table 2를 참고하세요.
  • steps_offset (int, 기본값 0) — 일부 모델 계열에서 요구하는 추론 단계에 추가되는 오프셋입니다.

이산 베타 스케줄을 위한 Heun 스텝을 사용하는 스케줄러.

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

add_noise

< >

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

매개변수

  • original_samples (torch.Tensor) — 노이즈가 추가될 원래 샘플입니다.
  • noise (torch.Tensor) — 원본 샘플에 추가할 노이즈 텐서입니다.
  • timesteps (torch.Tensor) — 노이즈를 추가할 타임스텝으로, 스케줄에서 노이즈 레벨을 결정합니다.

반환값

torch.Tensor

timestep 스케줄에 따라 노이즈가 스케일링되어 추가된 노이즈 샘플.

지정된 timesteps의 noise schedule에 따라 원래 샘플에 노이즈를 추가합니다.

index_for_timestep

< >

( 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

< >

( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → torch.Tensor

매개변수

  • sample (torch.Tensor) — 입력 샘플입니다.
  • timestep (float 또는 torch.Tensor) — 확산 체인에서의 현재 timestep입니다.

반환값

torch.Tensor

스케일된 입력 샘플.

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

set_begin_index

< >

( begin_index: int = 0 )

매개변수

  • begin_index (int, 기본값 0) — 스케줄러의 시작 인덱스입니다.

… 스케줄러의 시작 인덱스를 설정합니다. 이 함수는 추론 전에 파이프라인에서 실행해야 합니다.

set_timesteps

< >

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

매개변수

  • num_inference_steps (int, 선택 사항, 기본값 None) — 학습된 모델로 샘플을 생성할 때 사용되는 diffusion 단계 수입니다.
  • device (str, torch.device, 선택 사항, 기본값 None) — timesteps를 이동할 대상 디바이스입니다. None인 경우 timesteps는 이동되지 않습니다.
  • num_train_timesteps (int, 선택 사항, 기본값 None) — 모델을 학습할 때 사용되는 diffusion 단계 수입니다. None인 경우, 기본 num_train_timesteps 속성이 사용됩니다.
  • timesteps (list[int], 선택 사항) — timesteps 사이의 임의의 간격을 지원하기 위해 사용되는 사용자 지정 timesteps입니다. None인 경우, timestep_spacing 속성에 기반하여 timesteps가 생성됩니다. timesteps가 전달되면 num_inference_steps는 None이어야 하며, timestep_spacing 속성은 무시됩니다.

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

단계

< >

( model_output: typing.Union[torch.Tensor, numpy.ndarray]timestep: typing.Union[float, torch.Tensor]sample: typing.Union[torch.Tensor, numpy.ndarray]return_dict: bool = True ) → HeunDiscreteSchedulerOutput or tuple

매개변수

  • model_output (torch.Tensor) — 학습된 diffusion 모델의 직접적인 출력입니다.
  • timestep (float) — 확산 체인(diffusion chain)의 현재 이산 시간 단계(discrete timestep)입니다.
  • sample (torch.Tensor) — 확산 과정에 의해 생성된 샘플의 현재 인스턴스입니다.
  • return_dict (bool) — HeunDiscreteSchedulerOutput 또는 tuple을 반환할지 여부.

반환값

HeunDiscreteSchedulerOutput 또는 tuple

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

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

SchedulerOutput

class diffusers.schedulers.scheduling_utils.SchedulerOutput

< >

( prev_sample: Tensor )

매개변수

  • prev_sample (이미지의 경우 torch.Tensor, shape (batch_size, num_channels, height, width)) — 이전 timestep의 계산된 샘플 (x_{t-1}). prev_sample은 denoising 루프에서 다음 모델 입력으로 사용해야 합니다.

스케줄러의 step 함수 출력을 위한 베이스 클래스.

Update on GitHub