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
6 changes: 3 additions & 3 deletions docs/python/_common/onnx_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_domain_list():
"""
Returns the list of available domains.
"""
return list(sorted(set(map(lambda s: s.domain, get_all_schemas_with_history()))))
return sorted({s.domain for s in get_all_schemas_with_history()})


def get_operator_schemas(op_name, version=None, domain=None):
Expand Down Expand Up @@ -779,9 +779,9 @@ def render(self, indent=""):
name = op["name"]
dom = self.domain.replace(".", "-")
table_dom.append(f" * - :ref:`l-onnx-doc{dom}-{name}`")
versions = list(reversed(sorted((k, v) for k, v in op["links"].items() if isinstance(k, int))))
versions = sorted(((k, v) for k, v in op["links"].items() if isinstance(k, int)), reverse=True)
col1 = ", ".join(f":ref:`{k} <{v}>`" for k, v in versions)
diffs = list(reversed(sorted((k, v) for k, v in op["links"].items() if isinstance(k, tuple))))
diffs = sorted(((k, v) for k, v in op["links"].items() if isinstance(k, tuple)), reverse=True)
col2 = ", ".join(f":ref:`{k[1]}/{k[0]} <{v}>`" for k, v in diffs)
table_dom.append(f" - {col1}")
table_dom.append(f" - {col2}")
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/python/onnxruntime_inference_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def set_provider_options(name, options):
if len(providers) != len(provider_options):
raise ValueError("'providers' and 'provider_options' should be the same length if both are given.")

if not all([isinstance(provider, str) for provider in providers]):
if not all(isinstance(provider, str) for provider in providers):
raise ValueError("Only string values for 'providers' are supported if 'provider_options' is given.")

if not all([isinstance(options_for_provider, dict) for options_for_provider in provider_options]):
if not all(isinstance(options_for_provider, dict) for options_for_provider in provider_options):
raise ValueError("'provider_options' values must be dicts.")

