Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.16.3 patch release #18491

Merged
merged 7 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Linter] Bump ruff and remove pylint (#17797)
Bump ruff version and remove pylint from the linter list. Fix any new
error detected by ruff.

Ruff covers many of the pylint rules. Since pylint is not enabled in
this repo and runs slow, we remove it from the linters
  • Loading branch information
justinchuby authored and snnn committed Nov 17, 2023
commit 543abb17c621b886ef782f249f2380d4ebd3122d
27 changes: 0 additions & 27 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,6 @@ init_command = [
]
is_formatter = true

[[linter]]
code = 'PYLINT'
include_patterns = [
# TODO: Opt in to pylint by adding paths here
]
exclude_patterns = [
]
command = [
'python',
'-m',
'lintrunner_adapters',
'run',
'pylint_linter',
'--rcfile=pyproject.toml',
'--',
'@{{PATHSFILE}}'
]
init_command = [
'python',
'-m',
'lintrunner_adapters',
'run',
'pip_init',
'--dry-run={{DRYRUN}}',
'--requirement=requirements-lintrunner.txt',
]

[[linter]]
code = 'RUSTFMT'
include_patterns = ['**/*.rs']
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/onnxruntime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def generate_feeds(sess, symbolic_dims: dict | None = None):
if not dim:
# unknown dim
shape.append(1)
elif type(dim) == str:
elif isinstance(dim, str):
# symbolic dim. see if we have a value otherwise use 1
if dim in symbolic_dims:
shape.append(int(symbolic_dims[dim]))
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/profile_explorer/profile_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def _shape_to_string(shape):
for dict_obj in shape:
if len(dict_obj) > 1:
raise ValueError("Unhandled type in _shape_to_string()")
key = list(dict_obj.keys())[0]
value = list(dict_obj.values())[0]
key = next(iter(dict_obj.keys()))
value = next(iter(dict_obj.values()))
if len(res) != 0:
res += ","
res += f'{key}({"x".join(str(v) for v in value)})'
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/quantization/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ def compute_data(self) -> TensorsData:
else:
min_value_array = min(merged_added_output_dict[added_output_names[i]])
max_value_array = max(merged_added_output_dict[added_output_names[i + 1]])
if type(min_value_array) == int or min_value_array.size > 0:
if isinstance(min_value_array, int) or min_value_array.size > 0:
min_value = float(min_value_array)
if type(max_value_array) == int or max_value_array.size > 0:
if isinstance(max_value_array, int) or max_value_array.size > 0:
max_value = float(max_value_array)

if self.symmetric:
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/quantization/onnx_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def _get_quantization_params(self, param_name, use_scale=None, use_zeropoint=Non
if params is None or len(params) != 2:
raise ValueError(
"Quantization parameters should contain zero point and scale. "
"Specified values for output {}: {}".format(param_name, params)
f"Specified values for output {param_name}: {params}"
)

zero_point_values = [params["zero_point"]]
Expand Down
52 changes: 26 additions & 26 deletions onnxruntime/python/tools/symbolic_shape_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_attribute(node, attr_name, default_value=None):


def get_dim_from_proto(dim):
return getattr(dim, dim.WhichOneof("value")) if type(dim.WhichOneof("value")) == str else None
return getattr(dim, dim.WhichOneof("value")) if type(dim.WhichOneof("value")) is str else None # noqa: E721


def is_sequence(type_proto):
Expand Down Expand Up @@ -82,7 +82,7 @@ def handle_negative_axis(axis, rank):

def get_opset(mp, domain=None):
domain = domain or ["", "onnx", "ai.onnx"]
if type(domain) != list:
if type(domain) != list: # noqa: E721
domain = [domain]
for opset in mp.opset_import:
if opset.domain in domain:
Expand All @@ -92,7 +92,7 @@ def get_opset(mp, domain=None):


def as_scalar(x):
if type(x) == list:
if type(x) == list: # noqa: E721
assert len(x) == 1
return x[0]
elif type(x) == np.ndarray:
Expand All @@ -102,7 +102,7 @@ def as_scalar(x):


def as_list(x, keep_none):
if type(x) == list:
if type(x) == list: # noqa: E721
return x
elif type(x) == np.ndarray:
return list(x)
Expand All @@ -113,7 +113,7 @@ def as_list(x, keep_none):


def sympy_reduce_product(x):
if type(x) == list:
if type(x) == list: # noqa: E721
value = sympy.Integer(1)
for v in x:
value = value * v
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(self, int_max, auto_merge, guess_output_rank, verbose, prefix=""):
self.prefix_ = prefix

def _add_suggested_merge(self, symbols, apply=False):
assert all([(type(s) == str and s in self.symbolic_dims_) or is_literal(s) for s in symbols])
assert all([(type(s) == str and s in self.symbolic_dims_) or is_literal(s) for s in symbols]) # noqa: E721
symbols = set(symbols)
for k, v in self.suggested_merge_.items():
if k in symbols:
Expand Down Expand Up @@ -319,7 +319,7 @@ def _preprocess(self, in_mp):
)

def _merge_symbols(self, dims):
if not all([type(d) == str for d in dims]):
if not all([type(d) == str for d in dims]): # noqa: E721
if self.auto_merge_:
unique_dims = list(set(dims))
is_int = [is_literal(d) for d in unique_dims]
Expand Down Expand Up @@ -402,7 +402,7 @@ def _get_shape_rank(self, node, idx):
def _get_sympy_shape(self, node, idx):
sympy_shape = []
for d in self._get_shape(node, idx):
if type(d) == str:
if type(d) == str: # noqa: E721
sympy_shape.append(
self.symbolic_dims_[d]
if d in self.symbolic_dims_
Expand All @@ -428,7 +428,7 @@ def _try_get_value(self, node, idx):

def _update_computed_dims(self, new_sympy_shape):
for i, new_dim in enumerate(new_sympy_shape):
if not is_literal(new_dim) and type(new_dim) != str:
if not is_literal(new_dim) and type(new_dim) != str: # noqa: E721
str_dim = str(new_dim)
if str_dim in self.suggested_merge_:
if is_literal(self.suggested_merge_[str_dim]):
Expand Down Expand Up @@ -556,7 +556,7 @@ def _onnx_infer_subgraph(self, node, subgraph, use_node_input=True, inc_subgraph
# for new symbolic dims from subgraph output, add to main graph symbolic dims
subgraph_shapes = [get_shape_from_value_info(o) for o in symbolic_shape_inference.out_mp_.graph.output]
subgraph_new_symbolic_dims = {
d for s in subgraph_shapes if s for d in s if type(d) == str and d not in self.symbolic_dims_
d for s in subgraph_shapes if s for d in s if type(d) == str and d not in self.symbolic_dims_ # noqa: E721
}
new_dims = {}
for d in subgraph_new_symbolic_dims:
Expand Down Expand Up @@ -586,14 +586,14 @@ def int_or_float(value, allow_float_values):
assert len(v.shape) == 1
new_v = [int_or_float(vv, allow_float_values) for vv in v]
values[i] = new_v
values_len = [len(v) if type(v) == list else 0 for v in values]
values_len = [len(v) if isinstance(v, list) else 0 for v in values]
max_len = max(values_len)
if max_len >= 1 and broadcast:
# broadcast
for i, v in enumerate(values):
if v is None:
continue # don't broadcast if value is unknown
if type(v) == list:
if isinstance(v, list):
if len(v) < max_len:
values[i] = v * max_len
else:
Expand All @@ -614,7 +614,7 @@ def _compute_on_sympy_data(self, node, op_func):
values = self._get_int_or_float_values(node, broadcast=True)

if all([v is not None for v in values]):
is_list = [type(v) == list for v in values]
is_list = [isinstance(v, list) for v in values]
as_list = any(is_list)
if as_list:
self.sympy_data_[node.output[0]] = [op_func(vs) for vs in zip(*values)]
Expand Down Expand Up @@ -871,7 +871,7 @@ def _infer_Concat(self, node): # noqa: N802
self.sympy_data_[node.output[0]] = []
for i in range(len(node.input)):
value = values[i]
if type(value) == list:
if isinstance(value, list):
self.sympy_data_[node.output[0]].extend(value)
else:
self.sympy_data_[node.output[0]].append(value)
Expand All @@ -891,7 +891,7 @@ def _infer_Concat(self, node): # noqa: N802
if all([d == dims[0] for d in dims]):
continue
merged = self._merge_symbols(dims)
if type(merged) == str:
if type(merged) == str: # noqa: E721
sympy_shape[d] = self.symbolic_dims_[merged] if merged else None
else:
sympy_shape[d] = merged
Expand Down Expand Up @@ -931,7 +931,7 @@ def _infer_ConstantOfShape(self, node): # noqa: N802
sympy_shape = self._get_int_or_float_values(node)[0]
vi = self.known_vi_[node.output[0]]
if sympy_shape is not None:
if type(sympy_shape) != list:
if type(sympy_shape) != list: # noqa: E721
sympy_shape = [sympy_shape]
self._update_computed_dims(sympy_shape)
# update sympy data if output type is int, and shape is known
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def _infer_Einsum(self, node): # noqa: N802
letter = term[-i]
if letter != 46: # letter != b'.'
dim = shape[-i]
if letter not in letter_to_dim.keys():
if letter not in letter_to_dim:
letter_to_dim[letter] = dim
elif type(dim) != sympy.Symbol:
letter_to_dim[letter] = dim
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def _infer_Gather(self, node): # noqa: N802
idx = self._try_get_value(node, 1)
if idx is not None:
data = self.sympy_data_[node.input[0]]
if type(data) == list:
if type(data) == list: # noqa: E721
if type(idx) == np.ndarray and len(idx.shape) == 1:
self.sympy_data_[node.output[0]] = [data[int(i)] for i in idx]
else:
Expand Down Expand Up @@ -1563,12 +1563,12 @@ def _infer_Reshape(self, node): # noqa: N802
)
else:
input_sympy_shape = self._get_sympy_shape(node, 0)
total = int(1)
total = 1
for d in input_sympy_shape:
total = total * d
new_sympy_shape = []
deferred_dim_idx = -1
non_deferred_size = int(1)
non_deferred_size = 1
for i, d in enumerate(shape_value):
if type(d) == sympy.Symbol:
new_sympy_shape.append(d)
Expand Down Expand Up @@ -1874,7 +1874,7 @@ def handle_negative_index(index, bound):
and len(steps) == 1
):
input_sympy_data = self.sympy_data_[node.input[0]]
if type(input_sympy_data) == list or (
if type(input_sympy_data) == list or ( # noqa: E721
type(input_sympy_data) == np.array and len(input_sympy_data.shape) == 1
):
self.sympy_data_[node.output[0]] = input_sympy_data[starts[0] : ends[0] : steps[0]]
Expand Down Expand Up @@ -1942,7 +1942,7 @@ def _infer_Squeeze(self, node): # noqa: N802
# For symbolic dimensions we guess they are !=1.
output_shape = [s for s in input_shape if s != 1]
if self.verbose_ > 0:
symbolic_dimensions = [s for s in input_shape if type(s) != int]
symbolic_dimensions = [s for s in input_shape if type(s) != int] # noqa: E721
if len(symbolic_dimensions) > 0:
logger.debug(
f"Symbolic dimensions in input shape of op: '{node.op_type}' node: '{node.name}'. "
Expand All @@ -1955,8 +1955,8 @@ def _infer_Squeeze(self, node): # noqa: N802
if i not in axes:
output_shape.append(input_shape[i])
else:
assert input_shape[i] == 1 or type(input_shape[i]) != int
if self.verbose_ > 0 and type(input_shape[i]) != int:
assert input_shape[i] == 1 or type(input_shape[i]) != int # noqa: E721
if self.verbose_ > 0 and type(input_shape[i]) != int: # noqa: E721
logger.debug(
f"Symbolic dimensions in input shape of op: '{node.op_type}' node: '{node.name}'. "
f"Assuming the dimension '{input_shape[i]}' at index {i} of the input to be equal to 1."
Expand Down Expand Up @@ -2458,7 +2458,7 @@ def _propagate_shape_and_type(self, node, input_index=0, output_index=0):
vi.CopyFrom(helper.make_tensor_value_info(node.output[output_index], output_dtype, shape))

def _is_none_dim(self, dim_value):
if type(dim_value) != str:
if type(dim_value) != str: # noqa: E721
return False
if "unk__" not in dim_value:
return False
Expand Down Expand Up @@ -2492,7 +2492,7 @@ def _infer_impl(self, start_sympy_data=None):
# some models use None for symbolic dim in input, replace it with a string
input_dims[i_dim].dim_param = str(self._new_symbolic_dim(i.name, i_dim))

self.input_symbols_.update([d for d in input_shape if type(d) == str])
self.input_symbols_.update([d for d in input_shape if type(d) == str]) # noqa: E721

for s in self.input_symbols_:
if s in self.suggested_merge_:
Expand Down
10 changes: 5 additions & 5 deletions onnxruntime/python/tools/tensorrt/perf/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def write_map_to_file(result, file_name):
if os.path.exists(file_name):
existed_result = read_map_from_file(file_name)

for model, _ep_list in result.items():
for model in result:
if model in existed_result:
existed_result[model] = {**existed_result[model], **result[model]}
else:
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def calculate_gain(value, ep1, ep2):


def add_improvement_information(model_to_latency):
for _key, value in model_to_latency.items():
for value in model_to_latency.values():
if trt in value and cuda in value:
gain = calculate_gain(value, trt, cuda)
value[trt_cuda_gain] = f"{gain:.2f} %"
Expand Down Expand Up @@ -1209,13 +1209,13 @@ def add_status_dict(status_dict, model_name, ep, status):
def build_status(status_dict, results, is_fail):
if is_fail:
for model, model_info in results.items():
for ep, _ep_info in model_info.items():
for ep in model_info:
model_name = model
status = "Fail"
add_status_dict(status_dict, model_name, ep, status)
else:
for model, value in results.items():
for ep, _ep_info in value.items():
for ep in value:
model_name = model
status = "Pass"
add_status_dict(status_dict, model_name, ep, status)
Expand Down Expand Up @@ -2270,7 +2270,7 @@ def main():
logger.info(f"\nTotal models: {len(models)}")

fail_model_cnt = 0
for key, _value in models.items():
for key in models:
if key in model_to_fail_ep:
fail_model_cnt += 1
logger.info(f"Fail models: {fail_model_cnt}")
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/tensorrt/perf/perf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def calculate_trt_latency_percentage(trt_op_map):
op_map = trt_op_map[ep]

total_time = 0
for _key, value in op_map.items():
for value in op_map.values():
total_time += int(value)

if ep == "TensorrtExecutionProvider":
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/transformers/float16.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def convert_float_to_float16(

queue = next_level

for _key, value in fp32_initializers.items():
for value in fp32_initializers.values():
# By default, to avoid precision loss, do not convert an initializer to fp16 when it is used only by fp32 nodes.
if force_fp16_initializers or value.fp16_nodes:
value.initializer = convert_tensor_float_to_float16(value.initializer, min_positive_val, max_finite_val)
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/transformers/fusion_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ def create_multihead_attention_node(
else:
mha_inputs.extend([q_matmul.output[0], k_matmul.output[0], v_matmul.output[0]])
elif (
type(k_matmul) == str
and type(v_matmul) == str
type(k_matmul) == str # noqa: E721
and type(v_matmul) == str # noqa: E721
and k_matmul in graph_input_names
and v_matmul in graph_input_names
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def load_engines(

def max_device_memory(self):
max_device_memory = 0
for _model_name, engine in self.engines.items():
for engine in self.engines.values():
max_device_memory = max(max_device_memory, engine.engine.device_memory_size)
return max_device_memory

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/transformers/onnx_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def convert_float_to_float16(self, use_symbolic_shape_infer=True, **kwargs):
if vi.name in name_vi:
del name_vi[vi.name]
for vi in name_vi.values():
model.graph.value_info.append(vi) # noqa: PERF402
model.graph.value_info.append(vi)
except Exception:
logger.warning(
"Failed to run symbolic shape inference. Please file an issue in https://github.com/microsoft/onnxruntime."
Expand Down
Loading