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/_inductor/optimize_indexing.py | import math
import sympy
import torch
from torch.utils._sympy.value_ranges import ValueRanges
from .ir import LoopBody
from .utils import dominated_nodes
def val_expressable_in_32_bits(val):
if hasattr(val, "is_Boolean") and val.is_Boolean:
return True
if isinstance(val, sympy.Expr):
assert... | 3,881 | 31.621849 | 93 | py |
pytorch | pytorch-main/torch/_inductor/dependencies.py | import collections
import dataclasses
import itertools
import logging
import re
import typing
from typing import Callable, Dict, List, Optional, Set, Tuple, Union
import sympy
import torch
from .codegen.common import index_prevent_reordering
from .utils import get_dtype_size, sympy_str, sympy_subs, sympy_symbol, Var... | 11,098 | 31.644118 | 107 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/quantization.py | import torch
from ..ir import QConv
from ..pattern_matcher import Arg, CallFunction, KeywordArg, Match
from .post_grad import register_lowering_pattern
aten = torch.ops.aten
prims = torch.ops.prims
quantized_decomposed = torch.ops.quantized_decomposed
dequantize_per_channel = quantized_decomposed.dequantize_per_channe... | 3,915 | 26.006897 | 78 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/post_grad.py | import functools
import itertools
import logging
import operator
import torch
import torch._inductor as inductor
from .. import config, ir, pattern_matcher
from ..lowering import lowerings as L
from ..pattern_matcher import (
_return_true,
Arg,
CallFunction,
filter_nodes,
get_arg_value,
Ignor... | 13,985 | 27.896694 | 102 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/fuse_attention.py | import functools
import logging
import math
import torch
from ..._dynamo.utils import counters
from ..pattern_matcher import (
filter_nodes,
inference_graph,
register_replacement,
training_graph,
)
log = logging.getLogger(__name__)
aten = torch.ops.aten
def _sfdp_pattern_1(query, key, value, inv_sca... | 12,142 | 28.260241 | 102 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/group_batch_fusion.py | import collections
import logging
import operator
import torch
from torch._dynamo.utils import counters
from .. import config
from ..pattern_matcher import CallFunctionVarArgs
try:
# importing this will register fbgemm lowerings for inductor
import deeplearning.fbgemm.fbgemm_gpu.fb.inductor_lowerings # noqa... | 5,346 | 26.994764 | 90 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/replace_random.py | import collections
import logging
import torch
from torch.fx.passes.shape_prop import _extract_tensor_metadata
from .. import config, inductor_prims
from ..pattern_matcher import (
CallFunctionVarArgs,
Match,
PatternMatcherPass,
register_graph_pattern,
)
from ..virtualized import V
log = logging.getL... | 3,525 | 26.984127 | 86 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/mkldnn_fusion.py | import functools
from functools import reduce
import torch
from torch.fx.experimental.symbolic_shapes import free_symbols
from .. import ir
from ..lowering import lowerings as L
from ..pattern_matcher import Arg, CallFunction, filter_nodes, get_arg_value, KeywordArg
from ..virtualized import ops
from .freezing_patt... | 36,170 | 38.103784 | 110 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/pad_mm.py | import functools
from itertools import chain
from typing import Optional
import torch
from torch import Tensor
from torch._inductor import utils
from torch.utils._mode_utils import no_dispatch
from ..pattern_matcher import inference_graph, register_replacement, training_graph
aten = torch.ops.aten
def fetch_fake_t... | 14,288 | 30.335526 | 119 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/freezing_patterns.py | import functools
import torch
from .. import config
from ..pattern_matcher import (
_return_true,
inference_graph,
init_once_fakemode,
PatternMatcherPass,
register_graph_pattern,
register_replacement,
stable_topological_sort,
)
aten = torch.ops.aten
# First pass_patterns[0] are applied, t... | 3,192 | 25.38843 | 86 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/pre_grad.py | import copy
import logging
from typing import List, Optional
import torch
import torch.nn as nn
from torch._dynamo.utils import detect_fake_mode
from torch.fx.experimental.optimization import (
matches_module_pattern,
replace_node_module,
)
from torch.fx.passes.shape_prop import ShapeProp
from torch.nn import ... | 15,788 | 33.398693 | 88 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/split_cat.py | import logging
import operator
from typing import Callable, List, Sequence, Tuple, Union
import numpy
import torch
from torch._dynamo.utils import counters
from ..pattern_matcher import (
Arg,
CallFunction,
CallFunctionVarArgs,
CallMethodVarArgs,
config_flag,
FailedMatch,
get_arg_value,
... | 36,551 | 36.45082 | 122 | py |
pytorch | pytorch-main/torch/_inductor/fx_passes/joint_graph.py | import logging
from collections import Counter
from typing import Set
import torch
import torch._guards
from .. import config
from ..pattern_matcher import (
CallFunction,
init_once_fakemode,
KeywordArg,
Match,
PatternMatcherPass,
register_graph_pattern,
stable_topological_sort,
)
from .rep... | 8,021 | 30.582677 | 128 | py |
pytorch | pytorch-main/torch/_inductor/codegen/triton_foreach.py | import itertools
from .. import metrics
from ..utils import ceildiv, sympy_product
from ..virtualized import V
from .common import IndentedBuffer, Kernel
from .triton import TritonKernel
from .triton_utils import config_of, signature_of
class ForeachKernel(Kernel):
MAX_NUM_ARGS = 250 # number where I would no l... | 5,586 | 34.138365 | 90 | py |
pytorch | pytorch-main/torch/_inductor/codegen/wrapper.py | import collections
import contextlib
import dataclasses
import functools
import os
import re
from itertools import count
from typing import Any, Dict, List, Optional, Tuple
import sympy
from sympy import Expr
import torch
from torch._dynamo.utils import counters, dynamo_timed
from torch.fx.experimental.symbolic_shape... | 50,833 | 35.15505 | 123 | py |
pytorch | pytorch-main/torch/_inductor/codegen/common.py | import contextlib
import dataclasses
import functools
import itertools
import logging
import re
import typing
from collections import namedtuple
from itertools import chain
import sympy
from sympy.printing.printer import Printer
import torch
import torch.fx
from torch.utils._sympy.value_ranges import ValueRanges
fro... | 31,157 | 31.728992 | 128 | py |
pytorch | pytorch-main/torch/_inductor/codegen/triton.py | import collections
import contextlib
import dataclasses
import functools
import itertools
import logging
import math
import operator
from typing import Dict, Iterable, List, Set
import sympy
import torch
import torch._logging
from torch._prims_common import is_integer_dtype
from torch.utils._sympy.functions import F... | 97,009 | 36.311538 | 246 | py |
pytorch | pytorch-main/torch/_inductor/codegen/cpp.py | import contextlib
import dataclasses
import functools
import itertools
import logging
import math
import re
import sys
from copy import copy, deepcopy
from typing import Dict, List
import numpy
import sympy
import torch
import torch.fx
from torch._inductor import dependencies
from torch._inductor.ir import StorageBox... | 113,666 | 35.548875 | 131 | py |
pytorch | pytorch-main/torch/_inductor/kernel/bmm.py | import torch
from ..lowering import register_lowering
from ..select_algorithm import (
autotune_select_algorithm,
ExternKernelChoice,
TritonTemplate,
)
from ..utils import ceildiv as cdiv, use_triton_template
from .mm_common import addmm_epilogue, mm_args, mm_configs, mm_options
aten = torch.ops.aten
d... | 4,037 | 31.304 | 84 | py |
pytorch | pytorch-main/torch/_inductor/kernel/mm.py | import logging
import torch
from .. import config as inductor_config
from ..lowering import register_lowering
from ..select_algorithm import (
autotune_select_algorithm,
ExternKernelChoice,
TritonTemplate,
)
from ..utils import use_triton_template
from .mm_common import (
addmm_epilogue,
int8_mm_co... | 5,907 | 29.770833 | 87 | py |
pytorch | pytorch-main/torch/_inductor/kernel/mm_plus_mm.py | import functools
import torch
from ..lowering import lowerings
from ..select_algorithm import (
autotune_select_algorithm,
ExternKernelChoice,
TritonTemplate,
)
from ..utils import use_triton_template
from ..virtualized import V
from .mm_common import mm_args, mm_grid, mm_options
aten = torch.ops.aten
at... | 5,989 | 32.841808 | 86 | py |
pytorch | pytorch-main/torch/_inductor/kernel/mm_common.py | import functools
import logging
from typing import List, Tuple
import sympy
import torch
from torch._inductor.select_algorithm import realize_inputs
from torch._inductor.virtualized import V
from ..utils import ceildiv as cdiv, next_power_of_2
log = logging.getLogger(__name__)
def triton_config(num_stages, num_war... | 4,582 | 27.823899 | 80 | py |
pytorch | pytorch-main/torch/_inductor/kernel/conv.py | import functools
import logging
from typing import List
import torch
from .. import config, ir
from ..ir import TensorBox
from ..lowering import (
add_layout_constraint,
constrain_to_fx_strides,
lowerings as L,
register_lowering,
)
from ..select_algorithm import (
autotune_select_algorithm,
Ex... | 12,778 | 27.524554 | 87 | py |
pytorch | pytorch-main/torch/sparse/_triton_ops.py | import math
import torch
from torch._inductor.cuda_properties import get_device_capability
def _has_triton():
if not torch.cuda.is_available():
return False
try:
import triton
return triton is not None and get_device_capability() >= (7, 0)
except ImportError:
return False... | 31,607 | 34.003322 | 122 | py |
pytorch | pytorch-main/torch/sparse/_semi_structured_conversions.py | import torch
def _sparse_semi_structured_from_dense(dense):
if dense.dim() != 2:
raise RuntimeError(
f"Expected 2-dimensional dense tensor, got {dense.dim()}-dimensional tensor"
)
m, k = dense.shape
device = dense.device
meta_dtype = torch.int8
if dense.dtype == torch... | 13,363 | 38.538462 | 121 | py |
pytorch | pytorch-main/torch/sparse/__init__.py | # The Tensor classes are added to this module by python_tensor.cpp
from typing import Optional, Tuple, List, Union
import torch
from torch._C import _add_docstr, _sparse # type: ignore[attr-defined]
from torch import Tensor
# Semi structured sparsity support
from .semi_structured import SparseSemiStructuredTensor, t... | 17,913 | 34.971888 | 119 | py |
pytorch | pytorch-main/torch/sparse/semi_structured.py | import warnings
from collections import namedtuple
from typing import Any, Optional
import torch
__all__ = [
"SparseSemiStructuredTensor",
"to_sparse_semi_structured",
]
_SEMI_STRUCTURED_SPARSE_CONFIG = namedtuple(
"_SEMI_STRUCTURED_SPARSE_CONFIG", "compression_factor min_rows min_cols"
)
_DTYPE_TO_SEMI_... | 17,087 | 42.370558 | 129 | py |
pytorch | pytorch-main/torch/multiprocessing/spawn.py |
from typing import Optional
import multiprocessing
import multiprocessing.connection
import signal
import sys
import warnings
from . import _prctl_pr_set_pdeathsig # type: ignore[attr-defined]
class ProcessException(Exception):
__slots__ = ["error_index", "error_pid"]
def __init__(self, msg: str, error_in... | 8,649 | 35.041667 | 90 | py |
pytorch | pytorch-main/torch/multiprocessing/reductions.py | import torch
import torch.utils.hooks
from torch._namedtensor_internals import check_serializing_named_tensor
import os
import threading
import multiprocessing
from multiprocessing.util import register_after_fork
from multiprocessing.reduction import ForkingPickler
from typing import Union
try:
# Early load resour... | 16,943 | 40.837037 | 121 | py |
pytorch | pytorch-main/torch/multiprocessing/__init__.py | """
torch.multiprocessing is a wrapper around the native :mod:`multiprocessing`
module. It registers custom reducers, that use shared memory to provide shared
views on the same data in different processes. Once the tensor/storage is moved
to shared_memory (see :func:`~torch.Tensor.share_memory_`), it will be possible
t... | 2,477 | 32.945205 | 79 | py |
pytorch | pytorch-main/torch/testing/_creation.py | """
This module contains tensor creation utilities.
"""
import collections.abc
import math
import warnings
from typing import cast, List, Optional, Tuple, Union
import torch
_INTEGRAL_TYPES = [torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64]
_FLOATING_TYPES = [torch.float16, torch.bfloat16, torch.floa... | 11,216 | 45.543568 | 120 | py |
pytorch | pytorch-main/torch/testing/_comparison.py | import abc
import cmath
import collections.abc
import contextlib
import warnings
from typing import (
Any,
Callable,
Collection,
Dict,
List,
NoReturn,
Optional,
Sequence,
Tuple,
Type,
Union,
)
import torch
try:
import numpy as np
NUMPY_AVAILABLE = True
except Modul... | 61,901 | 38.579284 | 123 | py |
pytorch | pytorch-main/torch/testing/__init__.py | from torch._C import FileCheck as FileCheck
from ._comparison import assert_allclose, assert_close as assert_close
from ._creation import make_tensor as make_tensor
| 165 | 40.5 | 70 | py |
pytorch | pytorch-main/torch/testing/_internal/logging_utils.py | import torch._dynamo.test_case
import unittest.mock
import os
import contextlib
import torch._logging
import torch._logging._internal
import logging
@contextlib.contextmanager
def preserve_log_state():
prev_state = torch._logging._internal._get_log_state()
torch._logging._internal._set_log_state(torch._logging... | 4,986 | 31.174194 | 122 | py |
pytorch | pytorch-main/torch/testing/_internal/autograd_function_db.py | import torch
from functools import partial
from torch.testing import make_tensor
from torch.testing._internal.opinfo.core import (
OpInfo,
SampleInput,
)
from torch.testing._internal.common_dtype import all_types_and
import numpy as np
# Note: [autograd.Function db]
#
# This is a collection of autograd.Functio... | 18,134 | 29.841837 | 96 | py |
pytorch | pytorch-main/torch/testing/_internal/hypothesis_utils.py | from collections import defaultdict
from collections.abc import Iterable
import numpy as np
import torch
import hypothesis
from functools import reduce
from hypothesis import assume
from hypothesis import settings
from hypothesis import strategies as st
from hypothesis.extra import numpy as stnp
from hypothesis.strate... | 14,671 | 38.654054 | 119 | py |
pytorch | pytorch-main/torch/testing/_internal/common_pruning.py | # -*- coding: utf-8 -*-
# Owner(s): ["module: unknown"]
from torch.ao.pruning import BaseSparsifier
import torch
import torch.nn.functional as F
from torch import nn
class ImplementedSparsifier(BaseSparsifier):
def __init__(self, **kwargs):
super().__init__(defaults=kwargs)
def update_mask(self, modu... | 12,946 | 32.541451 | 107 | py |
pytorch | pytorch-main/torch/testing/_internal/common_nn.py | from abc import abstractmethod
import tempfile
import unittest
from copy import deepcopy
from functools import reduce, partial, wraps
from itertools import product
from operator import mul
from math import pi
import torch
import torch.cuda
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import _r... | 199,751 | 41.02651 | 132 | py |
pytorch | pytorch-main/torch/testing/_internal/common_jit.py | # Torch
import torch
import torch.cuda
import torch.jit
import torch.jit._logging
import torch.jit.frontend
import torch.jit.quantized
# Testing utils
from torch.testing._internal.common_dtype import floating_and_complex_types_and
from torch.testing._internal.common_utils import TestCase, \
freeze_rng_state, Tempo... | 15,830 | 48.164596 | 111 | py |
pytorch | pytorch-main/torch/testing/_internal/common_device_type.py | import copy
import gc
import inspect
import runpy
import sys
import threading
from collections import namedtuple
from enum import Enum
from functools import wraps, partial
from typing import List, Any, ClassVar, Optional, Sequence, Tuple, Union, Dict, Set
import unittest
import os
import torch
from torch.testing._inter... | 60,238 | 40.401375 | 130 | py |
pytorch | pytorch-main/torch/testing/_internal/jit_metaprogramming_utils.py | # Torch
from torch.jit.annotations import BroadcastingList2, BroadcastingList3 # noqa: F401
import torch.nn.functional as F
import torch
import torch.cuda
import torch.jit
import torch.jit._logging
import torch.jit.frontend
from torch.testing._internal.common_nn import module_tests, new_module_tests
from torch.testing... | 32,616 | 44.682073 | 124 | py |
pytorch | pytorch-main/torch/testing/_internal/common_subclass.py | import torch
from copy import deepcopy
from torch.utils._pytree import tree_map
# TODO: Move LoggingTensor here.
from torch.testing._internal.logging_tensor import LoggingTensor
# Base class for wrapper-style tensors.
class WrapperTensor(torch.Tensor):
@staticmethod
def __new__(cls, *args, **kwargs):
... | 8,028 | 35.495455 | 113 | py |
pytorch | pytorch-main/torch/testing/_internal/composite_compliance.py | import torch
from torch import Tensor
import itertools
from torch.utils._python_dispatch import TorchDispatchMode
from torch.utils._pytree import tree_map, tree_flatten, tree_unflatten
from functools import partial
from torch.utils._mode_utils import no_dispatch, all_same_mode
import torch.autograd.forward_ad as fwAD
... | 25,066 | 42.368512 | 114 | py |
pytorch | pytorch-main/torch/testing/_internal/dist_utils.py | import re
import sys
import time
from functools import partial, wraps
from typing import Tuple
import torch.distributed as dist
import torch.distributed.rpc as rpc
from torch.distributed.rpc import _rref_context_get_debug_info
from torch.testing._internal.common_utils import FILE_SCHEMA, TEST_WITH_TSAN
if not dist.i... | 7,400 | 35.102439 | 123 | py |
pytorch | pytorch-main/torch/testing/_internal/custom_op_db.py | import torch
import functools
from torch.testing import make_tensor
from torch.testing._internal.opinfo.core import (
OpInfo,
SampleInput,
)
from torch.testing._internal.common_dtype import all_types_and
import numpy as np
from torch._custom_op.impl import custom_op
from torch.testing._internal.autograd_functio... | 12,449 | 31.170543 | 108 | py |
pytorch | pytorch-main/torch/testing/_internal/common_dtype.py | from typing import List
import torch
# Functions and classes for describing the dtypes a function supports
# NOTE: these helpers should correspond to PyTorch's C++ dispatch macros
# Verifies each given dtype is a torch.dtype
def _validate_dtypes(*dtypes):
for dtype in dtypes:
assert isinstance(dtype, to... | 4,225 | 32.015625 | 125 | py |
pytorch | pytorch-main/torch/testing/_internal/common_cuda.py | r"""This file is allowed to initialize CUDA context when imported."""
import functools
import torch
import torch.cuda
from torch.testing._internal.common_utils import LazyVal, TEST_NUMBA, TEST_WITH_ROCM
import inspect
import contextlib
CUDA_ALREADY_INITIALIZED_ON_IMPORT = torch.cuda.is_initialized()
TEST_CUDA = to... | 9,538 | 38.912134 | 120 | py |
pytorch | pytorch-main/torch/testing/_internal/common_utils.py | r"""Importing this file must **not** initialize CUDA context. test_distributed
relies on this assumption to properly run. This means that when this is imported
no CUDA calls shall be made, including torch.cuda.device_count(), etc.
torch.testing._internal.common_cuda.py can freely initialize CUDA context when imported.... | 198,911 | 42.082521 | 143 | py |
pytorch | pytorch-main/torch/testing/_internal/common_quantized.py | r"""Importing this file includes common utility methods for checking quantized
tensors and modules.
"""
import numpy as np
import torch
from contextlib import contextmanager
from torch.testing._internal.common_utils import TEST_WITH_ASAN, TEST_WITH_TSAN, TEST_WITH_UBSAN, IS_PPC, IS_MACOS, IS_WINDOWS
supported_qengines... | 8,680 | 37.411504 | 131 | py |
pytorch | pytorch-main/torch/testing/_internal/common_modules.py | import torch
import unittest
from copy import deepcopy
from enum import Enum
from functools import wraps, partial
from itertools import chain, product
import itertools
import math
import torch.nn.functional as F
from torch.nn.utils.rnn import pack_padded_sequence
from torch.testing import make_tensor
from torch.testing... | 156,926 | 49.264894 | 126 | py |
pytorch | pytorch-main/torch/testing/_internal/common_methods_invocations.py | from functools import wraps, partial
from itertools import product, chain, islice
import itertools
import functools
import copy
import operator
import random
import unittest
import math
import enum
import torch
import numpy as np
from torch import inf, nan
from typing import Any, Dict, List, Tuple, Union, Sequence
fr... | 1,009,255 | 47.58499 | 160 | py |
pytorch | pytorch-main/torch/testing/_internal/control_flow_opinfo_db.py | import torch
import functools
from torch.testing import make_tensor
from functorch.experimental.control_flow import map
from torch.testing._internal.opinfo.core import (
OpInfo,
SampleInput,
)
from torch.testing._internal.common_dtype import all_types_and
def sample_inputs_map(opinfo, device, dtype, requires_g... | 2,445 | 31.184211 | 95 | py |
pytorch | pytorch-main/torch/testing/_internal/quantization_torch_package_models.py | import math
import torch
import torch.nn as nn
class LinearReluFunctionalChild(nn.Module):
def __init__(self, N):
super().__init__()
self.w1 = nn.Parameter(torch.empty(N, N))
self.b1 = nn.Parameter(torch.zeros(N))
torch.nn.init.kaiming_uniform_(self.w1, a=math.sqrt(5))
def fo... | 928 | 28.03125 | 63 | py |
pytorch | pytorch-main/torch/testing/_internal/jit_utils.py | # Torch
from torch.autograd import Variable
from torch.autograd.function import _nested_map
from torch.jit.annotations import BroadcastingList2, BroadcastingList3 # noqa: F401
from torch.onnx import OperatorExportTypes
import torch
import torch.cuda
import torch.jit
import torch.jit._logging
import torch.jit.frontend... | 34,197 | 37.210056 | 124 | py |
pytorch | pytorch-main/torch/testing/_internal/common_distributed.py | import faulthandler
import logging
import multiprocessing
import os
import queue
import subprocess
import sys
import tempfile
import threading
import time
import traceback
import types
import unittest
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import timedelta
from enum import... | 45,186 | 34.720949 | 115 | py |
pytorch | pytorch-main/torch/testing/_internal/common_dist_composable.py | # Owner(s): ["oncall: distributed"]
from typing import Tuple
import torch
import torch.nn as nn
class UnitModule(nn.Module):
def __init__(self, device: torch.device):
super().__init__()
self.l1 = nn.Linear(100, 100, device=device)
self.seq = nn.Sequential(
nn.ReLU(),
... | 3,283 | 29.691589 | 78 | py |
pytorch | pytorch-main/torch/testing/_internal/autocast_test_lists.py | import torch
from torch.testing._internal.common_utils import TEST_WITH_ROCM
class AutocastTestLists:
def _rnn_cell_args(self, n, num_chunks, is_lstm, dev, dtype):
input = (torch.randn((n, n), device=dev, dtype=torch.float32),)
hx = ((torch.randn((n, n), device=dev, dtype=torch.float32),
... | 22,360 | 61.811798 | 118 | py |
pytorch | pytorch-main/torch/testing/_internal/common_quantization.py | r"""Importing this file includes common utility methods and base clases for
checking quantization api and properties of resulting modules.
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.ao.nn.intrinsic.quantized.dynamic as nniqd
import torch.ao.nn.quantized as nnq
import torch.ao.n... | 90,320 | 36.138569 | 130 | py |
pytorch | pytorch-main/torch/testing/_internal/inductor_utils.py | from subprocess import CalledProcessError
from torch._inductor.codecache import CppCodeCache
from torch._inductor.utils import has_triton
from torch.testing._internal.common_utils import (
LazyVal,
IS_FBCODE,
)
import torch
def test_cpu():
try:
CppCodeCache.load("")
return not IS_FBCODE
... | 551 | 20.230769 | 50 | py |
pytorch | pytorch-main/torch/testing/_internal/common_fsdp.py | # Owner(s): ["oncall: distributed"]
import itertools
import os
import re
import sys
from abc import ABC, abstractmethod
from contextlib import nullcontext
from copy import deepcopy
from enum import auto, Enum
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from unittest import mock
import t... | 45,533 | 36.322951 | 93 | py |
pytorch | pytorch-main/torch/testing/_internal/logging_tensor.py | import torch
from torch.utils._pytree import tree_map
from typing import Iterator, List, Optional
import logging
import contextlib
import itertools
from torch.utils._python_dispatch import TorchDispatchMode
from torch.utils.weak import WeakTensorKeyDictionary
import functools
from torch._C._profiler import gather_trace... | 6,962 | 37.04918 | 103 | py |
pytorch | pytorch-main/torch/testing/_internal/check_kernel_launches.py | import os
import re
import sys
from typing import List
__all__ = [
"check_code_for_cuda_kernel_launches",
"check_cuda_kernel_launches",
]
# FILES TO EXCLUDE (match is done with suffix using `endswith`)
# You wouldn't drive without a seatbelt, though, so why would you
# launch a kernel without some safety? Use... | 6,035 | 35.804878 | 112 | py |
pytorch | pytorch-main/torch/testing/_internal/test_module/no_future_div.py | import torch # noqa: F401
def div_int_nofuture():
return 1 / 2
def div_float_nofuture():
return 3.14 / 0.125
| 122 | 11.3 | 26 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc_utils.py | #!/usr/bin/env python3
import os
import sys
import unittest
from typing import Dict, List, Type
from torch.testing._internal.common_distributed import MultiProcessTestCase
from torch.testing._internal.common_utils import (
TEST_WITH_DEV_DBG_ASAN,
find_free_port,
IS_SANDCASTLE,
)
from torch.testing._interna... | 6,711 | 35.281081 | 102 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/distributed_test.py | import copy
import itertools
import math
import os
import random
import sys
import tempfile
import time
from collections import namedtuple, OrderedDict
from contextlib import contextmanager, nullcontext
from dataclasses import dataclass
from datetime import timedelta
from functools import reduce
from typing import Unio... | 424,931 | 40.964448 | 126 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/ddp_under_dist_autograd_test.py | #!/usr/bin/env python3
import contextlib
import enum
import logging
import os
import threading
from typing import NamedTuple
import torch
import torch.distributed as dist
import torch.distributed.autograd as dist_autograd
import torch.nn as nn
from torch.distributed import rpc
from torch.distributed.nn import RemoteM... | 26,738 | 35.429155 | 107 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/checkpoint_utils.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import shutil
import tempfile
from functools import wraps
from typing import Any, Callable, Dict, Optional, Tuple
import torch.distributed as dist
def with_temp_dir(
func: Optional[Callable] = None,
) -> Optional[Callable]:
"""
Wrapper to initialize te... | 1,059 | 25.5 | 78 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/fake_pg.py | import torch.distributed as dist
from torch._C._distributed_c10d import (
_create_work_from_future,
AllgatherOptions,
AllreduceOptions,
BarrierOptions,
ReduceScatterOptions
)
from torch.futures import Future
def ret_work(ret):
fut = Future()
fut.set_result(ret)
return _create_work_fro... | 3,573 | 38.274725 | 93 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/multi_threaded_pg.py | import sys
import threading
from dataclasses import dataclass
from typing import Dict, List, Optional, Tuple, Union
from functools import partial, reduce
import torch
import torch.distributed as dist
import weakref
from torch._C._distributed_c10d import (
_create_work_from_future,
AllgatherOptions,
Allredu... | 15,826 | 32.460888 | 105 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/pipe_with_ddp_test.py | import torch
import torch.distributed as dist
from torch import nn
from torch.nn.parallel import DistributedDataParallel
from torch.testing._internal.dist_utils import INIT_METHOD_TEMPLATE, dist_init
from torch.testing._internal.distributed.rpc.rpc_agent_test_fixture import (
RpcAgentTestFixture,
)
from torch.test... | 5,152 | 33.817568 | 105 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/distributed_utils.py | from contextlib import contextmanager
from datetime import timedelta
from functools import (
partial,
wraps,
)
import torch.distributed as dist
import torch.distributed.distributed_c10d as c10d
class MockProcessGroup(dist.ProcessGroup):
def __init__(self, rank, world):
super().__init__(rank, worl... | 1,920 | 28.553846 | 80 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/nn/api/remote_module_test.py | #!/usr/bin/python3
import enum
from typing import Tuple
import torch
import torch.distributed.rpc as rpc
import torch.testing._internal.dist_utils as dist_utils
from torch import Tensor, nn
from torch._jit_internal import Future
from torch.distributed.nn import RemoteModule
from torch.distributed.nn.api.remote_module ... | 29,329 | 38.959128 | 132 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/_shard/test_common.py | import torch
import torch.nn as nn
from torch.distributed._shard.sharded_tensor import ShardedTensor
class SimpleMegatronLM(nn.Module):
def __init__(self, linear_size, rank=None, dtype=torch.float32):
super().__init__()
self.fc1 = nn.Linear(*linear_size[0], dtype=dtype)
self.gelu = nn.GEL... | 1,192 | 28.097561 | 68 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/_shard/sharded_tensor/_test_ops_common.py | import builtins
import torch
from torch.distributed._shard.sharding_spec import (
ChunkShardingSpec,
EnumerableShardingSpec,
ShardMetadata,
)
from torch.distributed._shard.sharding_spec._internals import (
get_chunked_dim_size,
get_split_size,
)
def generate_chunk_sharding_specs_for_test(sharding... | 3,982 | 28.503704 | 86 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/_shard/sharded_tensor/__init__.py | import sys
from functools import wraps, partial
import torch
import torch.distributed as dist
from torch.distributed import rpc
from torch.testing._internal.common_distributed import (
MultiProcessTestCase,
TEST_SKIPS,
tp_transports,
)
TEST_GPU_NUM = 4
class ShardedTensorTestBase(MultiProcessTestCase):
... | 3,151 | 31.494845 | 90 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/_shard/sharded_tensor/_test_st_common.py | import copy
import random
import torch
from torch.distributed._shard import sharded_tensor
from torch.distributed._shard.sharding_spec import (
ChunkShardingSpec,
)
PLACEMENTS = [
"rank:0/cuda:0",
"rank:1/cuda:1",
"rank:2/cuda:2",
"rank:3/cuda:3",
]
DEFAULT_GPU_NUM = 4
def _chunk_sharding_specs... | 1,673 | 24.753846 | 72 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/tensorpipe_rpc_agent_test_fixture.py | import torch.distributed.rpc as rpc
from torch.testing._internal.distributed.rpc.rpc_agent_test_fixture import (
RpcAgentTestFixture,
)
from torch.testing._internal.common_distributed import (
tp_transports,
)
class TensorPipeRpcAgentTestFixture(RpcAgentTestFixture):
@property
def rpc_backend(self):
... | 1,009 | 29.606061 | 82 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/dist_autograd_test.py | import sys
import threading
import time
from enum import Enum
import random
import torch
import torch.nn as nn
from datetime import timedelta
import torch.distributed as dist
import torch.distributed.autograd as dist_autograd
import torch.distributed.rpc as rpc
import torch.testing._internal.dist_utils
from torch.autog... | 107,767 | 37.70977 | 110 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/rpc_test.py | import concurrent.futures
import contextlib
import json
import os
import sys
import threading
import time
from collections import namedtuple
from functools import partial
from threading import Event
from threading import Lock
from unittest import mock
import torch
import torch.nn as nn
import torch.distributed as dis... | 228,911 | 34.238916 | 131 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/faulty_rpc_agent_test_fixture.py | import torch.distributed.rpc as rpc
import torch.distributed.rpc._testing # noqa: F401
from torch.testing._internal.distributed.rpc.rpc_agent_test_fixture import (
RpcAgentTestFixture,
)
# The following message types are currently retried in the RREF protocol and
# distributed autograd. Thus only these messages s... | 2,203 | 35.131148 | 82 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/dist_optimizer_test.py |
import threading
import torch
import torch.distributed.autograd as dist_autograd
import torch.distributed.rpc as rpc
from torch import optim
from torch.distributed.optim import DistributedOptimizer
from torch.testing._internal.dist_utils import dist_init
from torch.testing._internal.distributed.rpc.rpc_agent_test_fix... | 10,602 | 36.867857 | 97 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/rpc_agent_test_fixture.py | import os
from abc import ABC, abstractmethod
import torch.testing._internal.dist_utils
class RpcAgentTestFixture(ABC):
@property
def world_size(self) -> int:
return 4
@property
def init_method(self):
use_tcp_init = os.environ.get("RPC_INIT_WITH_TCP", None)
if use_tcp_init ==... | 1,885 | 28.015385 | 86 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/faulty_agent_rpc_test.py | import torch
import time
import torch.distributed.rpc as rpc
from torch.distributed.rpc.api import _delete_all_user_and_unforked_owner_rrefs
from torch.testing._internal.dist_utils import (
dist_init,
wait_until_pending_futures_and_users_flushed,
wait_until_owners_and_forks_on_rank,
worker_name,
)
from ... | 14,136 | 42.498462 | 101 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/examples/reinforcement_learning_rpc_test.py | # If you need to modify this file to make this test pass, please also apply same edits accordingly to
# https://github.com/pytorch/examples/blob/master/distributed/rpc/rl/main.py
# and https://pytorch.org/tutorials/intermediate/rpc_tutorial.html
import numpy as np
from itertools import count
import torch
import torch... | 9,317 | 34.838462 | 101 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/examples/parameter_server_test.py | # If you need to modify this file to make this test pass, please also apply same edits accordingly to
# https://github.com/pytorch/examples/blob/master/distributed/rpc/batch/parameter_server.py
# and https://pytorch.org/tutorials/intermediate/rpc_async_execution.html#batch-updating-parameter-server
import threading
fr... | 4,537 | 30.734266 | 105 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/jit/rpc_test_faulty.py | from typing import Dict, Tuple
import torch
import torch.distributed.rpc as rpc
from torch import Tensor
from torch.distributed.rpc import RRef
from torch.testing._internal.dist_utils import (
dist_init,
worker_name,
wait_until_pending_futures_and_users_flushed
)
from torch.testing._internal.distributed.rp... | 8,036 | 36.036866 | 88 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/jit/dist_autograd_test.py | from typing import Dict, Tuple
import torch
import torch.distributed.autograd as dist_autograd
import torch.distributed.rpc as rpc
from torch import Tensor
from torch.distributed.rpc import rpc_async
from torch.testing import FileCheck
from torch.testing._internal.dist_utils import dist_init, worker_name
from torch.te... | 4,207 | 35.591304 | 86 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/rpc/jit/rpc_test.py | import time
import io
from typing import Dict, List, Tuple, Any
import torch
import torch.distributed as dist
import torch.distributed.rpc as rpc
from torch import Tensor
from torch.autograd.profiler import record_function
from torch.distributed.rpc import RRef
from torch.distributed.rpc.internal import RPCExecMode, _... | 47,262 | 33.149566 | 108 | py |
pytorch | pytorch-main/torch/testing/_internal/distributed/_tensor/common_dtensor.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from contextlib import contextmanager
from dataclasses import dataclass
import itertools
import sys
from functools import wraps
from typing import (
Any,
Callable,
Generator,
Iterator,
Tuple,
Dict,
List,
Sequence,
TypeVar,
cast... | 12,684 | 32.917112 | 118 | py |
pytorch | pytorch-main/torch/testing/_internal/codegen/random_topo_test.py | import torch
import numpy as np
import argparse
from typing import Dict
# debug print
DEBUG_PRINT = False
################################################################################
# configuration for random tests setup
################################################################################
# maximum ... | 16,461 | 40.361809 | 117 | py |
pytorch | pytorch-main/torch/testing/_internal/data/network2.py | import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(10, 20)
self.relu = nn.ReLU()
| 168 | 15.9 | 39 | py |
pytorch | pytorch-main/torch/testing/_internal/data/network1.py | import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(10, 20)
| 138 | 14.444444 | 39 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/core.py | import collections
import collections.abc
import math
import operator
import unittest
from dataclasses import asdict, dataclass
from enum import Enum
from functools import partial
from itertools import product
from typing import Any, Callable, Iterable, List, Optional, Tuple
from torchgen.utils import dataclass_repr
... | 108,534 | 37.405874 | 130 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/utils.py | import collections
import warnings
from functools import partial, wraps
from typing import Sequence
import numpy as np
import torch
from torch.testing._internal.common_cuda import TEST_CUDA
from torch.testing._internal.common_dtype import (
_dispatch_dtypes,
all_types,
all_types_and,
all_types_and_com... | 8,767 | 30.768116 | 118 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/refs.py | from torch.testing._internal.opinfo.core import (
BinaryUfuncInfo,
OpInfo,
ReductionOpInfo,
UnaryUfuncInfo,
)
# NOTE [Python References]
# Python References emulate existing PyTorch operations, but can ultimately
# be expressed in terms of "primitive" operations from torch._prims.
#
# These reference... | 8,335 | 38.13615 | 92 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/__init__.py | import torch.testing._internal.opinfo.core
import torch.testing._internal.opinfo.definitions
| 93 | 30.333333 | 49 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/_masked.py | import unittest
from collections.abc import Sequence
from functools import partial
from typing import List
import numpy as np
import torch
from torch.testing import make_tensor
from torch.testing._internal.common_device_type import tol, toleranceOverride
from torch.testing._internal.common_dtype import (
all_type... | 47,345 | 37.430195 | 112 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/special.py | import unittest
from functools import partial
from itertools import product
from typing import List
import numpy as np
import torch
from torch.testing import make_tensor
from torch.testing._internal.common_device_type import (
precisionOverride,
tol,
toleranceOverride,
)
from torch.testing._internal.commo... | 25,612 | 32.220493 | 113 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/fft.py | import unittest
from functools import partial
from typing import List
import numpy as np
import torch
from torch.testing import make_tensor
from torch.testing._internal.common_cuda import SM53OrLater
from torch.testing._internal.common_device_type import precisionOverride
from torch.testing._internal.common_dtype im... | 26,744 | 34.423841 | 108 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/linalg.py | import itertools
import unittest
from functools import partial
from itertools import chain, product
from typing import Iterable, List
import numpy as np
from numpy import inf
import torch
from torch.testing import make_tensor
from torch.testing._internal.common_cuda import (
_get_magma_version,
_get_torch_cu... | 87,480 | 34.6193 | 130 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.