for name, options in zip(providers, provider_options, strict=False):
Expand All @@ -150,7 +150,7 @@ def set_provider_options(name, options):
else:
for provider in providers:
if isinstance(provider, str):
set_provider_options(provider, dict())
set_provider_options(provider, {})
elif (
isinstance(provider, tuple)
and len(provider) == 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def set_dispatch(name):
from difflib import SequenceMatcher as Matcher

valid_names = list(_ke_context.dispatchable.keys())
scored_names = list(reversed(sorted([(Matcher(None, name, a).ratio(), a) for a in valid_names])))
scored_names = sorted([(Matcher(None, name, a).ratio(), a) for a in valid_names], reverse=True)
top10 = "\n ".join([a for _, a in scored_names[:10]])
msg = f"'{name}' is not registered for dispatch. Top 10 matches are:\n {top10}"
print(msg)
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/python/tools/profile_explorer/profile_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _print_op_kernel_mapping_info(cpu_df, gpu_df, num_runs, csv=None):
# Count op occurrences in the selected runs
op_counts = defaultdict(int)
for op in cpu_df.T.to_dict().values():
identifiers = tuple([op["name"], op["input_type_shape"]])
identifiers = (op["name"], op["input_type_shape"])
op_counts[identifiers] += 1

# Collect kernel stats: count/duration
Expand All @@ -212,15 +212,15 @@ def _print_op_kernel_mapping_info(cpu_df, gpu_df, num_runs, csv=None):
input_type_shape = kernel["input_type_shape"]
kernel_name = kernel["name"]
dimensions = kernel["dimensions"]
identifiers = tuple([op_name, input_type_shape, kernel_name, dimensions])
identifiers = (op_name, input_type_shape, kernel_name, dimensions)
stat_dict[identifiers]["count"] += 1
stat_dict[identifiers]["duration"] += kernel["duration"]

# Create the DataFrame for kernel entries with op correlation info
kernel_list = []
for identifiers, stat in stat_dict.items():
op_name, input_type_shape, kernel_name, dimensions = identifiers
op_count = op_counts.get(tuple([op_name, input_type_shape]))
op_count = op_counts.get((op_name, input_type_shape))
if op_count is None:
continue
kernel_list.append(
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/quantization/base_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def __init__(
'Conv_4:0': [np.float32(1), np.float32(3.5)]
}
"""
if tensors_range is not None and any(map(lambda t: not isinstance(t, TensorData), tensors_range.values())):
if tensors_range is not None and any(not isinstance(t, TensorData) for t in tensors_range.values()):
raise TypeError(
f"tensors_range contains unexpected types {set(type(v) for v in tensors_range.values())}, not TensorData."
f"tensors_range contains unexpected types { {type(v) for v in tensors_range.values()} }, not TensorData."
)
self.tensors_range = tensors_range
self.nodes_to_quantize = nodes_to_quantize # specific nodes to quantize
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/python/tools/quantization/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ def compute_data(self) -> TensorsData:

if self.symmetric:
max_absolute_value = np.max([np.abs(min_value_array), np.abs(max_value_array)], axis=0)
pairs.append(tuple([-max_absolute_value, max_absolute_value]))
pairs.append((-max_absolute_value, max_absolute_value))
else:
pairs.append(tuple([min_value_array, max_value_array]))
pairs.append((min_value_array, max_value_array))

new_calibrate_tensors_range = TensorsData(
CalibrationMethod.MinMax, dict(zip(calibrate_tensor_names, pairs, strict=False))
Expand Down Expand Up @@ -823,7 +823,7 @@ def collect_absolute_value(self, name_to_arr):
if isinstance(data_arr, list):
for arr in data_arr:
assert isinstance(arr, np.ndarray), f"Unexpected type {type(arr)} for tensor={tensor!r}"
dtypes = set(a.dtype for a in data_arr)
dtypes = {a.dtype for a in data_arr}
assert len(dtypes) == 1, (
f"The calibration expects only one element type but got {dtypes} for tensor={tensor!r}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def apply(
# Use type requests to "fix" tensor quantization overrides by adding
# quantization type conversions where necessary.
for tensor_name, type_req in type_requests.items():
all_consumers = set([node.name for node in self.consumers.get(tensor_name, [])])
all_consumers = {node.name for node in self.consumers.get(tensor_name, [])}
has_producer_req = type_req.producer is not None
has_consumer_req = bool(type_req.consumers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def _generate_q4_node_config(self):
}
for node in self.model.model.graph.node:
if node.op_type in ["MatMul"]:
if not all([self.model.get_initializer(i) is None for i in node.input]):
if not all(self.model.get_initializer(i) is None for i in node.input):
q4_node_config[node.name] = template_config_q4
return q4_node_config

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/quantization/onnx_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _check_init(self, init, test=None):
if init.data_type == onnx.TensorProto.FLOAT8E4M3FN:
if init.HasField("raw_data"):
b = list(init.raw_data)
if any(map(lambda i: (i & 127) == 127, b)):
if any((i & 127) == 127 for i in b):
raise ValueError(f"Initializer {init.name!r} has nan.")
return init

Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/quantization/qdq_loss_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def create_weight_matching(float_model_path: str, qdq_model_path: str) -> dict[s
# Perform dequantization:
if weight_scale.size == weight_zp.size == 1:
# Avoids the confusion between a scaler and a tensor of one element.
weight_scale = weight_scale.reshape(tuple())
weight_zp = weight_zp.reshape(tuple())
weight_scale = weight_scale.reshape(())
weight_zp = weight_zp.reshape(())
if weight_scale.shape != weight_zp.shape:
raise RuntimeError(
f"scale and zero_point must have the same shape but {weight_scale.shape} != {weight_zp.shape}"
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/quantization/qdq_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def _add_qdq_ops_for_converted_activation(

<Producer> ---> Q1 ---> DQ1 ---> Q2 ---> DQ2 ---> <Graph output>
"""
tensor_recv_nodes = set([node.name for node in self.tensor_to_its_receiving_nodes.get(tensor_name, [])])
tensor_recv_nodes = {node.name for node in self.tensor_to_its_receiving_nodes.get(tensor_name, [])}

if (
self.dedicated_qdq_pair
Expand Down
34 changes: 17 additions & 17 deletions onnxruntime/python/tools/symbolic_shape_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,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) is str and s in self.symbolic_dims_) or is_literal(s) for s in symbols])
assert all((type(s) is str and s in self.symbolic_dims_) or is_literal(s) for s in symbols)
symbols = set(symbols)
for k, v in self.suggested_merge_.items():
if k in symbols:
Expand Down Expand Up @@ -328,7 +328,7 @@ def _preprocess(self, in_mp):
)

