text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
negative_prompt_attention_mask = negative_prompt_attention_mask.view(bs_embed, -1) negative_prompt_attention_mask = negative_prompt_attention_mask.repeat(num_images_per_prompt, 1) else: negative_prompt_embeds = None negative_prompt_attention_mask = None if self.text_...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs def prepare_extra_step_kwargs(self, generator, eta): # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature # eta (η) is only used w...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
def check_inputs( self, prompt, height, width, callback_on_step_end_tensor_inputs=None, negative_prompt=None, prompt_embeds=None, negative_prompt_embeds=None, prompt_attention_mask=None, negative_prompt_attention_mask=None, ): i...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
if prompt is not None and prompt_embeds is not None: raise ValueError( f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to" " only forward one of the two." ) elif prompt is None and prompt_embeds is None: ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
if negative_prompt is not None and negative_prompt_embeds is not None: raise ValueError( f"Cannot forward both `negative_prompt`: {negative_prompt} and `negative_prompt_embeds`:" f" {negative_prompt_embeds}. Please make sure to only forward one of the two." ) ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
if prompt_embeds is not None and negative_prompt_embeds is not None: if prompt_embeds.shape != negative_prompt_embeds.shape: raise ValueError( "`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but" f" got: `pr...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline._text_preprocessing def _text_preprocessing(self, text, clean_caption=False): if clean_caption and not is_bs4_available(): logger.warning(BACKENDS_MAPPING["bs4"][-1].format("Setting `clean_caption=True`")) logger.w...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline._clean_caption def _clean_caption(self, caption): caption = str(caption) caption = ul.unquote_plus(caption) caption = caption.strip().lower() caption = re.sub("<person>", "person", caption) # urls: ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# 31C0—31EF CJK Strokes # 31F0—31FF Katakana Phonetic Extensions # 3200—32FF Enclosed CJK Letters and Months # 3300—33FF CJK Compatibility # 3400—4DBF CJK Unified Ideographs Extension A # 4DC0—4DFF Yijing Hexagram Symbols # 4E00—9FFF CJK Unified Ideographs caption...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# все виды тире / all types of dash --> "-" caption = re.sub( r"[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D]+", # noqa "-", caption, ) # кавычки к одному стандарту caption...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# "#123" caption = re.sub(r"#\d{1,3}\b", "", caption) # "#12345.." caption = re.sub(r"#\d{5,}\b", "", caption) # "123456.." caption = re.sub(r"\b\d{6,}\b", "", caption) # filenames: caption = re.sub(r"[\S]+\.(?:png|jpg|jpeg|bmp|webp|eps|pdf|apk|mp4)", "", caption)...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
caption = re.sub(r"\b[a-zA-Z]{1,3}\d{3,15}\b", "", caption) # jc6640 caption = re.sub(r"\b[a-zA-Z]+\d+[a-zA-Z]+\b", "", caption) # jc6640vc caption = re.sub(r"\b\d+[a-zA-Z]+\d+\b", "", caption) # 6640vc231 caption = re.sub(r"(worldwide\s+)?(free\s+)?shipping", "", caption) caption = ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
caption = re.sub(r"^[\"\']([\w\W]+)[\"\']$", r"\1", caption) caption = re.sub(r"^[\'\_,\-\:;]", r"", caption) caption = re.sub(r"[\'\_,\-\:\-\+]$", r"", caption) caption = re.sub(r"^\.\S+$", "", caption) return caption.strip() def prepare_latents(self, batch_size, num_channels_late...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
latents = randn_tensor(shape, generator=generator, device=device, dtype=dtype) return latents @property def guidance_scale(self): return self._guidance_scale @property def attention_kwargs(self): return self._attention_kwargs @property def do_classifier_free_guidance(s...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]] = None, negative_prompt: str = "", num_inference_steps: int = 20, timesteps: List[int] = None, sigmas: List[float] = None, guidance_scale: flo...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
attention_kwargs: Optional[Dict[str, Any]] = None, callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None, callback_on_step_end_tensor_inputs: List[str] = ["latents"], max_sequence_length: int = 300, complex_human_instruction: List[str] = [ "Given a user prom...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
"- User Prompt: A cat sleeping -> Enhanced: A small, fluffy white cat curled up in a round shape, sleeping peacefully on a warm sunny windowsill, surrounded by pots of blooming red flowers.", "- User Prompt: A busy city street -> Enhanced: A bustling city street scene at dusk, featuring glowing street lamps...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
Args: prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`. instead. negative_prompt (`str` or `List[str]`, *optional*): The prompt or prompts not to guide t...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed will be used. Must be in descending order. sigmas (`List[float]`, *optional*): Custom sigmas to use for the denoising process with schedulers which support a `sigmas` ar...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
usually at the expense of lower image quality. num_images_per_prompt (`int`, *optional*, defaults to 1): The number of images to generate per prompt. height (`int`, *optional*, defaults to self.unet.config.sample_size): The height in pixels of the generated image....
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
latents (`torch.Tensor`, *optional*): Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image generation. Can be used to tweak the same generation with different prompts. If not provided, a latents tensor will ge generated by samp...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
provided, negative_prompt_embeds will be generated from `negative_prompt` input argument. negative_prompt_attention_mask (`torch.Tensor`, *optional*): Pre-generated attention mask for negative text embeddings. output_type (`str`, *optional*, defaults to `"pil"`): ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
clean_caption (`bool`, *optional*, defaults to `True`): Whether or not to clean the caption before creating embeddings. Requires `beautifulsoup4` and `ftfy` to be installed. If the dependencies are not installed, the embeddings will be created from the raw prompt. ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`List`, *optional*): The list of tensor inputs for the `callback_on_step_end` function. The tensors specifie...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
Examples: Returns: [`~pipelines.sana.pipeline_output.SanaPipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.sana.pipeline_output.SanaPipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# 1. Check inputs. Raise error if not correct if use_resolution_binning: if self.transformer.config.sample_size == 128: aspect_ratio_bin = ASPECT_RATIO_4096_BIN elif self.transformer.config.sample_size == 64: aspect_ratio_bin = ASPECT_RATIO_2048_BIN ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
self.check_inputs( prompt, height, width, callback_on_step_end_tensor_inputs, negative_prompt, prompt_embeds, negative_prompt_embeds, prompt_attention_mask, negative_prompt_attention_mask, ) self...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# 3. Encode input prompt ( prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask, ) = self.encode_prompt( prompt, self.do_classifier_free_guidance, negative_prompt=negative_prompt, ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
prompt_attention_mask = torch.cat([negative_prompt_attention_mask, prompt_attention_mask], dim=0)
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# 4. Prepare timesteps timesteps, num_inference_steps = retrieve_timesteps( self.scheduler, num_inference_steps, device, timesteps, sigmas ) # 5. Prepare latents. latent_channels = self.transformer.config.in_channels latents = self.prepare_latents( batch_...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): if self.interrupt: continue latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents latent_model_in...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
# perform guidance if self.do_classifier_free_guidance: noise_pred_uncond, noise_pred_text = noise_pred.chunk(2) noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond) # learned sigma if self.transf...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
latents = callback_outputs.pop("latents", latents) prompt_embeds = callback_outputs.pop("prompt_embeds", prompt_embeds) negative_prompt_embeds = callback_outputs.pop("negative_prompt_embeds", negative_prompt_embeds) # call the callback, if provided ...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
if output_type == "latent": image = latents else: latents = latents.to(self.vae.dtype) try: image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0] except torch.cuda.OutOfMemoryError as e: warnings.wa...
238
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/sana/pipeline_sana.py
class AudioLDMPipeline(DiffusionPipeline, StableDiffusionMixin): r""" Pipeline for text-to-audio generation using AudioLDM. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particu...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Args: vae ([`AutoencoderKL`]): Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations. text_encoder ([`~transformers.ClapTextModelWithProjection`]): Frozen text-encoder (`ClapTextModelWithProjection`, specifically the [laio...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
model_cpu_offload_seq = "text_encoder->unet->vae" def __init__( self, vae: AutoencoderKL, text_encoder: ClapTextModelWithProjection, tokenizer: Union[RobertaTokenizer, RobertaTokenizerFast], unet: UNet2DConditionModel, scheduler: KarrasDiffusionSchedulers, vo...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
def _encode_prompt( self, prompt, device, num_waveforms_per_prompt, do_classifier_free_guidance, negative_prompt=None, prompt_embeds: Optional[torch.Tensor] = None, negative_prompt_embeds: Optional[torch.Tensor] = None, ): r""" Encodes ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded device (`torch.device`): torch device num_waveforms_per_prompt (`int`): number of waveforms that should be generated per prompt do_classifier_free_guidanc...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
negative_prompt_embeds (`torch.Tensor`, *optional*): Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input argument. """ ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
if prompt_embeds is None: text_inputs = self.tokenizer( prompt, padding="max_length", max_length=self.tokenizer.model_max_length, truncation=True, return_tensors="pt", ) text_input_ids = text_inputs.input...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal( text_input_ids, untruncated_ids ): removed_text = self.tokenizer.batch_decode( untruncated_ids[:, self.tokenizer.model_max_length - 1 : -1] ) logg...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
( bs_embed, seq_len, ) = prompt_embeds.shape # duplicate text embeddings for each generation per prompt, using mps friendly method prompt_embeds = prompt_embeds.repeat(1, num_waveforms_per_prompt) prompt_embeds = prompt_embeds.view(bs_embed * num_waveforms_per_pro...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# get unconditional embeddings for classifier free guidance if do_classifier_free_guidance and negative_prompt_embeds is None: uncond_tokens: List[str] if negative_prompt is None: uncond_tokens = [""] * batch_size elif type(prompt) is not type(negative_prompt)...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
else: uncond_tokens = negative_prompt
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
max_length = prompt_embeds.shape[1] uncond_input = self.tokenizer( uncond_tokens, padding="max_length", max_length=max_length, truncation=True, return_tensors="pt", ) uncond_input_ids = uncond_input.inpu...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
negative_prompt_embeds = negative_prompt_embeds.to(dtype=self.text_encoder.dtype, device=device) negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_waveforms_per_prompt) negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_waveforms_per_prompt, seq_len) ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
waveform = self.vocoder(mel_spectrogram) # we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16 waveform = waveform.cpu().float() return waveform # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipe...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# check if the scheduler accepts generator accepts_generator = "generator" in set(inspect.signature(self.scheduler.step).parameters.keys()) if accepts_generator: extra_step_kwargs["generator"] = generator return extra_step_kwargs def check_inputs( self, prompt, ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
if self.vocoder.config.model_in_dim % self.vae_scale_factor != 0: raise ValueError( f"The number of frequency bins in the vocoder's log-mel spectrogram has to be divisible by the " f"VAE scale factor, but got {self.vocoder.config.model_in_dim} bins and a scale factor of " ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
if prompt is not None and prompt_embeds is not None: raise ValueError( f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to" " only forward one of the two." ) elif prompt is None and prompt_embeds is None: ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
if prompt_embeds is not None and negative_prompt_embeds is not None: if prompt_embeds.shape != negative_prompt_embeds.shape: raise ValueError( "`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but" f" got: `pr...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_latents with width->self.vocoder.config.model_in_dim def prepare_latents(self, batch_size, num_channels_latents, height, dtype, device, generator, latents=None): shape = ( batch_size, ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# scale the initial noise by the standard deviation required by the scheduler latents = latents * self.scheduler.init_noise_sigma return latents
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]] = None, audio_length_in_s: Optional[float] = None, num_inference_steps: int = 10, guidance_scale: float = 2.5, negative_prompt: Optional[Union[str, Li...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Args: prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide audio generation. If not defined, you need to pass `prompt_embeds`. audio_length_in_s (`int`, *optional*, defaults to 5.12): The length of the generated audio sample in seconds. ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
The prompt or prompts to guide what to not include in audio generation. If not defined, you need to pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`). num_waveforms_per_prompt (`int`, *optional*, defaults to 1): The number of wavefo...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image generation. Can be used to tweak the same generation with different prompts. If not provided, a latents tensor is generated by sampling using the supplied random `generator`. prom...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Whether or not to return a [`~pipelines.AudioPipelineOutput`] instead of a plain tuple. callback (`Callable`, *optional*): A function that calls every `callback_steps` steps during inference. The function is called with the following arguments: `callback(step: int, timestep: ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
The output format of the generated image. Choose between `"np"` to return a NumPy `np.ndarray` or `"pt"` to return a PyTorch `torch.Tensor` object.
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Examples: Returns: [`~pipelines.AudioPipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.AudioPipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated audio. """ # 0. Convert ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
original_waveform_length = int(audio_length_in_s * self.vocoder.config.sampling_rate) if height % self.vae_scale_factor != 0: height = int(np.ceil(height / self.vae_scale_factor)) * self.vae_scale_factor logger.info( f"Audio length in seconds {audio_length_in_s} is increa...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# 2. Define call parameters if prompt is not None and isinstance(prompt, str): batch_size = 1 elif prompt is not None and isinstance(prompt, list): batch_size = len(prompt) else: batch_size = prompt_embeds.shape[0] device = self._execution_device ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# 4. Prepare timesteps self.scheduler.set_timesteps(num_inference_steps, device=device) timesteps = self.scheduler.timesteps # 5. Prepare latent variables num_channels_latents = self.unet.config.in_channels latents = self.prepare_latents( batch_size * num_waveforms_p...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# 7. Denoising loop num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): # expand the latents if we are doing classifier free guidance ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
# perform guidance if do_classifier_free_guidance: noise_pred_uncond, noise_pred_text = noise_pred.chunk(2) noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond) # compute the previous noisy sample x_t -> x_t-1 ...
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
audio = self.mel_spectrogram_to_waveform(mel_spectrogram) audio = audio[:, :original_waveform_length] if output_type == "np": audio = audio.numpy() if not return_dict: return (audio,) return AudioPipelineOutput(audios=audio)
239
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/audioldm/pipeline_audioldm.py
class ConsisIDPipeline(DiffusionPipeline, CogVideoXLoraLoaderMixin): r""" Pipeline for image-to-video generation using ConsisID. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the library implements for all the pipelines (such as downloading o...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Args: vae ([`AutoencoderKL`]): Variational Auto-Encoder (VAE) Model to encode and decode videos to and from latent representations. text_encoder ([`T5EncoderModel`]): Frozen text-encoder. ConsisID uses [T5](https://huggingface.co/docs/transformers/model_doc/t5#transfo...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
_optional_components = [] model_cpu_offload_seq = "text_encoder->transformer->vae" _callback_tensor_inputs = [ "latents", "prompt_embeds", "negative_prompt_embeds", ] def __init__( self, tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, vae: ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
self.register_modules( tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler, ) self.vae_scale_factor_spatial = ( 2 ** (len(self.vae.config.block_out_channels) - 1) if hasattr(self, "v...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
# Copied from diffusers.pipelines.cogvideo.pipeline_cogvideox.CogVideoXPipeline._get_t5_prompt_embeds def _get_t5_prompt_embeds( self, prompt: Union[str, List[str]] = None, num_videos_per_prompt: int = 1, max_sequence_length: int = 226, device: Optional[torch.device] = None, ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(text_input_ids, untruncated_ids): removed_text = self.tokenizer.batch_decode(untruncated_ids[:, max_sequence_length - 1 : -1]) logger.warning( "The following part of your input was truncated because `max...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
# Copied from diffusers.pipelines.cogvideo.pipeline_cogvideox.CogVideoXPipeline.encode_prompt def encode_prompt( self, prompt: Union[str, List[str]], negative_prompt: Optional[Union[str, List[str]]] = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded negative_prompt (`str` or `List[str]`, *optional*): The prompt or prompts not to guide the image generation. If not defined, one has to pass `negative_prompt_embeds` instead. Ign...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
provided, text embeddings will be generated from `prompt` input argument. negative_prompt_embeds (`torch.Tensor`, *optional*): Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not provided, negative_prompt_embeds wil...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
prompt = [prompt] if isinstance(prompt, str) else prompt if prompt is not None: batch_size = len(prompt) else: batch_size = prompt_embeds.shape[0] if prompt_embeds is None: prompt_embeds = self._get_t5_prompt_embeds( prompt=prompt, ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if prompt is not None and type(prompt) is not type(negative_prompt): raise TypeError( f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !=" f" {type(prompt)}." ) elif batch_size != len(negative_pro...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
def prepare_latents( self, image: torch.Tensor, batch_size: int = 1, num_channels_latents: int = 16, num_frames: int = 13, height: int = 60, width: int = 90, dtype: Optional[torch.dtype] = None, device: Optional[torch.device] = None, genera...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
num_frames = (num_frames - 1) // self.vae_scale_factor_temporal + 1 shape = ( batch_size, num_frames, num_channels_latents, height // self.vae_scale_factor_spatial, width // self.vae_scale_factor_spatial, ) image = image.unsqueeze(2) ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if isinstance(generator, list): image_latents = [ retrieve_latents(self.vae.encode(image[i].unsqueeze(0)), generator[i]) for i in range(batch_size) ] if kps_cond is not None: kps_cond = kps_cond.unsqueeze(2) kps_cond_latents = [ ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if kps_cond is not None: kps_cond_latents = torch.cat(kps_cond_latents, dim=0).to(dtype).permute(0, 2, 1, 3, 4) # [B, F, C, H, W] kps_cond_latents = self.vae_scaling_factor_image * kps_cond_latents padding_shape = ( batch_size, num_frames - 2, ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
latent_padding = torch.zeros(padding_shape, device=device, dtype=dtype) if kps_cond is not None: image_latents = torch.cat([image_latents, kps_cond_latents, latent_padding], dim=1) else: image_latents = torch.cat([image_latents, latent_padding], dim=1) if latents is None...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
frames = self.vae.decode(latents).sample return frames # Copied from diffusers.pipelines.animatediff.pipeline_animatediff_video2video.AnimateDiffVideoToVideoPipeline.get_timesteps def get_timesteps(self, num_inference_steps, timesteps, strength, device): # get the original timestep using init_t...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs def prepare_extra_step_kwargs(self, generator, eta): # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature # eta (η) is only used w...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
def check_inputs( self, image, prompt, height, width, negative_prompt, callback_on_step_end_tensor_inputs, latents=None, prompt_embeds=None, negative_prompt_embeds=None, ): if ( not isinstance(image, torch.Tensor) ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if callback_on_step_end_tensor_inputs is not None and not all( k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs ): raise ValueError( f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in cal...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
raise ValueError(f"`prompt` has to be of type `str` or `list` but is {type(prompt)}")
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if prompt is not None and negative_prompt_embeds is not None: raise ValueError( f"Cannot forward both `prompt`: {prompt} and `negative_prompt_embeds`:" f" {negative_prompt_embeds}. Please make sure to only forward one of the two." ) if negative_prompt is ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
if prompt_embeds is not None and negative_prompt_embeds is not None: if prompt_embeds.shape != negative_prompt_embeds.shape: raise ValueError( "`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but" f" got: `pr...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
def _prepare_rotary_positional_embeddings( self, height: int, width: int, num_frames: int, device: torch.device, ) -> Tuple[torch.Tensor, torch.Tensor]: grid_height = height // (self.vae_scale_factor_spatial * self.transformer.config.patch_size) grid_width = w...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
grid_crops_coords = get_resize_crop_region_for_grid( (grid_height, grid_width), base_size_width, base_size_height ) freqs_cos, freqs_sin = get_3d_rotary_pos_embed( embed_dim=self.transformer.config.attention_head_dim, crops_coords=grid_crops_coords, grid_s...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, image: PipelineImageInput, prompt: Optional[Union[str, List[str]]] = None, negative_prompt: Optional[Union[str, List[str]]] = None, height: int = 480, width: int = 720, num...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Union[Callable[[int, int, Dict], None], PipelineCallback, MultiPipelineCallbacks] ] = None, callback_on_step_end_tensor_inputs: List[str] = ["latents"], max_sequence_length: int = 226, id_vit_hidden: Optional[torch.Tensor] = None, id_cond: Optional[torch.Tensor] = None, k...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Args: image (`PipelineImageInput`): The input image to condition the generation on. Must be an image, a list of images or a `torch.Tensor`. prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide the image generation. If not defined, one has to p...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
width (`int`, *optional*, defaults to self.transformer.config.sample_height * self.vae_scale_factor_spatial): The width in pixels of the generated image. This is set to 720 by default for the best results. num_frames (`int`, defaults to `49`): Number of frames to generate. Mu...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598). `guidance_scale` is defined as `w` of equation 2. of [Imagen Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale > 1`. Highe...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
more faithful image generation, while later steps reduce it for more diverse and natural results. num_videos_per_prompt (`int`, *optional*, defaults to 1): The number of videos to generate per prompt. generator (`torch.Generator` or `List[torch.Generator]`, *optional*): ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not provided, text embeddings will be generated from `prompt` input argument. negative_prompt_embeds (`torch.FloatTensor`, *optional*): Pre-generated negative text embeddings. ...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py
attention_kwargs (`dict`, *optional*): A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under `self.processor` in [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/att...
240
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/consisid/pipeline_consisid.py