code: def make_tensor(
      name: str,
      data_type: int,
      dims: Sequence[int],
      vals: Any,
      raw: bool = False,
  ) -> TensorProto:
      """Make a TensorProto with specified arguments.  If raw is False, this
      function will choose the corresponding proto field to store the
      values based on data_type. If raw is True, use "raw_data" proto
      field to store the values, and values should be of type bytes in
      this case.
  
      Args:
          name (string): tensor name
          data_type (int): a value such as onnx.TensorProto.FLOAT
          dims (List[int]): shape
          vals: values
          raw (bool): if True, vals contains the serialized content of the tensor,
              otherwise, vals should be a list of values of the type defined by *data_type*
  
      Returns:
          TensorProto
      """
      tensor = TensorProto()
      tensor.data_type = data_type
      tensor.name = name
  
      if data_type == TensorProto.STRING and raw:
          raise TypeError("Can not use raw_data to store string type.")
  
      np_dtype = tensor_dtype_to_np_dtype(data_type)
  
      # Check number of vals specified equals tensor size
      expected_size = 1
      if raw:
          # NumPy doesn't have BFLOAT16. TENSOR_TYPE_MAP maps it to float32, which has the wrong itemsize.
          if data_type == TensorProto.BFLOAT16:
              expected_size = 2
          elif data_type in (
              TensorProto.FLOAT8E4M3FN,
              TensorProto.FLOAT8E4M3FNUZ,
              TensorProto.FLOAT8E5M2,
              TensorProto.FLOAT8E5M2FNUZ,
          ):
              expected_size = 1
          # NumPy doesn't have INT4. It is packed in couples to UINT8 buffers.
          elif data_type in (TensorProto.UINT4, TensorProto.INT4):
              expected_size = 0.5  # type: ignore[assignment]
          else:
              expected_size = np_dtype.itemsize
  
      if type(vals) is np.ndarray and len(vals.shape) > 1:
          vals = vals.flatten()
      for d in dims:
          expected_size *= d
  
      if len(vals) != expected_size:
          # padding of half a byte is acceptable for 4bit types
          if not (
              data_type in (TensorProto.UINT4, TensorProto.INT4)
              and len(vals) == expected_size + 0.5
          ):
              raise ValueError(
                  f"Number of values does not match tensor's size. Expected {expected_size}, but it is {len(vals)}. "
              )
  
      if raw:
          tensor.raw_data = vals
      else:
          if data_type in (
              TensorProto.COMPLEX64,
              TensorProto.COMPLEX128,
          ):
              vals = split_complex_to_pairs(vals)
          elif data_type == TensorProto.FLOAT16:
              vals = (
                  np.array(vals)
                  .astype(np_dtype)
                  .view(dtype=np.uint16)
                  .flatten()
                  .tolist()
              )
          elif data_type in (
              TensorProto.BFLOAT16,
              TensorProto.FLOAT8E4M3FN,
              TensorProto.FLOAT8E4M3FNUZ,
              TensorProto.FLOAT8E5M2,
              TensorProto.FLOAT8E5M2FNUZ,
          ):
              fcast = {
                  TensorProto.BFLOAT16: float32_to_bfloat16,
                  TensorProto.FLOAT8E4M3FN: float32_to_float8e4m3,
                  TensorProto.FLOAT8E4M3FNUZ: lambda *args: float32_to_float8e4m3(  # type: ignore[misc]
                      *args, uz=True
                  ),
                  TensorProto.FLOAT8E5M2: float32_to_float8e5m2,
                  TensorProto.FLOAT8E5M2FNUZ: lambda *args: float32_to_float8e5m2(  # type: ignore[misc]
                      *args, fn=True, uz=True
                  ),
              }[
                  data_type  # type: ignore[index]
              ]
              vals = list(
                  map(  # type: ignore[call-overload]
                      fcast,
                      np.array(vals)
                      .astype(np_dtype)
                      .flatten()
                      .tolist(),
                  )
              )
          elif data_type in (
              TensorProto.UINT4,
              TensorProto.INT4,
          ):
              signed = data_type == TensorProto.INT4
              vals = (
                  pack_float32_to_4bit(vals, signed=signed)
                  .astype(np_dtype)
                  .flatten()
                  .tolist()
              )
          elif data_type == TensorProto.BOOL:
              vals = np.array(vals).astype(int)
          elif data_type == TensorProto.STRING:
              vals = np.array(vals).astype(bytes)
          field = tensor_dtype_to_field(data_type)
          getattr(tensor, field).extend(vals)
      tensor.dims.extend(dims)
      return tensor
  
imports: import collections.abc
  import numbers
  import struct
  from cmath import isnan
  from typing import Any, Callable, Dict, KeysView, List, Optional, Sequence, Tuple, TypeVar, Union, cast
  import google.protobuf.message
  import numpy
  from onnx import IR_VERSION, AttributeProto, FunctionProto, GraphProto, MapProto, ModelProto, NodeProto, OperatorSetIdProto, OptionalProto, SequenceProto, SparseTensorProto, TensorProto, TensorShapeProto, TrainingInfoProto, TypeProto, ValueInfoProto, defs, mapping, subbyte
label_desc: Use image node_id 16 for calling a global function with example usage: make_tensor(name, data_type, dims, vals, raw) and returns: tensor