repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
onnxruntime
tools/python/util/convert_onnx_models_to_ort.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import contextlib import enum import os import pathlib import tempfile import onnxruntime as ort from .file_utils import files_from_file_or_dir, pat...
381
16,559
onnxruntime
tools/python/util/get_azcopy.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import contextlib import logging import os import platform import re import shutil import stat import subprocess import tempfile import urllib.parse import urllib.request AZCOPY_VERSION = "...
82
2,862
onnxruntime
tools/python/util/make_dynamic_shape_fixed.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import os import pathlib import sys import onnx from .onnx_model_utils import fix_output_shapes, make_dim_param_fixed, make_input_shape_fixed def m...
74
2,569
onnxruntime
tools/python/util/optimize_onnx_model.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import os import pathlib from .onnx_model_utils import get_optimization_level, optimize_model def optimize_model_helper(): parser = argparse.Arg...
57
1,959
onnxruntime
tools/python/util/onnx_model_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import logging import pathlib import onnx from onnx import version_converter import onnxruntime as ort def iterate_graph_per_node_func(graph, per_node_func, **func_args): """ Ite...
417
16,402
onnxruntime
tools/python/util/vcpkg_helpers.py
.py
import os from pathlib import Path # Compile-time options that shrink the sqlite3 build used by 1DS as its offline-event store. # The SDK uses a single event table with parameter-bound INSERT/SELECT/DELETE, a small set of # PRAGMAs, and VACUUM. It does not use the omitted APIs or features. _SQLITE_TELEMETRY_MINIMAL_DE...
882
41,866
onnxruntime
tools/python/util/check_onnx_model_mobile_usability.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import logging import pathlib # need this before the mobile helper imports for some reason logging.basicConfig(format="%(levelname)s: %(message)s") from .mobile_helpers import usability_checker # noqa: E40...
48
1,670
onnxruntime
tools/python/util/qdq_helpers/optimize_qdq_model.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import pathlib import onnx def optimize_qdq_model(): parser = argparse.ArgumentParser( os.path.basename(__file__), description="Update a QDQ format ONNX ...
38
1,242
onnxruntime
tools/python/util/android/__init__.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from .android import ( # noqa: F401 SdkToolPaths, create_virtual_device, get_sdk_tool_paths, start_emulator, stop_emulator, )
11
242
onnxruntime
tools/python/util/android/android.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import collections import contextlib import datetime import os import signal import subprocess import time import typing from pathlib import Path from ..logger import get_logger from ..plat...
360
13,444
onnxruntime
tools/python/util/test/test_pytorch_export_helpers.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import unittest import torch from ..pytorch_export_helpers import infer_input_info # example usage from <ort root>/tools/python # python -m unittest util/test/test_pytorch_export_helpers.py # NOTE: at least on Windows you ...
43
1,520
onnxruntime
tools/python/util/test/test_onnx_model_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import pathlib import unittest import onnx from onnx import TensorProto, helper, shape_inference from ..mobile_helpers.usability_checker import check_shapes from ..onnx_model_utils import ( fix_output_shapes, get_pr...
266
11,759
onnxruntime
tools/python/util/ort_format_model/types.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import ort_flatbuffers_py.fbs as fbs class FbsTypeInfo: "Class to provide conversion between ORT flatbuffers schema values and C++ types" tensordatatype_to_string = { # noqa: RUF012 fbs.TensorDataType.Tens...
86
4,383
onnxruntime
tools/python/util/ort_format_model/utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import pathlib import typing from ..logger import get_logger from .operator_type_usage_processors import OperatorTypeUsageManager from .ort_model_processor import OrtFormatModelProcessor log = get_logger("ort_format_model.u...
62
2,534
onnxruntime
tools/python/util/ort_format_model/__init__.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import os import sys # need to add the path to the ORT flatbuffers python module before we import anything else here. # we also auto-magically adjust to whether we're running from the ORT repo, or from within the ORT python ...
28
1,280
onnxruntime
tools/python/util/ort_format_model/operator_type_usage_processors.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import json from abc import ABC, abstractmethod import ort_flatbuffers_py.fbs as fbs from .types import FbsTypeInfo, value_name_to_typestr def _create_op_key(domain: str, optype: str): ...
654
26,379
onnxruntime
tools/python/util/ort_format_model/ort_model_processor.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import ort_flatbuffers_py.fbs as fbs from .operator_type_usage_processors import OperatorTypeUsageManager class OrtFormatModelProcessor: "Class to process an ORT format model and determine required operators and types....
87
4,386
onnxruntime
tools/python/util/mobile_helpers/usability_checker.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import logging import os import pathlib import tempfile from collections import deque from enum import IntEnum import onnx from ..onnx_model_utils import ModelProtoWithShap...
739
31,640
onnxruntime
tools/python/util/mobile_helpers/test/test_usability_checker.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import logging import pathlib import unittest from testfixtures import LogCapture from ..usability_checker import analyze_model # example usage from <ort root>/tools/python # python -m un...
148
6,435
onnxruntime
tools/nuget/generate_nuspec_for_custom_nuget.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import glob import os import re import shutil from generate_nuspec_for_native_nuget import generate_metadata def generate_files(lines, args): files_list = ["<files>"] platform_map = { "win-a...
172
6,077
onnxruntime
tools/nuget/validate_package.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import glob import os import re import shutil import subprocess import sys import zipfile # Available Python 3.2 or higher linux_gpu_package_libraries = [ "libonnxruntime_providers_shared.so", "libon...
407
14,704
onnxruntime
tools/nuget/generate_nuspec_for_native_nuget.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import re import shutil import sys from pathlib import Path # These platform version values are the default target platform versions for .NET 9 from the table here: # https://learn.microsoft.com/en-...
1,261
52,190
onnxruntime
tools/android_custom_build/build_custom_android_package.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import pathlib import shlex import shutil import subprocess import sys SCRIPT_DIR = pathlib.Path(__file__).parent.resolve() def is_windows(): return sys.platform.startsw...
182
6,376
onnxruntime
tools/doc/rename_folders.py
.py
""" Github publishes the markdown documentation with jekyll enabled. This extension does not publish any folder starting with `_`. These folders need to be renamed. """ import os import re def rename_folder(root): """ Renames all folder starting with `_`. Returns the list of renamed folders. """ ...
86
2,681
onnxruntime
tools/perftest/benchmark_spin_settings.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """Benchmark thread-pool spin settings for ONNX Runtime. This script wraps ``onnxruntime_perf_test`` and runs the same model under several combinations of the spin configuration introduced by PR 27916 (...
399
13,780
onnxruntime
tools/ci_build/run_gh_action.py
.py
import os import platform import shutil import sys import tempfile import zipfile from pathlib import Path import requests SCRIPT_DIR = Path(__file__).resolve().parent REPO_DIR = (SCRIPT_DIR / ".." / "..").resolve() sys.path.insert(0, str(REPO_DIR / "tools" / "python")) from util import run # noqa: E402 # Hash st...
163
6,146
onnxruntime
tools/ci_build/logger.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import logging def get_logger(name): logging.basicConfig(format="%(asctime)s %(name)s [%(levelname)s] - %(message)s", level=logging.DEBUG) return logging.getLogger(name)
11
276
onnxruntime
tools/ci_build/linux_java_copy_strip_binary.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ Prepares native shared libraries for the ONNX Runtime Java package. This script is a build utility that run as part of a packaging pipeline and takes compiled C/C++ shared libraries (.so, .dylib) a...
198
8,406
onnxruntime
tools/ci_build/manage_java_artifacts.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # This script runs after ORT jars are built. It picks up the jars from ORT's build dir then repack them a bit. import argparse import logging import re import shutil import subprocess import sys import zipfile from pathlib i...
313
13,469
onnxruntime
tools/ci_build/test_compile_triton.py
.py
import importlib.util import subprocess import sys import tempfile import types import unittest import unittest.mock from pathlib import Path MODULE_PATH = Path(__file__).with_name("compile_triton.py") def load_compile_triton_module(): fake_triton = types.SimpleNamespace() with unittest.mock.patch.dict(sys.m...
112
4,347
onnxruntime
tools/ci_build/set_plugin_ep_build_variables.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """Set plugin EP package version variables for Azure Pipelines. Usage: python set_plugin_ep_build_variables.py <package_version> <version_file_rel> Where: package_version: 'release', 'rc', or ...
111
4,102
onnxruntime
tools/ci_build/coverage.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # # This script generates test code coverage for Android. # The prerequistes: # 1. The Onnxruntime build with coverage option to compile/link the source files using --coverage optoin # 2. The tes...
65
2,315
onnxruntime
tools/ci_build/compile_triton.py
.py
# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # -------------------------------------------------------------------------- import argparse import importlib.util import os import shutil import sub...
180
5,882
onnxruntime
tools/ci_build/update_tsaoptions.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import json import os from pathlib import Path SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__))) REPO_DIR = SCRIPT_DIR.parent.parent with (REPO_DIR / ".config" / "tsaoptions.j...
21
582
onnxruntime
tools/ci_build/upload_python_package_to_azure_storage.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import logging import os import subprocess import warnings log = logging.getLogger("Build") def parse_nightly_and_local_version_from_whl_name(blob_n...
91
2,915
onnxruntime
tools/ci_build/reduce_op_kernels.py
.py
# !/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import io import re import shutil import sys import typing from pathlib import Path import op_registration_utils from logger import get_logger # dir...
356
14,384
onnxruntime
tools/ci_build/gen_def.py
.py
#!/usr/bin/python3 import argparse import os import sys def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument("--src_root", required=True, help="input symbol file") parser.add_argument("--output", required=True, help="output file") parser.add_argument("--output_source", require...
114
3,903
onnxruntime
tools/ci_build/build_args.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License.import argparse import argparse import os import platform import shlex import sys import warnings from util import ( is_linux, is_macOS, is_windows, ) def _str_to_bool(s: str) -> bool: """Convert string to bo...
1,097
47,584
onnxruntime
tools/ci_build/prepare_macos_package.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import pathlib import shutil import stat as stat_module import subprocess import sys import tarfile from datetime import datetime def run_command(command: list[str | pathlib.Path], check: bool = Tr...
186
7,263
onnxruntime
tools/ci_build/set-trigger-rules.py
.py
# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # -------------------------------------------------------------------------- # This script is used to add trigger rules to the workflow files. from ...
84
2,843
onnxruntime
tools/ci_build/cuda_plugin_parity_report.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ CUDA EP Plugin Registration Parity Report Compares kernel registrations between the bundled CUDA EP and the plugin CUDA EP by statically parsing source files or interrogating the kernel registry at...
738
29,155
onnxruntime
tools/ci_build/op_registration_validator.py
.py
# !/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ Validate ORT kernel registrations. """ from __future__ import annotations import argparse import dataclasses import itertools import os import sys import typing import op_registration_utils from ...
224
8,860
onnxruntime
tools/ci_build/op_registration_utils.py
.py
# !/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ Utilities to help process files containing kernel registrations. """ from __future__ import annotations import os import pathlib import sys from logger import get_logger log = get_logger("op_reg...
268
11,017
onnxruntime
tools/ci_build/test_build_args.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import sys import unittest from pathlib import Path from unittest import mock sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "python")) sys.path.insert(0, str(Path(__file__).resolve().par...
60
2,521
onnxruntime
tools/ci_build/get_docker_image.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import shlex import shutil import sys from pathlib import Path from logger import get_logger SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_DIR = os.path.normp...
148
5,009
onnxruntime
tools/ci_build/patch_manylinux.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import os import shutil import sys from pathlib import Path from logger import get_logger SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) RE...
66
2,213
onnxruntime
tools/ci_build/build.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> # Licensed under the MIT License. from __future__ import annotations import contextlib import json import os import platform import ...
2,728
121,481
onnxruntime
tools/ci_build/github/js/validate-npm-packages.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import os import sys # This is a script to validate NPM packages. # If package version, publish tag and filename does not fulfill the requirement, an error will raise. # arg.1 - Folder of extracted ar...
186
8,828
onnxruntime
tools/ci_build/github/android/build_aar_package.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import json import os import pathlib import shutil import subprocess import sys SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_DIR = os.path.normpath(os.path.join(SCRIPT_...
270
11,176
onnxruntime
tools/ci_build/github/apple/test_apple_packages.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import contextlib import json import os import pathlib import shutil import subprocess import sys import tempfile from c.assemble_c_pod_package import assemble_c_pod_package from packag...
275
10,461
onnxruntime
tools/ci_build/github/apple/get_simulator_device_info.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import functools import itertools import json import os import subprocess @functools.total_ordering class Version: # noqa: PLW1641 """ A si...
166
6,360
onnxruntime
tools/ci_build/github/apple/build_and_assemble_apple_pods.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import logging import os import pathlib import shlex import shutil import subprocess import sys import tempfile from c.assemble_c_pod_package import assemble_c_pod_package from package...
184
6,213
onnxruntime
tools/ci_build/github/apple/package_assembly_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import json import os import pathlib import re import shutil _script_dir = pathlib.Path(__file__).parent.resolve(strict=True) repo_root = _script_dir.parents[3] _template_variable_pattern = re.compile(r"@(\w+)@") # match ...
152
5,554
onnxruntime
tools/ci_build/github/apple/package_release_tasks.py
.py
#!/usr/bin/env python3 # Note: This script is intended to be called from the CocoaPods package release pipeline or a similar context. from __future__ import annotations import argparse import glob import shlex import subprocess from enum import Enum from pathlib import Path class Task(Enum): upload_pod_archive...
105
3,212
onnxruntime
tools/ci_build/github/apple/build_apple_framework.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import argparse import json import os import pathlib import shutil import subprocess import sys from dataclasses import dataclass from build_settings_utils import ge...
424
17,291
onnxruntime
tools/ci_build/github/apple/build_settings_utils.py
.py
from __future__ import annotations import json import pathlib import typing _DEFAULT_BUILD_SYSROOT_ARCHS = { "iphoneos": ["arm64"], "iphonesimulator": ["arm64", "x86_64"], } def parse_build_settings_file(build_settings_file: pathlib.Path) -> dict[str, typing.Any]: """ Parses the provided build setti...
82
2,734
onnxruntime
tools/ci_build/github/apple/c/assemble_c_pod_package.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import pathlib import shutil import sys _script_dir = pathlib.Path(__file__).parent.resolve(strict=True) sys.path.append(str(_script_dir.parent)) from package_assembly_utils import (...
181
6,483
onnxruntime
tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import pathlib import sys _script_dir = pathlib.Path(__file__).parent.resolve(strict=True) sys.path.append(str(_script_dir.parent)) from c.assemble_c_pod_package import get_pod_confi...
205
6,820
onnxruntime
tools/ci_build/github/windows/jar_packaging.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ Packages ONNX Runtime Java artifacts by combining native libraries from various platform builds into final Java archive (JAR) files using 7z. """ import argparse import glob import os import re import shutil import subpr...
315
11,786
onnxruntime
tools/ci_build/github/windows/sign_java_artifacts.py
.py
import argparse import hashlib import os import platform import shutil import subprocess import sys import tempfile from pathlib import Path def clean_gpg_trustdb() -> None: if platform.system() == "Windows": # Clean up GPG trust database if it exists appdata = os.environ.get("APPDATA") if...
168
6,368
onnxruntime
tools/ci_build/github/windows/post_code_coverage_to_dashboard.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # command line arguments # --report_url=<string> # --report_file=<string, local file path, TXT/JSON file> # --commit_hash=<string, full git commit hash> import argparse import datetime import json imp...
116
3,952
onnxruntime
tools/ci_build/github/windows/jar_packaging_test.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import zipfile from pathlib import Path import jar_packaging # The refactored script import pytest # Helper to create an empty file def create_empty_file(path): Path(path).touch() # Helper to create a dummy JAR file...
145
6,757
onnxruntime
tools/ci_build/github/windows/post_binary_sizes_to_dashboard.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import datetime import os import sys # ingest from dataframe import pandas from azure.kusto.data import DataFormat, KustoConnectionStringBuilder from azure.kusto.ingest import Ingestio...
106
3,687
onnxruntime
tools/ci_build/github/linux/ort_minimal/build_ort_and_check_binary_size.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import json import pathlib import subprocess import sys REPO_ROOT = pathlib.Path(__file__).resolve().parents[5] def parse_args(): parser = argparse.ArgumentParser(description="Bui...
65
2,237
onnxruntime
tools/ci_build/github/linux/ort_minimal/readelf_utils.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """ Utilities to help analyze the sections in a binary using readelf. """ import argparse import collections import os import re import subprocess import sys def get_section_sizes(binary_path, readelf...
130
4,401
onnxruntime
tools/ci_build/github/linux/ort_minimal/check_build_binary_size.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import sys # local helpers import readelf_utils def _check_binary_size(path, readelf, threshold, os_str, arch, build_config): print(f"Checking binary size of {path} usin...
68
2,635
onnxruntime
orttraining/tools/ci_test/compare_huggingface.py
.py
import collections import json import sys actual = sys.argv[1] expect = sys.argv[2] with open(actual) as file_actual: json_actual = json.loads(file_actual.read()) with open(expect) as file_expect: json_expect = json.loads(file_expect.read()) def almost_equal(x, y, threshold=0.05): return abs(x - y) < t...
53
1,470
onnxruntime
orttraining/tools/ci_test/download_azure_blob_archive.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import hashlib import os import shutil import subprocess import sys import tempfile import urllib.request # noqa: F401 import zipfile # noqa: F401 SCRIPT_DIR = os.path.dirname(os.path...
76
2,550
onnxruntime
orttraining/tools/ci_test/run_gpt2_perf_test.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import subprocess import sys from collections import namedtuple SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) def parse_args(): parser = argparse.ArgumentPars...
72
2,297
onnxruntime
orttraining/tools/ci_test/run_convergence_test.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import os import subprocess import sys import tempfile from compare_results import Comparisons, compare_results_files SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) def par...
108
3,721
onnxruntime
orttraining/tools/ci_test/run_batch_size_test.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import collections import os import subprocess import sys def parse_args(): parser = argparse.ArgumentParser(description="Runs a BERT batch size test.") parser.add_argument("--...
118
3,499
onnxruntime
orttraining/tools/ci_test/run_bert_perf_test.py
.py
#!/usr/bin/env python3 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse import json import os import subprocess import sys from collections import namedtuple SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) def parse_args(): parser = argparse....
114
3,810
onnxruntime
orttraining/tools/ci_test/compare_results.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import argparse # noqa: F401 import collections import csv import re # noqa: F401 import sys Comparison = collections.namedtuple("Comparison", ["name", "fn"]) class Comparisons: @staticmethod def eq(): re...
77
2,740
onnxruntime
orttraining/tools/scripts/nv_run_pretraining.py
.py
# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. # Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at...
704
30,238
onnxruntime
orttraining/tools/scripts/pipeline_model_split.py
.py
import os import sys # noqa: F401 import onnx from onnx import OperatorSetIdProto, TensorProto, helper # noqa: F401 # Edge that needs to be cut for the split. # If the edge is feeding into more than one nodes, and not all the nodes belong to the same cut, # specify those consuming nodes that need to be cut class ...
410
15,126
onnxruntime
orttraining/tools/scripts/model_transform.py
.py
from __future__ import annotations import sys import numpy as np import onnx from onnx import numpy_helper if len(sys.argv) < 2: print("Please give model path...") exit(1) input_model_name = sys.argv[1] output_model_name = input_model_name[:-5] + "_optimized.onnx" model = onnx.load(input_model_name) def ...
328
11,556
onnxruntime
orttraining/tools/scripts/sqldb_to_tensors.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import sqlite3 import onnx from onnx import numpy_helper connection = sqlite3.connect("<path-to-sqldb-from-tracing>", detect_types=sqlite3.PARSE_DECLTYPES) def convert_tensor_proto_to_numpy_array(blob): tensor_proto =...
24
722
onnxruntime
orttraining/tools/scripts/train.py
.py
import shlex import subprocess import sys def main(argv=None): if argv is None: argv = sys.argv[1:] cmd = ["/workspace/onnxruntime_training_bert", *argv] print(shlex.join(cmd)) subprocess.run(cmd, check=True) if __name__ == "__main__": main()
17
276
onnxruntime
orttraining/tools/scripts/performance_investigation.py
.py
import argparse import onnx parser = argparse.ArgumentParser(description="ONNX file analyzer for performance investigation.") parser.add_argument("onnx_file", type=str, help="ONNX file to analyze") args = parser.parse_args() def process_file(onnx_file): model = onnx.load(onnx_file) # Map from output arg to...
91
2,822
onnxruntime
orttraining/tools/scripts/watch_experiment.py
.py
import argparse import os import sys from concurrent.futures import ThreadPoolExecutor from threading import Event, Thread # noqa: F401 from azureml._run_impl.run_watcher import RunWatcher from azureml.core import Experiment, Run, Workspace # noqa: F401 from requests import Session parser = argparse.ArgumentParser(...
78
3,183
onnxruntime
orttraining/tools/scripts/layer_norm_transform.py
.py
import os.path import sys import numpy as np import onnx from onnx import * # noqa: F403 def find_node(graph_proto, op_type): nodes = [] map_input_node = {} for node in graph_proto.node: if node.op_type == op_type: node_input = node.input[1] if op_type == "Div" or op_type == "Mul" el...
187
6,953
onnxruntime
orttraining/tools/scripts/experiment.py
.py
import argparse import os # noqa: F401 import re import sys # noqa: F401 from azure.common.client_factory import get_client_from_cli_profile from azure.mgmt.containerregistry import ContainerRegistryManagementClient from azureml.core import Datastore, Experiment, Run, Workspace # noqa: F401 from azureml.core.comput...
170
6,205
onnxruntime
orttraining/tools/scripts/gpt2_model_transform.py
.py
### Be noted: this script is developed against the model exported from Megatron GPT2 Pretraining script. import sys import numpy as np import onnx from onnx import numpy_helper if len(sys.argv) < 2: print("Please give model path...") exit(1) input_model_name = sys.argv[1] output_model_name = input_model_nam...
341
10,809
onnxruntime
orttraining/tools/scripts/opset12_model_transform.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # # This converter is an internal util to upgrade existing bert/gpt-2 models, # which were previously transformed/optimized from original model, to Opset 12 # version as well as replacing deprecated node, i.e., TrainableDropou...
127
4,528
onnxruntime
orttraining/orttraining/python/pt_patch.py
.py
import torch import torch.onnx.symbolic_helper as sym_help from torch.onnx import symbolic_opset10, symbolic_opset12 from torch.onnx.symbolic_helper import parse_args @parse_args("v", "v", "v", "v", "i", "none") def nll_loss_10(g, self, target, weight=None, reduction="mean", ignore_index=-100): if not weight and ...
48
1,977
onnxruntime
orttraining/orttraining/python/training/_utils.py
.py
# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # -------------------------------------------------------------------------- import importlib.util import os import sys import numpy as np import to...
205
6,553
onnxruntime
orttraining/orttraining/python/training/__init__.py
.py
# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # -------------------------------------------------------------------------- # isort: skip_file from onnxruntime.capi._pybind_state import ( Propa...
32
832
onnxruntime
orttraining/orttraining/python/training/artifacts.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import contextlib import logging import os import pathlib from enum import Enum import onnx from onnxruntime.tools.convert_onnx_models_to_ort import OptimizationStyle, convert_onnx_models_to_ort from onnxruntime.training im...
273
12,339
onnxruntime
orttraining/orttraining/python/training/onnxblock/_training_graph_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import copy import logging import os import onnx from onnxruntime import SessionOptions from onnxruntime.capi._pybind_state import GradientGraphBuilder, get_optimized_model def _disable_training_mode(model: onnx.ModelProt...
243
9,629
onnxruntime
orttraining/orttraining/python/training/onnxblock/model_accessor.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. from __future__ import annotations import copy import os from contextlib import contextmanager import onnx class ModelAccessor: """This class stores the onnx model that is manipulated by the onnx blocks. Attribut...
171
5,769
onnxruntime
orttraining/orttraining/python/training/onnxblock/_graph_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import onnx def get_output_from_output_name(onnx_model: onnx.ModelProto, output_name: str) -> onnx.ValueInfoProto: """Returns the graph output for the given output name""" for go in onnx_model.graph.output: ...
105
3,455
onnxruntime
orttraining/orttraining/python/training/onnxblock/__init__.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. """Offline tooling for generating files needed by ort training apis.""" import onnxruntime.training.onnxblock.blocks as blocks import onnxruntime.training.onnxblock.loss as loss import onnxruntime.training.onnxblock.optim as...
27
878
onnxruntime
orttraining/orttraining/python/training/onnxblock/onnxblock.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import logging from abc import abstractmethod import onnx import onnxruntime.training.onnxblock._graph_utils as _graph_utils import onnxruntime.training.onnxblock._training_graph_utils as _training_graph_utils import onnxru...
214
8,778
onnxruntime
orttraining/orttraining/python/training/onnxblock/checkpoint_utils.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import os import onnx from onnxruntime.capi._pybind_state import get_model_after_loading_checkpoint as _load_checkpoint_to_model from onnxruntime.capi._pybind_state import save_checkpoint as _save_checkpoint def save_chec...
43
1,733
onnxruntime
orttraining/orttraining/python/training/onnxblock/blocks.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import contextlib import copy import logging import os from abc import ABC, abstractmethod from typing import Any import numpy as np import onnx import onnxruntime.training.onnxblock._graph_utils as _graph_utils import onnx...
537
17,893
onnxruntime
orttraining/orttraining/python/training/onnxblock/loss/loss.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import copy import onnx import onnxruntime.training.onnxblock._graph_utils as _graph_utils import onnxruntime.training.onnxblock.blocks as blocks class MSELoss(blocks.Block): """MSELoss onnxblock for adding MSE loss t...
257
10,543
onnxruntime
orttraining/orttraining/python/training/onnxblock/optim/optim.py
.py
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import onnx import onnxruntime.training.onnxblock._graph_utils as _graph_utils import onnxruntime.training.onnxblock.blocks as blocks import onnxruntime.training.onnxblock.onnxblock as onnxblock_module class ClipGradNorm(...
320
10,204
onnxruntime
orttraining/orttraining/python/training/experimental/exporter.py
.py
import torch import torch.onnx.symbolic_helper import torch.onnx.utils def _export_jit_graph_to_onnx_model_proto(graph: torch._C.Graph, operator_export_type: int): from torch.onnx.symbolic_helper import ( # noqa: F401, PLC0415 _set_onnx_shape_inference, _set_operator_export_type, _set_ops...
31
842
onnxruntime
orttraining/orttraining/python/training/experimental/gradient_graph/_gradient_graph_tools.py
.py
import io from collections.abc import Callable from pathlib import Path from typing import Any import torch from torch.onnx import TrainingMode from onnxruntime.capi._pybind_state import GradientGraphBuilder from ...ortmodule._custom_op_symbolic_registry import CustomOpSymbolicRegistry def export_gradient_graph( ...
92
3,386
onnxruntime
orttraining/orttraining/python/training/amp/loss_scaler.py
.py
class LossScaler: r"""Base class for implementing custom loss scaler strategies Once the scaler is configured, no user intervention is needed to update loss scale during training. Note: This class should never be instantiated, but used as an abstract class for custom loss scaling strategy. """...
121
4,654