repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
pytorch | pytorch-main/torch/nn/modules/_functions.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=t... | 11,825 | 39.920415 | 116 | py |
pytorch | pytorch-main/torch/nn/modules/channelshuffle.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 ... | 1,366 | 23.854545 | 72 | py |
pytorch | pytorch-main/torch/nn/modules/upsampling.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-cha... | 11,317 | 41.871212 | 113 | py |
pytorch | pytorch-main/torch/nn/modules/sparse.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... | 23,396 | 50.421978 | 127 | py |
pytorch | pytorch-main/torch/nn/modules/adaptive.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... | 12,100 | 37.538217 | 125 | py |
pytorch | pytorch-main/torch/nn/modules/loss.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',
... | 90,695 | 50.153976 | 131 | py |
pytorch | pytorch-main/torch/nn/modules/utils.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... | 2,391 | 29.666667 | 87 | py |
pytorch | pytorch-main/torch/nn/modules/module.py | from collections import OrderedDict, namedtuple
import itertools
import warnings
import functools
import weakref
import torch
from ..parameter import Parameter, Buffer
import torch.utils.hooks as hooks
from torch import Tensor, device, dtype
from typing import Union, Tuple, Any, Callable, Iterator, Set, Optional, ove... | 111,051 | 42.652516 | 161 | py |
pytorch | pytorch-main/torch/nn/modules/flatten.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`.
See :meth:`torch.flatten` for details.
... | 5,479 | 37.055556 | 115 | py |
pytorch | pytorch-main/torch/nn/modules/instancenorm.py |
import warnings
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__(
... | 19,978 | 44.928736 | 109 | py |
pytorch | pytorch-main/torch/nn/modules/linear.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',
'... | 10,561 | 38.856604 | 131 | py |
pytorch | pytorch-main/torch/nn/modules/dropout.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, ... | 11,090 | 38.052817 | 99 | py |
pytorch | pytorch-main/torch/nn/modules/transformer.py | import copy
from typing import Optional, Any, Union, Callable
import torch
import warnings
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... | 40,786 | 48.259662 | 132 | py |
pytorch | pytorch-main/torch/nn/modules/pixelshuffle.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... | 3,580 | 32.157407 | 116 | py |
pytorch | pytorch-main/torch/nn/modules/rnn.py | import math
import warnings
import numbers
import weakref
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', 'L... | 65,777 | 46.39049 | 131 | py |
pytorch | pytorch-main/torch/nn/modules/conv.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... | 72,606 | 44.294448 | 134 | py |
pytorch | pytorch-main/torch/nn/modules/normalization.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... | 11,223 | 37.83737 | 102 | py |
pytorch | pytorch-main/torch/nn/modules/lazy.py | import itertools
import warnings
from typing import Protocol
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.html#mixin-cla... | 11,592 | 42.912879 | 116 | py |
pytorch | pytorch-main/torch/nn/modules/distance.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 input vectors, or between columns of input matrices.
Distances are computed using ``p``-norm, ... | 3,247 | 35.909091 | 116 | py |
pytorch | pytorch-main/torch/nn/modules/padding.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... | 23,616 | 37.030596 | 128 | py |
pytorch | pytorch-main/torch/nn/modules/fold.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... | 12,787 | 41.065789 | 120 | py |
pytorch | pytorch-main/torch/nn/qat/__init__.py | # flake8: noqa: F401
r"""QAT Dynamic Modules
This package is in the process of being deprecated.
Please, use `torch.ao.nn.qat.dynamic` instead.
"""
from . import dynamic # noqa: F403
from . import modules # noqa: F403
from .modules import * # noqa: F403
__all__ = [
"Linear",
"Conv1d",
"Conv2d",
"Co... | 366 | 18.315789 | 51 | py |
pytorch | pytorch-main/torch/nn/qat/modules/embedding_ops.py | # flake8: noqa: F401
r"""QAT Modules
This file is in the process of migration to `torch/ao/nn/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/qat/modules`,
while adding an import ... | 505 | 32.733333 | 70 | py |
pytorch | pytorch-main/torch/nn/qat/modules/linear.py | # flake8: noqa: F401
r"""QAT Modules
This file is in the process of migration to `torch/ao/nn/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/qat/modules`,
while adding an import ... | 390 | 34.545455 | 70 | py |
pytorch | pytorch-main/torch/nn/qat/modules/__init__.py | # flake8: noqa: F401
r"""QAT Modules
This package is in the process of being deprecated.
Please, use `torch.ao.nn.qat.modules` instead.
"""
from torch.ao.nn.qat.modules.linear import Linear
from torch.ao.nn.qat.modules.conv import Conv1d
from torch.ao.nn.qat.modules.conv import Conv2d
from torch.ao.nn.qat.modules.conv... | 586 | 22.48 | 73 | py |
pytorch | pytorch-main/torch/nn/qat/modules/conv.py | # flake8: noqa: F401
r"""QAT Modules
This file is in the process of migration to `torch/ao/nn/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/qat/modules`,
while adding an import ... | 484 | 36.307692 | 70 | py |
pytorch | pytorch-main/torch/nn/qat/dynamic/__init__.py | # flake8: noqa: F401
r"""QAT Dynamic Modules
This package is in the process of being deprecated.
Please, use `torch.ao.nn.qat.dynamic` instead.
"""
from .modules import * # noqa: F403
| 186 | 22.375 | 51 | py |
pytorch | pytorch-main/torch/nn/qat/dynamic/modules/linear.py | # flake8: noqa: F401
r"""QAT Modules
This file is in the process of migration to `torch/ao/nn/qat/dynamic`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/qat/dynamic/modules`,
while a... | 414 | 36.727273 | 74 | py |
pytorch | pytorch-main/torch/nn/parallel/replicate.py | import torch
from ..modules import Module
from . import comm
from typing import TYPE_CHECKING, Dict, Iterator, List, Optional, Sequence, Set, TypeVar, Union, cast
from torch._utils import _get_device_index
from collections import OrderedDict
if TYPE_CHECKING:
import torch.jit
import torch.jit._state
__all__ ... | 6,757 | 35.139037 | 101 | py |
pytorch | pytorch-main/torch/nn/parallel/data_parallel.py | import operator
import torch
import warnings
from itertools import chain
from typing import Any, Dict, Generic, List, Optional, Sequence, Tuple, TypeVar, Union
from ..modules import Module
from .scatter_gather import scatter_kwargs, gather
from .replicate import replicate
from .parallel_apply import parallel_apply
from... | 11,560 | 41.818519 | 108 | py |
pytorch | pytorch-main/torch/nn/parallel/_functions.py | import warnings
import torch
from . import comm
from torch.autograd import Function
from torch._utils import _get_device_index
from typing import List, Optional
class Broadcast(Function):
@staticmethod
def forward(ctx, target_gpus, *inputs):
assert all(i.device.type != 'cpu' for i in inputs), (
... | 4,829 | 37.031496 | 98 | py |
pytorch | pytorch-main/torch/nn/parallel/comm.py | import warnings
import torch
from torch.cuda import nccl
from torch._utils import _take_tensors, _flatten_dense_tensors, \
_unflatten_dense_tensors, _reorder_tensors_as, _get_device_index, _handle_complex
from typing import List
def broadcast(tensor, devices=None, *, out=None):
r"""Broadcasts a tensor to speci... | 10,788 | 43.582645 | 106 | py |
pytorch | pytorch-main/torch/nn/parallel/scatter_gather.py | import torch
from typing import Any, Dict, List, Optional, Sequence, Tuple, TypeVar, Union, overload
from ._functions import Scatter, Gather
import warnings
__all__ = ['scatter', 'scatter_kwargs', 'gather']
def is_namedtuple(obj: Any) -> bool:
# Check if type was created from collections.namedtuple or a typing.Na... | 4,309 | 38.541284 | 99 | py |
pytorch | pytorch-main/torch/nn/parallel/distributed.py | import copy
import functools
import inspect
import itertools
import logging
import os
import sys
import warnings
import weakref
from collections import defaultdict, deque
from contextlib import contextmanager
from dataclasses import dataclass, fields, is_dataclass
from enum import auto, Enum
from typing import Any, Cal... | 100,538 | 43.983893 | 131 | py |
pytorch | pytorch-main/torch/nn/parallel/__init__.py | from .parallel_apply import parallel_apply
from .replicate import replicate
from .data_parallel import DataParallel, data_parallel
from .scatter_gather import gather, scatter
from .distributed import DistributedDataParallel
__all__ = ['replicate', 'scatter', 'parallel_apply', 'gather', 'data_parallel',
'Dat... | 645 | 42.066667 | 82 | py |
pytorch | pytorch-main/torch/nn/parallel/parallel_apply.py | import threading
import torch
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast
from ..modules import Module
from torch.cuda._utils import _get_device_index
from torch.cuda.amp import autocast
from torch._utils import ExceptionWrapper
__all__ = ['get_a_var', 'parallel_apply']
def get_a_var(ob... | 4,407 | 38.00885 | 130 | py |
pytorch | pytorch-main/torch/nn/quantizable/modules/activation.py | # flake8: noqa: F401
r"""Quantizable Modules
This file is in the process of migration to `torch/ao/nn/quantizable`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/quantizable/modules`,... | 438 | 38.909091 | 74 | py |
pytorch | pytorch-main/torch/nn/quantizable/modules/__init__.py | from torch.ao.nn.quantizable.modules.activation import MultiheadAttention
from torch.ao.nn.quantizable.modules.rnn import LSTM
from torch.ao.nn.quantizable.modules.rnn import LSTMCell
__all__ = [
'LSTM',
'LSTMCell',
'MultiheadAttention',
]
| 253 | 24.4 | 73 | py |
pytorch | pytorch-main/torch/nn/quantizable/modules/rnn.py | # flake8: noqa: F401
r"""Quantizable Modules
This file is in the process of migration to `torch/ao/nn/quantizable`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/quantizable/modules`,... | 474 | 38.583333 | 74 | py |
pytorch | pytorch-main/torch/nn/utils/memory_format.py | import torch
def convert_conv2d_weight_memory_format(module, memory_format):
r"""Convert ``memory_format`` of ``nn.Conv2d.weight`` to ``memory_format``
The conversion recursively applies to nested ``nn.Module``, including ``module``.
Note that it only changes the memory_format, but not the semantics of ea... | 3,891 | 52.315068 | 97 | py |
pytorch | pytorch-main/torch/nn/utils/clip_grad.py | import warnings
from typing import Union, Iterable, List, Dict, Tuple, Optional, cast
import torch
from torch import Tensor, inf
from torch.utils._foreach_utils import _group_tensors_by_device_and_dtype, _has_foreach_support
_tensor_or_tensors = Union[torch.Tensor, Iterable[torch.Tensor]]
__all__ = ['clip_grad_norm_... | 6,727 | 49.208955 | 119 | py |
pytorch | pytorch-main/torch/nn/utils/_named_member_accessor.py | # This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
from typing import Dict, Iterable, List, Tuple
import torch
_MISSING: torch.Tensor = object() # type: ignore[assignment]
def set_tensor(module: "torch.nn.Module", name: str, tensor: t... | 14,316 | 37.280749 | 92 | py |
pytorch | pytorch-main/torch/nn/utils/parametrize.py | import torch
from torch.nn.modules.container import ModuleList, ModuleDict, Module
from torch.nn.parameter import Parameter
from torch import Tensor
import collections
import copyreg
from copy import deepcopy
from contextlib import contextmanager
from typing import Union, Optional, Dict, Tuple, Sequence
__all__ = ['c... | 34,888 | 44.906579 | 130 | py |
pytorch | pytorch-main/torch/nn/utils/_deprecation_utils.py | from typing import List, Callable
import importlib
import warnings
_MESSAGE_TEMPLATE = r"Usage of '{old_location}' is deprecated; please use '{new_location}' instead."
def lazy_deprecated_import(all: List[str], old_module: str, new_module: str) -> Callable:
r"""Import utility to lazily import deprecated packages... | 1,646 | 34.804348 | 100 | py |
pytorch | pytorch-main/torch/nn/utils/fusion.py |
import copy
import torch
def fuse_conv_bn_eval(conv, bn, transpose=False):
assert(not (conv.training or bn.training)), "Fusion only for eval!"
fused_conv = copy.deepcopy(conv)
fused_conv.weight, fused_conv.bias = \
fuse_conv_bn_weights(fused_conv.weight, fused_conv.bias,
... | 2,097 | 36.464286 | 121 | py |
pytorch | pytorch-main/torch/nn/utils/stateless.py | import contextlib
import warnings
from collections import defaultdict
from typing import Any, Dict, Iterator, Optional, Set, Tuple, Union
import torch
from torch import Tensor
from torch.nn.utils._named_member_accessor import NamedMemberAccessor
__all__ = ["functional_call"]
def _untie_named_tensors_map(
module... | 10,893 | 40.422053 | 120 | py |
pytorch | pytorch-main/torch/nn/utils/spectral_norm.py | """
Spectral Normalization from https://arxiv.org/abs/1802.05957
"""
import torch
from torch.nn.functional import normalize
from typing import Any, Optional, TypeVar
from ..modules import Module
__all__ = ['SpectralNorm', 'SpectralNormLoadStateDictPreHook', 'SpectralNormStateDictHook',
'spectral_norm', 'rem... | 14,586 | 45.015773 | 121 | py |
pytorch | pytorch-main/torch/nn/utils/prune.py | r"""
Pruning methods
"""
import numbers
from abc import ABC, abstractmethod
from collections.abc import Iterable
from typing import Tuple
import torch
class BasePruningMethod(ABC):
r"""Abstract base class for creation of new pruning techniques.
Provides a skeleton for customization requiring the overriding ... | 56,985 | 40.809244 | 88 | py |
pytorch | pytorch-main/torch/nn/utils/convert_parameters.py | import torch
from typing import Iterable, Optional
def parameters_to_vector(parameters: Iterable[torch.Tensor]) -> torch.Tensor:
r"""Convert parameters to one vector
Args:
parameters (Iterable[Tensor]): an iterator of Tensors that are the
parameters of a model.
Returns:
The p... | 3,172 | 35.895349 | 98 | py |
pytorch | pytorch-main/torch/nn/utils/init.py | import inspect
import torch
def skip_init(module_cls, *args, **kwargs):
r"""
Given a module class object and args / kwargs, instantiates the module without initializing
parameters / buffers. This can be useful if initialization is slow or if custom initialization will
be performed, making the default... | 2,233 | 41.150943 | 104 | py |
pytorch | pytorch-main/torch/nn/utils/parametrizations.py | from enum import Enum, auto
import torch
from torch import Tensor
from ..utils import parametrize
from ..modules import Module
from .. import functional as F
from typing import Optional
__all__ = ['orthogonal', 'spectral_norm', 'weight_norm']
def _is_orthogonal(Q, eps=None):
n, k = Q.size(-2), Q.size(-1)
I... | 25,187 | 43.112084 | 121 | py |
pytorch | pytorch-main/torch/nn/utils/rnn.py | import warnings
from typing import Iterable, List, NamedTuple, Tuple, Union
import torch
from torch import Tensor
from ... import _VF
from ..._jit_internal import Optional
__all__ = ['PackedSequence', 'invert_permutation', 'pack_padded_sequence', 'pad_packed_sequence', 'pad_sequence',
'unpad_sequence', 'p... | 21,178 | 39.650672 | 130 | py |
pytorch | pytorch-main/torch/nn/utils/weight_norm.py | r"""
Weight Normalization from https://arxiv.org/abs/1602.07868
"""
from torch.nn.parameter import Parameter, UninitializedParameter
from torch import _weight_norm, norm_except_dim
from typing import Any, TypeVar
import warnings
from ..modules import Module
__all__ = ['WeightNorm', 'weight_norm', 'remove_weight_norm']... | 5,775 | 36.025641 | 122 | py |
pytorch | pytorch-main/torch/nn/utils/_per_sample_grad.py | import functools
import torch
from torch.nn.utils._expanded_weights.expanded_weights_impl import ExpandedWeight
from torch.utils._pytree import tree_flatten
# dependency on `functional_call` means that this can't be exposed in utils
# without creating circular dependency
def call_for_per_sample_grads(module, *, bat... | 5,899 | 54.140187 | 126 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/embedding_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 standard_kwargs, forward_helper, set_grad_sample_if_exists
from typing import List, Optional
@implements_per_sample_grads(F.embedding)
class EmbeddingPerSampleGrad(torch.auto... | 2,473 | 43.981818 | 121 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/expanded_weights_utils.py | from typing import Optional
import torch
from .expanded_weights_impl import ExpandedWeight
def is_batch_first(expanded_args_and_kwargs):
batch_first = None
for arg in expanded_args_and_kwargs:
if not isinstance(arg, ExpandedWeight):
continue
if not batch_first:
batch_f... | 7,260 | 49.776224 | 129 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/group_norm_expanded_weights.py | from functools import reduce
import operator
import torch
import torch.nn.functional as F
from .expanded_weights_impl import ExpandedWeight, implements_per_sample_grads
from .expanded_weights_utils import standard_kwargs, \
forward_helper, set_grad_sample_if_exists, unpack_expanded_weight_or_tensor
from typing impo... | 2,938 | 44.215385 | 130 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/conv_utils.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 conv... | 9,708 | 39.286307 | 131 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/instance_norm_expanded_weights.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_... | 3,249 | 52.278689 | 131 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/layer_norm_expanded_weights.py |
import torch
import torch.nn.functional as F
from .expanded_weights_impl import ExpandedWeight, implements_per_sample_grads
from .expanded_weights_utils import forward_helper, set_grad_sample_if_exists, \
standard_kwargs, sum_over_all_but_batch_and_last_n, unpack_expanded_weight_or_tensor
from typing import List, ... | 2,861 | 46.7 | 132 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/conv_expanded_weights.py | import torch
import torch.nn.functional as F
from .conv_utils import conv_backward, conv_args_and_kwargs, conv_picker, conv_input_for_string_padding
from .expanded_weights_impl import ExpandedWeight, implements_per_sample_grads
from .expanded_weights_utils import forward_helper
@implements_per_sample_grads(F.conv1d)
... | 2,448 | 45.207547 | 117 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/expanded_weights_impl.py | from contextlib import contextmanager
import torch
import functools
from torch._decomp import decomposition_table
from typing import Callable, Dict
from torch.utils._pytree import tree_map_only
HANDLED_FUNCTIONS: Dict[Callable, torch.autograd.Function] = {}
aten = torch._ops.ops.aten
# __torch_function__ runs befo... | 5,859 | 37.051948 | 114 | py |
pytorch | pytorch-main/torch/nn/utils/_expanded_weights/linear_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, is_batch_first
from typing import List, Optional
@implements_per_sample_grads(F.linear)
clas... | 2,072 | 45.066667 | 111 | py |
pytorch | pytorch-main/torch/nn/intrinsic/__init__.py | from torch.ao.nn.intrinsic import ConvBn1d
from torch.ao.nn.intrinsic import ConvBn2d
from torch.ao.nn.intrinsic import ConvBn3d
from torch.ao.nn.intrinsic import ConvBnReLU1d
from torch.ao.nn.intrinsic import ConvBnReLU2d
from torch.ao.nn.intrinsic import ConvBnReLU3d
from torch.ao.nn.intrinsic import ConvReLU1d
from ... | 1,072 | 28.805556 | 74 | py |
pytorch | pytorch-main/torch/nn/intrinsic/quantized/__init__.py | from .modules import * # noqa: F403
# to ensure customers can use the module below
# without importing it directly
import torch.nn.intrinsic.quantized.dynamic
__all__ = [
'BNReLU2d',
'BNReLU3d',
'ConvReLU1d',
'ConvReLU2d',
'ConvReLU3d',
'LinearReLU',
]
| 279 | 19 | 46 | py |
pytorch | pytorch-main/torch/nn/intrinsic/quantized/modules/bn_relu.py | from torch.ao.nn.intrinsic.quantized import BNReLU2d
from torch.ao.nn.intrinsic.quantized import BNReLU3d
__all__ = [
'BNReLU2d',
'BNReLU3d',
]
| 153 | 18.25 | 52 | py |
pytorch | pytorch-main/torch/nn/intrinsic/quantized/modules/conv_relu.py | from torch.ao.nn.intrinsic.quantized import ConvReLU1d
from torch.ao.nn.intrinsic.quantized import ConvReLU2d
from torch.ao.nn.intrinsic.quantized import ConvReLU3d
__all__ = [
'ConvReLU1d',
'ConvReLU2d',
'ConvReLU3d',
]
| 234 | 22.5 | 54 | py |
pytorch | pytorch-main/torch/nn/intrinsic/quantized/modules/linear_relu.py | from torch.ao.nn.intrinsic.quantized import LinearReLU
__all__ = [
'LinearReLU',
]
| 88 | 13.833333 | 54 | py |
pytorch | pytorch-main/torch/nn/intrinsic/quantized/dynamic/modules/linear_relu.py | from torch.ao.nn.intrinsic.quantized.dynamic import LinearReLU
__all__ = [
'LinearReLU',
]
| 96 | 15.166667 | 62 | py |
pytorch | pytorch-main/torch/nn/intrinsic/modules/fused.py | from torch.ao.nn.intrinsic import BNReLU2d
from torch.ao.nn.intrinsic import BNReLU3d
from torch.ao.nn.intrinsic import ConvBn1d
from torch.ao.nn.intrinsic import ConvBn2d
from torch.ao.nn.intrinsic import ConvBn3d
from torch.ao.nn.intrinsic import ConvBnReLU1d
from torch.ao.nn.intrinsic import ConvBnReLU2d
from torch.... | 901 | 28.096774 | 74 | py |
pytorch | pytorch-main/torch/nn/intrinsic/qat/modules/linear_fused.py | # flake8: noqa: F401
r"""Intrinsic QAT Modules
This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/intrinsic/qat/mod... | 453 | 27.375 | 76 | py |
pytorch | pytorch-main/torch/nn/intrinsic/qat/modules/conv_fused.py | # flake8: noqa: F401
r"""Intrinsic QAT Modules
This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/intrinsic/qat/mod... | 1,173 | 29.894737 | 76 | py |
pytorch | pytorch-main/torch/nn/intrinsic/qat/modules/linear_relu.py | # flake8: noqa: F401
r"""Intrinsic QAT Modules
This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and
is kept here for compatibility while the migration process is ongoing.
If you are adding a new entry/functionality, please, add it to the
appropriate file under the `torch/ao/nn/intrinsic/qat/mod... | 453 | 27.375 | 76 | py |
pytorch | pytorch-main/torch/_awaits/__init__.py | from __future__ import annotations
from typing import cast, Callable, Generic, Type, TypeVar
import torch
__all__ = ['Await']
W = TypeVar("W")
class _PyAwaitMeta(type(torch._C._Await), type(Generic)): # type: ignore[misc, no-redef]
pass
class _Await(torch._C._Await, Generic[W], metaclass=_PyAwaitMeta):
r... | 1,683 | 29.618182 | 103 | py |
pytorch | pytorch-main/torch/_inductor/inductor_prims.py | import logging
import torch
from torch import _prims
from torch._prims_common import RETURN_TYPE
log = logging.getLogger(__name__)
def make_prim(
schema,
impl_aten,
return_type=_prims.RETURN_TYPE.NEW,
doc="",
tags=None,
):
def meta(*args, **kwargs):
return _prims.TensorMeta(impl_aten... | 3,169 | 32.020833 | 121 | py |
pytorch | pytorch-main/torch/_inductor/fx_utils.py | import torch
# Check the pattern: (nn.module, F.function/torch.Tensor.method) matched.
# Works for length 2 patterns with 1 module and 1 function/method.
def matches_module_function_pattern(pattern, node, modules):
if len(node.args) == 0:
return False
if not isinstance(node.args[0], torch.fx.Node) or ... | 1,039 | 32.548387 | 73 | py |
pytorch | pytorch-main/torch/_inductor/index_propagation.py | """This file implements the IndexPropagation ops handler, which wraps an
underlying handler to add a limited form of constant propagation, as well as
propagation of sympy expressions downstream of ops.index_expr calls.
For example, say we have the IR:
tmp0 = ops.index_expr(x, torch.int32)
tmp1 = ops.constant(2,... | 6,955 | 31.203704 | 98 | py |
pytorch | pytorch-main/torch/_inductor/codecache.py | import base64
import dataclasses
import functools
import getpass
import hashlib
import importlib
import json
import logging
import multiprocessing
import os
import pathlib
import platform
import re
import shutil
import signal
import subprocess
import sys
import sysconfig
import tempfile
import threading
import types
im... | 44,286 | 33.789474 | 124 | py |
pytorch | pytorch-main/torch/_inductor/select_algorithm.py | import builtins
import functools
import inspect
import itertools
import logging
import sys
import textwrap
import time
from io import StringIO
from typing import Any, List
from unittest.mock import patch
import sympy
import torch
from torch._dynamo.testing import rand_strided
from torch._dynamo.utils import counters... | 29,844 | 31.475517 | 106 | py |
pytorch | pytorch-main/torch/_inductor/compile_fx.py | import contextlib
import dataclasses
import functools
import itertools
import logging
import sys
import unittest
import warnings
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, Sequence
from functorch.compile import min_cut_rematerialization_partition
import torch._functorch.confi... | 40,371 | 33.476516 | 102 | py |
pytorch | pytorch-main/torch/_inductor/autotune_process.py | import dataclasses
import queue
import time
import warnings
from typing import Any, Dict, List
import torch
from torch import multiprocessing
from torch._dynamo.testing import rand_strided
from torch._inductor import ir
from torch._inductor.codecache import PyCodeCache
from .utils import do_bench
from .virtualized i... | 6,650 | 27.182203 | 172 | py |
pytorch | pytorch-main/torch/_inductor/utils.py | import collections
import contextlib
import dataclasses
import functools
import inspect
import itertools
import logging
import math
import operator
import os
import shutil
import sys
import tempfile
import textwrap
import time
from collections import defaultdict
from io import StringIO
from typing import Any, Dict, Ite... | 38,428 | 29.40269 | 126 | py |
pytorch | pytorch-main/torch/_inductor/lowering.py | import functools
import itertools
import logging
import os
import warnings
from collections import defaultdict
from collections.abc import Iterable
from typing import List, Optional, Tuple
import sympy
import torch
import torch.fx
import torch.utils._pytree as pytree
from torch._prims_common import (
canonicalize... | 146,644 | 31.279331 | 117 | py |
pytorch | pytorch-main/torch/_inductor/graph.py | import hashlib
import logging
import operator
import os
import re
import sys
import time
from contextlib import contextmanager
from typing import Dict, List, Optional, Set, Tuple
import sympy
import torch
import torch._logging
import torch.fx
from torch._decomp import get_decompositions
from torch._dynamo.utils impor... | 38,564 | 39.68038 | 132 | py |
pytorch | pytorch-main/torch/_inductor/test_operators.py | import torch.library
from torch import Tensor
from torch.autograd import Function
_test_lib_def = torch.library.Library("_inductor_test", "DEF")
_test_lib_def.define("realize(Tensor self) -> Tensor")
_test_lib_impl = torch.library.Library("_inductor_test", "IMPL")
for dispatch_key in ("CPU", "CUDA", "Meta"):
_tes... | 649 | 25 | 69 | py |
pytorch | pytorch-main/torch/_inductor/scheduler.py | import collections
import dataclasses
import functools
import itertools
import logging
import os
import pprint
import textwrap
from typing import Dict, List, Optional, Set
import sympy
import torch
from torch._dynamo.utils import dynamo_timed
from . import config, dependencies, ir, metrics
from .dependencies import ... | 54,462 | 36.483138 | 293 | py |
pytorch | pytorch-main/torch/_inductor/sizevars.py | import functools
import itertools
import logging
from typing import Callable, Dict, List, Tuple, Union
import sympy
from sympy import Expr
from torch.fx.experimental.symbolic_shapes import ShapeEnv
from torch.utils._sympy.functions import FloorDiv, ModularIndexing
from .utils import sympy_subs, sympy_symbol, VarRang... | 21,017 | 36.599284 | 118 | py |
pytorch | pytorch-main/torch/_inductor/pattern_matcher.py | import dataclasses
import functools
import inspect
import itertools
import logging
import os
import re
from collections import defaultdict
from typing import Any, Callable, Dict, List, Optional, Union
import torch
import torch._guards
import torch.fx
import torch.utils._pytree as pytree
from torch._dynamo.utils import... | 36,364 | 31.181416 | 106 | py |
pytorch | pytorch-main/torch/_inductor/bounds.py | import math
from functools import partial
from typing import Dict, Optional
import torch
from torch.fx.experimental.symbolic_shapes import free_symbols
from torch.utils._sympy.value_ranges import bound_sympy, ValueRangeAnalysis, ValueRanges
from .ir import InterpreterShim, LoopBody
from .utils import cache_on_self, do... | 4,317 | 40.92233 | 96 | py |
pytorch | pytorch-main/torch/_inductor/exc.py | import os
import tempfile
import textwrap
from functools import lru_cache
if os.environ.get("TORCHINDUCTOR_WRITE_MISSING_OPS") == "1":
@lru_cache(None)
def _record_missing_op(target):
with open(f"{tempfile.gettempdir()}/missing_ops.txt", "a") as fd:
fd.write(str(target) + "\n")
else:
... | 2,357 | 26.741176 | 91 | py |
pytorch | pytorch-main/torch/_inductor/ir.py | import collections
import contextlib
import dataclasses
import functools
import itertools
import logging
import re
import textwrap
import traceback
from contextlib import nullcontext
from enum import Enum
from functools import partial
from inspect import signature
from typing import (
Any,
Callable,
ClassVa... | 168,569 | 31.891707 | 128 | py |
pytorch | pytorch-main/torch/_inductor/config.py | import os
import sys
import torch
# add some debug printouts
debug = False
# Whether to disable a progress bar for autotuning
disable_progress = True
# Whether to enable printing the source code for each future
verbose_progress = False
# use cpp wrapper instead of python wrapper
cpp_wrapper = False
# dead code el... | 13,626 | 31.522673 | 105 | py |
pytorch | pytorch-main/torch/_inductor/triton_heuristics.py | import builtins
import copy
import functools
import hashlib
import inspect
import json
import logging
import operator
import os
import os.path
import re
import threading
from enum import auto, Enum
from typing import List, Set
import torch
from torch._dynamo.utils import dynamo_timed
from . import config
from .codeca... | 33,489 | 32.590772 | 125 | py |
pytorch | pytorch-main/torch/_inductor/decomposition.py | import functools
import logging
import math
import numbers
import torch
import torch._decomp as decomp
import torch.ao.quantization.fx._decomposed
from torch._decomp import core_aten_decompositions, get_decompositions
from torch._decomp.decompositions import pw_cast_for_opmath
from torch._decomp.decompositions_for_rng... | 10,536 | 26.656168 | 90 | py |
pytorch | pytorch-main/torch/_inductor/cudagraph_trees.py | """
CUDA graph trees are a safety abstraction over CUDAGraphs, similar to make_graph_callables,
which share the same memory pool. Sharing a memory pool is an extremely
important optimization when chaining multiple CUDA graphs together, as it
prevents you from needing to copy intermediate tensors from one graph to the
... | 83,471 | 38.078652 | 122 | py |
pytorch | pytorch-main/torch/_inductor/__init__.py | from typing import Any, Dict, List, Optional
import torch.fx
__all__ = ["compile", "list_mode_options", "list_options", "cudagraph_mark_step_begin"]
def compile(
gm: torch.fx.GraphModule,
example_inputs: List[torch.Tensor],
options: Optional[Dict[str, Any]] = None,
):
"""
Compile a given FX grap... | 3,138 | 26.778761 | 87 | py |
pytorch | pytorch-main/torch/_inductor/virtualized.py | import itertools
from contextlib import contextmanager
from itertools import chain
from threading import local
from typing import Any
from unittest.mock import patch
import sympy
from torch._inductor.utils import IndentedBuffer
from torch.fx.graph import inplace_methods, magic_methods
from .utils import sympy_str, ... | 7,828 | 25.449324 | 81 | py |
pytorch | pytorch-main/torch/_inductor/debug.py | import collections
import contextlib
import cProfile
import functools
import itertools
import logging
import os.path
import pstats
import shutil
import subprocess
from typing import Any, List
from unittest.mock import patch
from functorch.compile import draw_graph, get_aot_graph_name, get_graph_being_compiled
import ... | 11,543 | 28.906736 | 86 | py |
pytorch | pytorch-main/torch/_inductor/cuda_properties.py | import functools
import torch
# API to query cuda properties that will work in a triton compile process
# that cannot use the GPU APIs (due to processing fork() and initialization
# time issues). Properties are recorded in the main process before
# we fork the workers.
@functools.lru_cache(None)
def _properties():... | 1,309 | 22.818182 | 75 | py |
pytorch | pytorch-main/torch/_inductor/freezing.py | import itertools
import unittest
import weakref
from typing import List, Optional, Tuple
import torch
import torch.fx.traceback as fx_traceback
import torch.utils._pytree as pytree
from torch._dynamo.utils import detect_fake_mode, dynamo_timed
from torch._functorch.compile_utils import fx_graph_cse
from torch._induc... | 13,726 | 34.197436 | 125 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.