code: def load_lora(model, cfg, inference=False):
      # type: (PreTrainedModel, DictDefault, bool) -> Tuple[PreTrainedModel, Optional[PeftConfig]]
  
      from peft import LoraConfig, PeftModel, get_peft_model
  
      lora_target_modules = list(cfg.lora_target_modules or [])
  
      if cfg.lora_target_linear:
          linear_names = find_all_linear_names(model)
          LOG.info(f"found linear modules: {repr(linear_names)}")
          lora_target_modules = list(
              set(lora_target_modules + linear_names)
          )
  
      lora_config = LoraConfig(
          r=cfg.lora_r,
          lora_alpha=cfg.lora_alpha,
          target_modules=lora_target_modules,
          layers_to_transform=cfg.peft_layers_to_transform,
          lora_dropout=cfg.lora_dropout,
          fan_in_fan_out=cfg.lora_fan_in_fan_out,
          modules_to_save=cfg.lora_modules_to_save
          if cfg.lora_modules_to_save
          else None,
          bias="none",
          task_type="CAUSAL_LM",
      )
  
      if cfg.lora_model_dir:
          LOG.debug("Loading pretained PEFT - LoRA")
          model_kwargs: Any = {}
          if cfg.lora_on_cpu:
              model_kwargs["max_memory"] = {"cpu": "256GiB"}
              model_kwargs["device_map"] = {"": "cpu"}
          model = PeftModel.from_pretrained(
              model,
              cfg.lora_model_dir,
              is_trainable=(not inference),
              **model_kwargs,
          )
      else:
          model = get_peft_model(model, lora_config)
  
      model.print_trainable_parameters()
  
      return model, lora_config
  
imports: import logging
  import math
  import os
  from typing import Any, Optional, Tuple, Union
  import addict
  import bitsandbytes
  import torch
  import transformers
  from optimum.bettertransformer import BetterTransformer
  from peft import PeftConfig, prepare_model_for_kbit_training
  from peft.tuners.lora import QuantLinear
  from transformers import AddedToken, AutoConfig, AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, GPTQConfig, PreTrainedModel, PreTrainedTokenizerBase
  from transformers.deepspeed import is_deepspeed_zero3_enabled
  from axolotl.models.mamba import fix_mamba_attn_for_loss
  from axolotl.prompt_tokenizers import LLAMA_DEFAULT_EOS_TOKEN
  from axolotl.utils.bench import log_gpu_memory_usage
  from axolotl.utils.chat_templates import chat_templates
  from axolotl.utils.dict import DictDefault
  from axolotl.utils.lora_embeddings import get_linear_embedding_layers
label_desc: Use image node_id 8 for calling a global function with example usage: load_lora(model, cfg, inference) and returns: model,  lora_config