code: def _force_quantize_model(
      model: torch.nn.Module,
      q_dtype: torch.dtype,
      low: Optional[int] = None,
      high: Optional[int] = None,
      scale: Optional[float] = None,
      zero_point: Optional[int] = None,
      channel_axis: Optional[int] = None,
  ):
      """
      In torch, the quantized model can only be obtained from PTQ.
      This utility allows us to produce an int8 quantized model.
  
      If channel_axis is set, it will do per-channel quantization instead of per-tensor, for the param
      that channel_axis is valid for.
      """
      if scale is None:
          scale = 1.0
      if zero_point is None:
          zero_point = 0
  
      # modify the parameter to force the quantization within a specific range.
      with torch.no_grad():
          for name, param in model.named_parameters():
              shape = param.shape
              input_data = (
                  torch.rand(*shape)
                  if low is None
                  else torch.randint(low, high, shape).float()
              )
              input_data = (input_data - zero_point) * scale
  
              if channel_axis is not None and -len(
                  shape
              ) <= channel_axis < len(shape):
                  scale = torch.Tensor([scale] * shape[channel_axis])
                  zero_point = torch.Tensor(
                      [zero_point] * shape[channel_axis]
                  )
                  new_value = torch.quantize_per_channel(
                      input_data,
                      scales=scale,
                      zero_points=zero_point,
                      axis=channel_axis,
                      dtype=q_dtype,
                  )
              else:
                  new_value = torch.quantize_per_tensor(
                      input_data,
                      scale=scale,
                      zero_point=zero_point,
                      dtype=q_dtype,
                  )
  
              param_cls = type(param)
              new_value = param_cls(new_value, requires_grad=False).to(
                  torch.device("cpu")
              )
              model._parameters[name] = new_value
      return model
  
imports: import itertools
  from typing import Optional
  import numpy
  import pytest
  import torch
  import torchvision
  import coremltools
  from coremltools import TensorType
  from coremltools._deps import _HAS_TORCH, _HAS_TORCH_VISION, MSG_TORCH_NOT_FOUND, MSG_TORCH_VISION_NOT_FOUND
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
  from .testing_utils import TorchBaseTest
label_desc: Use image node_id 1 for calling a global function with example usage: _force_quantize_model(model, q_dtype, low, high, scale, zero_point, channel_axis) and returns: model