def _merge_symbols(self, dims):
if not all([type(d) is str for d in dims]):
if not all(type(d) is str for d in dims):
if self.auto_merge_:
unique_dims = list(set(dims))
is_int = [is_literal(d) for d in unique_dims]
Expand All @@ -347,10 +347,10 @@ def _merge_symbols(self, dims):
return dims[0]
else:
return None
if all([d == dims[0] for d in dims]):
if all(d == dims[0] for d in dims):
return dims[0]
merged = [self.suggested_merge_.get(d, d) for d in dims]
if all([d == merged[0] for d in merged]):
if all(d == merged[0] for d in merged):
assert merged[0] in self.symbolic_dims_
return merged[0]
else:
Expand Down Expand Up @@ -607,7 +607,7 @@ def int_or_float(value, allow_float_values):
return int(value)

values = [self._try_get_value(node, i) for i in range(len(node.input))]
if all([v is not None for v in values]):
if all(v is not None for v in values):
# some shape compute is in floating point, cast to int for sympy
for i, v in enumerate(values):
if type(v) is not np.ndarray:
Expand Down Expand Up @@ -647,7 +647,7 @@ def _compute_on_sympy_data(self, node, op_func):
else:
values = self._get_int_or_float_values(node, broadcast=True)

if all([v is not None for v in values]):
if all(v is not None for v in values):
is_list = [isinstance(v, list) for v in values]
as_list = any(is_list)
if as_list:
Expand Down Expand Up @@ -763,7 +763,7 @@ def _compute_conv_pool_shape(self, node, channels_last=False):
def _check_merged_dims(self, dims, allow_broadcast=True):
if allow_broadcast:
dims = [d for d in dims if not (is_literal(d) and int(d) <= 1)]
if not all([d == dims[0] for d in dims]):
if not all(d == dims[0] for d in dims):
self._add_suggested_merge(dims, apply=True)

def _compute_matmul_shape(self, node, output_dtype=None):
Expand Down Expand Up @@ -897,9 +897,9 @@ def _infer_Compress(self, node): # noqa: N802
)

def _infer_Concat(self, node): # noqa: N802
if any([i in self.sympy_data_ or i in self.initializers_ for i in node.input]):
if any(i in self.sympy_data_ or i in self.initializers_ for i in node.input):
values = self._get_int_or_float_values(node)
if all([v is not None for v in values]):
if all(v is not None for v in values):
assert get_attribute(node, "axis") == 0
self.sympy_data_[node.output[0]] = []
for i in range(len(node.input)):
Expand All @@ -921,7 +921,7 @@ def _infer_Concat(self, node): # noqa: N802
if d == axis:
continue
dims = [self._get_shape(node, i_idx)[d] for i_idx in range(len(node.input)) if self._get_shape(node, i_idx)]
if all([d == dims[0] for d in dims]):
if all(d == dims[0] for d in dims):
continue
merged = self._merge_symbols(dims)
if type(merged) is str:
Expand Down Expand Up @@ -968,7 +968,7 @@ def _infer_ConstantOfShape(self, node): # noqa: N802
sympy_shape = [sympy_shape]
self._update_computed_dims(sympy_shape)
# update sympy data if output type is int, and shape is known
if vi.type.tensor_type.elem_type == onnx.TensorProto.INT64 and all([is_literal(x) for x in sympy_shape]):
if vi.type.tensor_type.elem_type == onnx.TensorProto.INT64 and all(is_literal(x) for x in sympy_shape):
self.sympy_data_[node.output[0]] = np.ones(
[int(x) for x in sympy_shape], dtype=np.int64
) * numpy_helper.to_array(get_attribute(node, "value", 0))
Expand Down Expand Up @@ -1552,7 +1552,7 @@ def _infer_BatchNormalization(self, node): # noqa: N802
def _infer_Range(self, node): # noqa: N802
vi = self.known_vi_[node.output[0]]
input_data = self._get_int_or_float_values(node)
if all([i is not None for i in input_data]):
if all(i is not None for i in input_data):
start = as_scalar(input_data[0])
limit = as_scalar(input_data[1])
delta = as_scalar(input_data[2])
Expand Down Expand Up @@ -2670,25 +2670,25 @@ def get_prereq(node):
# topological sort nodes, note there might be dead nodes so we check if all graph outputs are reached to terminate
sorted_nodes = []
sorted_known_vi = {i.name for i in list(self.out_mp_.graph.input) + list(self.out_mp_.graph.initializer)}
if any([o.name in sorted_known_vi for o in self.out_mp_.graph.output]):
if any(o.name in sorted_known_vi for o in self.out_mp_.graph.output):
# Loop/Scan will have some graph output in graph inputs, so don't do topological sort
sorted_nodes = self.out_mp_.graph.node
else:
while not all([o.name in sorted_known_vi for o in self.out_mp_.graph.output]):
while not all(o.name in sorted_known_vi for o in self.out_mp_.graph.output):
old_sorted_nodes_len = len(sorted_nodes)
for node in self.out_mp_.graph.node:
if (node.output[0] not in sorted_known_vi) and all(
[i in sorted_known_vi for i in prereq_for_node[node.output[0]] if i]
i in sorted_known_vi for i in prereq_for_node[node.output[0]] if i
):
sorted_known_vi.update(node.output)
sorted_nodes.append(node)
if old_sorted_nodes_len == len(sorted_nodes) and not all(
[o.name in sorted_known_vi for o in self.out_mp_.graph.output]
o.name in sorted_known_vi for o in self.out_mp_.graph.output
):
raise Exception("Invalid model with cyclic graph")

