Skip to content

Commit

Permalink
Format all python files under onnxruntime with black and isort (micro…
Browse files Browse the repository at this point in the history
…soft#11324)

Description: Format all python files under onnxruntime with black and isort.

After checking in, we can use .git-blame-ignore-revs to ignore the formatting PR in git blame.

microsoft#11315, microsoft#11316
  • Loading branch information
justinchuby authored Apr 26, 2022
1 parent 13f86e7 commit fdce4fa
Show file tree
Hide file tree
Showing 526 changed files with 54,748 additions and 36,690 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ exclude =
./orttraining,
# ignore server code for now
./server,
ignore = W503, E203
41 changes: 25 additions & 16 deletions cgmanifests/generate_cgmanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

registrations = []

with open(os.path.join(REPO_DIR, 'tools', 'ci_build', 'github', 'linux', 'docker', 'Dockerfile.manylinux2014_cuda11'),
mode="r") as f:
with open(
os.path.join(REPO_DIR, "tools", "ci_build", "github", "linux", "docker", "Dockerfile.manylinux2014_cuda11"),
mode="r",
) as f:
for line in f:
if not line.strip():
package_name = None
Expand All @@ -36,15 +38,12 @@
m = re.match(r"(.+?)_DOWNLOAD_URL=(\S+)", line)
if m is not None:
package_url = m.group(2)
if package_name == 'LIBXCRYPT':
package_url = m.group(2) + "/v" + \
package_filename + ".tar.gz"
elif package_name == 'CMAKE':
package_url = m.group(
2) + "/v" + package_filename + "/cmake-" + package_filename + ".tar.gz"
if package_name == "LIBXCRYPT":
package_url = m.group(2) + "/v" + package_filename + ".tar.gz"
elif package_name == "CMAKE":
package_url = m.group(2) + "/v" + package_filename + "/cmake-" + package_filename + ".tar.gz"
else:
package_url = m.group(2) + "/" + \
package_filename + ".tar.gz"
package_url = m.group(2) + "/" + package_filename + ".tar.gz"
registration = {
"Component": {
"Type": "other",
Expand All @@ -53,7 +52,7 @@
"Version": package_filename.split("-")[-1],
"DownloadUrl": package_url,
},
"comments": "manylinux dependency"
"comments": "manylinux dependency",
}
}
registrations.append(registration)
Expand All @@ -67,14 +66,23 @@ def normalize_path_separators(path):


proc = subprocess.run(
["git", "submodule", "foreach", "--quiet", "--recursive", "{} {} $toplevel/$sm_path".format(
normalize_path_separators(sys.executable),
normalize_path_separators(os.path.join(SCRIPT_DIR, "print_submodule_info.py")))],
[
"git",
"submodule",
"foreach",
"--quiet",
"--recursive",
"{} {} $toplevel/$sm_path".format(
normalize_path_separators(sys.executable),
normalize_path_separators(os.path.join(SCRIPT_DIR, "print_submodule_info.py")),
),
],
check=True,
cwd=REPO_DIR,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
universal_newlines=True,
)


submodule_lines = proc.stdout.splitlines()
Expand All @@ -88,7 +96,8 @@ def normalize_path_separators(path):
"repositoryUrl": url,
},
"comments": "git submodule at {}".format(
normalize_path_separators(os.path.relpath(absolute_path, REPO_DIR)))
normalize_path_separators(os.path.relpath(absolute_path, REPO_DIR))
),
}
}
registrations.append(registration)
Expand Down
20 changes: 10 additions & 10 deletions cgmanifests/print_submodule_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

path = sys.argv[1]

proc = subprocess.run(["git", "config", "--get", "remote.origin.url"],
check=True,
cwd=path,
stdout=subprocess.PIPE,
universal_newlines=True)
proc = subprocess.run(
["git", "config", "--get", "remote.origin.url"],
check=True,
cwd=path,
stdout=subprocess.PIPE,
universal_newlines=True,
)

url = proc.stdout.strip()

proc = subprocess.run(["git", "rev-parse", "HEAD"],
check=True,
cwd=path,
stdout=subprocess.PIPE,
universal_newlines=True)
proc = subprocess.run(
["git", "rev-parse", "HEAD"], check=True, cwd=path, stdout=subprocess.PIPE, universal_newlines=True
)

commit = proc.stdout.strip()

Expand Down
21 changes: 7 additions & 14 deletions csharp/testdata/test_input_BFLOAT16.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@
# Licensed under the MIT License.

import onnx
from onnx import helper
from onnx import TensorProto, helper
from onnx.helper import make_opsetid
from onnx import TensorProto

input_info = helper.make_tensor_value_info('input', TensorProto.BFLOAT16, [1, 5])
output_info = helper.make_tensor_value_info('output', TensorProto.BFLOAT16, [1, 5])
input_info = helper.make_tensor_value_info("input", TensorProto.BFLOAT16, [1, 5])
output_info = helper.make_tensor_value_info("output", TensorProto.BFLOAT16, [1, 5])

# Create a node (NodeProto) - This is based on Pad-11
node_def = helper.make_node(
'Identity', # node name
['input'], # inputs
['output'] # outputs
)
node_def = helper.make_node("Identity", ["input"], ["output"]) # node name # inputs # outputs

graph_def = helper.make_graph(nodes=[node_def], name='test_types_BLOAT16',
inputs=[input_info], outputs=[output_info])
graph_def = helper.make_graph(nodes=[node_def], name="test_types_BLOAT16", inputs=[input_info], outputs=[output_info])

model_def = helper.make_model(graph_def, producer_name='AIInfra',
opset_imports=[make_opsetid('', 13)])
model_def = helper.make_model(graph_def, producer_name="AIInfra", opset_imports=[make_opsetid("", 13)])

