MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / UnCLIPScheduler

Class UnCLIPScheduler

diffusers/src/diffusers/schedulers/scheduling_unclip.py:92–352  ·  view source on GitHub ↗

NOTE: do not use this scheduler. The DDPM scheduler has been updated to support the changes made here. This scheduler will be removed and replaced with DDPM. This is a modified DDPM Scheduler specifically for the karlo unCLIP model. This scheduler has some minor variations in how

Source from the content-addressed store, hash-verified

90
91
92class UnCLIPScheduler(SchedulerMixin, ConfigMixin):
93 """
94 NOTE: do not use this scheduler. The DDPM scheduler has been updated to support the changes made here. This
95 scheduler will be removed and replaced with DDPM.
96
97 This is a modified DDPM Scheduler specifically for the karlo unCLIP model.
98
99 This scheduler has some minor variations in how it calculates the learned range variance and dynamically
100 re-calculates betas based off the timesteps it is skipping.
101
102 The scheduler also uses a slightly different step ratio when computing timesteps to use for inference.
103
104 See [`~DDPMScheduler`] for more information on DDPM scheduling
105
106 Args:
107 num_train_timesteps (`int`): number of diffusion steps used to train the model.
108 variance_type (`str`):
109 options to clip the variance used when adding noise to the denoised sample. Choose from `fixed_small_log`
110 or `learned_range`.
111 clip_sample (`bool`, default `True`):
112 option to clip predicted sample between `-clip_sample_range` and `clip_sample_range` for numerical
113 stability.
114 clip_sample_range (`float`, default `1.0`):
115 The range to clip the sample between. See `clip_sample`.
116 prediction_type (`str`, default `epsilon`, optional):
117 prediction type of the scheduler function, one of `epsilon` (predicting the noise of the diffusion process)
118 or `sample` (directly predicting the noisy sample`)
119 """
120
121 @register_to_config
122 def __init__(
123 self,
124 num_train_timesteps: int = 1000,
125 variance_type: str = "fixed_small_log",
126 clip_sample: bool = True,
127 clip_sample_range: Optional[float] = 1.0,
128 prediction_type: str = "epsilon",
129 beta_schedule: str = "squaredcos_cap_v2",
130 ):
131 if beta_schedule != "squaredcos_cap_v2":
132 raise ValueError("UnCLIPScheduler only supports `beta_schedule`: 'squaredcos_cap_v2'")
133
134 self.betas = betas_for_alpha_bar(num_train_timesteps)
135
136 self.alphas = 1.0 - self.betas
137 self.alphas_cumprod = torch.cumprod(self.alphas, dim=0)
138 self.one = torch.tensor(1.0)
139
140 # standard deviation of the initial noise distribution
141 self.init_noise_sigma = 1.0
142
143 # setable values
144 self.num_inference_steps = None
145 self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy())
146
147 self.variance_type = variance_type
148
149 def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor:

Calls

no outgoing calls

Tested by

no test coverage detected