code: def dump_state_dict(
      f, weight_names, state_dict, quantization_bit, ggml_type
  ):
      tensor_info = []
      for name in tqdm(weight_names, desc="Dumping model state"):
          tensor = state_dict[name]
          if tensor.ndim == 2:
              # 2d weight: should quantize it if needed
  
              # step 1: de-quantize it back to float32
              if tensor.dtype == torch.int8:
                  invalidInputError(
                      quantization_bit in [4, 8],
                      "quantization_bit should be 4 or 8.",
                  )
                  scale = state_dict[
                      f"{name}_scale"
                  ].float()  # channel-wise scale
  
                  if quantization_bit == 4:
                      # convert int4 weight to int8
                      low_bits = ((tensor << 4) & 0xF0) >> 4
                      high_bits = (tensor & 0xF0) >> 4
                      tensor = torch.stack(
                          (high_bits, low_bits), dim=-1
                      ).view(tensor.shape[0], -1)
                  tensor = tensor * scale[:, None]
              else:
                  tensor = tensor.float()
  
              # step 2: quantize it into ggml format
              tensor_ggml_type = ggml_type
          else:
              # 1d weight: convert it to float32
              invalidInputError(
                  tensor.ndim == 1, "tensor.ndim should be 1"
              )
              tensor = tensor.float()
              tensor_ggml_type = GGMLType.F32
  
          dump_tensor(f, name, tensor, tensor_ggml_type)
          tensor_info.append(
              (name, tensor.shape, tensor_ggml_type.name)
          )
  
      print(
          tabulate(
              tensor_info,
              headers=["name", "shape", "dtype"],
              tablefmt="psql",
          )
      )
  
imports: import argparse
  import platform
  import struct
  import sys
  from enum import Enum
  from pathlib import Path
  import torch
  from tabulate import tabulate
  from tqdm import tqdm
  from transformers import AutoModel, AutoTokenizer
  from bigdl.llm.utils.common import invalidInputError
label_desc: Use image node_id 7 for calling a global function with example usage: dump_state_dict(f, weight_names, state_dict, quantization_bit, ggml_type) without return types