code: def hf_state_dict(model):
      """
      Args:
          model: huggingface model replaced with lightseq layer
      Returns:
          Dict: The huggingface state dict
      """
  
      def unwrap_model(model):
          # since there could be multiple levels of wrapping, unwrap recursively
          if hasattr(model, "module"):
              return unwrap_model(model.module)
          else:
              return model
  
      def inject_hf_layer(config, hf_layer, ls_layer):
          for layer_id in range(config.num_hidden_layers):
              weight, bias = ls_layer[layer_id].params_dict()
              layer = hf_layer[layer_id]
              layer.attention.self.query.weight.data.copy_(
                  weight["self_attn.q_proj"]
              )
              layer.attention.self.query.bias.data.copy_(
                  bias["self_attn.q_proj"]
              )
              layer.attention.self.key.weight.data.copy_(
                  weight["self_attn.k_proj"]
              )
              layer.attention.self.key.bias.data.copy_(
                  bias["self_attn.k_proj"]
              )
              layer.attention.self.value.weight.data.copy_(
                  weight["self_attn.v_proj"]
              )
              layer.attention.self.value.bias.data.copy_(
                  bias["self_attn.v_proj"]
              )
              layer.attention.output.dense.weight.data.copy_(
                  weight["self_attn.out_proj"]
              )
              layer.attention.output.dense.bias.data.copy_(
                  bias["self_attn.out_proj"]
              )
              layer.attention.output.LayerNorm.weight.data.copy_(
                  weight["self_attn_layer_norm"]
              )
              layer.attention.output.LayerNorm.bias.data.copy_(
                  bias["self_attn_layer_norm"]
              )
              layer.intermediate.dense.weight.data.copy_(weight["fc1"])
              layer.intermediate.dense.bias.data.copy_(bias["fc1"])
              layer.output.dense.weight.data.copy_(weight["fc2"])
              layer.output.dense.bias.data.copy_(bias["fc2"])
              layer.output.LayerNorm.weight.data.copy_(
                  weight["final_layer_norm"]
              )
              layer.output.LayerNorm.bias.data.copy_(
                  bias["final_layer_norm"]
              )
  
      model_to_save = unwrap_model(model)
      if not isinstance(model_to_save, LSBertPreTrainedModel):
          raise ValueError("Must be ligtseq replaced model")
      # reload original modules
      ls_encoder_layer = model_to_save.bert.encoder.layer
      model_to_save.bert.encoder.layer = torch.nn.ModuleList(
          [
              BertLayer(model.config)
              for _ in range(model.config.num_hidden_layers)
          ]
      )
      inject_hf_layer(
          model_to_save.config,
          model_to_save.bert.encoder.layer,
          ls_encoder_layer,
      )
      state_dict = model_to_save.state_dict()
      # replace with lightseq modules
      model_to_save.bert.encoder.layer = ls_encoder_layer
      return state_dict
  
imports: import torch
  from lightseq.training.pytorch_quantization.nn.modules.tensor_quantizer import enable_quant
  from lightseq.training.ops.pytorch.quantization import qat_mode, disable_quant, weight_quant_config, act_quant_config, relu_quant_config
  from lightseq.training.ops.pytorch.torch_transformer_layers import BertEmbeddingLayer
  from transformers import BertForSequenceClassification, BertPreTrainedModel, BertLayer, BertLMHeadModel, BertForMaskedLM, BertForNextSentencePrediction, BertForMultipleChoice, BertForTokenClassification, BertForQuestionAnswering
label_desc: Use image node_id 5 for calling a global function with example usage: hf_state_dict(model) and returns: state_dict, unwrap_model, model