Buckets:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
CogView3Plus
CogView3: Finer and Faster Text-to-Image Generation via Relay Diffusion from Tsinghua University & ZhipuAI, by Wendi Zheng, Jiayan Teng, Zhuoyi Yang, Weihan Wang, Jidong Chen, Xiaotao Gu, Yuxiao Dong, Ming Ding, Jie Tang.
The abstract from the paper is:
Recent advancements in text-to-image generative systems have been largely driven by diffusion models. However, single-stage text-to-image diffusion models still face challenges, in terms of computational efficiency and the refinement of image details. To tackle the issue, we propose CogView3, an innovative cascaded framework that enhances the performance of text-to-image diffusion. CogView3 is the first model implementing relay diffusion in the realm of text-to-image generation, executing the task by first creating low-resolution images and subsequently applying relay-based super-resolution. This methodology not only results in competitive text-to-image outputs but also greatly reduces both training and inference costs. Our experimental results demonstrate that CogView3 outperforms SDXL, the current state-of-the-art open-source text-to-image diffusion model, by 77.0% in human evaluations, all while requiring only about 1/2 of the inference time. The distilled variant of CogView3 achieves comparable performance while only utilizing 1/10 of the inference time by SDXL.
Make sure to check out the Schedulers guide to learn how to explore the tradeoff between scheduler speed and quality, and see the reuse components across pipelines section to learn how to efficiently load the same components into multiple pipelines.
This pipeline was contributed by zRzRzRzRzRzRzR. The original codebase can be found here. The original weights can be found under hf.co/THUDM.
CogView3PlusPipeline[[diffusers.CogView3PlusPipeline]]
diffusers.CogView3PlusPipeline[[diffusers.CogView3PlusPipeline]]
Pipeline for text-to-image generation using CogView3Plus.
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 a particular device, etc.)
__call__diffusers.CogView3PlusPipeline.__call__https://github.com/huggingface/diffusers/blob/vr_12448/src/diffusers/pipelines/cogview3/pipeline_cogview3plus.py#L407[{"name": "prompt", "val": ": typing.Union[str, typing.List[str], NoneType] = None"}, {"name": "negative_prompt", "val": ": typing.Union[str, typing.List[str], NoneType] = None"}, {"name": "height", "val": ": typing.Optional[int] = None"}, {"name": "width", "val": ": typing.Optional[int] = None"}, {"name": "num_inference_steps", "val": ": int = 50"}, {"name": "timesteps", "val": ": typing.Optional[typing.List[int]] = None"}, {"name": "guidance_scale", "val": ": float = 5.0"}, {"name": "num_images_per_prompt", "val": ": int = 1"}, {"name": "eta", "val": ": float = 0.0"}, {"name": "generator", "val": ": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"}, {"name": "latents", "val": ": typing.Optional[torch.FloatTensor] = None"}, {"name": "prompt_embeds", "val": ": typing.Optional[torch.FloatTensor] = None"}, {"name": "negative_prompt_embeds", "val": ": typing.Optional[torch.FloatTensor] = None"}, {"name": "original_size", "val": ": typing.Optional[typing.Tuple[int, int]] = None"}, {"name": "crops_coords_top_left", "val": ": typing.Tuple[int, int] = (0, 0)"}, {"name": "output_type", "val": ": str = 'pil'"}, {"name": "return_dict", "val": ": bool = True"}, {"name": "callback_on_step_end", "val": ": typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None"}, {"name": "callback_on_step_end_tensor_inputs", "val": ": typing.List[str] = ['latents']"}, {"name": "max_sequence_length", "val": ": int = 224"}]- prompt (str or List[str], optional) --
The prompt or prompts to guide the image generation. If not defined, one has to pass prompt_embeds.
- negative_prompt (
strorList[str], optional) -- The prompt or prompts not to guide the image generation. If not defined, one has to passnegative_prompt_embedsinstead. Ignored when not using guidance (i.e., ignored ifguidance_scaleis less than1). - height (
int, optional, defaults to self.transformer.config.sample_size * self.vae_scale_factor) -- The height in pixels of the generated image. If not provided, it is set to 1024. - width (
int, optional, defaults to self.transformer.config.sample_size * self.vae_scale_factor) -- The width in pixels of the generated image. If not provided it is set to 1024. - num_inference_steps (
int, optional, defaults to50) -- The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference. - timesteps (
List[int], optional) -- Custom timesteps to use for the denoising process with schedulers which support atimestepsargument in theirset_timestepsmethod. If not defined, the default behavior whennum_inference_stepsis passed will be used. Must be in descending order. - guidance_scale (
float, optional, defaults to5.0) -- Guidance scale as defined in Classifier-Free Diffusion Guidance.guidance_scaleis defined aswof equation 2. of Imagen Paper. Guidance scale is enabled by settingguidance_scale > 1. Higher guidance scale encourages to generate images that are closely linked to the textprompt, usually at the expense of lower image quality. - num_images_per_prompt (
int, optional, defaults to1) -- The number of images to generate per prompt. - generator (
torch.GeneratororList[torch.Generator], optional) -- One or a list of torch generator(s) to make generation deterministic. - latents (
torch.FloatTensor, 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 be generated by sampling using the supplied randomgenerator. - prompt_embeds (
torch.FloatTensor, 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 frompromptinput argument. - negative_prompt_embeds (
torch.FloatTensor, 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 fromnegative_promptinput argument. - original_size (
Tuple[int], optional, defaults to (1024, 1024)) -- Iforiginal_sizeis not the same astarget_sizethe image will appear to be down- or upsampled.original_sizedefaults to(height, width)if not specified. Part of SDXL's micro-conditioning as explained in section 2.2 of https://huggingface.co/papers/2307.01952. - crops_coords_top_left (
Tuple[int], optional, defaults to (0, 0)) --crops_coords_top_leftcan be used to generate an image that appears to be "cropped" from the positioncrops_coords_top_leftdownwards. Favorable, well-centered images are usually achieved by settingcrops_coords_top_leftto (0, 0). Part of SDXL's micro-conditioning as explained in section 2.2 of https://huggingface.co/papers/2307.01952. - output_type (
str, optional, defaults to"pil") -- The output format of the generate image. Choose between PIL:PIL.Image.Imageornp.array. - return_dict (
bool, optional, defaults toTrue) -- Whether or not to return a~pipelines.stable_diffusion_xl.StableDiffusionXLPipelineOutputinstead of a plain tuple. - attention_kwargs (
dict, optional) -- A kwargs dictionary that if specified is passed along to theAttentionProcessoras defined underself.processorin diffusers.models.attention_processor. - callback_on_step_end (
Callable, optional) -- A function that calls at the end of each denoising steps during the inference. The function is called with the following arguments:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict).callback_kwargswill include a list of all tensors as specified bycallback_on_step_end_tensor_inputs. - callback_on_step_end_tensor_inputs (
List, optional) -- The list of tensor inputs for thecallback_on_step_endfunction. The tensors specified in the list will be passed ascallback_kwargsargument. You will only be able to include variables listed in the._callback_tensor_inputsattribute of your pipeline class. - max_sequence_length (
int, defaults to224) -- Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.0CogView3PipelineOutput ortupleCogView3PipelineOutput ifreturn_dictis True, otherwise atuple. When returning a tuple, the first element is a list with the generated images.
Function invoked when calling the pipeline for generation.
Examples:
>>> import torch
>>> from diffusers import CogView3PlusPipeline
>>> pipe = CogView3PlusPipeline.from_pretrained("THUDM/CogView3-Plus-3B", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> prompt = "A photo of an astronaut riding a horse on mars"
>>> image = pipe(prompt).images[0]
>>> image.save("output.png")
Parameters:
vae (AutoencoderKL) : Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
text_encoder (T5EncoderModel) : Frozen text-encoder. CogView3Plus uses T5; specifically the t5-v1_1-xxl variant.
tokenizer (T5Tokenizer) : Tokenizer of class T5Tokenizer.
transformer (CogView3PlusTransformer2DModel) : A text conditioned CogView3PlusTransformer2DModel to denoise the encoded image latents.
scheduler (SchedulerMixin) : A scheduler to be used in combination with transformer to denoise the encoded image latents.
Returns:
[CogView3PipelineOutput](/docs/diffusers/pr_12448/en/api/pipelines/cogview3#diffusers.pipelines.cogview3.pipeline_output.CogView3PipelineOutput) or tuple``
CogView3PipelineOutput if return_dict is True, otherwise a
tuple. When returning a tuple, the first element is a list with the generated images.
encode_prompt[[diffusers.CogView3PlusPipeline.encode_prompt]]
Encodes the prompt into text encoder hidden states.
Parameters:
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. Ignored when not using guidance (i.e., ignored if guidance_scale is less than 1).
do_classifier_free_guidance (bool, optional, defaults to True) : Whether to use classifier free guidance or not.
num_images_per_prompt (int, optional, defaults to 1) : Number of images that should be generated per prompt. torch device to place the resulting embeddings on
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.
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.
max_sequence_length (int, defaults to 224) : Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.
device : (torch.device, optional): torch device
dtype : (torch.dtype, optional): torch dtype
CogView3PipelineOutput[[diffusers.pipelines.cogview3.pipeline_output.CogView3PipelineOutput]]
diffusers.pipelines.cogview3.pipeline_output.CogView3PipelineOutput[[diffusers.pipelines.cogview3.pipeline_output.CogView3PipelineOutput]]
Output class for CogView3 pipelines.
Parameters:
images (List[PIL.Image.Image] or np.ndarray) : List of denoised PIL images of length batch_size or numpy array of shape (batch_size, height, width, num_channels). PIL images or numpy array present the denoised images of the diffusion pipeline.
Xet Storage Details
- Size:
- 15 kB
- Xet hash:
- 566021170a3bcbeff0f5e1b50a17d6e8d14cde6e75e16963e1296ce66f7135d7
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.