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/testing/_internal/opinfo/definitions/sparse.py | import os
import torch
from torch.testing import make_tensor # noqa: F401
from torch.testing._internal.opinfo.core import ( # noqa: F401
BinaryUfuncInfo,
ErrorInput,
generate_elementwise_binary_tensors,
ReductionOpInfo,
sample_inputs_reduction,
SampleInput,
)
def _check_validate(op_info, sa... | 33,842 | 35.706074 | 126 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/signal.py | import unittest
from functools import partial
from itertools import product
from typing import Callable, List, Tuple
import numpy
import torch
from torch.testing._internal.common_dtype import floating_types
from torch.testing._internal.common_utils import TEST_SCIPY
from torch.testing._internal.opinfo.core import (
... | 15,270 | 32.415755 | 103 | py |
pytorch | pytorch-main/torch/testing/_internal/opinfo/definitions/__init__.py | from typing import List
from torch.testing._internal.opinfo.core import OpInfo
from torch.testing._internal.opinfo.definitions import (
_masked,
fft,
linalg,
signal,
special,
)
# Operator database
op_db: List[OpInfo] = [
*fft.op_db,
*linalg.op_db,
*signal.op_db,
*special.op_db,
... | 453 | 16.461538 | 56 | py |
pytorch | pytorch-main/torch/testing/_internal/optests/fake_tensor.py | import torch._subclasses
from torch._subclasses.fake_tensor import DynamicOutputShapeException
def is_builtin(op):
return op.namespace in ('aten', 'prims', 'prim')
def fake_check(op, args, kwargs, dynamic_only):
with torch._subclasses.CrossRefFakeMode(ignore_op_fn=is_builtin):
try:
op(*a... | 881 | 35.75 | 82 | py |
pytorch | pytorch-main/torch/testing/_internal/optests/aot_autograd.py | import torch
import torch.utils._pytree as pytree
from torch.testing._internal.common_methods_invocations import wrapper_set_seed
from functorch.compile import compiled_function, min_cut_rematerialization_partition, nop
from .make_fx import randomize
import re
class assert_raises_regex:
def __init__(self, excepti... | 4,799 | 40.37931 | 107 | py |
pytorch | pytorch-main/torch/testing/_internal/optests/make_fx.py | import torch
from torch.fx.experimental.proxy_tensor import make_fx
from torch.testing._internal.common_methods_invocations import wrapper_set_seed
import torch.utils._pytree as pytree
def make_fx_check(
func,
args,
kwargs,
tracing_mode,
assert_close=torch.testing.assert_close,
randomize_data=... | 3,275 | 36.227273 | 83 | py |
pytorch | pytorch-main/torch/testing/_internal/optests/compile_check.py | import torch
from .make_fx import make_fx_check
from .aot_autograd import aot_autograd_check
from .fake_tensor import fake_check
from torch._subclasses.schema_check_mode import SchemaCheckMode
def operator_compile_check(
func,
args,
kwargs=None,
*,
dynamic_only=False,
s... | 3,962 | 38.63 | 100 | py |
pytorch | pytorch-main/torch/_subclasses/meta_utils.py | import contextlib
import warnings
import weakref
from typing import ContextManager, List, Optional
import torch
from torch._guards import Source
from torch.fx.experimental.symbolic_shapes import DimConstraint, DimDynamic
from torch.multiprocessing.reductions import StorageWeakRef
from torch.utils._python_dispatch impo... | 26,793 | 45.11704 | 90 | py |
pytorch | pytorch-main/torch/_subclasses/schema_check_mode.py | from collections import namedtuple
from copy import deepcopy
from itertools import combinations
import torch
from torch.fx.operator_schemas import normalize_function
from torch.testing._internal.jit_utils import clone_inputs
from torch.utils._python_dispatch import TorchDispatchMode
from torch.utils._pytree import tre... | 7,500 | 39.327957 | 103 | py |
pytorch | pytorch-main/torch/_subclasses/fake_utils.py | import warnings
from typing import Callable, Union
import torch
import torch.utils._pytree as pytree
from torch._ops import OpOverload
from torch._subclasses.fake_tensor import (
FakeTensorMode,
tree_flatten_only,
UnsupportedFakeTensorException,
)
from torch.utils._python_dispatch import TorchDispatchMode
... | 5,942 | 38.357616 | 103 | py |
pytorch | pytorch-main/torch/_subclasses/fake_tensor.py | import contextlib
import functools
import itertools
import logging
import os
import weakref
from dataclasses import dataclass
from functools import partial
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union
from weakref import ReferenceType
import torch
import torch._custom_op
import t... | 63,328 | 36.208578 | 129 | py |
pytorch | pytorch-main/torch/_subclasses/__init__.py | import torch
from torch._subclasses.fake_tensor import (
DynamicOutputShapeException,
FakeTensor,
FakeTensorMode,
UnsupportedFakeTensorException,
)
from torch._subclasses.fake_utils import CrossRefFakeMode
__all__ = [
"FakeTensor",
"FakeTensorMode",
"UnsupportedFakeTensorException",
"... | 376 | 18.842105 | 57 | py |
pytorch | pytorch-main/torch/distributions/gumbel.py | from numbers import Number
import math
import torch
from torch.distributions import constraints
from torch.distributions.uniform import Uniform
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import AffineTransform, ExpTransform
from torch.distributio... | 2,731 | 35.918919 | 101 | py |
pytorch | pytorch-main/torch/distributions/cauchy.py | import math
from torch import inf, nan
from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all
__all__ = ['Cauchy']
class Cauchy(Distribution):
r"""
Samples from a Cauchy ... | 2,832 | 33.54878 | 101 | py |
pytorch | pytorch-main/torch/distributions/pareto.py | from torch.distributions import constraints
from torch.distributions.exponential import Exponential
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import AffineTransform, ExpTransform
from torch.distributions.utils import broadcast_all
__all__ = ['P... | 2,175 | 35.266667 | 84 | py |
pytorch | pytorch-main/torch/distributions/binomial.py | import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all, probs_to_logits, lazy_property, logits_to_probs
__all__ = ['Binomial']
def _clamp_by_zero(x):
# works like clamp(x, min=0) but has grad at 0 is 0.... | 5,713 | 40.405797 | 104 | py |
pytorch | pytorch-main/torch/distributions/dirichlet.py | import torch
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
__all__ = ['Dirichlet']
# This helper is exposed for testing.
def _Dirichlet_backward(x, concentration, grad... | 3,993 | 36.679245 | 112 | py |
pytorch | pytorch-main/torch/distributions/uniform.py | from numbers import Number
import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all
__all__ = ['Uniform']
class Uniform(Distribution):
r"""
Generates uniformly distributed rando... | 3,239 | 32.402062 | 85 | py |
pytorch | pytorch-main/torch/distributions/geometric.py | from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all, probs_to_logits, logits_to_probs, lazy_property
from torch.nn.functional import binary_cross_entropy_with_logits
__all__ = ... | 4,411 | 37.701754 | 103 | py |
pytorch | pytorch-main/torch/distributions/transformed_distribution.py | import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.independent import Independent
from torch.distributions.transforms import ComposeTransform, Transform
from torch.distributions.utils import _sum_rightmost
from typing import Dict
... | 8,417 | 42.84375 | 104 | py |
pytorch | pytorch-main/torch/distributions/normal.py | import math
from numbers import Real
from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import _standard_normal, broadcast_all
__all__ = ['Normal']
class Normal(ExponentialFamily):
r"""
... | 3,476 | 33.088235 | 100 | py |
pytorch | pytorch-main/torch/distributions/wishart.py | import math
import warnings
from numbers import Number
from typing import Optional, Union
import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import lazy_property
from torch.distributions.multivariate... | 13,259 | 42.618421 | 131 | py |
pytorch | pytorch-main/torch/distributions/lkj_cholesky.py | """
This closely follows the implementation in NumPyro (https://github.com/pyro-ppl/numpyro).
Original copyright notice:
# Copyright: Contributors to the Pyro project.
# SPDX-License-Identifier: Apache-2.0
"""
import math
import torch
from torch.distributions import constraints, Beta
from torch.distributions.distri... | 6,308 | 46.08209 | 109 | py |
pytorch | pytorch-main/torch/distributions/constraint_registry.py | r"""
PyTorch provides two global :class:`ConstraintRegistry` objects that link
:class:`~torch.distributions.constraints.Constraint` objects to
:class:`~torch.distributions.transforms.Transform` objects. These objects both
input constraints and return transforms, but they have different guarantees on
bijectivity.
1. ``... | 10,415 | 37.294118 | 99 | py |
pytorch | pytorch-main/torch/distributions/logistic_normal.py | from torch.distributions import constraints
from torch.distributions.normal import Normal
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import StickBreakingTransform
__all__ = ['LogisticNormal']
class LogisticNormal(TransformedDistribution):
r... | 1,925 | 36.038462 | 90 | py |
pytorch | pytorch-main/torch/distributions/beta.py | from numbers import Real, Number
import torch
from torch.distributions import constraints
from torch.distributions.dirichlet import Dirichlet
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all
__all__ = ['Beta']
class Beta(ExponentialFamily):
r"""
... | 3,551 | 35.618557 | 104 | py |
pytorch | pytorch-main/torch/distributions/von_mises.py | import math
import torch
import torch.jit
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all, lazy_property
__all__ = ['VonMises']
def _eval_poly(y, coef):
coef = list(coef)
result = coef.pop()
while c... | 5,199 | 34.135135 | 106 | py |
pytorch | pytorch-main/torch/distributions/one_hot_categorical.py | import torch
from torch.distributions import constraints
from torch.distributions.categorical import Categorical
from torch.distributions.distribution import Distribution
__all__ = ['OneHotCategorical', 'OneHotCategoricalStraightThrough']
class OneHotCategorical(Distribution):
r"""
Creates a one-hot categoric... | 4,677 | 35.834646 | 98 | py |
pytorch | pytorch-main/torch/distributions/log_normal.py | from torch.distributions import constraints
from torch.distributions.transforms import ExpTransform
from torch.distributions.normal import Normal
from torch.distributions.transformed_distribution import TransformedDistribution
__all__ = ['LogNormal']
class LogNormal(TransformedDistribution):
r"""
Creates a lo... | 1,927 | 30.096774 | 80 | py |
pytorch | pytorch-main/torch/distributions/utils.py | from functools import update_wrapper
from numbers import Number
import torch
import torch.nn.functional as F
from typing import Dict, Any
from torch.overrides import is_tensor_like
euler_constant = 0.57721566490153286060 # Euler Mascheroni Constant
__all__ = ["broadcast_all", "logits_to_probs", "clamp_probs", "probs... | 6,290 | 38.816456 | 105 | py |
pytorch | pytorch-main/torch/distributions/distribution.py | import torch
import warnings
from torch.distributions import constraints
from torch.distributions.utils import lazy_property
from torch.types import _size
from typing import Dict, Optional, Any, Tuple
__all__ = ['Distribution']
class Distribution:
r"""
Distribution is the abstract base class for probability d... | 12,297 | 37.311526 | 104 | py |
pytorch | pytorch-main/torch/distributions/negative_binomial.py | import torch
import torch.nn.functional as F
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all, probs_to_logits, lazy_property, logits_to_probs
__all__ = ['NegativeBinomial']
class NegativeBinomial(Distribution):
... | 4,541 | 40.290909 | 100 | py |
pytorch | pytorch-main/torch/distributions/multivariate_normal.py | import math
import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import _standard_normal, lazy_property
__all__ = ['MultivariateNormal']
def _batch_mv(bmat, bvec):
r"""
Performs a batched matrix-vector product, with... | 10,539 | 45.431718 | 116 | py |
pytorch | pytorch-main/torch/distributions/kl.py | import math
import warnings
from functools import total_ordering
from typing import Type, Dict, Callable, Tuple
import torch
from torch import inf
from .bernoulli import Bernoulli
from .beta import Beta
from .binomial import Binomial
from .categorical import Categorical
from .cauchy import Cauchy
from .continuous_ber... | 31,294 | 36.795894 | 126 | py |
pytorch | pytorch-main/torch/distributions/poisson.py | from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all
__all__ = ['Poisson']
class Poisson(ExponentialFamily):
r"""
Creates a Poisson distribution parameterized by :at... | 2,215 | 27.779221 | 85 | py |
pytorch | pytorch-main/torch/distributions/laplace.py | from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import broadcast_all
__all__ = ['Laplace']
class Laplace(Distribution):
r"""
Creates a Laplace distribution parameterized by :attr:`loc` ... | 3,179 | 34.730337 | 106 | py |
pytorch | pytorch-main/torch/distributions/half_normal.py | import math
import torch
from torch import inf
from torch.distributions import constraints
from torch.distributions.transforms import AbsTransform
from torch.distributions.normal import Normal
from torch.distributions.transformed_distribution import TransformedDistribution
__all__ = ['HalfNormal']
class HalfNormal(T... | 2,158 | 28.175676 | 80 | py |
pytorch | pytorch-main/torch/distributions/multinomial.py | import torch
from torch import inf
from torch.distributions.binomial import Binomial
from torch.distributions.distribution import Distribution
from torch.distributions import Categorical
from torch.distributions import constraints
from torch.distributions.utils import broadcast_all
__all__ = ['Multinomial']
class Mul... | 5,409 | 39.676692 | 92 | py |
pytorch | pytorch-main/torch/distributions/chi2.py | from torch.distributions import constraints
from torch.distributions.gamma import Gamma
__all__ = ['Chi2']
class Chi2(Gamma):
r"""
Creates a Chi-squared distribution parameterized by shape parameter :attr:`df`.
This is exactly equivalent to ``Gamma(alpha=0.5*df, beta=0.5)``
Example::
>>> # x... | 972 | 28.484848 | 83 | py |
pytorch | pytorch-main/torch/distributions/categorical.py | import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import probs_to_logits, logits_to_probs, lazy_property
__all__ = ['Categorical']
class Categorical(Distribution):
r"""
Creates a categorical d... | 5,626 | 38.626761 | 104 | py |
pytorch | pytorch-main/torch/distributions/independent.py | import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import _sum_rightmost
from typing import Dict
__all__ = ['Independent']
class Independent(Distribution):
r"""
Reinterprets some of the batch dims of a distribution ... | 4,579 | 39.530973 | 106 | py |
pytorch | pytorch-main/torch/distributions/fishersnedecor.py | from numbers import Number
import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.gamma import Gamma
from torch.distributions.utils import broadcast_all
__all__ = ['FisherSnedecor']
class FisherSnedecor(Distribu... | 3,371 | 35.652174 | 96 | py |
pytorch | pytorch-main/torch/distributions/constraints.py | r"""
The following constraints are implemented:
- ``constraints.boolean``
- ``constraints.cat``
- ``constraints.corr_cholesky``
- ``constraints.dependent``
- ``constraints.greater_than(lower_bound)``
- ``constraints.greater_than_eq(lower_bound)``
- ``constraints.independent(constraint, reinterpreted_batch_ndims)``
- `... | 18,410 | 29.181967 | 101 | py |
pytorch | pytorch-main/torch/distributions/lowrank_multivariate_normal.py | import math
import torch
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.multivariate_normal import _batch_mahalanobis, _batch_mv
from torch.distributions.utils import _standard_normal, lazy_property
__all__ = ['LowRankMultivariateNormal']... | 9,931 | 46.75 | 106 | py |
pytorch | pytorch-main/torch/distributions/exp_family.py | import torch
from torch.distributions.distribution import Distribution
__all__ = ['ExponentialFamily']
class ExponentialFamily(Distribution):
r"""
ExponentialFamily is the abstract base class for probability distributions belonging to an
exponential family, whose probability mass/density function has the ... | 2,352 | 36.951613 | 103 | py |
pytorch | pytorch-main/torch/distributions/mixture_same_family.py | import torch
from torch.distributions.distribution import Distribution
from torch.distributions import Categorical
from torch.distributions import constraints
from typing import Dict
__all__ = ['MixtureSameFamily']
class MixtureSameFamily(Distribution):
r"""
The `MixtureSameFamily` distribution implements a (... | 8,620 | 43.210256 | 96 | py |
pytorch | pytorch-main/torch/distributions/half_cauchy.py | import math
import torch
from torch import inf
from torch.distributions import constraints
from torch.distributions.transforms import AbsTransform
from torch.distributions.cauchy import Cauchy
from torch.distributions.transformed_distribution import TransformedDistribution
__all__ = ['HalfCauchy']
class HalfCauchy(T... | 2,344 | 29.855263 | 109 | py |
pytorch | pytorch-main/torch/distributions/weibull.py | import torch
from torch.distributions import constraints
from torch.distributions.exponential import Exponential
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import AffineTransform, PowerTransform
from torch.distributions.utils import broadcast_all... | 2,990 | 43.641791 | 110 | py |
pytorch | pytorch-main/torch/distributions/__init__.py | r"""
The ``distributions`` package contains parameterizable probability distributions
and sampling functions. This allows the construction of stochastic computation
graphs and stochastic gradient estimators for optimization. This package
generally follows the design of the `TensorFlow Distributions`_ package.
.. _`Ten... | 5,975 | 34.152941 | 84 | py |
pytorch | pytorch-main/torch/distributions/kumaraswamy.py | import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.uniform import Uniform
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import AffineTransform, PowerTransform
from torch.distributions.utils import... | 3,352 | 41.443038 | 102 | py |
pytorch | pytorch-main/torch/distributions/relaxed_categorical.py | import torch
from torch.distributions import constraints
from torch.distributions.categorical import Categorical
from torch.distributions.utils import clamp_probs, broadcast_all
from torch.distributions.distribution import Distribution
from torch.distributions.transformed_distribution import TransformedDistribution
fro... | 5,126 | 37.840909 | 102 | py |
pytorch | pytorch-main/torch/distributions/gamma.py | from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all
__all__ = ['Gamma']
def _standard_gamma(concentration):
return torch._standard_gamma(concentration)
class Gamma(Ex... | 3,469 | 35.914894 | 99 | py |
pytorch | pytorch-main/torch/distributions/exponential.py | from numbers import Number
import torch
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all
__all__ = ['Exponential']
class Exponential(ExponentialFamily):
r"""
Creates a Exponential distribution paramete... | 2,435 | 28 | 84 | py |
pytorch | pytorch-main/torch/distributions/bernoulli.py | from numbers import Number
import torch
from torch import nan
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all, probs_to_logits, logits_to_probs, lazy_property
from torch.nn.functional import binary_cross_entrop... | 4,116 | 32.745902 | 100 | py |
pytorch | pytorch-main/torch/distributions/studentT.py | import math
import torch
from torch import inf, nan
from torch.distributions import Chi2, constraints
from torch.distributions.distribution import Distribution
from torch.distributions.utils import _standard_normal, broadcast_all
__all__ = ['StudentT']
class StudentT(Distribution):
r"""
Creates a Student's t... | 3,670 | 36.459184 | 107 | py |
pytorch | pytorch-main/torch/distributions/transforms.py | import functools
import math
import numbers
import operator
import weakref
from typing import List
import torch
import torch.nn.functional as F
from torch.distributions import constraints
from torch.distributions.utils import (_sum_rightmost, broadcast_all,
lazy_property, tril_ma... | 41,020 | 32.84571 | 119 | py |
pytorch | pytorch-main/torch/distributions/relaxed_bernoulli.py | import torch
from numbers import Number
from torch.distributions import constraints
from torch.distributions.distribution import Distribution
from torch.distributions.transformed_distribution import TransformedDistribution
from torch.distributions.transforms import SigmoidTransform
from torch.distributions.utils import... | 5,308 | 37.471014 | 113 | py |
pytorch | pytorch-main/torch/distributions/continuous_bernoulli.py | from numbers import Number
import math
import torch
from torch.distributions import constraints
from torch.distributions.exp_family import ExponentialFamily
from torch.distributions.utils import broadcast_all, probs_to_logits, logits_to_probs, lazy_property, clamp_probs
from torch.nn.functional import binary_cross_ent... | 8,586 | 42.150754 | 113 | py |
pytorch | pytorch-main/torch/_export/exported_program.py | from collections import defaultdict
import copy
import dataclasses
import sympy
from typing import Any, Dict, List, Optional, Tuple, Union
from torch._functorch.aot_autograd import FQN, GraphInputName, GraphOutputName
import torch
from torch.fx.passes.infra.pass_manager import PassManager
import torch.fx._pytree as fx... | 14,832 | 37.72846 | 108 | py |
pytorch | pytorch-main/torch/_export/pass_base.py | import operator
import traceback
import typing
from contextlib import nullcontext
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import torch
from functorch.experimental import control_flow
from functorch.experimental import _map
from torch import fx
from torch._dispatch.python import enable_pyth... | 16,324 | 37.961814 | 92 | py |
pytorch | pytorch-main/torch/_export/verifier.py | import itertools
import operator
from collections.abc import Iterable
from typing import Set
import torch
from functorch.experimental import control_flow
from torch._ops import OpOverload
from torch._subclasses.fake_tensor import FakeTensor
from torch.fx import GraphModule
from torch.fx._compatibility import compatibi... | 4,735 | 31.888889 | 93 | py |
pytorch | pytorch-main/torch/_export/constraints.py | from typing import Optional, Callable, Union
import torch
from torch import SymInt, SymFloat
from torch._dynamo import allow_in_graph
from torch.fx.experimental.symbolic_shapes import constrain_range_int
from torch.utils._sympy.value_ranges import ValueRangeError
# `Scalar` type used in native_functions.ymal will be ... | 1,662 | 32.938776 | 93 | py |
pytorch | pytorch-main/torch/_export/__init__.py | import dataclasses
import inspect
import weakref
import re
from collections import OrderedDict
from typing import Any, Callable, List, Tuple, Optional, Dict, Union
import sympy
import torch
import torch._dynamo
import torch.fx
from torch.fx.graph import _PyTreeCodeGen, _PyTreeInfo
from .exported_program import (
... | 12,387 | 39.090615 | 126 | py |
pytorch | pytorch-main/torch/_export/trace.py | import copy
from typing import Callable, Tuple
from unittest.mock import patch
import torch
import torch._dynamo as torchdynamo
from torch._decomp import core_aten_decompositions
from torch._dispatch.python import enable_python_dispatcher
from torch.nn.utils import stateless
from torch.utils import _pytree as pytree
... | 6,902 | 33.173267 | 121 | py |
pytorch | pytorch-main/torch/_export/workflow.py | import dataclasses
from typing import Callable, Tuple
import torch
from torch.fx.passes.pass_manager import PassManager
from torch.utils._pytree import TreeSpec
@dataclasses.dataclass
class ExportedProgram:
fw_module: torch.fx.GraphModule
example_inputs: Tuple[torch.Tensor, ...]
in_spec: TreeSpec
out_... | 591 | 28.6 | 75 | py |
pytorch | pytorch-main/torch/_export/serde/upgrade.py | import logging
from collections import defaultdict
from typing import Tuple, Dict, Optional, List
import torch
from torch._export import export
from torch._export.pass_base import ExportPassBase
from torch._export.pass_infra.node_metadata import NodeMetadata
from torch._export.pass_infra.proxy_value import ProxyValue
... | 10,148 | 48.995074 | 127 | py |
pytorch | pytorch-main/torch/_export/serde/serialize.py | import dataclasses
import io
import json
import logging
import math
import operator
import typing
from contextlib import contextmanager
from dataclasses import dataclass, field
from enum import Enum
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
import sympy
import torch
import ... | 52,554 | 40.187304 | 116 | py |
pytorch | pytorch-main/torch/_export/pass_infra/proxy_value.py | # pyre-strict
from typing import Union
import torch
class ProxyValue:
# pyre-ignore
def __init__(self, data, proxy: Union[torch.fx.Proxy, torch.fx.Node]):
# pyre-ignore
self.data = data
self.proxy_or_node = proxy
@property
def node(self) -> torch.fx.Node:
if isinstanc... | 1,140 | 26.166667 | 106 | py |
pytorch | pytorch-main/torch/_export/db/case.py | import inspect
import re
import string
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Dict, List, Optional, Set, Tuple, Union
import torch
from torch._dynamo.eval_frame import Constraint
_TAGS: Dict[str, Dict[str, Any]] = {
"torch": {
"cond": {},
"dynamic-sh... | 5,235 | 27.150538 | 90 | py |
pytorch | pytorch-main/torch/_export/db/gen_example.py | import os
import sys
import torch._export.db.examples as examples
TEMPLATE = '''import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.randn(3, 2),),
tags={{}},
)
def {case_name}(x):
"""
"""
return
'''
if __name__ == "__main__":
assert len(sys.argv)... | 581 | 19.068966 | 69 | py |
pytorch | pytorch-main/torch/_export/db/examples/decorator.py | import functools
import torch
from torch._export.db.case import export_case
def test_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs) + 1
return wrapper
@export_case(
example_inputs=(torch.ones(3, 2), torch.ones(3, 2)),
)
class Decorator(t... | 500 | 17.555556 | 75 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_closed_over_variable.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import cond
@export_case(
example_inputs=(torch.tensor(True), torch.ones(3, 2)),
tags={"torch.cond", "python.closure"},
)
class CondClosedOverVariable(torch.nn.Module):
"""
torch.cond() supports branch... | 556 | 22.208333 | 67 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_map.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import map
@export_case(
example_inputs=(torch.ones(3, 2), torch.ones(2)),
tags={"torch.dynamic-shape", "torch.map"},
)
def dynamic_shape_map(xs, y):
"""
functorch map() maps a function over the first ... | 417 | 19.9 | 68 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_branch_class_method.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import cond
class MySubModule(torch.nn.Module):
def foo(self, x):
return x.cos()
def forward(self, x):
return self.foo(x)
@export_case(
example_inputs=(torch.ones(3),),
tags={
... | 1,342 | 27.574468 | 100 | py |
pytorch | pytorch-main/torch/_export/db/examples/specialized_attribute.py | from enum import Enum
import torch
from torch._export.db.case import export_case
class Animal(Enum):
COW = "moo"
@export_case(
example_inputs=(torch.ones(3, 2),),
)
class SpecializedAttribute(torch.nn.Module):
"""
Model attributes are specialized.
"""
def __init__(self):
super()._... | 522 | 16.433333 | 45 | py |
pytorch | pytorch-main/torch/_export/db/examples/null_context_manager.py | import contextlib
import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"python.context-manager"},
)
def null_context_manager(x):
"""
Null context manager in Python will be traced out.
"""
ctx = contextlib.nullcontext()
with ct... | 356 | 17.789474 | 54 | py |
pytorch | pytorch-main/torch/_export/db/examples/list_contains.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"torch.dynamic-shape", "python.data-structure", "python.assert"},
)
def list_contains(x):
"""
List containment relation can be checked on a dynamic shape or constants.
"""
assert... | 439 | 23.444444 | 77 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_branch_nested_function.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import cond
@export_case(
example_inputs=(torch.ones(3),),
tags={
"torch.cond",
"torch.dynamic-shape",
},
)
def cond_branch_nested_function(x):
"""
The branch functions (`true_fn` a... | 1,246 | 28.690476 | 100 | py |
pytorch | pytorch-main/torch/_export/db/examples/static_for_loop.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"python.control-flow"},
)
class StaticForLoop(torch.nn.Module):
"""
A for loop with constant number of iterations should be unrolled in the exported graph.
"""
def __init__(self... | 483 | 20.043478 | 91 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_predicate.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import cond
@export_case(
example_inputs=(torch.ones(6, 4, 3),),
tags={
"torch.cond",
"torch.dynamic-shape",
},
)
def cond_predicate(x):
"""
The conditional statement (aka predicate... | 644 | 23.807692 | 92 | py |
pytorch | pytorch-main/torch/_export/db/examples/scalar_output.py | import torch
from torch._export.db.case import export_case
from torch._export import dynamic_dim
x = torch.ones(3, 2)
dynamic_constraint = dynamic_dim(x, 1)
@export_case(
example_inputs=(x,),
tags={"torch.dynamic-shape"},
constraints=[dynamic_constraint]
)
def scalar_output(x):
"""
Returning scal... | 482 | 23.15 | 78 | py |
pytorch | pytorch-main/torch/_export/db/examples/static_if.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2, 2),),
tags={"python.control-flow"},
)
class StaticIf(torch.nn.Module):
"""
`if` statement with static predicate value should be traced through with the
taken branch.
"""
def __init__... | 473 | 18.75 | 80 | py |
pytorch | pytorch-main/torch/_export/db/examples/dictionary.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2), torch.tensor(4)),
tags={"python.data-structure"},
)
def dictionary(x, y):
"""
Dictionary structures are inlined and flattened along tracing.
"""
elements = {}
elements["x2"] = x * x
... | 367 | 19.444444 | 66 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_branch_nonlocal_variables.py | import torch
from torch._export.db.case import export_case
from functorch.experimental.control_flow import cond
@export_case(
example_inputs=(torch.ones(6),),
tags={
"torch.cond",
"torch.dynamic-shape",
},
)
def cond_branch_nonlocal_variables(x):
"""
The branch functions (`true_fn... | 1,782 | 28.716667 | 107 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_round.py | import torch
from torch._export.db.case import export_case, SupportLevel
from torch._export import dynamic_dim
x = torch.ones(3, 2)
dynamic_constraint = dynamic_dim(x, 0)
@export_case(
example_inputs=(x,),
tags={"torch.dynamic-shape", "python.builtin"},
support_level=SupportLevel.NOT_SUPPORTED_YET,
c... | 490 | 23.55 | 59 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_slicing.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"torch.dynamic-shape"},
)
def dynamic_shape_slicing(x):
"""
Slices with dynamic shape arguments should be captured into the graph
rather than being baked in.
"""
return x[: x... | 356 | 21.3125 | 73 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_assert.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"python.assert"},
)
def dynamic_shape_assert(x):
"""
A basic usage of python assertion.
"""
# assertion with error message
assert x.shape[0] > 2, f"{x.shape[0]} is greater th... | 403 | 20.263158 | 60 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_constructor.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2),),
tags={"torch.dynamic-shape"},
)
def dynamic_shape_constructor(x):
"""
Tensor constructors should be captured with dynamic shape inputs rather
than being baked in with static shape.
"""... | 359 | 21.5 | 75 | py |
pytorch | pytorch-main/torch/_export/db/examples/tensor_setattr.py | import torch
from torch._export.db.case import export_case, SupportLevel
@export_case(
example_inputs=(torch.randn(3, 2), "attr"),
tags={"python.builtin"},
support_level=SupportLevel.SUPPORTED,
)
def tensor_setattr(x, attr):
"""
setattr() call onto tensors is not supported.
"""
setattr(x,... | 363 | 20.411765 | 59 | py |
pytorch | pytorch-main/torch/_export/db/examples/class_method.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 4),),
)
class ClassMethod(torch.nn.Module):
"""
Class methods are inlined during tracing.
"""
@classmethod
def method(cls, x):
return x + 1
def __init__(self):
super().... | 509 | 19.4 | 79 | py |
pytorch | pytorch-main/torch/_export/db/examples/nested_function.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2), torch.ones(2)),
tags={"python.closure"},
)
def nested_function(a, b):
"""
Nested functions are traced through. Side effects on global captures
are not supported though.
"""
x = a + b... | 438 | 17.291667 | 72 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_if_guard.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2, 2),),
tags={"torch.dynamic-shape", "python.control-flow"},
)
class DynamicShapeIfGuard(torch.nn.Module):
"""
`if` statement with backed dynamic shape predicate will be specialized into
one pa... | 573 | 25.090909 | 80 | py |
pytorch | pytorch-main/torch/_export/db/examples/__init__.py | import glob
import importlib
from os.path import basename, dirname, isfile, join
import torch
from torch._export.db.case import (
_EXAMPLE_CASES,
_EXAMPLE_CONFLICT_CASES,
_EXAMPLE_REWRITE_CASES,
SupportLevel,
)
modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [
basename(f)[:-3] for ... | 1,264 | 22.867925 | 84 | py |
pytorch | pytorch-main/torch/_export/db/examples/dynamic_shape_view.py | import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(10, 10),),
tags={"torch.dynamic-shape"},
)
def dynamic_shape_view(x):
"""
Dynamic shapes should be propagated to view arguments instead of being
baked into the exported graph.
"""
new_x_sha... | 407 | 21.666667 | 74 | py |
pytorch | pytorch-main/torch/_export/db/examples/type_reflection_method.py | import torch
from torch._export.db.case import export_case, SupportLevel, export_rewrite_case
class A:
@classmethod
def func(cls, x):
return 1 + x
@export_case(
example_inputs=(torch.ones(3, 4),),
tags={"python.builtin"},
support_level=SupportLevel.NOT_SUPPORTED_YET,
)
def type_reflecti... | 682 | 20.34375 | 80 | py |
pytorch | pytorch-main/torch/_export/db/examples/list_unpack.py | from typing import List
import torch
from torch._export.db.case import export_case
@export_case(
example_inputs=([torch.ones(3, 2), torch.tensor(4), torch.tensor(5)],),
tags={"python.control-flow", "python.data-structure"},
)
def list_unpack(args: List[torch.Tensor]):
"""
Lists are treated as static... | 433 | 21.842105 | 75 | py |
pytorch | pytorch-main/torch/_export/db/examples/assume_constant_result.py | import torch
import torch._dynamo as torchdynamo
from torch._export.db.case import export_case
@export_case(
example_inputs=(torch.ones(3, 2), torch.tensor(4)),
tags={"torch.escape-hatch"},
)
class AssumeConstantResult(torch.nn.Module):
"""
Applying `assume_constant_result` decorator to burn make non... | 573 | 21.96 | 91 | py |
pytorch | pytorch-main/torch/_export/db/examples/cond_operands.py | import torch
from torch._export.db.case import export_case
from torch._export import dynamic_dim
from functorch.experimental.control_flow import cond
x = torch.randn(3, 2)
y = torch.ones(2)
dynamic_constraint = dynamic_dim(x, 0)
@export_case(
example_inputs=(x, y),
tags={
"torch.cond",
"torch... | 836 | 22.25 | 85 | py |
pytorch | pytorch-main/torch/_export/db/examples/fn_with_kwargs.py | import torch
from torch._export.db.case import export_case, ExportArgs, SupportLevel
@export_case(
example_inputs=ExportArgs(
torch.randn(4),
(torch.randn(4), torch.randn(4)),
*[torch.randn(4), torch.randn(4)],
mykw0=torch.randn(4),
**{"input0": torch.randn(4), "input1": t... | 750 | 24.896552 | 71 | py |
pytorch | pytorch-main/torch/_export/db/examples/autograd_function.py | import torch
from torch._export.db.case import export_case
class MyAutogradFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, x):
return x.clone()
@staticmethod
def backward(ctx, grad_output):
return grad_output + 1
@export_case(
example_inputs=(torch.randn(3, 2)... | 593 | 21 | 88 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.