code: def construct_peft_loraconfig(
      info: Dict[str, LoRAInfo], **kwargs
  ) -> LoraConfig:
      """Constructs LoraConfig from data extracted from adapter checkpoint
  
      Args:
          info (Dict[str, LoRAInfo]): Information extracted from adapter checkpoint
  
      Returns:
          LoraConfig: config for constructing LoRA
      """
  
      # Unpack all ranks and alphas
      ranks = {key: val.rank for key, val in info.items()}
      alphas = {x[0]: x[1].alpha or x[1].rank for x in info.items()}
  
      # Determine which modules needs to be transformed
      target_modules = sorted(info.keys())
  
      # Determine most common rank and alpha
      r = int(Counter(ranks.values()).most_common(1)[0][0])
      lora_alpha = Counter(alphas.values()).most_common(1)[0][0]
  
      # Determine which modules have different rank and alpha
      rank_pattern = dict(
          sorted(
              filter(lambda x: x[1] != r, ranks.items()),
              key=lambda x: x[0],
          )
      )
      alpha_pattern = dict(
          sorted(
              filter(lambda x: x[1] != lora_alpha, alphas.items()),
              key=lambda x: x[0],
          )
      )
  
      config = LoraConfig(
          r=r,
          lora_alpha=lora_alpha,
          target_modules=target_modules,
          lora_dropout=0.0,
          bias="none",
          init_lora_weights=False,
          rank_pattern=rank_pattern,
          alpha_pattern=alpha_pattern,
      )
  
      return config
  
imports: import argparse
  import json
  import logging
  import os
  from collections import Counter
  from dataclasses import dataclass
  from operator import attrgetter
  from typing import Dict, List, Optional, Union
  import safetensors
  import torch
  import torch.nn
  from diffusers import UNet2DConditionModel
  from transformers import CLIPTextModel
  from peft import LoHaConfig, LoKrConfig, LoraConfig, PeftType, get_peft_model, set_peft_model_state_dict
  from peft.tuners.lokr.layer import factorization
label_desc: Use image node_id 1 for calling a global function with example usage: construct_peft_loraconfig(info) and returns: config