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/ao/quantization/observer.py | """
This module implements observers which are used to collect statistics about
the values observed during calibration (PTQ) or training (QAT).
"""
import re
import warnings
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
from functools import partial
from typing import Any, List, Tuple, Op... | 63,382 | 38.197897 | 131 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/_propagate_annotation.py | from typing import Callable
import torch
from torch.ao.quantization.pt2e.quantizer import (
QuantizationAnnotation,
SharedQuantizationSpec,
)
from torch.fx import Node
def _is_share_obs_or_fq_op(op: Callable) -> bool:
# TODO: remove some of these ops in qnnpack_quantizer
return op in [
torch.... | 1,740 | 29.017241 | 85 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/utils.py | import torch
from torch.fx import (
Graph,
GraphModule,
Node,
)
from torch.fx.subgraph_rewriter import replace_pattern_with_filters
import torch.nn.functional as F
from torch.nn.utils.fusion import fuse_conv_bn_weights
# TODO[jerryzh168]: move this to a more general util function
from torch.ao.quantization.... | 11,708 | 38.962457 | 125 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/prepare.py | import torch
from torch._subclasses import FakeTensor
from torch.ao.quantization.fx.prepare import (
_get_arg_as_input_act_obs_or_fq,
_get_output_act_obs_or_fq,
_get_dtype_and_is_dynamic,
_insert_obs_or_fq,
_maybe_insert_output_observer_for_node,
_save_state,
_is_activation_post_process_node... | 7,627 | 34.152074 | 130 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/graph_utils.py | import itertools
from typing import Any, List, OrderedDict, Set
import operator
import torch
from torch.fx.passes.utils.source_matcher_utils import (
check_subgraphs_connected,
get_source_partitions,
SourcePartition,
)
__all__ = [
"find_sequential_partitions",
"get_equivalent_types",
"update_... | 3,634 | 33.292453 | 102 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/qat_utils.py | import dataclasses
import itertools
import operator
from typing import Any, Callable, Dict, List, Tuple
import torch
from torch.fx import Graph, GraphModule, Node
from torch.fx.subgraph_rewriter import replace_pattern_with_filters
import torch.nn.functional as F
from torch.ao.quantization.fx._decomposed import quantiz... | 31,048 | 41.243537 | 119 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/qnnpack_quantizer.py | from __future__ import annotations
import copy
import functools
import itertools
import operator
from typing import Any, Callable, Dict, List, Optional, Set
import torch
import torch._dynamo as torchdynamo
import torch.nn.functional as F
from torch.ao.quantization.pt2e.graph_utils import find_sequential_partitions
... | 32,706 | 39.832709 | 110 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/composable_quantizer.py | from __future__ import annotations
from typing import Dict, List
import torch
from torch.fx import Node
from .quantizer import OperatorConfig, QuantizationAnnotation, Quantizer
__all__ = [
"ComposableQuantizer",
]
class ComposableQuantizer(Quantizer):
"""
ComposableQuantizer allows users to combine m... | 2,833 | 36.289474 | 104 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/embedding_quantizer.py | from __future__ import annotations
import copy
from typing import List, Set
import torch
import torch.nn.functional as F
from torch.ao.quantization.pt2e.quantizer.quantizer import (
OperatorConfig,
OperatorPatternType,
QuantizationAnnotation,
QuantizationConfig,
QuantizationSpec,
Quantizer,
)
... | 3,403 | 35.212766 | 88 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/utils.py | from typing import List
import torch
from torch.ao.quantization.pt2e.quantizer.quantizer import (
QuantizationAnnotation,
QuantizationConfig,
QuantizationSpec,
)
from torch.fx import Node
__all__ = [
"get_input_act_qspec",
"get_output_act_qspec",
"get_weight_qspec",
"get_bias_qspec",
]
de... | 3,967 | 32.344538 | 84 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/x86_inductor_quantizer.py | import torch
import torch.nn.functional as F
import copy
import functools
import itertools
import operator
from .quantizer import (
OperatorConfig,
OperatorPatternType,
QuantizationConfig,
QuantizationSpec,
Quantizer,
QuantizationAnnotation,
)
from torch.ao.quantization.pt2e.graph_utils import f... | 16,029 | 41.407407 | 109 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/quantizer/quantizer.py | from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from torch.fx import Node
from typing import Callable, List, NamedTuple, Optional, Dict, Union, Tuple
from torch.ao.quantization import ObserverOrFakeQuantize
from torch.ao.quantization.qconfig import _ObserverOrFakeQuantizeConstructor
from to... | 6,814 | 35.639785 | 109 | py |
pytorch | pytorch-main/torch/ao/quantization/pt2e/representation/rewrite.py | import torch
from torch.fx import GraphModule
from ..utils import get_aten_graph_module
from ..utils import remove_tensor_overload_for_qdq_ops
from torch.ao.quantization.fx._decomposed import quantized_decomposed_lib # noqa: F401
from torch.fx.subgraph_rewriter import replace_pattern
__all__ = [
"reference_repres... | 6,150 | 47.054688 | 130 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/backend_config.py | from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Type, Union
import torch
from torch.ao.quantization.utils import Pattern
from enum import Enum
__all__ = [
"BackendConfig",
"BackendPatternConfig",
"DTypeConfig",
"DTypeWithCon... | 30,446 | 45.272036 | 132 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/qnnpack.py | import torch
from ._common_operator_config_utils import (
_get_binary_op_configs,
_get_bn_configs,
_get_cat_config,
_get_conv_configs,
_get_default_op_configs,
_get_embedding_op_configs,
_get_fixed_qparams_op_configs,
_get_linear_configs,
_get_rnn_op_configs,
_get_share_qparams_o... | 5,339 | 32.167702 | 101 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/_x86_inductor_pt2e.py | import torch
from torch.ao.quantization.backend_config import (
BackendConfig,
DTypeConfig,
ObservationType,
BackendPatternConfig,
)
weighted_op_quint8_dtype_config = DTypeConfig(
input_dtype=torch.quint8,
output_dtype=torch.quint8,
weight_dtype=torch.qint8,
bias_dtype=torch.float,
)
d... | 1,605 | 33.913043 | 96 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/x86.py | import torch
from ._common_operator_config_utils import (
_get_binary_op_configs,
_get_bn_configs,
_get_cat_config,
_get_conv_configs,
_get_default_op_configs,
_get_embedding_op_configs,
_get_fixed_qparams_op_configs,
_get_linear_configs,
_get_rnn_op_configs,
_get_share_qparams_o... | 3,784 | 32.201754 | 101 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/tensorrt.py | import torch
from .backend_config import (
BackendConfig,
BackendPatternConfig,
DTypeConfig,
ObservationType
)
from ._common_operator_config_utils import (
_get_binary_op_configs,
_get_linear_configs,
_get_conv_configs,
_get_share_qparams_op_configs,
_get_tensor_info_op_configs,
)
_... | 2,883 | 34.170732 | 101 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/fbgemm.py | import torch
from ._common_operator_config_utils import (
_get_binary_op_configs,
_get_bn_configs,
_get_cat_config,
_get_conv_configs,
_get_default_op_configs,
_get_embedding_op_configs,
_get_fixed_qparams_op_configs,
_get_linear_configs,
_get_rnn_op_configs,
_get_share_qparams_o... | 4,123 | 34.247863 | 101 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/onednn.py | import torch
import torch.nn as nn
import torch.ao.nn.intrinsic as nni
import torch.nn.functional as F
import torch.ao.nn.quantized.reference as nnqr
from ._common_operator_config_utils import (
_get_conv_configs,
_get_linear_configs,
_get_binary_op_configs,
_get_bn_configs,
_get_cat_config,
_ge... | 19,198 | 34.357274 | 122 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/utils.py | from typing import Dict, Any, List, Callable, Union, Tuple, Type
import torch
import torch.nn as nn
import torch.nn.functional as F
from .backend_config import (
BackendConfig,
BackendPatternConfig,
DTypeConfig,
)
from ..utils import Pattern
from ..fuser_method_mappings import (
_reverse2,
_reverse... | 12,342 | 43.082143 | 109 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/_qnnpack_pt2e.py | import operator
import torch
from torch.ao.quantization.backend_config import (
BackendConfig,
DTypeConfig,
ObservationType,
BackendPatternConfig,
)
weighted_op_quint8_dtype_config = DTypeConfig(
input_dtype=torch.quint8,
output_dtype=torch.quint8,
weight_dtype=torch.qint8,
bias_dtype=t... | 6,306 | 38.173913 | 116 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/executorch.py | # TODO: rename executorch to qnnpack_executorch since executorch is a general runtime
# not a specific backend
import operator
from typing import List
import torch
import torch.ao.nn.qat as nnqat
import torch.ao.nn.quantized.reference as nnqr
import torch.nn as nn
import torch.nn.functional as F
from ..fuser_method_... | 16,532 | 33.159091 | 91 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/__init__.py | from .backend_config import BackendConfig, BackendPatternConfig, DTypeConfig, DTypeWithConstraints, ObservationType
from .fbgemm import get_fbgemm_backend_config
from .native import get_native_backend_config, get_native_backend_config_dict
from .qnnpack import get_qnnpack_backend_config
from .tensorrt import get_tensor... | 889 | 36.083333 | 115 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/native.py | import torch
from ._common_operator_config_utils import (
_get_binary_op_configs,
_get_bn_configs,
_get_cat_config,
_get_conv_configs,
_get_default_op_configs,
_get_embedding_op_configs,
_get_fixed_qparams_op_configs,
_get_linear_configs,
_get_ln_configs,
_get_rnn_op_configs,
... | 8,048 | 38.263415 | 108 | py |
pytorch | pytorch-main/torch/ao/quantization/backend_config/_common_operator_config_utils.py | import copy
import operator
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.ao.nn.intrinsic as nni
import torch.ao.nn.intrinsic.qat as nniqat
import torch.ao.nn.qat as nnqat
import torch.ao.nn.quantized.reference as nnqr
from collections import namedtuple
from typing import Callable, Dic... | 27,077 | 41.442006 | 109 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/fake_quantize.py | import torch
from torch import Tensor
from torch.ao.quantization.experimental.observer import APoTObserver
from torch.ao.quantization.fake_quantize import FakeQuantizeBase
from torch.ao.quantization.experimental.fake_quantize_function import fake_quantize_function
class APoTFakeQuantize(FakeQuantizeBase):
alpha: T... | 1,599 | 40.025641 | 117 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/fake_quantize_function.py | import torch
from torch import Tensor
from torch.ao.quantization.experimental.quantizer import quantize_APoT, dequantize_APoT
class fake_quantize_function(torch.autograd.Function):
@staticmethod
def forward(ctx, # type: ignore[override]
x: Tensor,
alpha: Tensor,
... | 909 | 31.5 | 93 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/qconfig.py | import torch
from torch.ao.quantization.qconfig import QConfig
from torch.ao.quantization import MinMaxObserver
from torch.ao.quantization.fake_quantize import FakeQuantize
from torch.ao.quantization.experimental.fake_quantize import APoTFakeQuantize
"""
Default symmetric fake_quant for activations.
"""
default_symmet... | 2,532 | 52.893617 | 99 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/linear.py | import torch
import numpy as np
from torch.ao.nn.quantized.modules.utils import WeightedQuantizedModule
from torch.ao.quantization.experimental.observer import APoTObserver
from torch.ao.quantization.experimental.quantizer import quantize_APoT
class LinearAPoT(WeightedQuantizedModule):
r"""
A quantized linear... | 5,436 | 33.852564 | 127 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/APoT_tensor.py | import torch
from torch.ao.quantization.experimental.quantizer import APoTQuantizer
# class to store APoT quantized tensor
class TensorAPoT():
quantizer: APoTQuantizer
data: torch.Tensor
def __init__(self, quantizer: APoTQuantizer, apot_data: torch.Tensor):
self.quantizer = quantizer
self.... | 387 | 24.866667 | 74 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/observer.py | """
This module implements nonuniform observers used to collect statistics about
the values observed during calibration (PTQ) or training (QAT).
"""
import torch
import itertools
import matplotlib.pyplot as plt
from torch.ao.quantization.observer import ObserverBase
from torch.ao.quantization.experimental.apot_utils i... | 5,578 | 34.310127 | 101 | py |
pytorch | pytorch-main/torch/ao/quantization/experimental/quantizer.py | import torch
from torch import Tensor
import numpy as np
from torch.ao.quantization.experimental.apot_utils import float_to_apot, apot_to_float, quant_dequant_util
# class to store APoT quantizer and
# implement quantize and dequantize
class APoTQuantizer():
alpha: torch.Tensor
gamma: torch.Tensor
quantiza... | 5,671 | 40.40146 | 125 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_equalize.py | import warnings
from collections import namedtuple
from typing import Any, Dict, List, Optional, Tuple
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.ao.nn.intrinsic as nni
from torch.fx import GraphModule
from torch.fx.graph import Node
from torch.ao.quantization.fx.graph_module impo... | 37,069 | 44.152253 | 126 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/tracer.py | import torch
from torch.fx._symbolic_trace import Tracer
from torch.fx.proxy import Scope
from torch.ao.nn.intrinsic import _FusedModule
from typing import List, Callable
__all__ = [
"QuantizationTracer",
]
class ScopeContextManager(torch.fx.proxy.ScopeContextManager):
def __init__(
self,
scop... | 1,657 | 35.043478 | 95 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/custom_config.py | from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Tuple, Type
from torch.ao.quantization import QConfigMapping
from torch.ao.quantization.backend_config import BackendConfig
from torch.ao.quantization.quant_type import QuantType, _quant_type_from_str, _g... | 20,798 | 48.170213 | 129 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/pattern_utils.py | from collections import OrderedDict
from typing import Dict, Any
from torch.ao.quantization.utils import Pattern
from ..fake_quantize import FixedQParamsFakeQuantize
from ..observer import ObserverBase
import copy
__all__ = [
"get_default_fusion_patterns",
"get_default_quant_patterns",
"get_default_output_... | 3,372 | 37.329545 | 124 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/lower_to_qnnpack.py | from ._lower_to_native_backend import _lower_to_native_backend
from ..qconfig import QConfigAny
from torch.fx import GraphModule
from typing import Dict, Tuple
__all__ = [
"lower_to_qnnpack"
]
def lower_to_qnnpack(
model: GraphModule,
qconfig_map: Dict[str, QConfigAny],
node_name_to_scope: Dict[str, T... | 541 | 27.526316 | 86 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/quantize_handler.py | import torch
from torch.fx.graph import (
Node,
)
from .utils import (
all_node_args_have_no_tensors,
)
from torch.ao.quantization.backend_config import (
BackendConfig,
DTypeConfig,
ObservationType,
)
from torch.ao.quantization.utils import (
NodePattern,
Pattern,
QuantizerCls,
)
from... | 7,207 | 34.333333 | 102 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/qconfig_mapping_utils.py | import torch
import re
from collections import defaultdict, OrderedDict
from typing import Callable, Any, Dict, Tuple, Set, List, Union
from torch.ao.quantization import QConfig
from torch.ao.quantization.qconfig import _add_module_to_qconfig_obs_ctr, QConfigAny, qconfig_equals
from torch.ao.quantization.observer impor... | 14,823 | 42.093023 | 117 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/fuse_handler.py | import torch
from torch.ao.quantization.backend_config import BackendConfig
from torch.fx.graph import Node, Graph
from ..utils import _parent_name, NodePattern, Pattern
from ..fuser_method_mappings import get_fuser_method_new
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, List, Union
from ... | 4,688 | 37.752066 | 98 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/utils.py | import copy
import torch
import torch.nn as nn
from torch.ao.quantization import (
QConfigAny,
QuantType,
)
from torch.ao.quantization.backend_config import (
DTypeWithConstraints,
)
from torch.ao.quantization.fake_quantize import (
FakeQuantizeBase,
FixedQParamsFakeQuantize,
)
from torch.ao.quantiz... | 37,303 | 41.681922 | 128 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/graph_module.py | import torch
import copy
from torch.fx import GraphModule
from torch.fx.graph import Graph
from typing import Union, Dict, Any, Set
__all__ = [
"FusedGraphModule",
"ObservedGraphModule",
"ObservedStandaloneGraphModule",
"QuantizedGraphModule",
]
class FusedGraphModule(GraphModule):
def __init__(se... | 5,879 | 48 | 158 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/fuse.py | from torch.fx import (
GraphModule,
Node,
map_arg
)
from torch.fx.graph import Graph
from .match_utils import (
_is_match,
MatchAllNode,
)
from .pattern_utils import (
_sorted_patterns_dict,
)
from ..backend_config import (
BackendConfig,
get_native_backend_config,
)
from ..backend_conf... | 6,541 | 39.382716 | 129 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/prepare.py | import copy
import torch
import warnings
from torch.fx import (
GraphModule,
)
from torch.fx.graph import (
Graph,
Node,
)
from torch.fx.node import Argument
from ..quantize import (
propagate_qconfig_,
)
from ..observer import (
_is_activation_post_process,
_PartialWrapper,
)
from ..qconfig im... | 83,003 | 43.245203 | 129 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/convert.py | from typing import Any, Dict, List, Optional, Set, Tuple, Union, Type, Callable
from torch.ao.quantization.quant_type import QuantType
import torch
import copy
import warnings
from torch.fx import (
GraphModule,
)
from torch.fx.graph import (
Graph,
Node,
Argument,
)
from ..utils import (
activation... | 54,346 | 48.541477 | 126 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_decomposed.py | import torch
from torch.library import Library, impl
from torch.ao.quantization.utils import determine_qparams, validate_qmin_qmax
from typing import Tuple
# Note: decomposed means decomposed quantized tensor, using decomposed so that the
# name is not too long
quantized_decomposed_lib = Library("quantized_decomposed... | 21,282 | 43.900844 | 122 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_lower_to_native_backend.py | import torch
from torch.fx import map_arg, Node
from torch.fx.graph import Graph
import torch.nn as nn
import torch.nn.functional as F
import torch.ao.nn.intrinsic as nni
import torch.ao.nn.intrinsic.quantized as nniq
import torch.ao.nn.intrinsic.quantized.dynamic as nniqd
import torch.ao.nn.quantized as nnq
import tor... | 51,531 | 43.082121 | 154 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/lstm_utils.py | import copy
import operator
import torch
from typing import Any, Callable, Optional, Tuple
from torch.ao.quantization import (
default_weight_observer,
default_weight_fake_quant,
FakeQuantizeBase,
QConfig,
QConfigMapping,
)
from torch.ao.quantization.backend_config import BackendConfig
from torch.ao... | 9,325 | 49.684783 | 116 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/match_utils.py | import sys
import torch
from torch.fx.graph import (
Graph,
Node,
)
from torch.ao.quantization.utils import Pattern
from .quantize_handler import (
QuantizeHandler,
)
from ..qconfig import (
QConfigAny,
)
from ..utils import (
MatchAllNode
)
from .graph_module import (
_is_observed_standalone_mo... | 9,116 | 37.306723 | 120 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/lower_to_fbgemm.py | from ._lower_to_native_backend import _lower_to_native_backend
from ..qconfig import QConfigAny
from torch.fx import GraphModule
from typing import Dict, Tuple
__all__ = ['lower_to_fbgemm']
def lower_to_fbgemm(
model: GraphModule,
qconfig_map: Dict[str, QConfigAny],
node_name_to_scope: Dict[str, Tuple[str... | 532 | 30.352941 | 86 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_model_report/model_report_visualizer.py | import torch
from typing import Any, Set, Dict, List, Tuple, OrderedDict
from collections import OrderedDict as OrdDict
# try to import tablate
got_tabulate = True
try:
from tabulate import tabulate
except ImportError:
got_tabulate = False
# var to see if we could import matplotlib
got_matplotlib = True
try:... | 32,150 | 47.202399 | 126 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_model_report/model_report_observer.py | import torch
from torch.ao.quantization.observer import ObserverBase
class ModelReportObserver(ObserverBase):
r"""This observer is used to record additional information regarding keeping track
of S = average_batch_activation_range/epoch_activation_range.
The purpose of this information is to prepare a re... | 11,789 | 43.323308 | 131 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_model_report/model_report.py | from typing import Any, Dict, Set, Tuple, Callable
from collections import OrderedDict
import torch
from torch.ao.quantization.fx._model_report.detector import (
DetectorBase,
DETECTOR_OBS_ARGS_KEY,
DETECTOR_OBS_TO_INSERT_KEY,
DETECTOR_IS_POST_OBS_KEY,
DETECTOR_TARGET_NODE_KEY,
DetectorQConfigIn... | 28,697 | 46.278418 | 127 | py |
pytorch | pytorch-main/torch/ao/quantization/fx/_model_report/detector.py | from typing import Any, Dict, Set, Tuple, Callable, List
import torch
import torch.nn as nn
import torch.ao.nn.qat as nnqat
from abc import ABC, abstractmethod
from torch.ao.quantization.fake_quantize import FakeQuantize
from torch.ao.quantization.fx.graph_module import GraphModule
from torch.ao.quantization.fx._model... | 73,969 | 46.970169 | 131 | py |
pytorch | pytorch-main/torch/_dispatch/python.py | import torch._C
from contextlib import contextmanager
import unittest.mock
import torch
import torch.utils._pytree as pytree
import itertools
from typing import Iterator
import torch._ops
__all__ = ['enable_python_dispatcher', 'no_python_dispatcher', 'enable_pre_dispatch']
no_python_dispatcher = torch._C._DisablePyth... | 5,936 | 38.58 | 126 | py |
pytorch | pytorch-main/torch/_prims/nvfuser_executor.py | import operator
from copy import deepcopy
from dataclasses import dataclass
from functools import lru_cache
from types import MappingProxyType
from warnings import warn
import torch
import torch.fx
import torch.overrides
from torch._prims_common import (
_torch_dtype_to_nvfuser_dtype_map,
getnvFuserDtype,
... | 19,402 | 36.896484 | 131 | py |
pytorch | pytorch-main/torch/_prims/context.py | import functools
from contextlib import nullcontext
from typing import Any, Callable, Dict, Optional, Sequence
from warnings import warn
import torch
import torch._decomp
import torch._prims
import torch._refs
import torch._refs.nn
import torch._refs.nn.functional
import torch._refs.special
import torch.overrides
fr... | 15,246 | 34.540793 | 98 | py |
pytorch | pytorch-main/torch/_prims/executor.py | from typing import Callable, Optional
from torch._prims.context import NvfuserPrimsMode, TorchRefsMode
from torch._prims.nvfuser_executor import nvfuser_execute, nvfuser_execute_partitioned
from torch.fx import GraphModule
from torch.fx.experimental.proxy_tensor import make_fx, wrapper_and_args_for_make_fx
def exec... | 2,119 | 28.444444 | 101 | py |
pytorch | pytorch-main/torch/_prims/nvfuser_prims.py | # Module for defining "primitive" operations executable by the nvFuser. This
# list exists to decouple main set of primitives from the ones that provide a
# lowering of the op to nvFuser’s Python interface. Mostly torch.ops.nvprims is
# a subset of the primitives in torch.ops.prims, but some additional primitives
# can... | 23,922 | 27.445898 | 118 | py |
pytorch | pytorch-main/torch/_prims/__init__.py | import contextlib
import itertools
import operator
import weakref
from enum import Enum
from functools import partial, reduce
from typing import Any, Callable, List, Optional, Sequence, Tuple, Type, Union
import torch
import torch._prims_common as utils
import torch.library
from torch import sym_float, Tensor, TypedS... | 81,512 | 26.189126 | 147 | py |
pytorch | pytorch-main/torch/_prims/debug_prims.py | import contextlib
from typing import Sequence
import torch
from torch._custom_op.impl import custom_op
from torch.utils._content_store import ContentStoreReader
LOAD_TENSOR_READER = None
@contextlib.contextmanager
def load_tensor_reader(loc):
global LOAD_TENSOR_READER
assert LOAD_TENSOR_READER is None
#... | 1,952 | 31.55 | 74 | py |
pytorch | pytorch-main/torch/_prims/rng_prims.py | from typing import Optional, Tuple
import torch
import torch.utils._pytree as pytree
from torch import _prims
from torch._C import DispatchKey
from torch._ops import HigherOrderOperator
from torch._prims_common import CUDARngStateHelper, make_contiguous_strides_for
from torch._prims_common.wrappers import backwards_n... | 10,867 | 36.475862 | 163 | py |
pytorch | pytorch-main/torch/nested/__init__.py | from typing import List, Optional
import torch
from torch import Tensor
from torch._C import _add_docstr, _nested # type: ignore[attr-defined]
from torch.types import _device as Device, _dtype as DType
__all__ = [
"to_padded_tensor",
"as_nested_tensor",
"nested_tensor",
]
# Nested Tensor constructor fu... | 6,087 | 39.586667 | 117 | py |
pytorch | pytorch-main/torch/fx/immutable_collections.py | from typing import Any, Dict, Tuple, List
from ._compatibility import compatibility
from torch.utils._pytree import Context, _register_pytree_node
__all__ = ["immutable_list", "immutable_dict"]
_help_mutation = """\
If you are attempting to modify the kwargs or args of a torch.fx.Node object,
instead create a new co... | 2,176 | 40.075472 | 119 | py |
pytorch | pytorch-main/torch/fx/tensor_type.py | from torch.fx.experimental.unification import Var # type: ignore[attr-defined]
from ._compatibility import compatibility
@compatibility(is_backward_compatible=False)
class TensorType:
"""
TensorType defines a type for tensors, which consists of a list of dimensions.
Example:
class M(torch.nn.Mod... | 2,932 | 26.933333 | 96 | py |
pytorch | pytorch-main/torch/fx/annotate.py | from torch.fx.proxy import Proxy
from ._compatibility import compatibility
@compatibility(is_backward_compatible=False)
def annotate(val, type):
# val could be either a regular value (not tracing)
# or fx.Proxy (tracing)
if isinstance(val, Proxy):
if val.node.type:
raise RuntimeError(f"... | 929 | 41.272727 | 98 | py |
pytorch | pytorch-main/torch/fx/proxy.py | import dis
import copy
import sys
import torch
import inspect
import operator
import traceback
import collections
from dataclasses import is_dataclass, fields
from .graph import magic_methods, reflectable_magic_methods, Graph
from typing import Tuple, Dict, OrderedDict, Optional, Iterable, Any, Iterator, Callable
fr... | 21,577 | 38.73849 | 108 | py |
pytorch | pytorch-main/torch/fx/_symbolic_trace.py | import builtins
import copy
import functools
import inspect
import math
import os
import warnings
import collections
from itertools import chain
from types import CodeType, FunctionType, ModuleType
from typing import (
Any,
Callable,
Dict,
List,
NamedTuple,
Optional,
Set,
Tuple,
Type... | 44,731 | 37.562069 | 130 | py |
pytorch | pytorch-main/torch/fx/subgraph_rewriter.py | from .graph_module import GraphModule
from .graph import Graph
from .node import Node
from ._symbolic_trace import symbolic_trace
from ._compatibility import compatibility
import copy
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Set, Union
import torch
__all__ ... | 13,457 | 38.582353 | 120 | py |
pytorch | pytorch-main/torch/fx/node.py | # Nodes represent a definition of a value in our graph of operators.
from typing import TYPE_CHECKING, Union, Callable, Any, Tuple, List, Optional, Dict, Set
from ._compatibility import compatibility
from .immutable_collections import immutable_dict, immutable_list
import torch
import builtins
import types
import warni... | 28,500 | 42.512977 | 132 | py |
pytorch | pytorch-main/torch/fx/interpreter.py | from .graph_module import GraphModule
from .graph import Graph
from .node import Argument, Node, Target, map_arg, map_aggregate
from .proxy import Proxy
from ._symbolic_trace import Tracer
from ._compatibility import compatibility
from . import config
import torch.fx.traceback as fx_traceback
import torch
from typing i... | 21,414 | 41.322134 | 130 | py |
pytorch | pytorch-main/torch/fx/graph_module.py | import torch
import torch.nn as nn
import torch.overrides
from torch.nn.modules.module import _addindent
from torch.package import PackageImporter, PackageExporter
import linecache
from typing import Type, Dict, List, Any, Union, Optional, Set
from .graph import Graph, _PyTreeCodeGen, _is_from_torch, _custom_builtins, ... | 33,413 | 40.7675 | 131 | py |
pytorch | pytorch-main/torch/fx/graph.py | from collections import defaultdict
from .node import Node, Argument, Target, map_arg, _type_repr, _get_qualified_name
import torch.utils._pytree as pytree
from . import _pytree as fx_pytree
from ._compatibility import compatibility
import contextlib
from typing import TYPE_CHECKING, Callable, Any, List, Dict, NamedTu... | 64,570 | 40.154238 | 124 | py |
pytorch | pytorch-main/torch/fx/operator_schemas.py | import torch
import inspect
import numbers
import types
import typing
import enum
import warnings
from typing import Any, Callable, Dict, List, Optional, Tuple, NamedTuple, cast, TYPE_CHECKING
from torch._jit_internal import boolean_dispatched
from ._compatibility import compatibility
from torch._ops import OpOverloadP... | 19,776 | 45.207944 | 132 | py |
pytorch | pytorch-main/torch/fx/_pytree.py | from typing import Callable, Any, Tuple, List, Dict, Type, NamedTuple
from torch.utils._pytree import PyTree, TreeSpec, LeafSpec
from collections import namedtuple
FlattenFuncSpec = Callable[[PyTree, TreeSpec], List]
SUPPORTED_NODES: Dict[Type[Any], Any] = {}
def register_pytree_flatten_spec(typ: Any, flatten_fn_spec... | 1,892 | 43.023256 | 106 | py |
pytorch | pytorch-main/torch/fx/__init__.py | r'''
FX is a toolkit for developers to use to transform ``nn.Module``
instances. FX consists of three main components: a **symbolic tracer,**
an **intermediate representation**, and **Python code generation**. A
demonstration of these components in action:
::
import torch
# Simple module for demonstration
... | 3,810 | 41.344444 | 108 | py |
pytorch | pytorch-main/torch/fx/experimental/const_fold.py | import re
from typing import Callable, Dict, Optional, Set, Union
import torch.fx
from torch.fx.node import map_arg
from torch.fx.passes.split_module import split_module
__all__ = ['FoldedGraphModule', 'get_unique_attr_name_in_module', 'split_const_subgraphs']
class FoldedGraphModule(torch.fx.GraphModule):
"""
... | 11,885 | 39.986207 | 104 | py |
pytorch | pytorch-main/torch/fx/experimental/meta_tracer.py | import torch
import torch.fx
import warnings
import functools
import builtins
from typing import Any, Callable, Dict, Optional, Union
def embedding_override(self, input):
return torch.empty(*input.shape, self.weight.shape[-1], device='meta')
def nn_layernorm_override(self, input):
return input
def torch_r... | 10,025 | 36.271375 | 119 | py |
pytorch | pytorch-main/torch/fx/experimental/optimization.py | import torch.fx as fx
from torch.fx.node import Argument, Target
from torch.nn.utils.fusion import fuse_conv_bn_eval
from typing import Type, Dict, Any, Tuple, Iterable, Optional, List, cast
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.fx.passes.shape_prop import ShapeProp
import copy
f... | 16,549 | 39.763547 | 123 | py |
pytorch | pytorch-main/torch/fx/experimental/unify_refinements.py | from torch.fx.experimental.graph_gradual_typechecker import Refine
from torch.fx.tensor_type import TensorType
from torch.fx.experimental.unification import Var, unify # type: ignore[attr-defined]
def infer_symbolic_types_single_pass(traced):
"""
Calls our symbolic inferencer once.
"""
r = Refine(tra... | 3,121 | 24.801653 | 86 | py |
pytorch | pytorch-main/torch/fx/experimental/proxy_tensor.py | # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import functools
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import tor... | 35,396 | 40.159302 | 130 | py |
pytorch | pytorch-main/torch/fx/experimental/partitioner_utils.py | from enum import Enum
from typing import NamedTuple, Dict, List, Set
from torch.fx.node import Node, map_arg
class Partition:
"""Partition class contains all the information about an individual partition.
It also provides necessary methods for manipulation the partition.
"""
def __init__(self, parti... | 12,504 | 38.323899 | 96 | py |
pytorch | pytorch-main/torch/fx/experimental/accelerator_partitioner.py | import operator
from collections import deque
from typing import Dict, List, Set, NamedTuple, Tuple, Deque
import torch
from torch.fx.passes.graph_manipulation import get_size_of_all_nodes
from torch.fx.experimental.partitioner_utils import (
Partition,
Device,
PartitionerConfig,
get_partition_to_laten... | 47,928 | 43.419833 | 107 | py |
pytorch | pytorch-main/torch/fx/experimental/symbolic_shapes.py | import builtins
import collections
import functools
import inspect
import itertools
import logging
import math
import operator
import re
import sys
import textwrap
import threading
import traceback
from collections import defaultdict
from contextlib import contextmanager
from dataclasses import dataclass
from enum impo... | 147,650 | 41.538462 | 127 | py |
pytorch | pytorch-main/torch/fx/experimental/rewriter.py | import ast
import inspect
import textwrap
import copy
import functools
from types import FunctionType
from typing import cast, Union, Callable, Dict, Optional, Any
from torch.fx._symbolic_trace import Tracer
from torch.fx.graph import Graph
from torch._sources import normalize_source_lines
import torch
class AST_Rewri... | 4,943 | 39.52459 | 117 | py |
pytorch | pytorch-main/torch/fx/experimental/validator.py | import functools
import logging
import math
import operator
import sympy
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
import torch
import torch.fx
import torch.fx.traceback as fx_traceback
from torch.fx.node import Argument, Target
from torch.utils... | 18,711 | 40.861298 | 107 | py |
pytorch | pytorch-main/torch/fx/experimental/merge_matmul.py | import torch
from torch.fx.node import Node
from torch.fx._symbolic_trace import symbolic_trace
from torch.fx.passes.tools_common import legalize_graph
import itertools
import operator
from typing import Dict, List, Tuple
def split_result_tensors(
result: torch.Tensor, inputs: List[torch.Tensor]
) -> Tuple[torc... | 5,981 | 33.77907 | 116 | py |
pytorch | pytorch-main/torch/fx/experimental/schema_type_annotation.py | import torch
import torch.fx
import inspect
from typing import Any, Dict, Optional, Tuple
from torch.fx.node import Argument, Target
from torch._jit_internal import boolean_dispatched
from torch.fx.operator_schemas import _torchscript_type_to_python_type
from torch.fx import Transformer
class AnnotateTypesWithSchema(... | 5,000 | 43.651786 | 113 | py |
pytorch | pytorch-main/torch/fx/experimental/debug.py | import torch.fx as fx
def set_trace(gm: fx.GraphModule) -> fx.GraphModule:
"""
Sets a breakpoint in `gm`'s generated python code. It drops into pdb when
`gm` gets run.
Args:
gm: graph module to insert breakpoint. It is then recompiled for it to
take effect.
Returns:
th... | 805 | 24.1875 | 78 | py |
pytorch | pytorch-main/torch/fx/experimental/normalize.py | import operator
from typing import Any, Callable, Dict, Tuple, Optional
import torch
import torch.fx
import torch.fx as fx
from torch.fx import Transformer, Proxy
from torch.fx.node import Argument, Target, Node, map_aggregate
from torch.fx.operator_schemas import (
normalize_module,
normalize_function,
cr... | 5,478 | 32.613497 | 162 | py |
pytorch | pytorch-main/torch/fx/experimental/graph_gradual_typechecker.py | from functools import reduce
import torch
import operator
from torch.fx.tensor_type import Dyn, is_consistent, TensorType, is_more_precise
from typing import Callable, Dict
from torch.fx.node import Target, Node
from torch.nn.modules.batchnorm import BatchNorm2d
from torch.nn.modules.conv import Conv2d
from torch.fx.ex... | 32,328 | 34.33224 | 128 | py |
pytorch | pytorch-main/torch/fx/experimental/migrate_gradual_types/constraint.py | # -*- coding: utf-8 -*-
from torch.fx.experimental.migrate_gradual_types.operation import op_add, op_sub, op_mul, op_div, \
op_mod, op_gt, op_lt, op_neq, op_eq
from torch.fx.tensor_type import TensorType, Dyn
class Constraint:
pass
class Conj(Constraint):
def __init__(self, conjuncts):
"""
... | 16,387 | 28.316637 | 115 | py |
pytorch | pytorch-main/torch/fx/experimental/migrate_gradual_types/constraint_generator.py | import torch
import operator
import warnings
from typing import Callable, Dict, Iterable
from torch.fx._symbolic_trace import _assert_is_none
from torch.fx.experimental.migrate_gradual_types.constraint import ApplyBroadcasting, CalcProduct, \
Disj, TGreatestUpperBound, CalcMaxPool, CalcConv, Conj, BinConstraintT, ... | 47,599 | 36.129485 | 128 | py |
pytorch | pytorch-main/torch/fx/experimental/migrate_gradual_types/util.py | from torch.fx.experimental.migrate_gradual_types.constraint import TVar, DVar, BinConstraintD, \
BVar
from torch.fx.experimental.migrate_gradual_types.operation import op_leq
def gen_tvar(curr):
"""
Generate a tensor variable
:param curr: The current counter
:return: a tensor variable and the upda... | 1,321 | 23.943396 | 96 | py |
pytorch | pytorch-main/torch/fx/experimental/migrate_gradual_types/transform_to_z3.py | from torch.fx.experimental.migrate_gradual_types.constraint import Conj, Disj, T, F, BinConstraintT, BVar, is_bool_expr
from torch.fx.experimental.migrate_gradual_types.constraint import BinConstraintD, TVar, DVar
from torch.fx.experimental.migrate_gradual_types.constraint import Prod, is_algebraic_expression, is_dim
f... | 14,703 | 41.131805 | 119 | py |
pytorch | pytorch-main/torch/fx/experimental/migrate_gradual_types/constraint_transformation.py | # mypy: ignore-errors
import copy
import itertools
from torch.fx.experimental.migrate_gradual_types.constraint_generator import BinConstraintT, MAX_TENSOR_RANK
from torch.fx.experimental.migrate_gradual_types.constraint import T, BinConstraintD, Conj, Constraint, DVar, TVar, \
Transpose
from torch.fx.experimental.m... | 39,368 | 36.818444 | 130 | py |
pytorch | pytorch-main/torch/fx/passes/reinplace.py | import torch
from torch.fx import Node
from torch.fx._compatibility import compatibility
from torch._subclasses.fake_tensor import FakeTensorMode, FakeTensor
from torch.utils._pytree import tree_map, tree_flatten, tree_map_only
from torch.multiprocessing.reductions import StorageWeakRef
import _operator
from enum impo... | 33,233 | 48.235556 | 129 | py |
pytorch | pytorch-main/torch/fx/passes/split_module.py | import inspect
from typing import Any, Callable, Dict, List, Optional
import torch
from torch.fx._compatibility import compatibility
from torch.fx.graph_module import GraphModule
__all__ = ["Partition", "split_module"]
@compatibility(is_backward_compatible=True)
class Partition:
def __init__(self, name: str):
... | 15,358 | 41.195055 | 106 | py |
pytorch | pytorch-main/torch/fx/passes/splitter_base.py | import argparse
import copy
from collections import defaultdict
from dataclasses import dataclass
from typing import NamedTuple, Sequence, Iterable, Any, List, Dict, Optional, Tuple
import logging
import torch
from torch.fx.passes.graph_manipulation import get_size_of_node
from torch.fx.node import map_arg
from torch.... | 32,264 | 36.001147 | 131 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.