code: def download_controlnet_from_original_ckpt(
      checkpoint_path: str,
      original_config_file: str,
      image_size: int = 512,
      extract_ema: bool = False,
      num_in_channels: Optional[int] = None,
      upcast_attention: Optional[bool] = None,
      device: str = None,
      from_safetensors: bool = False,
      use_linear_projection: Optional[bool] = None,
      cross_attention_dim: Optional[bool] = None,
  ) -> DiffusionPipeline:
      if not is_omegaconf_available():
          raise ValueError(BACKENDS_MAPPING["omegaconf"][1])
  
      from omegaconf import OmegaConf
  
      if from_safetensors:
          from safetensors import safe_open
  
          checkpoint = {}
          with safe_open(
              checkpoint_path, framework="pt", device="cpu"
          ) as f:
              for key in f.keys():
                  checkpoint[key] = f.get_tensor(key)
      else:
          if device is None:
              device = "cuda" if torch.cuda.is_available() else "cpu"
              checkpoint = torch.load(
                  checkpoint_path, map_location=device
              )
          else:
              checkpoint = torch.load(
                  checkpoint_path, map_location=device
              )
  
      # NOTE: this while loop isn't great but this controlnet checkpoint has one additional
      # "state_dict" key https://huggingface.co/thibaud/controlnet-canny-sd21
      while "state_dict" in checkpoint:
          checkpoint = checkpoint["state_dict"]
  
      original_config = OmegaConf.load(original_config_file)
  
      if num_in_channels is not None:
          original_config["model"]["params"]["unet_config"]["params"][
              "in_channels"
          ] = num_in_channels
  
      if "control_stage_config" not in original_config.model.params:
          raise ValueError(
              "`control_stage_config` not present in original config"
          )
  
      controlnet = convert_controlnet_checkpoint(
          checkpoint,
          original_config,
          checkpoint_path,
          image_size,
          upcast_attention,
          extract_ema,
          use_linear_projection=use_linear_projection,
          cross_attention_dim=cross_attention_dim,
      )
  
      return controlnet
  
imports: import re
  from contextlib import nullcontext
  from io import BytesIO
  from typing import Dict, Optional, Union
  import requests
  import torch
  from transformers import AutoFeatureExtractor, BertTokenizerFast, CLIPImageProcessor, CLIPTextConfig, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionConfig, CLIPVisionModelWithProjection
  from ...models import AutoencoderKL, ControlNetModel, PriorTransformer, UNet2DConditionModel
  from ...schedulers import DDIMScheduler, DDPMScheduler, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler, HeunDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler, UnCLIPScheduler
  from ...utils import is_accelerate_available, is_omegaconf_available, logging
  from ...utils.import_utils import BACKENDS_MAPPING
  from ..latent_diffusion.pipeline_latent_diffusion import LDMBertConfig, LDMBertModel
  from ..paint_by_example import PaintByExampleImageEncoder
  from ..pipeline_utils import DiffusionPipeline
  from .safety_checker import StableDiffusionSafetyChecker
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
label_desc: Use image node_id 22 for calling a global function with example usage: download_controlnet_from_original_ckpt(checkpoint_path, original_config_file, image_size, extract_ema, num_in_channels, upcast_attention, device, from_safetensors, use_linear_projection, cross_attention_dim) and returns: controlnet