code: def adjust_group_norms(
      unet: UNet2DConditionModel, max_num_group: int = 32
  ):
      def find_denominator(number, start):
          if start >= number:
              return number
          while start != 0:
              residual = number % start
              if residual == 0:
                  return start
              start -= 1
  
      for block in [*unet.down_blocks, unet.mid_block]:
          # resnets
          for r in block.resnets:
              if r.norm1.num_groups < max_num_group:
                  r.norm1.num_groups = find_denominator(
                      r.norm1.num_channels, start=max_num_group
                  )
  
              if r.norm2.num_groups < max_num_group:
                  r.norm2.num_groups = find_denominator(
                      r.norm2.num_channels, start=max_num_group
                  )
  
          # transformers
          if hasattr(block, "attentions"):
              for a in block.attentions:
                  if a.norm.num_groups < max_num_group:
                      a.norm.num_groups = find_denominator(
                          a.norm.num_channels, start=max_num_group
                      )
  
imports: import math
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import functional
  from torch.nn.modules.normalization import GroupNorm
  from diffusers.configuration_utils import ConfigMixin, register_to_config
  from diffusers.models.attention_processor import USE_PEFT_BACKEND, AttentionProcessor
  from diffusers.models.autoencoders import AutoencoderKL
  from diffusers.models.lora import LoRACompatibleConv
  from diffusers.models.modeling_utils import ModelMixin
  from diffusers.models.unet_2d_blocks import CrossAttnDownBlock2D, CrossAttnUpBlock2D, DownBlock2D, Downsample2D, ResnetBlock2D, Transformer2DModel, UpBlock2D, Upsample2D
  from diffusers.models.unet_2d_condition import UNet2DConditionModel
  from diffusers.utils import BaseOutput, logging
label_desc: Use image node_id 5 for calling a global function with example usage: adjust_group_norms(unet, max_num_group) and returns: number, start