code: def fill_encdec_weight(
      file,
      state_dict,
      mapping_dict,
      is_encoder,
      save_pb,
      enc_out_mapping_dict=None,
  ):
      var_name_list = list(state_dict.keys())
  
      tensor_names = {}
      for name in var_name_list:
          name_split = name.split(".")
          # assert the layer name like `xxx.0.xxx.para`
          if name_split[-1] != "para":
              continue
          for s in name_split[::-1]:
              if s.isdigit():
                  tensor_names.setdefault(int(s), []).append(name)
                  break
      assert len(tensor_names) > 0
  
      for layer_id in sorted(tensor_names.keys()):
          if save_pb:
              if is_encoder:
                  layer = file.encoder_stack.add()
              else:
                  layer = file.decoder_stack.add()
              fill_pb_layer(
                  tensor_names[layer_id],
                  state_dict,
                  layer,
                  mapping_dict,
              )
          else:
              if is_encoder:
                  dataset_prefix = f"encoder_stack/{layer_id}/"
              else:
                  dataset_prefix = f"decoder_stack/{layer_id}/"
              fill_hdf5_layer(
                  tensor_names[layer_id],
                  state_dict,
                  file,
                  dataset_prefix,
                  mapping_dict,
              )
  
      if not is_encoder:
          if save_pb:
              fill_pb_layer(
                  tensor_names[0],
                  state_dict,
                  file.trg_embedding,
                  enc_out_mapping_dict,
              )
          else:
              fill_hdf5_layer(
                  tensor_names[0],
                  state_dict,
                  file,
                  f"trg_embedding/",
                  enc_out_mapping_dict,
              )
  
file_path: lightseq/lightseq/training/ops/pytorch/export.py
imports: from collections import OrderedDict
  import numpy
  from lightseq.training.ops.pytorch.util import get_pos_embedding
  from lightseq.training import LSTransformerEncoderLayer, LSTransformerDecoderLayer
label_desc: Use image node_id 5 for calling a global function with example usage: fill_encdec_weight(file, state_dict, mapping_dict, is_encoder, save_pb, enc_out_mapping_dict) without return types