for node in sorted_nodes:
assert all([i in self.known_vi_ for i in node.input if i])
assert all(i in self.known_vi_ for i in node.input if i)
self._onnx_infer_single_node(node)
known_aten_op = False
if node.op_type in self.dispatcher_:
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/python/tools/tensorrt/perf/perf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ def parse_single_file(f):
print("------First run ops map (START)------")
for key, map in provider_op_map_first_run.items():
print(key)
pp.pprint({k: v for k, v in sorted(map.items(), key=lambda item: item[1], reverse=True)})
pp.pprint(dict(sorted(map.items(), key=lambda item: item[1], reverse=True)))

print("------First run ops map (END) ------")
print("------Second run ops map (START)------")
for key, map in provider_op_map.items():
print(key)
pp.pprint({k: v for k, v in sorted(map.items(), key=lambda item: item[1], reverse=True)})
pp.pprint(dict(sorted(map.items(), key=lambda item: item[1], reverse=True)))
print("------Second run ops map (END) ------")

if model_run_flag:
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/transformers/bert_perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def main():
Path(args.model).parent,
"perf_results_{}_B{}_S{}_{}.txt".format(
"GPU" if args.use_gpu else "CPU",
"-".join([str(x) for x in sorted(list(batch_size_set))]),
"-".join([str(x) for x in sorted(batch_size_set)]),
args.sequence_length,
datetime.now().strftime("%Y%m%d-%H%M%S"),
),
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/transformers/fusion_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def create_multihead_attention_node(
logger.debug("input hidden size %d is not a multiple of num of heads %d", hidden_size, num_heads)
return None

graph_input_names = set([node.name for node in self.model.graph().input])
graph_input_names = {node.name for node in self.model.graph().input}
mha_node_name = self.model.create_node_name("Attention")

# Add initial Q/K/V inputs for MHA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def fuse(self, normalize_node, input_name_to_nodes, output_name_to_node):
root_input = output
break

graph_input_names = set([node.name for node in self.model.graph().input])
graph_output_names = set([node.name for node in self.model.graph().output])
graph_input_names = {node.name for node in self.model.graph().input}
graph_output_names = {node.name for node in self.model.graph().output}

v_nodes = self.model.match_parent_path(
matmul_qkv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def run_tuning_step0(task, fp16_baseline, all_ops, optimized_ops):

# Only weights in FP16
task.run(
fp16_baseline + fp32_io + ["--op_block_list"] + [o for o in all_ops] + ["--force_fp16_initializers"],
fp16_baseline + fp32_io + ["--op_block_list"] + list(all_ops) + ["--force_fp16_initializers"],
"FP32 except weights in FP16",
)

Expand Down
Loading