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

Commit

Permalink
Reduce after quantization memory usage (#20894)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgawrych committed Feb 21, 2022
1 parent abf35b8 commit f6266f0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/mxnet/contrib/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,9 @@ def quantize_net(network, quantized_dtype='auto', quantize_mode='full', quantize
if calib_mode in ['naive', 'entropy', 'custom']:
inputs = [mx.sym.var(desc.name) for desc in data_descs]
calib_net = SymbolBlock(symnet, inputs)
for k, v in calib_net.collect_params().items():
v.grad_req = 'null'

calib_net.load_dict(params, cast_dtype=True, dtype_source='saved')
calib_net.hybridize(static_alloc=False, static_shape=False)
num_batches = _collect_layer_statistics(calib_net, calib_data, collector, num_inputs,
Expand All @@ -939,6 +942,9 @@ def quantize_net(network, quantized_dtype='auto', quantize_mode='full', quantize
inputs = [mx.sym.var(desc.name) for desc in data_descs]

net = SymbolBlock(qsym, inputs)
for k, v in net.collect_params().items():
v.grad_req = 'null'

all_params = {('arg:%s' % k): v.as_in_context(cpu()) for k, v in qarg_params.items()}
all_params.update({('aux:%s' % k): v.as_in_context(cpu()) for k, v in aux_params.items()})
net.load_dict(all_params, cast_dtype=True, dtype_source='saved')
Expand Down

0 comments on commit f6266f0

Please sign in to comment.