onnx.checker.check_model(model_def)
onnx.helper.strip_doc_string(model_def)
final_model = onnx.shape_inference.infer_shapes(model_def)
onnx.checker.check_model(final_model)
onnx.save(final_model, 'test_types_BFLOAT16.onnx')
onnx.save(final_model, "test_types_BFLOAT16.onnx")
23 changes: 10 additions & 13 deletions csharp/testdata/test_input_FLOAT16.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@
# Licensed under the MIT License.

import onnx
from onnx import helper
from onnx import TensorProto, helper
from onnx.helper import make_opsetid
from onnx import TensorProto

input_info = helper.make_tensor_value_info('input', TensorProto.FLOAT16, [1, 5])
output_info = helper.make_tensor_value_info('output', TensorProto.FLOAT16, [1, 5])
input_info = helper.make_tensor_value_info("input", TensorProto.FLOAT16, [1, 5])
output_info = helper.make_tensor_value_info("output", TensorProto.FLOAT16, [1, 5])

# Create a node (NodeProto) - This is based on Pad-11
node_def = helper.make_node(
'Slice', # node name
['input'], # inputs
['output'], # outputs
"Slice", # node name
["input"], # inputs
["output"], # outputs
axes=[0, 1], # attributes
ends=[1, 5],
starts=[0, 0]
starts=[0, 0],
)

graph_def = helper.make_graph(nodes=[node_def], name='test_input_FLOAT16',
inputs=[input_info], outputs=[output_info])
graph_def = helper.make_graph(nodes=[node_def], name="test_input_FLOAT16", inputs=[input_info], outputs=[output_info])

model_def = helper.make_model(graph_def, producer_name='AIInfra',
opset_imports=[make_opsetid('', 7)])
model_def = helper.make_model(graph_def, producer_name="AIInfra", opset_imports=[make_opsetid("", 7)])

onnx.checker.check_model(model_def)
onnx.helper.strip_doc_string(model_def)
final_model = onnx.shape_inference.infer_shapes(model_def)
onnx.checker.check_model(final_model)
onnx.save(final_model, 'test_types_FLOAT16.onnx')
onnx.save(final_model, "test_types_FLOAT16.onnx")
50 changes: 27 additions & 23 deletions docs/python/inference/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,91 @@
# Configuration file for the Sphinx documentation builder.

import os
import sys
import shutil
import sys

import onnxruntime

# import recommonmark

# -- Project information -----------------------------------------------------

project = 'ONNX Runtime'
copyright = '2018-2021, Microsoft'
author = 'Microsoft'
project = "ONNX Runtime"
copyright = "2018-2021, Microsoft"
author = "Microsoft"
version = onnxruntime.__version__
release = version

# -- General configuration ---------------------------------------------------

extensions = [
"alabaster",
'sphinx.ext.intersphinx',
'sphinx.ext.imgmath',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
"sphinx.ext.intersphinx",
"sphinx.ext.imgmath",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.autodoc",
'sphinx.ext.githubpages',
"sphinx.ext.githubpages",
"sphinx_gallery.gen_gallery",
'sphinx.ext.graphviz',
"sphinx.ext.graphviz",
"pyquickhelper.sphinxext.sphinx_runpython_extension",
]

templates_path = ['_templates']
templates_path = ["_templates"]

source_parsers = {
'.md': 'recommonmark.parser.CommonMarkParser',
".md": "recommonmark.parser.CommonMarkParser",
}

source_suffix = ['.rst'] # , '.md']
source_suffix = [".rst"] # , '.md']

master_doc = 'index'
master_doc = "index"
language = "en"
exclude_patterns = []
pygments_style = 'default'
autoclass_content = 'both'
pygments_style = "default"
autoclass_content = "both"

# -- Options for HTML output -------------------------------------------------

html_theme = "alabaster"
html_logo = "ONNX_Runtime_icon.png"
html_static_path = ['_static']
html_static_path = ["_static"]
graphviz_output_format = "svg"

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}

# -- Options for Sphinx Gallery ----------------------------------------------

sphinx_gallery_conf = {
'examples_dirs': 'examples',
'gallery_dirs': 'auto_examples',
"examples_dirs": "examples",
"gallery_dirs": "auto_examples",
}

# -- markdown options -----------------------------------------------------------

md_image_dest = "media"
md_link_replace = {
'#onnxruntimesessionoptionsenable-profiling)': '#class-onnxruntimesessionoptions)',
"#onnxruntimesessionoptionsenable-profiling)": "#class-onnxruntimesessionoptions)",
}

# -- Setup actions -----------------------------------------------------------


def setup(app):
# download examples for the documentation
this = os.path.abspath(os.path.dirname(__file__))
dest = os.path.join(this, "model.onnx")
if not os.path.exists(dest):
import urllib.request
url = 'https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_sigmoid/model.onnx'

url = "https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_sigmoid/model.onnx"
urllib.request.urlretrieve(url, dest)
loc = os.path.split(dest)[-1]
if not os.path.exists(loc):
import shutil

shutil.copy(dest, loc)
return app

9 changes: 5 additions & 4 deletions docs/python/inference/examples/plot_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
of a simple logistic regression model.
"""
import numpy as np
from onnxruntime import datasets
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument
import onnxruntime.backend as backend
from onnx import load

import onnxruntime.backend as backend

########################################
# The device depends on how the package was compiled,
# GPU or CPU.
from onnxruntime import get_device
from onnxruntime import datasets, get_device
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument

device = get_device()

name = datasets.get_example("logreg_iris.onnx")
Expand Down
Loading

0 comments on commit fdce4fa

Please sign in to comment.