Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions onnxruntime/python/tools/quantization/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,14 @@ def compute_data(self) -> TensorsData:
pairs = []
for i in range(0, len(added_output_names), 2):
if self.moving_average:
min_value_array = np.mean(merged_added_output_dict[added_output_names[i]], axis=0)
max_value_array = np.mean(merged_added_output_dict[added_output_names[i + 1]], axis=0)
min_value_array = np.nanmean(merged_added_output_dict[added_output_names[i]], axis=0)
max_value_array = np.nanmean(merged_added_output_dict[added_output_names[i + 1]], axis=0)
else:
min_value_array = np.min(merged_added_output_dict[added_output_names[i]], axis=0)
max_value_array = np.max(merged_added_output_dict[added_output_names[i + 1]], axis=0)
min_value_array = np.nanmin(merged_added_output_dict[added_output_names[i]], axis=0)
max_value_array = np.nanmax(merged_added_output_dict[added_output_names[i + 1]], axis=0)

if self.symmetric:
max_absolute_value = np.max([np.abs(min_value_array), np.abs(max_value_array)], axis=0)
max_absolute_value = np.nanmax([np.abs(min_value_array), np.abs(max_value_array)], axis=0)
pairs.append((-max_absolute_value, max_absolute_value))
else:
pairs.append((min_value_array, max_value_array))
Expand Down Expand Up @@ -834,8 +834,8 @@ def collect_absolute_value(self, name_to_arr):
data_arr_np = data_arr
data_arr_np = data_arr_np.flatten()
if data_arr_np.size > 0:
min_value = np.min(data_arr_np)
max_value = np.max(data_arr_np)
min_value = np.nanmin(data_arr_np)
max_value = np.nanmax(data_arr_np)
else:
min_value = np.array(0, dtype=data_arr_np.dtype)
max_value = np.array(0, dtype=data_arr_np.dtype)
Expand All @@ -858,7 +858,7 @@ def collect_absolute_value(self, name_to_arr):
assert hasattr(old_max, "dtype"), f"old_min should be a numpy array but is {type(old_max)}"
old_hist = old_histogram[0]
old_hist_edges = old_histogram[1]
temp_amax = np.max(data_arr_np)
temp_amax = np.nanmax(data_arr_np)
if temp_amax > old_hist_edges[-1]:
# increase the number of bins
width = old_hist_edges[1] - old_hist_edges[0]
Expand All @@ -882,8 +882,8 @@ def collect_value(self, name_to_arr):
data_arr = data_arr.flatten() # noqa: PLW2901

if data_arr.size > 0:
min_value = np.min(data_arr)
max_value = np.max(data_arr)
min_value = np.nanmin(data_arr)
max_value = np.nanmax(data_arr)
else:
min_value = np.array(0, dtype=data_arr.dtype)
max_value = np.array(0, dtype=data_arr.dtype)
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/quantization/quant_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def compute_scale_zp(rmin, rmax, qmin, qmax, symmetric=False, min_real_range=Non
dr = numpy.array(rmax - rmin, dtype=numpy.float64)
dq = numpy.array(qmax, dtype=numpy.float64) - numpy.array(qmin, dtype=numpy.float64)
scale = numpy.array(dr / dq)
assert scale >= 0, "scale isse"
assert scale >= 0, "scale issue"
if scale < numpy.finfo(rmax.dtype).tiny:
scale = numpy.array(1.0, dtype=rmax.dtype)
zero_point = numpy.array(0, dtype=qmin.dtype)
Expand Down