python_code
stringlengths
0
1.02M
repo_name
stringlengths
9
48
file_path
stringlengths
5
114
import torch import torch.nn.functional as F from .conv_utils import conv_backward, conv_args_and_kwargs, conv_picker from .expanded_weights_impl import ExpandedWeight, implements_per_sample_grads from .expanded_weights_utils import forward_helper @implements_per_sample_grads(F.conv1d) @implements_per_sample_grads(F....
pytorch-master
torch/nn/utils/_expanded_weights/conv_expanded_weights.py
from typing import Optional import torch from .expanded_weights_impl import ExpandedWeight def standard_kwargs(kwarg_names, expanded_args): r'''Most `__torch_function__`s standardize the kwargs that they give, so this will separate the args and kwargs they pass. Functions that don't are linear and convND ...
pytorch-master
torch/nn/utils/_expanded_weights/expanded_weights_utils.py
from .conv_expanded_weights import ConvPerSampleGrad from .embedding_expanded_weights import EmbeddingPerSampleGrad from .group_norm_expanded_weights import GroupNormPerSampleGrad from .instance_norm_expanded_weights import InstanceNormPerSampleGrad from .layer_norm_expanded_weights import LayerNormPerSampleGrad from ....
pytorch-master
torch/nn/utils/_expanded_weights/__init__.py
import torch import torch.nn.functional as F from .expanded_weights_impl import implements_per_sample_grads from .expanded_weights_utils import standard_kwargs, forward_helper, set_grad_sample_if_exists from typing import List, Optional @implements_per_sample_grads(F.embedding) class EmbeddingPerSampleGrad(torch.auto...
pytorch-master
torch/nn/utils/_expanded_weights/embedding_expanded_weights.py
import torch import torch.nn.functional as F import numpy as np from typing import List, Optional from .expanded_weights_utils import \ set_grad_sample_if_exists, unpack_expanded_weight_or_tensor THRESHOLD = 32 def conv_picker(func, conv1dOpt, conv2dOpt, conv3dOpt): if func == F.conv1d: return conv1...
pytorch-master
torch/nn/utils/_expanded_weights/conv_utils.py
from functools import partial import torch import torch.nn.functional as F from .expanded_weights_impl import implements_per_sample_grads from .expanded_weights_utils import \ forward_helper, set_grad_sample_if_exists, standard_kwargs, unpack_expanded_weight_or_tensor from typing import List, Optional @implements_...
pytorch-master
torch/nn/utils/_expanded_weights/instance_norm_expanded_weights.py
import torch import torch.nn.functional as F from .expanded_weights_impl import implements_per_sample_grads from .expanded_weights_utils import \ forward_helper, set_grad_sample_if_exists, unpack_expanded_weight_or_tensor from typing import List, Optional @implements_per_sample_grads(F.linear) class LinearPerSampl...
pytorch-master
torch/nn/utils/_expanded_weights/linear_expanded_weights.py
from torch._C import _TensorBase import torch import functools from typing import Callable, Dict, cast HANDLED_FUNCTIONS: Dict[Callable, torch.autograd.Function] = {} def implements_per_sample_grads(torch_function): @functools.wraps(torch_function) def decorator(autograd_func): HANDLED_FUNCTIONS[torc...
pytorch-master
torch/nn/utils/_expanded_weights/expanded_weights_impl.py
from .modules import * # noqa: F403
pytorch-master
torch/nn/quantizable/__init__.py
from .activation import MultiheadAttention from .rnn import LSTM from .rnn import LSTMCell __all__ = [ 'LSTM', 'LSTMCell', 'MultiheadAttention', ]
pytorch-master
torch/nn/quantizable/modules/__init__.py
import torch import torch.jit # this is needed to avoid a circular import from torch import nn import torch.nn.functional as nnF from torch import Tensor from typing import Optional, Tuple import warnings class MultiheadAttention(nn.MultiheadAttention): _FLOAT_MODULE = nn.MultiheadAttention r"""Quantizable...
pytorch-master
torch/nn/quantizable/modules/activation.py
import numbers from typing import Optional, Tuple import warnings import torch from torch import Tensor """ We will recreate all the RNN modules as we require the modules to be decomposed into its building blocks to be able to observe. """ class LSTMCell(torch.nn.Module): r"""A quantizable long short-term memory...
pytorch-master
torch/nn/quantizable/modules/rnn.py
from .modules import * # noqa: F403
pytorch-master
torch/nn/intrinsic/__init__.py
from .modules import * # noqa: F403
pytorch-master
torch/nn/intrinsic/qat/__init__.py
import math import torch import torch.nn as nn import torch.nn.intrinsic as nni import torch.nn.qat as nnqat import torch.nn.functional as F from torch.nn import init from torch.nn.utils import fuse_conv_bn_weights from torch.nn.modules.utils import _single, _pair, _triple from torch.nn.parameter import Parameter from ...
pytorch-master
torch/nn/intrinsic/qat/modules/conv_fused.py
from .linear_relu import LinearReLU from .linear_fused import LinearBn1d from .conv_fused import ( ConvBn1d, ConvBn2d, ConvBn3d, ConvBnReLU1d, ConvBnReLU2d, ConvBnReLU3d, ConvReLU1d, ConvReLU2d, ConvReLU3d, update_bn_stats, freeze_bn_stats, ) __all__ = [ "LinearReLU", ...
pytorch-master
torch/nn/intrinsic/qat/modules/__init__.py
import torch import torch.nn.qat as nnqat import torch.nn.intrinsic as nni import torch.nn.functional as F class LinearReLU(nnqat.Linear, nni._FusedModule): r""" A LinearReLU module fused from Linear and ReLU modules, attached with FakeQuantize modules for weight, used in quantization aware training. ...
pytorch-master
torch/nn/intrinsic/qat/modules/linear_relu.py
import torch import torch.nn as nn import torch.nn.intrinsic as nni import torch.nn.functional as F from torch.nn import init from torch.nn.parameter import Parameter from torch.nn.utils.fusion import fuse_linear_bn_weights class LinearBn1d(nn.modules.linear.Linear, nni._FusedModule): r""" A LinearBn1d module...
pytorch-master
torch/nn/intrinsic/qat/modules/linear_fused.py
from .modules import * # noqa: F403
pytorch-master
torch/nn/intrinsic/quantized/__init__.py
from .modules import * # noqa: F403
pytorch-master
torch/nn/intrinsic/quantized/dynamic/__init__.py
import torch from .linear_relu import LinearReLU __all__ = [ 'LinearReLU', ]
pytorch-master
torch/nn/intrinsic/quantized/dynamic/modules/__init__.py
import torch import torch.nn.quantized.dynamic as nnqd import torch.nn.intrinsic as nni class LinearReLU(nnqd.Linear): r""" A LinearReLU module fused from Linear and ReLU modules that can be used for dynamic quantization. Supports both, FP16 and INT8 quantization. We adopt the same interface as :c...
pytorch-master
torch/nn/intrinsic/quantized/dynamic/modules/linear_relu.py
import torch import torch.nn.intrinsic import torch.nn.intrinsic.qat import torch.nn.quantized as nnq class BNReLU2d(nnq.BatchNorm2d): r""" A BNReLU2d module is a fused module of BatchNorm2d and ReLU We adopt the same interface as :class:`torch.nn.quantized.BatchNorm2d`. Attributes: Same as...
pytorch-master
torch/nn/intrinsic/quantized/modules/bn_relu.py
from .linear_relu import LinearReLU from .conv_relu import ConvReLU1d, ConvReLU2d, ConvReLU3d from .bn_relu import BNReLU2d, BNReLU3d __all__ = [ 'LinearReLU', 'ConvReLU1d', 'ConvReLU2d', 'ConvReLU3d', 'BNReLU2d', 'BNReLU3d', ]
pytorch-master
torch/nn/intrinsic/quantized/modules/__init__.py
import torch import torch.nn.intrinsic import torch.nn.intrinsic.qat import torch.nn.functional as F import torch.nn.quantized as nnq from torch.nn.utils import fuse_conv_bn_weights _reverse_repeat_padding = nnq.modules.conv._reverse_repeat_padding # TODO: factor out the common parts to ConvNd class ConvReLU1d(nnq....
pytorch-master
torch/nn/intrinsic/quantized/modules/conv_relu.py
import torch import torch.nn.quantized as nnq import torch.nn.intrinsic as nni class LinearReLU(nnq.Linear): r""" A LinearReLU module fused from Linear and ReLU modules We adopt the same interface as :class:`torch.nn.quantized.Linear`. Attributes: Same as torch.nn.quantized.Linear Exampl...
pytorch-master
torch/nn/intrinsic/quantized/modules/linear_relu.py
import torch from torch.nn import Conv1d, Conv2d, Conv3d, ReLU, Linear, BatchNorm1d, BatchNorm2d, BatchNorm3d from torch.nn.utils.parametrize import type_before_parametrizations __all__ = ['ConvReLU1d', 'ConvReLU2d', 'ConvReLU3d', 'LinearReLU', 'ConvBn1d', 'ConvBn2d', 'ConvBnReLU1d', 'ConvBnReLU2d', 'ConvBn...
pytorch-master
torch/nn/intrinsic/modules/fused.py
from .fused import _FusedModule from .fused import ConvBn1d from .fused import ConvBn2d from .fused import ConvBn3d from .fused import ConvBnReLU1d from .fused import ConvBnReLU2d from .fused import ConvBnReLU3d from .fused import ConvReLU1d from .fused import ConvReLU2d from .fused import ConvReLU3d from .fused import...
pytorch-master
torch/nn/intrinsic/modules/__init__.py
from .module import Module from .. import functional as F from torch import Tensor from typing import Optional from ..common_types import _size_2_t, _ratio_2_t, _size_any_t, _ratio_any_t __all__ = ['Upsample', 'UpsamplingNearest2d', 'UpsamplingBilinear2d'] class Upsample(Module): r"""Upsamples a given multi-chan...
pytorch-master
torch/nn/modules/upsampling.py
from .module import Module from .. import functional as F from torch import Tensor __all__ = ['ChannelShuffle'] class ChannelShuffle(Module): r"""Divide the channels in a tensor of shape :math:`(*, C , H, W)` into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`, while keeping the original ...
pytorch-master
torch/nn/modules/channelshuffle.py
from torch import Tensor from .batchnorm import _LazyNormBase, _NormBase from .. import functional as F __all__ = ['InstanceNorm1d', 'InstanceNorm2d', 'InstanceNorm3d', 'LazyInstanceNorm1d', 'LazyInstanceNorm2d', 'LazyInstanceNorm3d'] class _InstanceNorm(_NormBase): def __init__( self, ...
pytorch-master
torch/nn/modules/instancenorm.py
from .module import Module from typing import Tuple, Union from torch import Tensor from torch.types import _size __all__ = ['Flatten', 'Unflatten'] class Flatten(Module): r""" Flattens a contiguous range of dims into a tensor. For use with :class:`~nn.Sequential`. Shape: - Input: :math:`(*, S_{...
pytorch-master
torch/nn/modules/flatten.py
from typing import Optional, Any import torch from torch import Tensor from torch.nn.parameter import Parameter, UninitializedParameter, UninitializedBuffer from .. import functional as F from .. import init from ._functions import SyncBatchNorm as sync_batch_norm from .lazy import LazyModuleMixin from .module import...
pytorch-master
torch/nn/modules/batchnorm.py
import math from typing import Any import torch from torch import Tensor from torch.nn.parameter import Parameter, UninitializedParameter from .. import functional as F from .. import init from .module import Module from .lazy import LazyModuleMixin __all__ = [ 'Bilinear', 'Identity', 'LazyLinear', '...
pytorch-master
torch/nn/modules/linear.py
import torch import torch.distributed as dist from torch.autograd.function import Function class SyncBatchNorm(Function): @staticmethod def forward(self, input, weight, bias, running_mean, running_var, eps, momentum, process_group, world_size): if not input.is_contiguous(memory_format=torch.channels_...
pytorch-master
torch/nn/modules/_functions.py
from typing import List, Optional from torch import Tensor from .module import Module from .utils import _single, _pair, _triple from .. import functional as F from ..common_types import (_size_any_t, _size_1_t, _size_2_t, _size_3_t, _ratio_3_t, _ratio_2_t, _size_any_opt_t, _size_2_opt_t, ...
pytorch-master
torch/nn/modules/pooling.py
from .module import Module from .linear import Identity, Linear, Bilinear, LazyLinear from .conv import Conv1d, Conv2d, Conv3d, \ ConvTranspose1d, ConvTranspose2d, ConvTranspose3d, \ LazyConv1d, LazyConv2d, LazyConv3d, LazyConvTranspose1d, LazyConvTranspose2d, LazyConvTranspose3d from .activation import Thresho...
pytorch-master
torch/nn/modules/__init__.py
from .module import Module from .. import functional as F from torch import Tensor __all__ = ['PairwiseDistance', 'CosineSimilarity'] class PairwiseDistance(Module): r""" Computes the pairwise distance between vectors :math:`v_1`, :math:`v_2` using the p-norm: .. math :: \Vert x \Vert _p = \left...
pytorch-master
torch/nn/modules/distance.py
import warnings from collections import OrderedDict, abc as container_abcs from itertools import chain, islice import operator import torch from .module import Module from ..parameter import Parameter from torch._jit_internal import _copy_to_script_wrapper from typing import Any, Dict, Iterable, Iterator, Mapping, Op...
pytorch-master
torch/nn/modules/container.py
from .module import Module from .. import functional as F from torch import Tensor __all__ = ['PixelShuffle', 'PixelUnshuffle'] class PixelShuffle(Module): r"""Rearranges elements in a tensor of shape :math:`(*, C \times r^2, H, W)` to a tensor of shape :math:`(*, C, H \times r, W \times r)`, where r is an u...
pytorch-master
torch/nn/modules/pixelshuffle.py
# -*- coding: utf-8 -*- from collections import namedtuple import torch from torch import Tensor from typing import List, Sequence from . import Sequential, ModuleList, Linear from .module import Module from ..functional import log_softmax __all__ = ['AdaptiveLogSoftmaxWithLoss'] _ASMoutput = namedtuple('_ASMoutp...
pytorch-master
torch/nn/modules/adaptive.py
import warnings from .distance import PairwiseDistance from .module import Module from .. import functional as F from .. import _reduction as _Reduction from torch import Tensor from typing import Callable, Optional __all__ = ['L1Loss', 'NLLLoss', 'NLLLoss2d', 'PoissonNLLLoss', 'GaussianNLLLoss', 'KLDivLoss', ...
pytorch-master
torch/nn/modules/loss.py
import warnings from typing import Optional, Tuple import torch from torch import Tensor from .linear import NonDynamicallyQuantizableLinear from torch.nn.init import constant_, xavier_normal_, xavier_uniform_ from torch.nn.parameter import Parameter from .module import Module from .. import functional as F __all__ =...
pytorch-master
torch/nn/modules/activation.py
import collections from itertools import repeat from typing import List, Dict, Any __all__ = ['consume_prefix_in_state_dict_if_present'] def _ntuple(n, name="parse"): def parse(x): if isinstance(x, collections.abc.Iterable): return tuple(x) return tuple(repeat(x, n)) parse.__name_...
pytorch-master
torch/nn/modules/utils.py
import copy from typing import Optional, Any, Union, Callable import torch from torch import Tensor from .. import functional as F from .module import Module from .activation import MultiheadAttention from .container import ModuleList from ..init import xavier_uniform_ from .dropout import Dropout from .linear import ...
pytorch-master
torch/nn/modules/transformer.py
from typing import Optional import torch from torch import Tensor from torch.nn.parameter import Parameter from .module import Module from .. import functional as F from .. import init __all__ = ['Embedding', 'EmbeddingBag'] class Embedding(Module): r"""A simple lookup table that stores embeddings of a fixed di...
pytorch-master
torch/nn/modules/sparse.py
from collections import OrderedDict, namedtuple import itertools import warnings import functools import weakref import torch from ..parameter import Parameter import torch.utils.hooks as hooks from torch import Tensor, device, dtype from typing import Union, Tuple, Any, Callable, Iterator, Set, Optional, overload, T...
pytorch-master
torch/nn/modules/module.py
from .module import Module from .. import functional as F from torch import Tensor __all__ = ['Dropout', 'Dropout1d', 'Dropout2d', 'Dropout3d', 'AlphaDropout', 'FeatureAlphaDropout'] class _DropoutNd(Module): __constants__ = ['p', 'inplace'] p: float inplace: bool def __init__(self, p: float = 0.5, ...
pytorch-master
torch/nn/modules/dropout.py
# -*- coding: utf-8 -*- import math import warnings import torch from torch import Tensor from torch.nn.parameter import Parameter, UninitializedParameter from .. import functional as F from .. import init from .lazy import LazyModuleMixin from .module import Module from .utils import _single, _pair, _triple, _reverse...
pytorch-master
torch/nn/modules/conv.py
import itertools from typing_extensions import Protocol import warnings import torch from ..parameter import is_lazy __all__ = ['LazyModuleMixin'] class _LazyProtocol(Protocol): """This is to avoid errors with mypy checks for The attributes in a mixin: https://mypy.readthedocs.io/en/latest/more_types.htm...
pytorch-master
torch/nn/modules/lazy.py
import torch import numbers from torch.nn.parameter import Parameter from .module import Module from ._functions import CrossMapLRN2d as _cross_map_lrn2d from .. import functional as F from .. import init from torch import Tensor, Size from typing import Union, List, Tuple __all__ = ['LocalResponseNorm', 'CrossMapLRN...
pytorch-master
torch/nn/modules/normalization.py
import math import warnings import numbers from typing import List, Tuple, Optional, overload import torch from torch import Tensor from .module import Module from ..parameter import Parameter from ..utils.rnn import PackedSequence from .. import init from ... import _VF __all__ = ['RNNBase', 'RNN', 'LSTM', 'GRU', 'R...
pytorch-master
torch/nn/modules/rnn.py
from .module import Module from .utils import _pair, _quadruple, _ntuple from .. import functional as F from torch import Tensor from ..common_types import _size_2_t, _size_4_t, _size_6_t from typing import Sequence, Tuple # TODO: grad_output size asserts in THNN __all__ = ['ConstantPad1d', 'ConstantPad2d', 'Consta...
pytorch-master
torch/nn/modules/padding.py
# -*- coding: utf-8 -*- from .module import Module from .. import functional as F from torch import Tensor from ..common_types import _size_any_t __all__ = ['Fold', 'Unfold'] class Fold(Module): r"""Combines an array of sliding local blocks into a large containing tensor. Consider a batched :attr:`input...
pytorch-master
torch/nn/modules/fold.py
"""Utilities for converting and operating on ONNX, JIT and torch types.""" from __future__ import annotations import enum from typing import Dict, Optional, Union from typing_extensions import Literal import torch from torch._C import _onnx as _C_onnx ScalarName = Literal[ "Byte", "Char", "Double", ...
pytorch-master
torch/onnx/_type_utils.py
"""Constant values used in ONNX.""" ONNX_ARCHIVE_MODEL_PROTO_NAME = "__MODEL_PROTO" onnx_default_opset = 13 onnx_main_opset = 16 onnx_stable_opsets = tuple(range(7, onnx_main_opset)) onnx_constant_folding_opsets = tuple(range(9, onnx_main_opset + 1)) PYTORCH_GITHUB_ISSUES_URL = "https://github.com/pytorch/pytorch/iss...
pytorch-master
torch/onnx/_constants.py
"""This file exports ONNX ops for opset 15. Note [ONNX operators that are added/updated in opset 15] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://github.com/onnx/onnx/blob/master/docs/Changelog.md#version-15-of-the-default-onnx-operator-set New operators: Bernoulli CastLike Optional ...
pytorch-master
torch/onnx/symbolic_opset15.py
import inspect from typing import Dict, List, Union from torch import _C from torch.onnx import _constants, symbolic_registry for v in _constants.onnx_stable_opsets: symbolic_registry.register_version("", v) symbolic_registry.register_version("", _constants.onnx_main_opset) class _TorchSchema: def __init__(...
pytorch-master
torch/onnx/_onnx_supported_ops.py
""" Note [ONNX operators that are added/updated from opset 7 to opset 8] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New operators: Expand Updated operators: Min, Max, Sum, Mean: supports multidirectional broadcasting. MaxPool: added optional indices output. Scan """ import warnings ...
pytorch-master
torch/onnx/symbolic_opset7.py
import importlib import inspect from torch.onnx import symbolic_helper, symbolic_opset9 as opset9, symbolic_registry def register_quantized_ops(domain: str, version: int): # Register all the non-quantized ops symbolic_registry.register_version("", version) # Register all quantized ops module = import...
pytorch-master
torch/onnx/symbolic_caffe2.py
"""This file exports ONNX ops for opset 11.""" import sys import warnings from typing import Tuple, Union import torch from torch import _C from torch._C import _onnx as _C_onnx from torch.onnx import ( _type_utils, symbolic_helper, symbolic_opset10 as opset10, symbolic_opset9 as opset9, utils, ) ...
pytorch-master
torch/onnx/symbolic_opset11.py
"""Functions to verify exported ONNX model is functionally equivalent to original PyTorch model. ONNX Runtime is required, and is used as the ONNX backend for export verification. """ from __future__ import annotations import contextlib import copy import difflib import io import itertools import os import tempfile ...
pytorch-master
torch/onnx/verification.py
import sys import warnings from typing import Sequence import torch import torch._C._onnx as _C_onnx import torch.onnx from torch import _C # Monkey-patch graph manipulation methods on Graph, used for the ONNX symbolics from torch.onnx import ( # noqa: F401 _patch_torch, _type_utils, symbolic_helper, ...
pytorch-master
torch/onnx/symbolic_opset10.py
"""This file exports ONNX ops for opset 14. Note [ONNX operators that are added/updated in opset 14] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New operators: HardSwish, Trilu Updated operators: Reshape Add, Sub, Mul, Div GRU, LSTM, RNN BatchNorm, Cumsum, Relu """ # EDITING THIS FIL...
pytorch-master
torch/onnx/symbolic_opset14.py
"""Globals used internally by the ONNX exporter. Do not use this module outside of `torch.onnx` and its tests. Be very judicious when adding any new global variables. Do not create new global variables unless they are absolutely necessary. """ from typing import Optional import torch._C._onnx as _C_onnx # This mod...
pytorch-master
torch/onnx/_globals.py
from __future__ import annotations import functools import inspect import sys import typing import warnings from typing import Any, Callable, List, Optional, Sequence, Set, Tuple, Union from typing_extensions import Literal import torch import torch._C._onnx as _C_onnx from torch import _C # Monkey-patch graph mani...
pytorch-master
torch/onnx/symbolic_helper.py
"""This file exports ONNX ops for opset 9. Opset 9 is supported by ONNX release 1.4.1 release on 01/23/19 """ import functools import math import sys import warnings from typing import List, Optional, Sequence, Tuple, Union import torch import torch._C._onnx as _C_onnx import torch.nn.modules.utils import torch.onnx...
pytorch-master
torch/onnx/symbolic_opset9.py
"""Importing this patches torch._C classes to add ONNX conveniences.""" import numbers import re from typing import Any, Iterable, Tuple, Union import torch from torch import _C from torch._C import _onnx as _C_onnx from torch.onnx import _deprecation from torch.onnx._globals import GLOBALS # TODO(#78694): Refactor ...
pytorch-master
torch/onnx/_patch_torch.py
"""Utility for deprecating functions.""" import functools import warnings def deprecated(since: str, removed_in: str, instructions: str): """Marks functions as deprecated. It will result in a warning when the function is called. Args: since: The version when the function was first deprecated. ...
pytorch-master
torch/onnx/_deprecation.py
from __future__ import annotations from typing import Dict from torch import _C as _C class ExportTypes: r"""Specifies how the ONNX model is stored.""" PROTOBUF_FILE = "Saves model in the specified protobuf file." ZIP_ARCHIVE = "Saves model in the specified ZIP file (uncompressed)." COMPRESSED_ZIP_...
pytorch-master
torch/onnx/_exporter_states.py
"""ONNX exporter.""" import warnings from torch import _C from torch._C import _onnx as _C_onnx from torch._C._onnx import ( _CAFFE2_ATEN_FALLBACK, OperatorExportTypes, TensorProtoDataType, TrainingMode, ) from . import ( # usort:skip. Keep the order instead of sorting lexicographically _deprecat...
pytorch-master
torch/onnx/__init__.py
""" Note [ONNX operators that are added/updated from opset 8 to opset 9] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New operators: Compress ConstantOfShape EyeLike MaxUnpool OneHot Sinh Cosh Asinh Acosh Atanh Shrink IsNaN Sign Erf Sca...
pytorch-master
torch/onnx/symbolic_opset8.py
"""Functions to export models into the ONNX IR format. These models can be loaded with the ONNX library and then converted to models which run on other deep learning frameworks. """ from __future__ import annotations import contextlib import copy import inspect import io import itertools import os import re import te...
pytorch-master
torch/onnx/utils.py
"""Experimental classes and functions used by ONNX export.""" import dataclasses from typing import Mapping, Optional, Sequence, Set, Type, Union import torch import torch._C._onnx as _C_onnx @dataclasses.dataclass class ExportOptions: """Arguments used by :func:`torch.onnx.export`. TODO: Adopt this in `to...
pytorch-master
torch/onnx/_experimental.py
import importlib import inspect import itertools import warnings from typing import Any, Callable, Dict, Tuple, Union from torch import _C from torch.onnx import _constants, errors __all__ = [ "get_op_supported_version", "get_ops_in_version", "get_registered_op", "is_registered_op", "is_registered...
pytorch-master
torch/onnx/symbolic_registry.py
"""ONNX exporter exceptions.""" from __future__ import annotations import textwrap from typing import Optional from torch import _C from torch.onnx import _constants __all__ = [ "OnnxExporterError", "CheckerError", "UnsupportedOperatorError", "SymbolicValueError", ] class OnnxExporterError(RuntimeE...
pytorch-master
torch/onnx/errors.py
# EDITING THIS FILE? READ THIS FIRST! # see Note [Edit Symbolic Files] in symbolic_helper.py # This file exports ONNX ops for opset 13 import torch import torch._C._onnx as _C_onnx from torch.onnx import ( _type_utils, symbolic_helper, symbolic_opset11 as opset11, symbolic_opset9 as opset9, utils, ...
pytorch-master
torch/onnx/symbolic_opset13.py
r"""This file provides a location for operators that help exporting models via onnx. E.g. `shape_as_tensor` and `reshape_from_tensor_shape` are to make all dynamic sizes operations traceable. NOTE: at one point these functions were implemented differently. Since then we have implemented these directly in ATen, so thi...
pytorch-master
torch/onnx/operators.py
"""This file exports ONNX ops for opset 16. Note [ONNX Operators that are added/updated in opset 16] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://github.com/onnx/onnx/blob/main/docs/Changelog.md#version-16-of-the-default-onnx-operator-set New operators: GridSample https://github.com/onnx/onnx/...
pytorch-master
torch/onnx/symbolic_opset16.py
import sys from typing import Optional, Tuple import torch from torch._C import _onnx as _C_onnx from torch.onnx import _type_utils, symbolic_helper, symbolic_opset9 as opset9, utils # EDITING THIS FILE? READ THIS FIRST! # see Note [Edit Symbolic Files] in symbolic_helper.py # This file exports ONNX ops for opset 1...
pytorch-master
torch/onnx/symbolic_opset12.py
from . import amp
pytorch-master
torch/cpu/__init__.py
import torch from typing import Any class autocast(torch.amp.autocast_mode.autocast): r""" See :class:`torch.autocast`. ``torch.cpu.amp.autocast(args...)`` is equivalent to ``torch.autocast("cpu", args...)`` """ def __init__(self, enabled : bool = True, dtype : torch.dtype = torch.bfloat16, cache_e...
pytorch-master
torch/cpu/amp/autocast_mode.py
from .autocast_mode import autocast
pytorch-master
torch/cpu/amp/__init__.py
try: from urllib.parse import urlparse, urlunparse except ImportError: raise ImportError( "urllib cannot be found, urlparse from python2 is no longer supported." ) import numbers import os import sys from datetime import timedelta from typing import Dict, Optional import torch._six as six from tor...
pytorch-master
torch/distributed/rendezvous.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. """ ``torchrun`` provides a superset of the functionality as ``torch.distributed.launch``...
pytorch-master
torch/distributed/run.py
import contextlib import io import logging import os import pickle import time import warnings from datetime import timedelta from typing import Callable, Dict, Optional, Tuple, Union import torch from torch._C._distributed_c10d import ( AllreduceCoalescedOptions, AllreduceOptions, AllToAllOptions, Bar...
pytorch-master
torch/distributed/distributed_c10d.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os from argparse import Action class env(Action): """ Gets argument value...
pytorch-master
torch/distributed/argparse_util.py
from torch._C._distributed_c10d import _DEFAULT_PG_TIMEOUT # Default process group wide timeout, if applicable. # This only applies to the gloo and nccl backends # (only if NCCL_BLOCKING_WAIT or NCCL_ASYNC_ERROR_HANDLING is set to 1). # To make an attempt at backwards compatibility with THD, we use an # extraordinarily...
pytorch-master
torch/distributed/constants.py
import os import sys from enum import Enum import torch def is_available() -> bool: """ Returns ``True`` if the distributed package is available. Otherwise, ``torch.distributed`` does not expose any other APIs. Currently, ``torch.distributed`` is available on Linux, MacOS and Windows. Set ``USE_D...
pytorch-master
torch/distributed/__init__.py
r""" ``torch.distributed.launch`` is a module that spawns up multiple distributed training processes on each of the training nodes. .. warning:: This module is going to be deprecated in favor of :ref:`torchrun <launcher-api>`. The utility can be used for single-node distributed training, in which one or more pro...
pytorch-master
torch/distributed/launch.py
import collections import torch import torch.distributed as dist from torch.nn.parallel._functions import _get_stream from torch.nn.parallel.scatter_gather import ( # type: ignore[attr-defined] is_namedtuple as _is_namedtuple ) from typing import Dict, Any, List __all__ = [] # type: ignore[var-annotated] def _...
pytorch-master
torch/distributed/utils.py
from typing import Optional, Union import torch class _remote_device(object): """ Represents a device on a remote worker. Args: remote_device (str or torch.device): Represents a device on a remote worker. The string format should be one of the following: 1. "<workern...
pytorch-master
torch/distributed/remote_device.py
# Keep old package for BC purposes, this file should be removed once # everything moves to the `torch.distributed._shard` package. import sys import torch import warnings from torch.distributed._shard.sharding_spec import * # noqa: F403 warnings.warn( "torch.distributed._sharding_spec will be deprecated, use torc...
pytorch-master
torch/distributed/_sharding_spec/__init__.py
pytorch-master
torch/distributed/pipeline/__init__.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """Multithreading in pipeline parallelism.""" from contextlib import contextmanager from qu...
pytorch-master
torch/distributed/pipeline/sync/worker.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """Provides phony for arbitrary dependency in a autograd graph.""" from typing import Dict,...
pytorch-master
torch/distributed/pipeline/sync/phony.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """Checkpointing with preceding recomputation. PyTorch already provides the official check...
pytorch-master
torch/distributed/pipeline/sync/checkpoint.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """Tracks the running statistics per mini-batch instead of micro-batch.""" from typing impo...
pytorch-master
torch/distributed/pipeline/sync/batchnorm.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """A Pipe implementation in PyTorch.""" from .checkpoint import is_checkpointing, is_recomp...
pytorch-master
torch/distributed/pipeline/sync/__init__.py
# Copyright 2019 Kakao Brain # # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. """Autograd functions for stream-aware CUDA copy. It is used to overlap copy and computatio...
pytorch-master
torch/distributed/pipeline/sync/copy.py