code: def encode_weights(
      tir_extern_call: tvm.tir.Call,
      values: np.ndarray,
      accel_config: vapi.NpuAccelerator,
  ):
      """This is an API function to compress weights by passing
      a tir_extern_call to NPU Convolution operation and values.
  
      Parameters
      ----------
      tir_extern_call : tvm.tir.Call
          tir_extern_call to NPU Convolution operation
      values : numpy.ndarray
          The constant flattened weight data in OHWI layout
      accel_config : ethosu.vela.api.NpuAccelerator
          The NPU accelerator config
  
      Returns
      -------
      bytearray
          Compressed weights
      """
      supported_ops = {
          "ethosu_conv2d": tirtocs.translate_ethosu_conv2d,
          "ethosu_depthwise_conv2d": tirtocs.translate_ethosu_depthwise_conv2d,
      }
      op = str(tir_extern_call.args[0].value)
      assert op in supported_ops.keys()
      npu_op, weights_zero_point = supported_ops[op](tir_extern_call)
      is_depthwise = op == "ethosu_depthwise_conv2d"
      # Recover the original shape if we are dealing with a flattened tensor
      if len(values.shape) == 1:
          shape_ohwi = (
              npu_op.ofm.shape.depth,
              npu_op.kernel.height,
              npu_op.kernel.width,
              1 if is_depthwise else npu_op.ifm.shape.depth,
          )
          assert values.size == np.prod(shape_ohwi)
          values = np.reshape(values, shape_ohwi)
  
      return compress_weights(
          weights=values,
          weights_zp=weights_zero_point,
          # The weight layout is assumed to be OHWI, always.
          weights_layout="OHWI",
          ifm_bitdepth=npu_op.ifm.data_type.size_in_bits(),
          block_depth=npu_op.block_config.depth,
          dilation=(npu_op.kernel.dilation_x, npu_op.kernel.dilation_y),
          accel_config=accel_config,
          is_depthwise=is_depthwise,
      )
  
imports: import logging
  import math
  from typing import List, Optional, Tuple
  import numpy
  from ethosu.vela import api
  from ethosu.vela.architecture_allocator import find_block_config
  from ethosu.vela.architecture_features import Accelerator, create_default_arch
  from ethosu.vela.operation import NpuBlockType
  from ethosu.vela.register_command_stream_generator import resampling_mode_map
  from ethosu.vela.register_command_stream_util import to_kernel
  from ethosu.vela.shape4d import Shape4D
  import tvm
  from tvm.relay.backend.contrib.ethosu import tir_to_cs_translator
  from tvm.relay.backend.contrib.ethosu import util
label_desc: Use image node_id 4 for calling a global function with example usage: encode_weights(tir_extern_call, values, accel_config) and returns: compress_weights