code: def _quantize_spec_weights(spec, nbits, quantization_mode, **kwargs):
      nn_model_types = [
          "neuralNetwork",
          "neuralNetworkClassifier",
          "neuralNetworkRegressor",
      ]
  
      model_type = spec.WhichOneof("Type")
  
      # Neural network models
      if model_type in nn_model_types:
          # Bump up to appropriate spec version if required
          if nbits == 16:
              spec.specificationVersion = max(
                  _MINIMUM_FP16_SPEC_VERSION, spec.specificationVersion
              )
          else:
              spec.specificationVersion = max(
                  _MINIMUM_QUANTIZED_MODEL_SPEC_VERSION,
                  spec.specificationVersion,
              )
  
          if spec.WhichOneof("Type") == "neuralNetwork":
              _quantize_nn_spec(
                  spec.neuralNetwork, nbits, quantization_mode, **kwargs
              )
  
          elif spec.WhichOneof("Type") in "neuralNetworkClassifier":
              _quantize_nn_spec(
                  spec.neuralNetworkClassifier,
                  nbits,
                  quantization_mode,
                  **kwargs,
              )
  
          elif spec.WhichOneof("Type") in "neuralNetworkRegressor":
              _quantize_nn_spec(
                  spec.neuralNetworkRegressor,
                  nbits,
                  quantization_mode,
                  **kwargs,
              )
  
      # Recursively convert all pipeline models
      elif spec.WhichOneof("Type") == "pipeline":
          for model_spec in spec.pipeline.models:
              _quantize_spec_weights(
                  model_spec, nbits, quantization_mode, **kwargs
              )
  
      elif spec.WhichOneof("Type") in [
          "pipelineClassifier",
          "pipelineRegressor",
      ]:
          _quantize_spec_weights(
              spec.pipeline, nbits, quantization_mode, **kwargs
          )
  
      return spec
  
imports: from os import listdir
  from sys import stdout
  import numpy
  from coremltools import ComputeUnit, _logger
  from coremltools._deps import _HAS_KMEANS1D, _kmeans1d
  from coremltools.models import _QUANTIZATION_MODE_CUSTOM_LOOKUP_TABLE, _QUANTIZATION_MODE_DEQUANTIZE, _QUANTIZATION_MODE_LINEAR_QUANTIZATION, _QUANTIZATION_MODE_LINEAR_SYMMETRIC, _QUANTIZATION_MODE_LOOKUP_TABLE_KMEANS, _QUANTIZATION_MODE_LOOKUP_TABLE_LINEAR, _SUPPORTED_QUANTIZATION_MODES, MLModel
  from ...None import _MINIMUM_FP16_SPEC_VERSION, _MINIMUM_QUANTIZED_MODEL_SPEC_VERSION, _SPECIFICATION_VERSION_IOS_14
  from ..utils import _get_model, _macos_version, _wp_to_fp16wp
  from .optimization_utils import _optimize_nn
label_desc: Use image node_id 15 for calling a global function with example usage: _quantize_spec_weights(spec, nbits, quantization_mode) and returns: spec