code: def convert_ldm_bert_checkpoint(checkpoint, config):
      def _copy_attn_layer(hf_attn_layer, pt_attn_layer):
          hf_attn_layer.q_proj.weight.data = pt_attn_layer.to_q.weight
          hf_attn_layer.k_proj.weight.data = pt_attn_layer.to_k.weight
          hf_attn_layer.v_proj.weight.data = pt_attn_layer.to_v.weight
  
          hf_attn_layer.out_proj.weight = pt_attn_layer.to_out.weight
          hf_attn_layer.out_proj.bias = pt_attn_layer.to_out.bias
  
      def _copy_linear(hf_linear, pt_linear):
          hf_linear.weight = pt_linear.weight
          hf_linear.bias = pt_linear.bias
  
      def _copy_layer(hf_layer, pt_layer):
          # copy layer norms
          _copy_linear(hf_layer.self_attn_layer_norm, pt_layer[0][0])
          _copy_linear(hf_layer.final_layer_norm, pt_layer[1][0])
  
          # copy attn
          _copy_attn_layer(hf_layer.self_attn, pt_layer[0][1])
  
          # copy MLP
          pt_mlp = pt_layer[1][1]
          _copy_linear(hf_layer.fc1, pt_mlp.net[0][0])
          _copy_linear(hf_layer.fc2, pt_mlp.net[2])
  
      def _copy_layers(hf_layers, pt_layers):
          for i, hf_layer in enumerate(hf_layers):
              if i != 0:
                  i += i
              pt_layer = pt_layers[i : i + 2]
              _copy_layer(hf_layer, pt_layer)
  
      hf_model = LDMBertModel(config).eval()
  
      # copy  embeds
      hf_model.model.embed_tokens.weight = (
          checkpoint.transformer.token_emb.weight
      )
      hf_model.model.embed_positions.weight.data = (
          checkpoint.transformer.pos_emb.emb.weight
      )
  
      # copy layer norm
      _copy_linear(
          hf_model.model.layer_norm, checkpoint.transformer.norm
      )
  
      # copy hidden layers
      _copy_layers(
          hf_model.model.layers,
          checkpoint.transformer.attn_layers.layers,
      )
  
      _copy_linear(hf_model.to_logits, checkpoint.transformer.to_logits)
  
      return hf_model
  
imports: import re
  from contextlib import nullcontext
  from io import BytesIO
  from typing import Dict, Optional, Union
  import requests
  import torch
  import yaml
  from transformers import AutoFeatureExtractor, BertTokenizerFast, CLIPImageProcessor, CLIPTextConfig, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionConfig, CLIPVisionModelWithProjection
  from ...models import AutoencoderKL, ControlNetModel, PriorTransformer, UNet2DConditionModel
  from ...schedulers import DDIMScheduler, DDPMScheduler, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler, HeunDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler, UnCLIPScheduler
  from ...utils import is_accelerate_available, logging
  from ..latent_diffusion.pipeline_latent_diffusion import LDMBertConfig, LDMBertModel
  from ..paint_by_example import PaintByExampleImageEncoder
  from ..pipeline_utils import DiffusionPipeline
  from .safety_checker import StableDiffusionSafetyChecker
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
label_desc: Use image node_id 14 for calling a global function with example usage: convert_ldm_bert_checkpoint(checkpoint, config) and returns: hf_model