class_docstr: Saves layer histogram in a dict with layer names as keys and lists of NDArrays as
  values. The collected histogram will be used for calculating the optimal thresholds for
  quantization using KL divergence.
class_docstr_tok: ["Saves","layer","histogram","in","a","dict","with","layer","names","as","keys","and","lists","of","NDArrays","as","values",".","The","collected","histogram","will","be","used","for","calculating","the","optimal","thresholds","for","quantization","using","KL","divergence","."]
docstr: Given a dataset, find the optimal threshold for quantizing it.
  The reference distribution is `q`, and the candidate distribution is `p`.
  `q` is a truncated version of the original distribution.
  
  Ref: http://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf
code: def get_optimal_threshold(
      hist_data, quantized_dtype, num_quantized_bins=255
  ):
      """Given a dataset, find the optimal threshold for quantizing it.
      The reference distribution is `q`, and the candidate distribution is `p`.
      `q` is a truncated version of the original distribution.
  
      Ref: http://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf
      """
      (hist, hist_edges, min_val, max_val, _) = hist_data
      num_bins = len(hist)
      assert num_bins % 2 == 1
      if min_val >= 0 and quantized_dtype in ["auto", "uint8"]:
          # We need to move negative bins to positive bins to fit uint8 range.
          num_quantized_bins = num_quantized_bins * 2 + 1
      hist = ndarray.array(hist, ctx=cpu())
      hist_edges = ndarray.array(hist_edges, ctx=cpu())
      threshold, divergence = ndarray.contrib.calibrate_entropy(
          hist=hist,
          hist_edges=hist_edges,
          num_quantized_bins=num_quantized_bins,
      )
      threshold = threshold.asnumpy()
      divergence = divergence.asnumpy()
      return min_val, max_val, threshold, divergence
  
imports: import abc
  import ctypes
  import logging
  import os
  import warnings
  import numpy
  import mxnet
  from ..base import _LIB, check_call, py_str
  from ..base import c_array, c_str, mx_uint, mx_real_t, c_str_array
  from ..base import SymbolHandle
  from ..symbol import Symbol
  from ..None import ndarray
  from ..io import DataDesc
  from ..device import cpu, Device
  from ..util import is_np_array, wrap_ctx_to_device_func
label_desc: Use image node_id 5 for calling the _LayerHistogramCollector obj's underlying member method code with example usage: obj.get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins) and returns: min_val,  max_val,  threshold,  divergence