MCPcopy
hub / github.com/OpenPPL/ppq / setDynamicRange

Function setDynamicRange

ppq/utils/TensorRTUtil.py:185–209  ·  view source on GitHub ↗

Sets ranges for network layers.

(network, json_file: str)

Source from the content-addressed store, hash-verified

183
184
185def setDynamicRange(network, json_file: str):
186 """Sets ranges for network layers."""
187 with open(json_file) as file:
188 quant_param_json = json.load(file)
189 act_quant = quant_param_json["act_quant_info"]
190
191 for i in range(network.num_inputs):
192 input_tensor = network.get_input(i)
193 if act_quant.__contains__(input_tensor.name):
194 value = act_quant[input_tensor.name]
195 tensor_max = abs(value)
196 tensor_min = -abs(value)
197 input_tensor.dynamic_range = (tensor_min, tensor_max)
198
199 for i in range(network.num_layers):
200 layer = network.get_layer(i)
201
202 for output_index in range(layer.num_outputs):
203 tensor = layer.get_output(output_index)
204
205 if act_quant.__contains__(tensor.name):
206 value = act_quant[tensor.name]
207 tensor_max = abs(value)
208 tensor_min = -abs(value)
209 tensor.dynamic_range = (tensor_min, tensor_max)
210
211
212def build_engine(

Callers 1

build_engineFunction · 0.70

Calls 1

__contains__Method · 0.80

Tested by

no test coverage detected