Zhijxu/improve ortmodule python perf a little bit (#13716)

improve 2 python functions a little bit.

according to a profiling result from a real user case, we find that 2
python function can be improved. the first is the result before
improvement, the second is after improvement, we can see 8ms saved from
the improvement.

![image](https://user-images.githubusercontent.com/43435212/202961725-b88d679e-993b-4910-a339-253f3ed5dcde.png)

![image](https://user-images.githubusercontent.com/43435212/202961732-6c6deebf-962f-4392-90d7-03705433e3ee.png)
This commit is contained in:
zhijiang 2023-11-07 15:24:57 +08:00 committed by GitHub
parent 00c2bf39bd
commit 630c877b43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -206,7 +206,7 @@ def _combine_input_buffers_initializers(
_expand_inputs(inputs, non_none_inputs)
flattened_kwargs_inputs = {}
_expand_inputs(kwargs, flattened_kwargs_inputs)
buffer_names_dict = {buffer_name: inp for buffer_name, inp in named_buffer}
buffer_names_dict = None
result = []
embed_sparsity_results = OrderedDict()
label_sparsity_results = OrderedDict()
@ -232,6 +232,8 @@ def _combine_input_buffers_initializers(
if inp is None:
# Registered buffers are translated to user_input+initializer in ONNX
if buffer_names_dict is None:
buffer_names_dict = {buffer_name: i for buffer_name, i in named_buffer}
try: # noqa: SIM105
inp = buffer_names_dict[name]
except KeyError: