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

    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.
    
coremltools/converters/mil/frontend/torch/test/test_torch_quantization_ops.py