text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
prompt_embeds = prompt_embeds.to(device=device) prompt_attention_mask = prompt_attention_mask.to(device=device) prompt_embeds_2 = prompt_embeds_2.to(device=device) prompt_attention_mask_2 = prompt_attention_mask_2.to(device=device) add_time_ids = add_time_ids.to(dtype=prompt_embeds.dtype...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
# expand the latents if we are doing classifier free guidance latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents latent_model_input = self.scheduler.scale_model_input(latent_model_input, t) # expand scalar t to 1-D tensor to ma...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
# predict the noise residual noise_pred = self.transformer( latent_model_input, t_expand, encoder_hidden_states=prompt_embeds, text_embedding_mask=prompt_attention_mask, encoder_hidden_states_t5=prompt_em...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
if self.do_classifier_free_guidance and guidance_rescale > 0.0: # Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdf noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale) # compute the previous noisy sample x_t -> x_t-1...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.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) prompt_embeds_2 = callback_outputs.pop("prom...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
if not output_type == "latent": image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0] image, has_nsfw_concept = self.run_safety_checker(image, device, prompt_embeds.dtype) else: image = latents has_nsfw_concept = None if ...
328
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
class PixArtAlphaPipeline(DiffusionPipeline): r""" Pipeline for text-to-image generation using PixArt-Alpha. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the library implements for all the pipelines (such as downloading or saving, running on...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
Args: vae ([`AutoencoderKL`]): Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. text_encoder ([`T5EncoderModel`]): Frozen text-encoder. PixArt-Alpha uses [T5](https://huggingface.co/docs/transformers/model_doc/t5#tra...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
bad_punct_regex = re.compile( r"[" + "#®•©™&@·º½¾¿¡§~" + r"\)" + r"\(" + r"\]" + r"\[" + r"\}" + r"\{" + r"\|" + "\\" + r"\/" + r"\*" + r"]{1,}" ) # noqa _optional_components = ["tokenizer", "text_encoder"]...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# Adapted from diffusers.pipelines.deepfloyd_if.pipeline_if.encode_prompt def encode_prompt( self, prompt: Union[str, List[str]], do_classifier_free_guidance: bool = True, negative_prompt: str = "", num_images_per_prompt: int = 1, device: Optional[torch.device] = None...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded negative_prompt (`str` or `List[str]`, *optional*): The prompt not to guide the image generation. If not defined, one has to pass `negative_prompt_embeds` instead. Ignored when n...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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.Tensor`, *optional*): Pre-generated negative text embeddings. For P...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
if "mask_feature" in kwargs: deprecation_message = "The use of `mask_feature` is deprecated. It is no longer used in any computation and that doesn't affect the end results. It will be removed in a future version." deprecate("mask_feature", "1.0.0", deprecation_message, standard_warn=False) ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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_length - 1 : -1]) logger.warning( "The following part of your...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
prompt_embeds = prompt_embeds.to(dtype=dtype, device=device) bs_embed, seq_len, _ = prompt_embeds.shape # duplicate text embeddings and attention mask for each generation per prompt, using mps friendly method prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1) prompt_embed...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# get unconditional embeddings for classifier free guidance if do_classifier_free_guidance and negative_prompt_embeds is None: uncond_tokens = [negative_prompt] * bs_embed if isinstance(negative_prompt, str) else negative_prompt uncond_tokens = self._text_preprocessing(uncond_tokens, cle...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
negative_prompt_embeds = self.text_encoder( uncond_input.input_ids.to(device), attention_mask=negative_prompt_attention_mask ) negative_prompt_embeds = negative_prompt_embeds[0] if do_classifier_free_guidance: # duplicate unconditional embeddings for each gen...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
negative_prompt_attention_mask = negative_prompt_attention_mask.repeat(1, num_images_per_prompt) negative_prompt_attention_mask = negative_prompt_attention_mask.view(bs_embed * num_images_per_prompt, -1) else: negative_prompt_embeds = None negative_prompt_attention_mask = Non...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
accepts_eta = "eta" in set(inspect.signature(self.scheduler.step).parameters.keys()) extra_step_kwargs = {} if accepts_eta: extra_step_kwargs["eta"] = eta # check if the scheduler accepts generator accepts_generator = "generator" in set(inspect.signature(self.scheduler.step)...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
if (callback_steps is None) or ( callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0) ): raise ValueError( f"`callback_steps` has to be a positive integer but is {callback_steps} of type" f" {type(callback_steps)}." ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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: ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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." ) ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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: ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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)...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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 = ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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()
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_latents def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype, device, generator, latents=None): shape = ( batch_size, num_channels_latents, ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# scale the initial noise by the standard deviation required by the scheduler latents = latents * self.scheduler.init_noise_sigma return latents
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
callback_steps: int = 1, clean_caption: bool = True, use_resolution_binning: bool = True, max_sequence_length: int = 120, **kwargs, ) -> Union[ImagePipelineOutput, Tuple]: """ Function invoked when calling the pipeline for generation.
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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....
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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"`): ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. clean_caption (`bool`, *optional*, defaults to `True`): Whether or not to clean the caption before creating embeddings. Requires `beautifulsoup4` and `f...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
Examples:
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
Returns: [`~pipelines.ImagePipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.ImagePipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated images """ if "mask_feature" in kwargs: ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
elif self.transformer.config.sample_size == 64: aspect_ratio_bin = ASPECT_RATIO_512_BIN elif self.transformer.config.sample_size == 32: aspect_ratio_bin = ASPECT_RATIO_256_BIN else: raise ValueError("Invalid sample size") orig_height, o...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
self.check_inputs( prompt, height, width, negative_prompt, callback_steps, prompt_embeds, negative_prompt_embeds, prompt_attention_mask, negative_prompt_attention_mask, ) # 2. Default height and ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# 3. Encode input prompt ( prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask, ) = self.encode_prompt( prompt, do_classifier_free_guidance, negative_prompt=negative_prompt, ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.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_...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# 6.1 Prepare micro-conditions. added_cond_kwargs = {"resolution": None, "aspect_ratio": None} if self.transformer.config.sample_size == 128: resolution = torch.tensor([height, width]).repeat(batch_size * num_images_per_prompt, 1) aspect_ratio = torch.tensor([float(height / width...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
current_timestep = t if not torch.is_tensor(current_timestep): # TODO: this requires sync between CPU and GPU. So try to pass timesteps as tensors if you can # This would be a good case for the `match` statement (Python 3.10+) is_mps = latent_m...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
current_timestep = current_timestep.expand(latent_model_input.shape[0])
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# predict noise model_output noise_pred = self.transformer( latent_model_input, encoder_hidden_states=prompt_embeds, encoder_attention_mask=prompt_attention_mask, timestep=current_timestep, added_cond_kwa...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
# compute previous image: x_t -> x_t-1 if num_inference_steps == 1: # For DMD one step sampling: https://arxiv.org/abs/2311.18828 latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs).pred_original_sample else: ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
if not output_type == "latent": image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0] if use_resolution_binning: image = self.image_processor.resize_and_crop_tensor(image, orig_width, orig_height) else: image = latents ...
329
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.py
class PixArtSigmaPipeline(DiffusionPipeline): r""" Pipeline for text-to-image generation using PixArt-Sigma. """ bad_punct_regex = re.compile( r"[" + "#®•©™&@·º½¾¿¡§~" + r"\)" + r"\(" + r"\]" + r"\[" + r"\}" + r"\{" + r"\|" ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) if getattr(self, "vae", None) else 8 self.image_processor = PixArtImageProcessor(vae_scale_factor=self.vae_scale_factor) # Copied from diffusers.pipelines.pixart_alpha.pipeline_pixart_alpha.PixArtAlphaPipeline.encode_prompt with 120...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded negative_prompt (`str` or `List[str]`, *optional*): The prompt not to guide the image generation. If not defined, one has to pass `negative_prompt_embeds` instead. Ignored when n...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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.Tensor`, *optional*): Pre-generated negative text embeddings. For P...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
if "mask_feature" in kwargs: deprecation_message = "The use of `mask_feature` is deprecated. It is no longer used in any computation and that doesn't affect the end results. It will be removed in a future version." deprecate("mask_feature", "1.0.0", deprecation_message, standard_warn=False) ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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_length - 1 : -1]) logger.warning( "The following part of your...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
prompt_embeds = prompt_embeds.to(dtype=dtype, device=device) bs_embed, seq_len, _ = prompt_embeds.shape # duplicate text embeddings and attention mask for each generation per prompt, using mps friendly method prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1) prompt_embed...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# get unconditional embeddings for classifier free guidance if do_classifier_free_guidance and negative_prompt_embeds is None: uncond_tokens = [negative_prompt] * bs_embed if isinstance(negative_prompt, str) else negative_prompt uncond_tokens = self._text_preprocessing(uncond_tokens, cle...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
negative_prompt_embeds = self.text_encoder( uncond_input.input_ids.to(device), attention_mask=negative_prompt_attention_mask ) negative_prompt_embeds = negative_prompt_embeds[0] if do_classifier_free_guidance: # duplicate unconditional embeddings for each gen...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
negative_prompt_attention_mask = negative_prompt_attention_mask.repeat(1, num_images_per_prompt) negative_prompt_attention_mask = negative_prompt_attention_mask.view(bs_embed * num_images_per_prompt, -1) else: negative_prompt_embeds = None negative_prompt_attention_mask = Non...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
accepts_eta = "eta" in set(inspect.signature(self.scheduler.step).parameters.keys()) extra_step_kwargs = {} if accepts_eta: extra_step_kwargs["eta"] = eta # check if the scheduler accepts generator accepts_generator = "generator" in set(inspect.signature(self.scheduler.step)...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
if (callback_steps is None) or ( callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0) ): raise ValueError( f"`callback_steps` has to be a positive integer but is {callback_steps} of type" f" {type(callback_steps)}." ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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: ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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." ) ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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: ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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)...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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 = ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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()
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_latents def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype, device, generator, latents=None): shape = ( batch_size, num_channels_latents, ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# scale the initial noise by the standard deviation required by the scheduler latents = latents * self.scheduler.init_noise_sigma return latents
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
callback_steps: int = 1, clean_caption: bool = True, use_resolution_binning: bool = True, max_sequence_length: int = 300, **kwargs, ) -> Union[ImagePipelineOutput, Tuple]: """ Function invoked when calling the pipeline for generation.
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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....
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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"`): ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
The frequency at which the `callback` function will be called. If not specified, the callback will be called at every step. clean_caption (`bool`, *optional*, defaults to `True`): Whether or not to clean the caption before creating embeddings. Requires `beautifulsoup4` and `f...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
Examples:
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
Returns: [`~pipelines.ImagePipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.ImagePipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated images """ # 1. Check inputs. Raise error i...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
else: raise ValueError("Invalid sample size") orig_height, orig_width = height, width height, width = self.image_processor.classify_height_width_bin(height, width, ratios=aspect_ratio_bin)
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
self.check_inputs( prompt, height, width, negative_prompt, callback_steps, prompt_embeds, negative_prompt_embeds, prompt_attention_mask, negative_prompt_attention_mask, ) # 2. Default height and ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# 3. Encode input prompt ( prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask, ) = self.encode_prompt( prompt, do_classifier_free_guidance, negative_prompt=negative_prompt, ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.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_...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
current_timestep = t if not torch.is_tensor(current_timestep): # TODO: this requires sync between CPU and GPU. So try to pass timesteps as tensors if you can # This would be a good case for the `match` statement (Python 3.10+) is_mps = latent_m...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
current_timestep = current_timestep.expand(latent_model_input.shape[0])
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# predict noise model_output noise_pred = self.transformer( latent_model_input, encoder_hidden_states=prompt_embeds, encoder_attention_mask=prompt_attention_mask, timestep=current_timestep, added_cond_kwa...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
# compute previous image: x_t -> x_t-1 latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0] # call the callback, if provided if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0): ...
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
if not output_type == "latent": image = self.image_processor.postprocess(image, output_type=output_type) # Offload all models self.maybe_free_model_hooks() if not return_dict: return (image,) return ImagePipelineOutput(images=image)
330
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/pixart_alpha/pipeline_pixart_sigma.py
class DDPMPipeline(DiffusionPipeline): r""" Pipeline for image generation. This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particular device, etc.). Parameters: unet ...
331
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/ddpm/pipeline_ddpm.py
@torch.no_grad() def __call__( self, batch_size: int = 1, generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None, num_inference_steps: int = 1000, output_type: Optional[str] = "pil", return_dict: bool = True, ) -> Union[ImagePipelineOutput, Tupl...
331
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/ddpm/pipeline_ddpm.py
Args: batch_size (`int`, *optional*, defaults to 1): The number of images to generate. generator (`torch.Generator`, *optional*): A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make generation deterministic...
331
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/ddpm/pipeline_ddpm.py