docstr: Initialize StableDiffusion with model_key, t_range, precision and device.
  
  Parameters:
      model_key (str): Pre-trained model key.
      t_range (List[float]): Range for timesteps.
      precision (str): Model precision ("16", "bf16" or other for float32).
      device (torch.device): Device for torch tensor.
docstr_tok: ["Initialize","StableDiffusion","with","model_key",",","t_range",",","precision","and","device",".","Parameters",":","model_key","(","str",")",":","Pre-trained","model","key",".","t_range","(","List","[","float","]",")",":","Range","for","timesteps",".","precision","(","str",")",":","Model","precision","(","``","16","''",",","``","bf16","''","or","other","for","float32",")",".","device","(","torch.device",")",":","Device","for","torch","tensor","."]
code: def __init__(
      self,
      model_key: str = "stabilityai/stable-diffusion-2-1-base",
      t_range: List[float] = [0.02, 0.98],
      precision: str = "16",
      device: torch.device = torch.device("cuda"),
  ):
      """
      Initialize StableDiffusion with model_key, t_range, precision and device.
  
      Parameters:
          model_key (str): Pre-trained model key.
          t_range (List[float]): Range for timesteps.
          precision (str): Model precision ("16", "bf16" or other for float32).
          device (torch.device): Device for torch tensor.
      """
      super().__init__()
  
      self.device = device
      self.model_key = model_key
      self.precision_t = self._get_precision_type(precision)
  
      # Create model
      pipe = StableDiffusionPipeline.from_pretrained(
          model_key, torch_dtype=self.precision_t
      ).to(self.device)
      if self.precision_t in [torch.float16, torch.bfloat16]:
          pipe.unet.to(memory_format=torch.channels_last)
  
      self.vae = pipe.vae
      self.tokenizer = pipe.tokenizer
      self.text_encoder = pipe.text_encoder
      self.unet = pipe.unet
      self.scheduler = DDIMScheduler.from_pretrained(
          model_key, subfolder="scheduler", torch_dtype=self.precision_t
      )
  
      del pipe
  
      self.num_train_timesteps = (
          self.scheduler.config.num_train_timesteps
      )
      self.min_step = int(self.num_train_timesteps * t_range[0])
      self.max_step = int(self.num_train_timesteps * t_range[1])
      self.alphas = self.scheduler.alphas_cumprod.to(self.device)
  
file_path: NeMo/nemo/collections/multimodal/modules/nerf/guidance/stablediffusion_huggingface_pipeline.py
imports: from typing import List
  import torch
  import torch.nn.functional
  from diffusers import DDIMScheduler, StableDiffusionPipeline
  from nemo.collections.multimodal.modules.nerf.guidance.txt2img_guidance_base import Txt2ImgGuidanceBase
label_desc: Use image node_id 1 to create a new StableDiffusion object from inherited base classes: Txt2ImgGuidanceBase with example: obj = StableDiffusion(model_key, t_range, precision, device)