code: def inject_ls_layer(model, training_args, model_args, config):
      init_ws = get_hf_gpt_emb_layer_params(model.transformer)
      model.transformer.wte = GptEmbedding(
          training_args,
          init_ws[0],
          config.vocab_size,
          config.hidden_size,
      )
      if model_args.enable_quant:
          model.transformer.wte.apply(qat_mode)
      else:
          model.transformer.wte.apply(disable_quant)
  
      if model_args.module_type == 1:
          from lightseq.training import ls_hf_gpt_enc_convert
  
          ls_hf_gpt_enc_convert(model, training_args, config)
          for i in range(config.num_hidden_layers):
              if model_args.enable_quant:
                  model.transformer.h[i].apply(enable_quant)
              else:
                  model.transformer.h[i].apply(disable_quant)
      elif model_args.module_type == 2:
          for i in range(config.num_hidden_layers):
              gpt_enc_config = gen_gpt_enc_config(training_args, config)
              init_ws, init_bs = get_hf_gpt_enc_layer_params(
                  model.transformer.h[i], config
              )
              model.transformer.h[i] = LSHFGptEncoderLayer(
                  gpt_enc_config, init_ws, init_bs
              ).cuda()
              if model_args.enable_quant:
                  model.transformer.h[i].apply(qat_mode)
              else:
                  model.transformer.h[i].apply(disable_quant)
  
      q_lm_head = QuantLinear(
          config.n_embd, config.vocab_size, bias=False
      )
      q_lm_head.weight = model.transformer.wte.weight
      q_lm_head.weight_quant = model.transformer.wte.emb_quant
      model.lm_head = q_lm_head
      if model_args.enable_quant:
          model.lm_head.apply(qat_mode)
      else:
          model.lm_head.apply(disable_quant)
  
file_path: lightseq/examples/training/huggingface/gpt/ls_hf_gpt_layer.py
imports: from torch import nn
  from lightseq.training.ops.pytorch.quantization import qat_mode, enable_quant, disable_quant, QuantLinear, TensorQuantizer, emb_quant_config
  from lightseq.training.ops.pytorch.torch_transformer_layers import TransformerDecoderLayer, copy_para
label_desc: Use image node_id 4 for calling a global function with example usage: inject_ls_layer(model, training_args, model_args, config) without return types