Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 70b9e38

Browse files
committed
Simplify releasing memory of used ndarrays for calibration
1 parent c1fe124 commit 70b9e38

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

python/mxnet/quantization.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,14 @@ def _get_optimal_thresholds(nd_dict, num_bins=8001, num_quantized_bins=255, logg
273273
logger.info('Calculating optimal thresholds for quantization using KL divergence'
274274
' with num_bins=%d and num_quantized_bins=%d' % (num_bins, num_quantized_bins))
275275
th_dict = {}
276-
layer_names = nd_dict.keys()
277-
for name in layer_names:
278-
assert name in nd_dict
279-
min_val, max_val, min_divergence, opt_th = _get_optimal_threshold(nd_dict[name], num_bins=num_bins,
276+
for k, v in nd_dict:
277+
min_val, max_val, min_divergence, opt_th = _get_optimal_threshold(v, num_bins=num_bins,
280278
num_quantized_bins=num_quantized_bins)
281-
del nd_dict[name] # release the memory of ndarray
282-
th_dict[name] = (-opt_th, opt_th)
279+
del v # release the memory of ndarray
280+
th_dict[k] = (-opt_th, opt_th)
283281
if logger is not None:
284282
logger.info('layer=%s, min_val=%f, max_val=%f, min_divergence=%f, optimal_threshold=%f'
285-
% (name, min_val, max_val, min_divergence, opt_th))
283+
% (k, min_val, max_val, min_divergence, opt_th))
286284
return th_dict
287285

288286

0 commit comments

Comments
 (0)