code: def unet_lora_state_dict(
      unet: UNet2DConditionModel,
  ) -> Dict[str, torch.Tensor]:
      r"""
      Returns:
          A state dict containing just the LoRA parameters.
      """
      lora_state_dict = {}
  
      for name, module in unet.named_modules():
          if hasattr(module, "set_lora_layer"):
              lora_layer = getattr(module, "lora_layer")
              if lora_layer is not None:
                  current_lora_layer_sd = lora_layer.state_dict()
                  for (
                      lora_layer_matrix_name,
                      lora_param,
                  ) in current_lora_layer_sd.items():
                      # The matrix name can either be "down" or "up".
                      lora_state_dict[
                          f"{name}.lora.{lora_layer_matrix_name}"
                      ] = lora_param
  
      return lora_state_dict
  
imports: import contextlib
  import copy
  import random
  from typing import Any, Dict, Iterable, List, Optional, Union
  import numpy
  import torch
  from torchvision import transforms
  from .models import UNet2DConditionModel
  from .utils import convert_state_dict_to_diffusers, convert_state_dict_to_peft, deprecate, is_peft_available, is_transformers_available
label_desc: Use image node_id 4 for calling a global function with example usage: unet_lora_state_dict(unet) and returns: lora_state_dict