class_docstr: Multiple `ControlNetModel` wrapper class for Multi-ControlNet
  
  This module is a wrapper for multiple instances of the `ControlNetModel`. The `forward()` API is designed to be
  compatible with `ControlNetModel`.
  
  Args:
      controlnets (`List[ControlNetModel]`):
          Provides additional conditioning to the unet during the denoising process. You must set multiple
          `ControlNetModel` as a list.
class_docstr_tok: ["Multiple","`","ControlNetModel","`","wrapper","class","for","Multi-ControlNet","This","module","is","a","wrapper","for","multiple","instances","of","the","`","ControlNetModel","`",".","The","`","forward","(",")","`","API","is","designed","to","be","compatible","with","`","ControlNetModel","`",".","Args",":","controlnets","(","`","List","[","ControlNetModel","]","`",")",":","Provides","additional","conditioning","to","the","unet","during","the","denoising","process",".","You","must","set","multiple","`","ControlNetModel","`","as","a","list","."]
docstr: Instantiate a pretrained MultiControlNet model from multiple pre-trained controlnet models.
  
  The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
  the model, you should first set it back in training mode with `model.train()`.
  
  The warning *Weights from XXX not initialized from pretrained model* means that the weights of XXX do not come
  pretrained with the rest of the model. It is up to you to train those weights with a downstream fine-tuning
  task.
  
  The warning *Weights from XXX not used in YYY* means that the layer XXX is not used by YYY, therefore those
  weights are discarded.
  
  Parameters:
      pretrained_model_path (`os.PathLike`):
          A path to a *directory* containing model weights saved using
          [`~diffusers.pipelines.controlnet.MultiControlNetModel.save_pretrained`], e.g.,
          `./my_model_directory/controlnet`.
      torch_dtype (`str` or `torch.dtype`, *optional*):
          Override the default `torch.dtype` and load the model under this dtype. If `"auto"` is passed the dtype
          will be automatically derived from the model's weights.
      output_loading_info(`bool`, *optional*, defaults to `False`):
          Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
      device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
          A map that specifies where each submodule should go. It doesn't need to be refined to each
          parameter/buffer name, once a given module name is inside, every submodule of it will be sent to the
          same device.
  
          To have Accelerate compute the most optimized `device_map` automatically, set `device_map="auto"`. For
          more information about each option see [designing a device
          map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
      max_memory (`Dict`, *optional*):
          A dictionary device identifier to maximum memory. Will default to the maximum memory available for each
          GPU and the available CPU RAM if unset.
      low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
          Speed up model loading by not initializing the weights and only loading the pre-trained weights. This
          also tries to not use more than 1x model size in CPU memory (including peak memory) while loading the
          model. This is only supported when torch version >= 1.9.0. If you are using an older version of torch,
          setting this argument to `True` will raise an error.
      variant (`str`, *optional*):
          If specified load weights from `variant` filename, *e.g.* pytorch_model.<variant>.bin. `variant` is
          ignored when using `from_flax`.
      use_safetensors (`bool`, *optional*, defaults to `None`):
          If set to `None`, the `safetensors` weights will be downloaded if they're available **and** if the
          `safetensors` library is installed. If set to `True`, the model will be forcibly loaded from
          `safetensors` weights. If set to `False`, loading will *not* use `safetensors`.
docstr_tok: ["Instantiate","a","pretrained","MultiControlNet","model","from","multiple","pre-trained","controlnet","models",".","The","model","is","set","in","evaluation","mode","by","default","using","`","model.eval","(",")","`","(","Dropout","modules","are","deactivated",")",".","To","train","the","model",",","you","should","first","set","it","back","in","training","mode","with","`","model.train","(",")","`",".","The","warning","*","Weights","from","XXX","not","initialized","from","pretrained","model","*","means","that","the","weights","of","XXX","do","not","come","pretrained","with","the","rest","of","the","model",".","It","is","up","to","you","to","train","those","weights","with","a","downstream","fine-tuning","task",".","The","warning","*","Weights","from","XXX","not","used","in","YYY","*","means","that","the","layer","XXX","is","not","used","by","YYY",",","therefore","those","weights","are","discarded",".","Parameters",":","pretrained_model_path","(","`","os.PathLike","`",")",":","A","path","to","a","*","directory","*","containing","model","weights","saved","using","[","`","~diffusers.pipelines.controlnet.MultiControlNetModel.save_pretrained","`","]",",","e.g.",",","`",".\/my_model_directory\/controlnet","`",".","torch_dtype","(","`","str","`","or","`","torch.dtype","`",",","*","optional","*",")",":","Override","the","default","`","torch.dtype","`","and","load","the","model","under","this","dtype",".","If","`","``","auto","''","`","is","passed","the","dtype","will","be","automatically","derived","from","the","model","'s","weights",".","output_loading_info","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","also","return","a","dictionary","containing","missing","keys",",","unexpected","keys","and","error","messages",".","device_map","(","`","str","`","or","`","Dict","[","str",",","Union","[","int",",","str",",","torch.device","]","]","`",",","*","optional","*",")",":","A","map","that","specifies","where","each","submodule","should","go",".","It","does","n't","need","to","be","refined","to","each","parameter\/buffer","name",",","once","a","given","module","name","is","inside",",","every","submodule","of","it","will","be","sent","to","the","same","device",".","To","have","Accelerate","compute","the","most","optimized","`","device_map","`","automatically",",","set","`","device_map=","''","auto","''","`",".","For","more","information","about","each","option","see","[","designing","a","device","map","]","(","https",":","\/\/hf.co\/docs\/accelerate\/main\/en\/usage_guides\/big_modeling","#","designing-a-device-map",")",".","max_memory","(","`","Dict","`",",","*","optional","*",")",":","A","dictionary","device","identifier","to","maximum","memory",".","Will","default","to","the","maximum","memory","available","for","each","GPU","and","the","available","CPU","RAM","if","unset",".","low_cpu_mem_usage","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`","if","torch","version",">","=","1.9.0","else","`","False","`",")",":","Speed","up","model","loading","by","not","initializing","the","weights","and","only","loading","the","pre-trained","weights",".","This","also","tries","to","not","use","more","than","1x","model","size","in","CPU","memory","(","including","peak","memory",")","while","loading","the","model",".","This","is","only","supported","when","torch","version",">","=","1.9.0",".","If","you","are","using","an","older","version","of","torch",",","setting","this","argument","to","`","True","`","will","raise","an","error",".","variant","(","`","str","`",",","*","optional","*",")",":","If","specified","load","weights","from","`","variant","`","filename",",","*","e.g",".","*","pytorch_model.","<","variant",">",".bin",".","`","variant","`","is","ignored","when","using","`","from_flax","`",".","use_safetensors","(","`","bool","`",",","*","optional","*",",","defaults","to","`","None","`",")",":","If","set","to","`","None","`",",","the","`","safetensors","`","weights","will","be","downloaded","if","they","'re","available","*","*","and","*","*","if","the","`","safetensors","`","library","is","installed",".","If","set","to","`","True","`",",","the","model","will","be","forcibly","loaded","from","`","safetensors","`","weights",".","If","set","to","`","False","`",",","loading","will","*","not","*","use","`","safetensors","`","."]
code: def from_pretrained(
      cls,
      pretrained_model_path: Optional[Union[str, os.PathLike]],
      **kwargs,
  ):
      r"""
      Instantiate a pretrained MultiControlNet model from multiple pre-trained controlnet models.
  
      The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
      the model, you should first set it back in training mode with `model.train()`.
  
      The warning *Weights from XXX not initialized from pretrained model* means that the weights of XXX do not come
      pretrained with the rest of the model. It is up to you to train those weights with a downstream fine-tuning
      task.
  
      The warning *Weights from XXX not used in YYY* means that the layer XXX is not used by YYY, therefore those
      weights are discarded.
  
      Parameters:
          pretrained_model_path (`os.PathLike`):
              A path to a *directory* containing model weights saved using
              [`~diffusers.pipelines.controlnet.MultiControlNetModel.save_pretrained`], e.g.,
              `./my_model_directory/controlnet`.
          torch_dtype (`str` or `torch.dtype`, *optional*):
              Override the default `torch.dtype` and load the model under this dtype. If `"auto"` is passed the dtype
              will be automatically derived from the model's weights.
          output_loading_info(`bool`, *optional*, defaults to `False`):
              Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
          device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
              A map that specifies where each submodule should go. It doesn't need to be refined to each
              parameter/buffer name, once a given module name is inside, every submodule of it will be sent to the
              same device.
  
              To have Accelerate compute the most optimized `device_map` automatically, set `device_map="auto"`. For
              more information about each option see [designing a device
              map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
          max_memory (`Dict`, *optional*):
              A dictionary device identifier to maximum memory. Will default to the maximum memory available for each
              GPU and the available CPU RAM if unset.
          low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
              Speed up model loading by not initializing the weights and only loading the pre-trained weights. This
              also tries to not use more than 1x model size in CPU memory (including peak memory) while loading the
              model. This is only supported when torch version >= 1.9.0. If you are using an older version of torch,
              setting this argument to `True` will raise an error.
          variant (`str`, *optional*):
              If specified load weights from `variant` filename, *e.g.* pytorch_model.<variant>.bin. `variant` is
              ignored when using `from_flax`.
          use_safetensors (`bool`, *optional*, defaults to `None`):
              If set to `None`, the `safetensors` weights will be downloaded if they're available **and** if the
              `safetensors` library is installed. If set to `True`, the model will be forcibly loaded from
              `safetensors` weights. If set to `False`, loading will *not* use `safetensors`.
      """
      idx = 0
      controlnets = []
  
      # load controlnet and append to list until no controlnet directory exists anymore
      # first controlnet has to be saved under `./mydirectory/controlnet` to be compliant with `DiffusionPipeline.from_prertained`
      # second, third, ... controlnets have to be saved under `./mydirectory/controlnet_1`, `./mydirectory/controlnet_2`, ...
      model_path_to_load = pretrained_model_path
      while os.path.isdir(model_path_to_load):
          controlnet = ControlNetModel.from_pretrained(
              model_path_to_load, **kwargs
          )
          controlnets.append(controlnet)
  
          idx += 1
          model_path_to_load = pretrained_model_path + f"_{idx}"
  
      logger.info(
          f"{len(controlnets)} controlnets loaded from {pretrained_model_path}."
      )
  
      if len(controlnets) == 0:
          raise ValueError(
              f"No ControlNets found under {os.path.dirname(pretrained_model_path)}. Expected at least {pretrained_model_path + '_0'}."
          )
  
      return cls(controlnets)
  
file_path: diffusers/src/diffusers/pipelines/controlnet/multicontrolnet.py
imports: import os
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  from torch import nn
  from ...models.controlnet import ControlNetModel, ControlNetOutput
  from ...models.modeling_utils import ModelMixin
  from ...utils import logging
label_desc: Use image node_id 4 for calling the MultiControlNetModel obj's underlying member method code with example usage: obj.from_pretrained(cls, pretrained_model_path) and returns: cls