text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
# 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta) # 8. Denoising loop latents = image_latents[0].clone() num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler...
243
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py
# predict the noise residual noise_pred = self.unet( latent_model_input, t, encoder_hidden_states=prompt_embeds, cross_attention_kwargs=cross_attention_kwargs, ).sample # perform guidance ...
243
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py
# call the callback, if provided if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0): progress_bar.update() if callback is not None and i % callback_steps == 0: step_idx = i // getattr(self.sch...
243
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py
image = self.image_processor.postprocess(image, output_type=output_type, do_denormalize=do_denormalize) # Offload all models self.maybe_free_model_hooks() if not return_dict: return (image, has_nsfw_concept) return StableDiffusionPipelineOutput(images=image, nsfw_content_d...
243
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/stable_diffusion_diffedit/pipeline_stable_diffusion_diffedit.py
class AmusedInpaintPipeline(DiffusionPipeline): image_processor: VaeImageProcessor vqvae: VQModel tokenizer: CLIPTokenizer text_encoder: CLIPTextModelWithProjection transformer: UVit2DModel scheduler: AmusedScheduler model_cpu_offload_seq = "text_encoder->transformer->vqvae" # TODO - w...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
self.register_modules( vqvae=vqvae, tokenizer=tokenizer, text_encoder=text_encoder, transformer=transformer, scheduler=scheduler, ) self.vae_scale_factor = ( 2 ** (len(self.vqvae.config.block_out_channels) - 1) if getattr(self, "vqv...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Optional[Union[List[str], str]] = None, image: PipelineImageInput = None, mask_image: PipelineImageInput = None, strength: float = 1.0, num_inference_steps: int = 12, ...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
micro_conditioning_aesthetic_score: int = 6, micro_conditioning_crop_coord: Tuple[int, int] = (0, 0), temperature: Union[int, Tuple[int, int], List[int]] = (2, 0), ): """ The call function to the pipeline for generation.
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
Args: prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`. image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, or `List[np.ndarray]`): ...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
mask_image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, or `List[np.ndarray]`): `Image`, numpy array or tensor representing an image batch to mask `image`. White pixels in the mask are repainted while black pixels are preserved. If `mas...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
starting point and more noise is added the higher the `strength`. The number of denoising steps depends on the amount of noise initially added. When `strength` is 1, added noise is maximum and the denoising process runs for the full number of iterations specified in `num_inference_steps`...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
The prompt or prompts to guide what to not include in image generation. If not defined, you need to pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`). num_images_per_prompt (`int`, *optional*, defaults to 1): The number of images to...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
Pre-generated penultimate hidden states from the text encoder providing additional text conditioning. negative_prompt_embeds (`torch.Tensor`, *optional*): Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not provided, `neg...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
A function that calls every `callback_steps` steps during inference. The function is called with the following arguments: `callback(step: int, timestep: int, latents: torch.Tensor)`. callback_steps (`int`, *optional*, defaults to 1): The frequency at which the `callback` func...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
https://arxiv.org/abs/2307.01952. micro_conditioning_crop_coord (`Tuple[int]`, *optional*, defaults to (0, 0)): The targeted height, width crop coordinates. See the micro-conditioning section of https://arxiv.org/abs/2307.01952. temperature (`Union[int, Tuple[int,...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
Examples: Returns: [`~pipelines.pipeline_utils.ImagePipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.pipeline_utils.ImagePipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated images. ...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
if (prompt is None and prompt_embeds is None) or (prompt is not None and prompt_embeds is not None): raise ValueError("pass only one of `prompt` or `prompt_embeds`") if isinstance(prompt, str): prompt = [prompt] if prompt is not None: batch_size = len(prompt) ...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
prompt_embeds = prompt_embeds.repeat(num_images_per_prompt, 1) encoder_hidden_states = encoder_hidden_states.repeat(num_images_per_prompt, 1, 1) if guidance_scale > 1.0: if negative_prompt_embeds is None: if negative_prompt is None: negative_prompt = [""]...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
negative_prompt_embeds = negative_prompt_embeds.repeat(num_images_per_prompt, 1) negative_encoder_hidden_states = negative_encoder_hidden_states.repeat(num_images_per_prompt, 1, 1) prompt_embeds = torch.concat([negative_prompt_embeds, prompt_embeds]) encoder_hidden_states = torch.co...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
# Note that the micro conditionings _do_ flip the order of width, height for the original size # and the crop coordinates. This is how it was done in the original code base micro_conds = torch.tensor( [ width, height, micro_conditioning_crop_co...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
needs_upcasting = self.vqvae.dtype == torch.float16 and self.vqvae.config.force_upcast if needs_upcasting: self.vqvae.float() latents = self.vqvae.encode(image.to(dtype=self.vqvae.dtype, device=self._execution_device)).latents latents_bsz, channels, latents_height, latents_width = ...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
with self.progress_bar(total=num_inference_steps) as progress_bar: for i in range(start_timestep_idx, len(self.scheduler.timesteps)): timestep = self.scheduler.timesteps[i] if guidance_scale > 1.0: model_input = torch.cat([latents] * 2) el...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
latents = self.scheduler.step( model_output=model_output, timestep=timestep, sample=latents, generator=generator, starting_mask_ratio=starting_mask_ratio, ).prev_sample if i == len(self.s...
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
if output_type == "latent": output = latents else: output = self.vqvae.decode( latents, force_not_quantize=True, shape=( batch_size, height // self.vae_scale_factor, width // self....
244
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_inpaint.py
class AmusedImg2ImgPipeline(DiffusionPipeline): image_processor: VaeImageProcessor vqvae: VQModel tokenizer: CLIPTokenizer text_encoder: CLIPTextModelWithProjection transformer: UVit2DModel scheduler: AmusedScheduler model_cpu_offload_seq = "text_encoder->transformer->vqvae" # TODO - w...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
self.register_modules( vqvae=vqvae, tokenizer=tokenizer, text_encoder=text_encoder, transformer=transformer, scheduler=scheduler, ) self.vae_scale_factor = ( 2 ** (len(self.vqvae.config.block_out_channels) - 1) if getattr(self, "vqv...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Optional[Union[List[str], str]] = None, image: PipelineImageInput = None, strength: float = 0.5, num_inference_steps: int = 12, guidance_scale: float = 10.0, negati...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
micro_conditioning_crop_coord: Tuple[int, int] = (0, 0), temperature: Union[int, Tuple[int, int], List[int]] = (2, 0), ): """ The call function to the pipeline for generation.
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
Args: prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`. image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, or `List[np.ndarray]`): ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
Indicates extent to transform the reference `image`. Must be between 0 and 1. `image` is used as a starting point and more noise is added the higher the `strength`. The number of denoising steps depends on the amount of noise initially added. When `strength` is 1, added noise is maximum ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
`prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`. negative_prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide what to not include in image generation. If not defined, you need to pass `negative_prompt_e...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
provided, text embeddings are generated from the `prompt` input argument. A single vector from the pooled and projected final hidden states. encoder_hidden_states (`torch.Tensor`, *optional*): Pre-generated penultimate hidden states from the text encoder providing additional ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
return_dict (`bool`, *optional*, defaults to `True`): Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a plain tuple. callback (`Callable`, *optional*): A function that calls every `callback_steps` steps durin...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
micro_conditioning_aesthetic_score (`int`, *optional*, defaults to 6): The targeted aesthetic score according to the laion aesthetic classifier. See https://laion.ai/blog/laion-aesthetics/ and the micro-conditioning section of https://arxiv.org/abs/2307.01952. ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
Examples: Returns: [`~pipelines.pipeline_utils.ImagePipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.pipeline_utils.ImagePipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated images. ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
if (prompt is None and prompt_embeds is None) or (prompt is not None and prompt_embeds is not None): raise ValueError("pass only one of `prompt` or `prompt_embeds`") if isinstance(prompt, str): prompt = [prompt] if prompt is not None: batch_size = len(prompt) ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
prompt_embeds = prompt_embeds.repeat(num_images_per_prompt, 1) encoder_hidden_states = encoder_hidden_states.repeat(num_images_per_prompt, 1, 1) if guidance_scale > 1.0: if negative_prompt_embeds is None: if negative_prompt is None: negative_prompt = [""]...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
negative_prompt_embeds = negative_prompt_embeds.repeat(num_images_per_prompt, 1) negative_encoder_hidden_states = negative_encoder_hidden_states.repeat(num_images_per_prompt, 1, 1) prompt_embeds = torch.concat([negative_prompt_embeds, prompt_embeds]) encoder_hidden_states = torch.co...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
# Note that the micro conditionings _do_ flip the order of width, height for the original size # and the crop coordinates. This is how it was done in the original code base micro_conds = torch.tensor( [ width, height, micro_conditioning_crop_co...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
needs_upcasting = self.vqvae.dtype == torch.float16 and self.vqvae.config.force_upcast if needs_upcasting: self.vqvae.float() latents = self.vqvae.encode(image.to(dtype=self.vqvae.dtype, device=self._execution_device)).latents latents_bsz, channels, latents_height, latents_width = ...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
if guidance_scale > 1.0: model_input = torch.cat([latents] * 2) else: model_input = latents model_output = self.transformer( model_input, micro_conds=micro_conds, pooled_text_emb=prompt_e...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
if i == len(self.scheduler.timesteps) - 1 or ((i + 1) % self.scheduler.order == 0): progress_bar.update() if callback is not None and i % callback_steps == 0: step_idx = i // getattr(self.scheduler, "order", 1) callback(step_idx, ti...
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
self.maybe_free_model_hooks() if not return_dict: return (output,) return ImagePipelineOutput(output)
245
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused_img2img.py
class AmusedPipeline(DiffusionPipeline): image_processor: VaeImageProcessor vqvae: VQModel tokenizer: CLIPTokenizer text_encoder: CLIPTextModelWithProjection transformer: UVit2DModel scheduler: AmusedScheduler model_cpu_offload_seq = "text_encoder->transformer->vqvae" def __init__( ...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Optional[Union[List[str], str]] = None, height: Optional[int] = None, width: Optional[int] = None, num_inference_steps: int = 12, guidance_scale: float = 10.0, nega...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
micro_conditioning_aesthetic_score: int = 6, micro_conditioning_crop_coord: Tuple[int, int] = (0, 0), temperature: Union[int, Tuple[int, int], List[int]] = (2, 0), ): """ The call function to the pipeline for generation.
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
Args: prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`. height (`int`, *optional*, defaults to `self.transformer.config.sample_size * self.vae_scale_factor`): The height in...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
`prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`. negative_prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide what to not include in image generation. If not defined, you need to pass `negative_prompt_e...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
prompt_embeds (`torch.Tensor`, *optional*): Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not provided, text embeddings are generated from the `prompt` input argument. A single vector from the pooled and projected final hidd...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
output_type (`str`, *optional*, defaults to `"pil"`): The output format of the generated image. Choose between `PIL.Image` or `np.array`. return_dict (`bool`, *optional*, defaults to `True`): Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutp...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
[`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py). micro_conditioning_aesthetic_score (`int`, *optional*, defaults to 6): The targeted aesthetic score according to the laion aesthetic classifier. See https://lai...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
Examples: Returns: [`~pipelines.pipeline_utils.ImagePipelineOutput`] or `tuple`: If `return_dict` is `True`, [`~pipelines.pipeline_utils.ImagePipelineOutput`] is returned, otherwise a `tuple` is returned where the first element is a list with the generated images. ...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
if (prompt is None and prompt_embeds is None) or (prompt is not None and prompt_embeds is not None): raise ValueError("pass only one of `prompt` or `prompt_embeds`") if isinstance(prompt, str): prompt = [prompt] if prompt is not None: batch_size = len(prompt) ...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
outputs = self.text_encoder(input_ids, return_dict=True, output_hidden_states=True) prompt_embeds = outputs.text_embeds encoder_hidden_states = outputs.hidden_states[-2] prompt_embeds = prompt_embeds.repeat(num_images_per_prompt, 1) encoder_hidden_states = encoder_hidden_states....
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
outputs = self.text_encoder(input_ids, return_dict=True, output_hidden_states=True) negative_prompt_embeds = outputs.text_embeds negative_encoder_hidden_states = outputs.hidden_states[-2] negative_prompt_embeds = negative_prompt_embeds.repeat(num_images_per_prompt, 1) ...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
# Note that the micro conditionings _do_ flip the order of width, height for the original size # and the crop coordinates. This is how it was done in the original code base micro_conds = torch.tensor( [ width, height, micro_conditioning_crop_co...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
self.scheduler.set_timesteps(num_inference_steps, temperature, self._execution_device) num_warmup_steps = len(self.scheduler.timesteps) - num_inference_steps * self.scheduler.order with self.progress_bar(total=num_inference_steps) as progress_bar: for i, timestep in enumerate(self.scheduler...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
if guidance_scale > 1.0: uncond_logits, cond_logits = model_output.chunk(2) model_output = uncond_logits + guidance_scale * (cond_logits - uncond_logits) latents = self.scheduler.step( model_output=model_output, timestep=ti...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
if output_type == "latent": output = latents else: needs_upcasting = self.vqvae.dtype == torch.float16 and self.vqvae.config.force_upcast if needs_upcasting: self.vqvae.float() output = self.vqvae.decode( latents, ...
246
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/amused/pipeline_amused.py
class LuminaText2ImgPipeline(DiffusionPipeline): r""" Pipeline for text-to-image generation using Lumina-T2I. 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 o...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
Args: vae ([`AutoencoderKL`]): Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. text_encoder ([`AutoModel`]): Frozen text-encoder. Lumina-T2I uses [T5](https://huggingface.co/docs/transformers/model_doc/t5#transforme...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
bad_punct_regex = re.compile( r"[" + "#®•©™&@·º½¾¿¡§~" + r"\)" + r"\(" + r"\]" + r"\[" + r"\}" + r"\{" + r"\|" + "\\" + r"\/" + r"\*" + r"]{1,}" ) # noqa _optional_components = [] model_cpu_offload_seq ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
self.register_modules( vae=vae, text_encoder=text_encoder, tokenizer=tokenizer, transformer=transformer, scheduler=scheduler, ) self.vae_scale_factor = 8 self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor) ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
def _get_gemma_prompt_embeds( self, prompt: Union[str, List[str]], num_images_per_prompt: int = 1, device: Optional[torch.device] = None, clean_caption: Optional[bool] = False, max_length: Optional[int] = None, ): device = device or self._execution_device ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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.max_sequence_length - 1 : -1]) logger.warning( "The following part of your input was truncated because...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
_, 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_embeds = prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1) ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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: Union[str, List[str]] = None, num_images_per_prompt: int = 1, device: Optional[...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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 L...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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, prompt_attention_mask = self._get_gemma_prompt_embeds( ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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 isinstance(negative_prompt, st...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
max_length=prompt_max_length, truncation=True, return_tensors="pt", ) negative_text_input_ids = negative_text_inputs.input_ids.to(device) negative_prompt_attention_mask = negative_text_inputs.attention_mask.to(device) # Get the negative pro...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
negative_dtype = self.text_encoder.dtype negative_prompt_embeds = negative_prompt_embeds.hidden_states[-2] _, seq_len, _ = negative_prompt_embeds.shape negative_prompt_embeds = negative_prompt_embeds.to(dtype=negative_dtype, device=device) # duplicate text embeddings and...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
def check_inputs( self, prompt, height, width, negative_prompt, prompt_embeds=None, negative_prompt_embeds=None, prompt_attention_mask=None, negative_prompt_attention_mask=None, ): if height % 8 != 0 or width % 8 != 0: raise...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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: ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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." ) ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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: ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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)...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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 = ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
if latents is None: latents = randn_tensor(shape, generator=generator, device=device, dtype=dtype) else: latents = latents.to(device) return latents @property def guidance_scale(self): return self._guidance_scale # here `guidance_scale` is defined analog to...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]] = None, width: Optional[int] = None, height: Optional[int] = None, num_inference_steps: int = 30, guidance_scale: float = 4.0, negative_prompt...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
scaling_watershed: Optional[float] = 1.0, proportional_attn: Optional[bool] = True, ) -> Union[ImagePipelineOutput, Tuple]: """ Function invoked when calling the pipeline for generation.
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed will be used. guidance_scale (`float`, *optional*, defaults to 4.0): Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598). ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
width (`int`, *optional*, defaults to self.unet.config.sample_size): The width in pixels of the generated image. eta (`float`, *optional*, defaults to 0.0): Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to [...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
prompt_embeds (`torch.Tensor`, *optional*): 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. prompt_attention_mask (`torch.Tensor`, *optional*): Pr...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
[PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`. return_dict (`bool`, *optional*, defaults to `True`): Whether or not to return a [`~pipelines.stable_diffusion.IFPipelineOutput`] instead of a plain tuple. clean_caption (`bool`, *optional*, default...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, 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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
Examples: 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 """ height = heig...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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] if proportional_attn: cr...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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, ...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
# 4. Prepare timesteps timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, sigmas=sigmas) # 5. Prepare latents. latent_channels = self.transformer.config.in_channels latents = self.prepare_latents( batch_size * num_images_per_prom...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.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...
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML current_timestep = current_timestep.expand(latent_model_input.shape[0])
247
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/lumina/pipeline_lumina.py