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

[GitHub] [incubator-mxnet] wanghr323 opened a new issue #19235: question about function _get_optimal_threshold

wanghr323 opened a new issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235


   Hello, I’m doing work on the weighting of the convolutional layer. I tried the "_get_optimal_threshold" function of incubator-mxnet/python/mxnet/contrib/quantization.py in mxnet, but I found that no matter what value I pass in , The final threshold return value of this function will return the maximum and minimum values of arrary (finally implemented using the C function), 
   but when I try to use the v1.0.0 version, his return value is different (finally use python achieve).
   Why is the return value of the two versions of the function so different? Is there a problem with my usage?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700717277


   I think the old version is buggy. How are you using it?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek edited a comment on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek edited a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700717277


   I think the old version is buggy. I got an error when executing it. How are you using the new one?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700014370


   Hi,
   What do you mean by v1.0.0 version? Could you give a link to code of that version?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek edited a comment on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek edited a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly or I am misunderstanding something. The new code seems to return results that look like they make sense.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```python
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   I hope this helps?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek edited a comment on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek edited a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly. The new code seems to return results that look like they make sense.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```python
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   I hope this helps?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek edited a comment on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek edited a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly. The new code seems to return results that look like they make sense.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```python
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] szha closed issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
szha closed issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] github-actions[bot] commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-699594388


   Welcome to Apache MXNet (incubating)! We are on a mission to democratize AI, and we are glad that you are contributing to it by opening this issue.
   Please make sure to include all the relevant context, and one of the @apache/mxnet-committers will be here shortly.
   If you are interested in contributing to our project, let us know! Also, be sure to check out our guide on [contributing to MXNet](https://mxnet.apache.org/community/contribute) and our [development guides wiki](https://cwiki.apache.org/confluence/display/MXNET/Developments).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-770763385


   @szha Can we close this issue?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] sfraczek removed a comment on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
sfraczek removed a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly or I am misunderstanding something. The new code seems to return results that look like they make sense.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```python
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   I hope this helps?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org


[GitHub] [incubator-mxnet] wanghr323 commented on issue #19235: question about function _get_optimal_threshold

Posted by GitBox <gi...@apache.org>.
wanghr323 commented on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700017106


   sorry,its the branch v1.2.0……
   function is in
   https://github.com/apache/incubator-mxnet/blob/v1.2.0/python/mxnet/contrib/quantization.py   line249


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org