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

Reduce after quantization memory usage #20894

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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