class_docstr: Peft model for mixing different types of adapters.
  
  This class currently does not support saving and loading. Instead, it is assumed that the adapters are already
  trained and loading the model requires a script to be run each time.
  
  Currently, the main purpose of mixed adapter types is to combine trained adapters for inference. Although it is
  technically possible to train a mixed adapter model, this has not been tested and is not recommended.
  
  Note: This class should usually not be initialized directly. Instead, use `get_peft_model` with the argument
  `mixed=True`.
  
  Below is an example that shows how to load a mixed model with two different types of adapters.
  
  ```py
  >>> from peft import get_peft_model
  
  >>> base_model = ...  # load the base model, e.g. from transformers
  >>> peft_model = PeftMixedModel.from_pretrained(base_model, path_to_adapter1, "adapter1").eval()
  >>> peft_model.load_adapter(path_to_adapter2, "adapter2")
  >>> peft_model.set_adapter(["adapter1", "adapter2"])  # activate both adapters
  >>> peft_model(data)  # forward pass using both adapters
  ```
  
  Tips:
  
  - Not all adapter types can be combined. See `peft.tuners.mixed.COMPATIBLE_TUNER_TYPES` for a list of compatible
    types. An error will be raised if you are trying to combine incompatible adapter types.
  - It is possible to mix multiple adapters of the same type. This can be useful to combine adapters with very
    different configs.
  - If you want to combine a lot of different adapters, it is most performant to add the same types of adapters
    consecutively. E.g., add LoRA1, LoRA2, LoHa1, LoHa2 in this order, instead of LoRA1, LoHa1, LoRA2, LoHa2. As long
    as the adapters are commutative, the order does not matter for the final result.
  
  Args:
      model (`torch.nn.Module`):
          The model to be tuned.
      config (`PeftConfig`):
          The config of the model to be tuned. The adapter type must be compatible.
      adapter_name (`str`, `optional`, defaults to `"default"`):
          The name of the first adapter.
docstr: Instantiate a PEFT mixed model from a pretrained model and loaded PEFT weights.
  
  Note that the passed `model` may be modified inplace.
  
  Args:
      model (`nn.Module`):
          The model to be adapted.
      model_id (`str` or `os.PathLike`):
          The name of the PEFT configuration to use. Can be either:
              - A string, the `model id` of a PEFT configuration hosted inside a model repo on the Hugging Face
                Hub.
              - A path to a directory containing a PEFT configuration file saved using the `save_pretrained`
                method (`./my_peft_config_directory/`).
      adapter_name (`str`, *optional*, defaults to `"default"`):
          The name of the adapter to be loaded. This is useful for loading multiple adapters.
      is_trainable (`bool`, *optional*, defaults to `False`):
          Whether the adapter should be trainable or not. If `False`, the adapter will be frozen and use for
          inference
      config ([`~peft.PeftConfig`], *optional*):
          The configuration object to use instead of an automatically loaded configuation. This configuration
          object is mutually exclusive with `model_id` and `kwargs`. This is useful when configuration is already
          loaded before calling `from_pretrained`.
      kwargs: (`optional`):
          Additional keyword arguments passed along to the specific PEFT configuration class.
code: def from_pretrained(
      cls,
      model: nn.Module,
      model_id: str | os.PathLike,
      adapter_name: str = "default",
      is_trainable: bool = False,
      config: Optional[PeftConfig] = None,
      **kwargs: Any,
  ):
      r"""
      Instantiate a PEFT mixed model from a pretrained model and loaded PEFT weights.
  
      Note that the passed `model` may be modified inplace.
  
      Args:
          model (`nn.Module`):
              The model to be adapted.
          model_id (`str` or `os.PathLike`):
              The name of the PEFT configuration to use. Can be either:
                  - A string, the `model id` of a PEFT configuration hosted inside a model repo on the Hugging Face
                    Hub.
                  - A path to a directory containing a PEFT configuration file saved using the `save_pretrained`
                    method (`./my_peft_config_directory/`).
          adapter_name (`str`, *optional*, defaults to `"default"`):
              The name of the adapter to be loaded. This is useful for loading multiple adapters.
          is_trainable (`bool`, *optional*, defaults to `False`):
              Whether the adapter should be trainable or not. If `False`, the adapter will be frozen and use for
              inference
          config ([`~peft.PeftConfig`], *optional*):
              The configuration object to use instead of an automatically loaded configuation. This configuration
              object is mutually exclusive with `model_id` and `kwargs`. This is useful when configuration is already
              loaded before calling `from_pretrained`.
          kwargs: (`optional`):
              Additional keyword arguments passed along to the specific PEFT configuration class.
      """
      # note: adapted from PeftModel.from_pretrained
      from .mapping import PEFT_TYPE_TO_CONFIG_MAPPING
  
      # load the config
      if config is None:
          config = PEFT_TYPE_TO_CONFIG_MAPPING[
              PeftConfig._get_peft_type(
                  model_id,
                  subfolder=kwargs.get("subfolder", None),
                  revision=kwargs.get("revision", None),
                  cache_dir=kwargs.get("cache_dir", None),
                  use_auth_token=kwargs.get("use_auth_token", None),
              )
          ].from_pretrained(model_id, **kwargs)
      elif isinstance(config, PeftConfig):
          config.inference_mode = not is_trainable
      else:
          raise ValueError(
              f"The input config must be a PeftConfig, got {config.__class__}"
          )
  
      # note: this is different from PeftModel.from_pretrained
      if config.peft_type not in PEFT_TYPE_TO_MODEL_MAPPING:
          raise ValueError(
              f"Adapter of type {config.peft_type} is not supported for mixed models."
          )
  
      if (getattr(model, "hf_device_map", None) is not None) and len(
          set(model.hf_device_map.values()).intersection(
              {"cpu", "disk"}
          )
      ) > 0:
          remove_hook_from_submodules(model)
  
      if config.is_prompt_learning and is_trainable:
          # note: should not be possible to reach, but just in case
          raise ValueError(
              "Cannot set a prompt learning adapter to trainable when loading pretrained adapter."
          )
      else:
          config.inference_mode = not is_trainable
  
      # note: this is different from PeftModel.from_pretrained, we always return a PeftMixedModel
      model = cls(model, config, adapter_name)
      model.load_adapter(
          model_id, adapter_name, is_trainable=is_trainable, **kwargs
      )
      return model
  
imports: from __future__ import annotations
  import os
  from contextlib import contextmanager
  from typing import Any, Optional, Union
  import torch
  from accelerate.hooks import remove_hook_from_submodules
  from torch import nn
  from transformers.utils import PushToHubMixin
  from peft.tuners.mixed import COMPATIBLE_TUNER_TYPES
  from .config import PeftConfig
  from .peft_model import PeftModel
  from .tuners import AdaLoraModel, IA3Model, LoHaModel, LoKrModel, LoraModel, MixedModel, OFTModel
  from .utils import PeftType, _set_adapter, _set_trainable
label_desc: Use image node_id 20 for calling the PeftMixedModel obj's underlying member method code with example usage: obj.from_pretrained(cls, model, model_id, adapter_name, is_trainable, config) and returns: model