class_docstr: Pipeline for text-to-image generation using VQ Diffusion.
  
  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.).
  
  Args:
      vqvae ([`VQModel`]):
          Vector Quantized Variational Auto-Encoder (VAE) model to encode and decode images to and from latent
          representations.
      text_encoder ([`~transformers.CLIPTextModel`]):
          Frozen text-encoder ([clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32)).
      tokenizer ([`~transformers.CLIPTokenizer`]):
          A `CLIPTokenizer` to tokenize text.
      transformer ([`Transformer2DModel`]):
          A conditional `Transformer2DModel` to denoise the encoded image latents.
      scheduler ([`VQDiffusionScheduler`]):
          A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
class_docstr_tok: ["Pipeline","for","text-to-image","generation","using","VQ","Diffusion",".","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.",")",".","Args",":","vqvae","(","[","`","VQModel","`","]",")",":","Vector","Quantized","Variational","Auto-Encoder","(","VAE",")","model","to","encode","and","decode","images","to","and","from","latent","representations",".","text_encoder","(","[","`","~transformers.CLIPTextModel","`","]",")",":","Frozen","text-encoder","(","[","clip-vit-base-patch32","]","(","https",":","\/\/huggingface.co\/openai\/clip-vit-base-patch32",")",")",".","tokenizer","(","[","`","~transformers.CLIPTokenizer","`","]",")",":","A","`","CLIPTokenizer","`","to","tokenize","text",".","transformer","(","[","`","Transformer2DModel","`","]",")",":","A","conditional","`","Transformer2DModel","`","to","denoise","the","encoded","image","latents",".","scheduler","(","[","`","VQDiffusionScheduler","`","]",")",":","A","scheduler","to","be","used","in","combination","with","`","transformer","`","to","denoise","the","encoded","image","latents","."]
docstr: Truncates `log_p_x_0` such that for each column vector, the total cumulative probability is `truncation_rate`
  The lowest probabilities that would increase the cumulative probability above `truncation_rate` are set to
  zero.
docstr_tok: ["Truncates","`","log_p_x_0","`","such","that","for","each","column","vector",",","the","total","cumulative","probability","is","`","truncation_rate","`","The","lowest","probabilities","that","would","increase","the","cumulative","probability","above","`","truncation_rate","`","are","set","to","zero","."]
code: def truncate(
      self, log_p_x_0: torch.FloatTensor, truncation_rate: float
  ) -> torch.FloatTensor:
      """
      Truncates `log_p_x_0` such that for each column vector, the total cumulative probability is `truncation_rate`
      The lowest probabilities that would increase the cumulative probability above `truncation_rate` are set to
      zero.
      """
      sorted_log_p_x_0, indices = torch.sort(
          log_p_x_0, 1, descending=True
      )
      sorted_p_x_0 = torch.exp(sorted_log_p_x_0)
      keep_mask = sorted_p_x_0.cumsum(dim=1) < truncation_rate
  
      # Ensure that at least the largest probability is not zeroed out
      all_true = torch.full_like(keep_mask[:, 0:1, :], True)
      keep_mask = torch.cat((all_true, keep_mask), dim=1)
      keep_mask = keep_mask[:, :-1, :]
  
      keep_mask = keep_mask.gather(1, indices.argsort(1))
  
      rv = log_p_x_0.clone()
  
      rv[~keep_mask] = -torch.inf  # -inf = log(0)
  
      return rv
  
file_path: llmga/llmga/diffusers/src/diffusers/pipelines/vq_diffusion/pipeline_vq_diffusion.py
imports: from typing import Callable, List, Optional, Tuple, Union
  import torch
  from transformers import CLIPTextModel, CLIPTokenizer
  from ...configuration_utils import ConfigMixin, register_to_config
  from ...models import ModelMixin, Transformer2DModel, VQModel
  from ...schedulers import VQDiffusionScheduler
  from ...utils import logging
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
label_desc: Use image node_id 4 for calling the VQDiffusionPipeline obj's underlying member method code with example usage: obj.truncate(log_p_x_0, truncation_rate) and returns: rv