You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/01/27 06:39:35 UTC

[GitHub] marcoabreu commented on issue #9552: [REQUEST FOR REVIEW | DO NOT MERGE] Model Quantization with Calibration

marcoabreu commented on issue #9552: [REQUEST FOR REVIEW | DO NOT MERGE] Model Quantization with Calibration
URL: https://github.com/apache/incubator-mxnet/pull/9552#issuecomment-360964643
 
 
   From the perspective of a resource constrained Edge device, could there be
   different optimal values? What platform factors could play an important
   role here?
   
   On Fri, Jan 26, 2018 at 10:29 PM, reminisce <no...@github.com>
   wrote:
   
   > *@reminisce* commented on this pull request.
   > ------------------------------
   >
   > In python/mxnet/quantization.py
   > <https://github.com/apache/incubator-mxnet/pull/9552#discussion_r164265094>
   > :
   >
   > > +    with eps multiplied by a scaling factor and taking the corresponding amount off the non-zero values.
   > +    Ref: http://web.engr.illinois.edu/~hanj/cs412/bk3/KL-divergence.pdf
   > +    """
   > +    is_zeros = (p == 0).astype(np.float32)
   > +    is_nonzeros = (p != 0).astype(np.float32)
   > +    n_zeros = is_zeros.sum()
   > +    n_nonzeros = p.size - n_zeros
   > +    eps1 = eps * float(n_zeros) / float(n_nonzeros)
   > +    assert eps1 < 1.0, 'n_zeros=%d, n_nonzeros=%d, eps1=%f' % (n_zeros, n_nonzeros, eps1)
   > +    hist = p.astype(np.float32)
   > +    hist += eps * is_zeros + (-eps1) * is_nonzeros
   > +    assert (hist <= 0).sum() == 0
   > +    return hist
   > +
   > +
   > +def _get_optimal_threshold(arr, num_bins=8001, num_quantized_bins=255):
   >
   >
   >    - num_quantized_bins represents the number of values in the int8
   >    range. If we want to use 4 bits as quantized values, num_quantized_bins
   >    would be 15.
   >    - num_bins I tried different numbers of bins from 500 to 40,000. It
   >    has little effect on the optimal thresholds. So I picked a value in
   >    between. Too small values might not be suitable considering the tensor size
   >    is large, and too big value leads to more compute time of KL divergence.
   >    Here is a good article explaining the good rules of choosing the number of
   >    bins. http://www.statisticshowto.com/choose-bin-sizes-statistics/
   >
   > ?
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/incubator-mxnet/pull/9552#discussion_r164265094>,
   > or mute the thread
   > <https://github.com/notifications/unsubscribe-auth/ARxB63nkeG0cbJy6kyTlifnSpyxJ-_Kdks5tOsI_gaJpZM4RsJmp>
   > .
   >
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services