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 | orttraining/orttraining/python/training/ort_triton/_decompose.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Decompose a complicated op into a series of simple ops.
"simple ops"... | 376 | 18,633 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_op_config.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
This file controls the Ops supported by Triton codegen.
The Triton fu... | 68 | 3,300 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_utils.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import re
import uuid
from collections import defaultdict
from typing im... | 169 | 5,595 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import threading
from functools import wraps
from onnxruntime.capi impo... | 43 | 1,530 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_codegen.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Generate code for each IR node.
Mostly, Nodes are classified into tw... | 525 | 24,895 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_common.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from abc import abstractmethod
from typing import Any
import sympy
from... | 267 | 9,718 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_ir.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from abc import abstractmethod
from collections import defaultdict
from ... | 399 | 17,314 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_cache.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# from torch/_inductor/codecache.py
import base64
import functools
impor... | 81 | 2,472 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_sorted_graph.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import copy
import itertools
import onnx
import sympy
from onnx import ... | 224 | 10,254 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_sympy_utils.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import re
from typing import Any
import sympy
def extract_shape_from_... | 33 | 1,022 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/triton_op_executor.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import functools
import json
import os
import re
import sys
from types i... | 187 | 8,077 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/_lowering.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import itertools
import warnings
from collections import defaultdict
fro... | 561 | 26,270 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/kernel/_mm.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import math
import os
from types import ModuleType
import torch
from .... | 484 | 16,310 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/kernel/_slice_scel.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import itertools
import sys
import torch
import triton
import triton.la... | 368 | 14,360 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/kernel/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
import torch
from ._mm import triton_gemm, triton_gemm_out, ... | 33 | 992 |
onnxruntime | orttraining/orttraining/python/training/ort_triton/kernel/_flash_attn.py | .py | """
*Experimental* implementation of FlashAttention in Triton.
Tested with triton==2.0.0.dev20221202.
Triton 2.0 has a new backend (MLIR) but seems like it doesn't yet work for head dimensions
other than 64:
https://github.com/openai/triton/blob/d376020f90002757eea3ea9475d4f7cfc2ec5ead/python/triton/ops/flash_attention... | 1,244 | 45,607 |
onnxruntime | orttraining/orttraining/python/training/api/__init__.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from onnxruntime.training.api.checkpoint_state import CheckpointState
from onnxruntime.training.api.lr_scheduler import LinearLRScheduler
from onnxruntime.training.api.module import Module
from onnxruntime.training.api.optimi... | 15 | 435 |
onnxruntime | orttraining/orttraining/python/training/api/module.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from __future__ import annotations
import os
import numpy as np
from onnxruntime.capi import _pybind_state as C
from onnxruntime.capi.onnxruntime_inference_collection import OrtValue, get_ort_device_type
from onnxruntime.c... | 213 | 7,762 |
onnxruntime | orttraining/orttraining/python/training/api/checkpoint_state.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from __future__ import annotations
import os
import numpy as np
from onnxruntime.capi import _pybind_state as C
from onnxruntime.capi.onnxruntime_inference_collection import OrtValue
class Parameter:
"""Class that re... | 257 | 8,461 |
onnxruntime | orttraining/orttraining/python/training/api/lr_scheduler.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from onnxruntime.capi import _pybind_state as C
from onnxruntime.training.api.optimizer import Optimizer
class LinearLRScheduler:
"""Linearly updates the learning rate in the optimizer
The linear learning rate sche... | 32 | 1,367 |
onnxruntime | orttraining/orttraining/python/training/api/optimizer.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from __future__ import annotations
import os
from typing import TYPE_CHECKING
from onnxruntime.capi import _pybind_state as C
if TYPE_CHECKING:
from onnxruntime.training.api.module import Module
class Optimizer:
... | 51 | 1,569 |
onnxruntime | orttraining/orttraining/python/training/utils/ptable.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
class Row:
"""A row in a PTable"""
def __init__(self, columns:... | 72 | 2,709 |
onnxruntime | orttraining/orttraining/python/training/utils/torch_io_helper.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import copy
import warnings
from collections import OrderedDict, abc
fro... | 314 | 12,930 |
onnxruntime | orttraining/orttraining/python/training/utils/torch_profile_utils.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import torch
def torch_nvtx_range_... | 105 | 3,969 |
onnxruntime | orttraining/orttraining/python/training/utils/__init__.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# __init__.py
from onnxruntime.training.utils.ptable import PTable
from onnxruntime.training.utils.torch_io_helper import (
ORTModelInputOutputSchemaType,
ORTModelInputOutputType,
PrimitiveType,
extract_data_... | 41 | 1,108 |
onnxruntime | orttraining/orttraining/python/training/utils/torch_type_map.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import torch
# Mapping from pytorch scalar type to onnx scalar type.
_... | 65 | 2,935 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/_zero_offload_subscriber.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import ctypes
import inspect
import warnings
from collections import Ord... | 653 | 28,667 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/_subscriber_base.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import sys
import torch
from onnxruntime.training.utils import ORTMod... | 211 | 9,095 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import torch
__all__ = [
"GlobalSubscriberManager",
"Statistic... | 38 | 1,388 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/_subscriber_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import inspect
from contextlib import contextmanager
import onnx
impor... | 292 | 13,800 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/_statistics_subscriber.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
import shutil
import warnings
from io import TextIOWrapper
fro... | 288 | 12,735 |
onnxruntime | orttraining/orttraining/python/training/utils/hooks/merge_activation_summary.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
This merges convergence debugging per activation summary files into... | 156 | 5,536 |
onnxruntime | orttraining/orttraining/python/training/utils/data/sampler.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# sampler.py
import math
from collections.abc import Callable, Iterator
import numpy as np
import torch
import torch.distributed as dist
from torch.utils.data.dataset import Dataset
from torch.utils.data.sampler import Sampl... | 358 | 17,342 |
onnxruntime | orttraining/orttraining/python/training/optim/_multi_tensor_apply.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# multi_tensor_apply.py
# This file has been adapted from microsoft/DeepSpeed
"""
Copyright 2020 The Microsoft DeepSpeed Team
Copyright NVIDIA/apex
This file is adapted from NVIDIA/apex, commit a109f85
"""
class MultiTenso... | 20 | 543 |
onnxruntime | orttraining/orttraining/python/training/optim/_apex_amp_modifier.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# Copyright (c) 2020, NVIDIA CORPORATION.
# Some functions in this file are adapted from NVIDIA/apex, commit 082f999a6e18a3d02306e27482cc7486dab71a5... | 142 | 6,452 |
onnxruntime | orttraining/orttraining/python/training/optim/_megatron_modifier.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# Copyright 2020 The Microsoft DeepSpeed Team
# Copyright (c) 2020, NVIDIA CORPORATION.
# Some functions in this file are adapted from following sou... | 87 | 4,085 |
onnxruntime | orttraining/orttraining/python/training/optim/__init__.py | .py | from .config import AdamConfig, LambConfig, SGDConfig, _OptimizerConfig # noqa: F401
from .fp16_optimizer import FP16_Optimizer # noqa: F401
from .fused_adam import AdamWMode, FusedAdam # noqa: F401
from .lr_scheduler import (
ConstantWarmupLRScheduler, # noqa: F401
CosineWarmupLRScheduler, # noqa: F401
... | 11 | 436 |
onnxruntime | orttraining/orttraining/python/training/optim/fp16_optimizer.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from ._modifier_registry import OptimizerModifierTypeRegistry, get_full... | 92 | 3,870 |
onnxruntime | orttraining/orttraining/python/training/optim/_modifier.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# Copyright (c) 2020, NVIDIA CORPORATION.
# Some functions in this file are adapted from following sources:
# - clip_grad_norm_fp32 : https://github... | 163 | 6,669 |
onnxruntime | orttraining/orttraining/python/training/optim/_modifier_registry.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import warnings
from typing import C... | 62 | 2,513 |
onnxruntime | orttraining/orttraining/python/training/optim/lr_scheduler.py | .py | import math
class _LRScheduler:
r"""Base class for implementing custom learning rate schedulers
Schedulers can be either stateful or stateless.
Stateless implementation can only rely on information available at
:py:class:`.TrainStepInfo`.
Stateful implementation, on the other hand, can store addi... | 293 | 12,685 |
onnxruntime | orttraining/orttraining/python/training/optim/fused_adam.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# fused_adam.py
# This file has been adapted from microsoft/DeepSpeed
"""
Copyright 2020 The Microsoft DeepSpeed Team
Copyright NVIDIA/apex
This file is adapted from fused adam in NVIDIA/apex, commit a109f85
"""
import warn... | 293 | 12,791 |
onnxruntime | orttraining/orttraining/python/training/optim/_ds_code_store.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# Copyright 2020 The Microsoft DeepSpeed Team
#
# !!!IMPORTANT: This file is a copy of the original one in DeepSpeed repo at given version,
# It is ... | 78 | 3,793 |
onnxruntime | orttraining/orttraining/python/training/optim/_ds_modifier.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# Copyright 2020 The Microsoft DeepSpeed Team
# Copyright (c) 2020, NVIDIA CORPORATION.
# Some functions in this file are adapted from following sou... | 257 | 12,585 |
onnxruntime | orttraining/orttraining/python/training/optim/config.py | .py | from enum import IntEnum, unique
class _OptimizerConfig:
r"""Base class for optimizer configuration
This class is not an optimizer, but a means to configure existing ones from ORT backend.
Once configured, no user intervention is needed to update weights or zero gradients during training.
The 'parame... | 275 | 12,348 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_torch_module_factory.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _torch_module_factory.py
from logging import Logger
from ._fallback import _FallbackManager
from ._torch_module_ort import TorchModuleORT
from .options import DebugOptions
class TorchModuleFactory:
def __call__(self,... | 17 | 563 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_pythonop_helper.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import inspect
import onnx
import t... | 241 | 9,396 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/options.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# options.py
import os
from enum import IntFlag
from functools import reduce
from logging import Logger
from packaging import version
from onnxruntime.capi import _pybind_state as C
from onnxruntime.training import ortmodul... | 443 | 20,834 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_inference_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from logging import Logger
import onnx
import torch
from onnxruntime.c... | 228 | 11,080 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_utils.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# pylint: disable=W0511
import copy
import functools
import inspect
impo... | 475 | 20,364 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_custom_autograd_function.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from onnxruntime.capi._pybind_state import is_torch_interop_default_on
f... | 92 | 3,860 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_torch_module_interface.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _torch_module_interface.py
from collections import OrderedDict
from collections.abc import Callable, Iterator
from typing import Optional, TypeVar
import torch
from typing_extensions import Self
T = TypeVar("T", bound="to... | 106 | 4,556 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_graph_transition_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import copy
import inspect
import io... | 1,059 | 54,225 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_io.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import copy
import gc
import inspect
from collections import OrderedDict... | 591 | 26,116 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_mem_efficient_grad_mgmt.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import ctypes
import torch
from onn... | 184 | 6,981 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_logger.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import logging
import os
import sys
import tempfile
import textwrap
impo... | 300 | 11,247 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_gradient_accumulation_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from onnxruntime.capi import _pybind_state as C
from . import _utils
c... | 89 | 4,084 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import contextlib
import inspect
import os
import sys
import warnings
i... | 236 | 9,304 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_custom_gradient_registry.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# Support registration of ATen op's symbolic (PyTorch exporter overridin... | 316 | 12,623 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_torch_module_ort.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _torch_module_ort.py
from collections import OrderedDict
from collections.abc import Callable, Iterator
from logging import Logger
from typing import Optional, TypeVar
import torch
from typing_extensions import Self
from ... | 184 | 8,336 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_graph_execution_interface.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _graph_execution_interface.py
from abc import ABC
class GraphExecutionInterface(ABC): # noqa: B024
def __init__(self, module):
self._original_module = module
self._validate_module_type(module)
de... | 30 | 1,092 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_onnx_models.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _onnx_models.py
import os
from dataclasses import dataclass
import onnx
import torch
def _get_onnx_file_name(name_prefix, name, export_mode):
suffix = "training" if export_mode == torch.onnx.TrainingMode.TRAINING els... | 40 | 1,424 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/graph_optimizer_registry.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from collections.abc import Callable
from onnx.onnx_ml_pb2 import Graph... | 48 | 1,982 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_training_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from logging import Logger
import onnx
import torch
from onnxruntime.c... | 467 | 23,149 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_fallback.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
from enum import IntFlag
from logging import Logger
import to... | 189 | 7,959 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_fallback_exceptions.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _fallback_exceptions.py
class ORTModuleFallbackException(Exception): # noqa: N818
"""Base exception class for fallback
Although it must be specialized for specific scenarios,
it can also be used for generic e... | 66 | 2,349 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_torch_module_pytorch.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _torch_module_pytorch.py
from collections import OrderedDict
from collections.abc import Callable, Iterator
from typing import Optional, TypeVar
import torch
from typing_extensions import Self
from ._torch_module_interfac... | 94 | 3,793 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_custom_autograd_function_exporter.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations
import sys
from typing import ClassV... | 645 | 27,073 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/ortmodule.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# isort: skip_file
# Import ordering is important in this module to avoid... | 339 | 16,188 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_custom_op_symbolic_registry.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
from collections.abc import Callable
import torch
import torc... | 997 | 42,027 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_graph_execution_manager_factory.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from logging import Logger
from ._fallback import _FallbackManager
from... | 31 | 1,093 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_runtime_inspector.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import json
import tempfile
from enum import IntEnum
from logging import... | 398 | 15,702 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_zero_stage3_compatibility.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from contextlib import contextmanager
import torch
from onnx import Mo... | 443 | 18,423 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_execution_agent.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import onnxruntime
from onnxruntime.capi import _pybind_state as C
from... | 175 | 7,714 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/_graph_execution_manager.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import copy
import logging
import os
from abc import ABC, abstractmethod... | 557 | 25,378 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/experimental/pipe/_ort_pipeline_module.py | .py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import importlib.metadata
from functools import partial
import torch.nn as nn
from deepspeed.pipe import LayerSpec, PipelineModule, TiedLayerSpec
from deepspeed.runtime import utils as ds_utils
from deepspeed.runtime.activation_checkpointing imp... | 170 | 8,145 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/experimental/hierarchical_ortmodule/_hierarchical_ortmodule.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _hierarchical_ortmodule.py
import tempfile
import warnings
import torch
from onnxruntime.training import ortmodule
from onnxruntime.training.ortmodule import ORTModule
from onnxruntime.training.ortmodule.options import Deb... | 280 | 12,838 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/experimental/json_config/_load_config_from_json.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# _load_config_from_json.py
import json
import logging
import os
from functools import reduce
from types import SimpleNamespace
from onnxruntime.capi import _pybind_state as C
from onnxruntime.training.ortmodule._fallback im... | 306 | 12,996 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/graph_optimizers/utils.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import itertools
from collections.abc import Sequence
from typing import... | 180 | 7,842 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/graph_optimizers/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
import torch
from packaging.version import Version
_all_opti... | 23 | 720 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/graph_optimizers/_aten_attn.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
PyTorch's _efficient_attention_forward/_efficient_attention_backward... | 269 | 10,540 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/__init__.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""Support for PyTorch C++ extensions within ORTModule
Pytorch C++ exte... | 40 | 1,755 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/install.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
import subprocess
import sys
from glob import glob
from shutil... | 102 | 4,121 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils/fake_ctx.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
class FakeContext:
"""A mock up class used to represent ctx in unsf... | 14 | 471 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils/setup.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import os
from setuptools import Extension, setup # noqa: F401
from to... | 39 | 1,128 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils/__init__.py | .py | def clear_all_grad_fns():
from onnxruntime.training.ortmodule.torch_cpp_extensions import torch_interop_utils # noqa: PLC0415
torch_interop_utils.clear_all_grad_fns()
import atexit # noqa: E402
# Clear all gradient functions, to avoid a deadlock issue.
# Check the called function for more detailed comment... | 12 | 359 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/cuda/torch_gpu_allocator/setup.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import fileinput
import os
import sys
from setuptools import setup
from... | 40 | 1,438 |
onnxruntime | orttraining/orttraining/python/training/ortmodule/torch_cpp_extensions/cuda/fused_ops/setup.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import fileinput # noqa: F401
import os
import sys # noqa: F401
from ... | 33 | 1,198 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_layer_norm_transform.py | .py | import onnx
def find_node(graph_proto, op_type):
nodes = []
map_input_node = {}
for node in graph_proto.node:
if node.op_type == op_type:
map_input_node[node.input[0]] = node
if op_type == "Div" or op_type == "Mul":
map_input_node[node.input[1]] = node
... | 183 | 5,623 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_ort_apis.py | .py | #!/usr/bin/env python3
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# This file contains calls to the tests for ONNXBlock (front end tooling for ort training apis) and training apis.
# The tests are run in a separate process to avoid testing the entire ort suite of test... | 60 | 1,692 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_ort_apis_py_bindings.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from __future__ import annotations
import os
import pathlib
import tempfile
from dataclasses import dataclass
import numpy as np
import onnx
import packaging.version as pv
import pytest
import torch
from orttraining_test_or... | 676 | 27,623 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_ortmodule_autograd_dist.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import copy
import os
import sys
import _test_helpers
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from torch.nn.parallel import DistributedDataParallel as DDP # noqa: N817
from torch.nn... | 131 | 4,374 |
onnxruntime | orttraining/orttraining/test/python/orttraining_ortmodule_distributed_tests.py | .py | #!/usr/bin/env python3
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import argparse
import logging
import sys
from _test_commons import run_subprocess
logging.basicConfig(format="%(asctime)s %(name)s [%(levelname)s] - %(message)s", level=logging.DEBUG)
log = logging.g... | 126 | 3,597 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_dort_custom_ops.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import sys
import unittest
import onnxscript
import torch
import torch._dynamo
from functorch.compile import min_cut_rematerialization_partition
from torch._dynamo.backends.common import aot_autograd
from torch.lib... | 207 | 7,836 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_lort.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import unittest
import torch
import torch.nn as nn
import torch.nn.functional as F
# Ask lazy backend to use Pytorch's JIT as
# lazy backend's executor.
from torch._lazy.ts_backend import init as init_ts_backend
init_ts_ba... | 120 | 4,135 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_data_loader.py | .py | import random
from enum import Enum
import torch
from torch.utils.data import DataLoader, Dataset
global_rng = random.Random()
def ids_tensor(shape, vocab_size, rng=None, name=None):
"""Creates a random int32 tensor of the shape within the vocab size."""
if rng is None:
rng = global_rng
total_d... | 102 | 3,228 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_ortmodule_onnx_ops.py | .py | """
@brief test log(time=3s)
"""
import copy
import unittest
import numpy as np
import torch
from onnxruntime.training.ortmodule import ORTModule
class TestOnnxOpsOrtModule(unittest.TestCase):
def assert_values_are_close(self, tensor, other, rtol=1e-05, atol=1e-06):
are_close = torch.allclose(tens... | 186 | 7,827 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_gru.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import tempfile
import numpy as np
import onnx
import pytest
from onnx import TensorProto, helper
import onnxruntime as ort
def sigmoid(z):
"""Computes the sigmoid of the given numpy array."""
return 1 /... | 721 | 30,663 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_hierarchical_ortmodule.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from collections.abc import Iterable
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.checkpoint import checkpoint
from onnxruntime.training.ortmodule import ORTModule # noqa: F401
from o... | 249 | 6,872 |
onnxruntime | orttraining/orttraining/test/python/orttraining_test_ortmodule_fallback.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# orttraining_test_ortmodule_api.py
import copy
import itertools
import math
import os
import warnings
from dataclasses import dataclass
import _test_helpers
import numpy as np
import pytest
import torch
from _orttraining_or... | 746 | 33,704 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.