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/quantization/fx/convert.py
# flake8: noqa: F401 r""" This file is in the process of migration to `torch/ao/quantization`, and is kept here for compatibility while the migration process is ongoing. If you are adding a new entry/functionality, please, add it to the appropriate files under `torch/ao/quantization/fx/`, while adding an import stateme...
386
37.7
85
py
pytorch
pytorch-main/torch/quantization/fx/__init__.py
# flake8: noqa: F401 r""" This file is in the process of migration to `torch/ao/quantization`, and is kept here for compatibility while the migration process is ongoing. If you are adding a new entry/functionality, please, add it to the appropriate files under `torch/ao/quantization/fx/`, while adding an import stateme...
593
38.6
85
py
pytorch
pytorch-main/torch/quantization/fx/match_utils.py
# flake8: noqa: F401 r""" This file is in the process of migration to `torch/ao/quantization`, and is kept here for compatibility while the migration process is ongoing. If you are adding a new entry/functionality, please, add it to the appropriate files under `torch/ao/quantization/fx/`, while adding an import stateme...
455
29.4
85
py
pytorch
pytorch-main/torch/quantization/fx/quantization_types.py
# flake8: noqa: F401 r""" This file is in the process of migration to `torch/ao/quantization`, and is kept here for compatibility while the migration process is ongoing. If you are adding a new entry/functionality, please, add it to the appropriate files under `torch/ao/quantization/fx/`, while adding an import stateme...
407
30.384615
85
py
pytorch
pytorch-main/torch/package/package_importer.py
import builtins import importlib import importlib.machinery import inspect import io import linecache import os.path import types from contextlib import contextmanager from pathlib import Path from typing import Any, BinaryIO, Callable, cast, Dict, Iterable, List, Optional, Union from weakref import WeakValueDictionary...
30,756
39.576517
132
py
pytorch
pytorch-main/torch/package/importer.py
import importlib from abc import ABC, abstractmethod from pickle import ( # type: ignore[attr-defined] # type: ignore[attr-defined] _getattribute, _Pickler, whichmodule as _pickle_whichmodule, ) from types import ModuleType from typing import Any, Dict, List, Optional, Tuple from ._mangling import demang...
8,950
36.609244
109
py
pytorch
pytorch-main/torch/package/package_exporter.py
import collections import importlib.machinery import io import linecache import pickletools import platform import types from collections import defaultdict, OrderedDict from dataclasses import dataclass from enum import Enum from importlib.machinery import SourceFileLoader from pathlib import Path from typing import (...
50,999
41.358804
132
py
pytorch
pytorch-main/torch/package/_mangling.py
"""Import mangling. See mangling.md for details. """ import re _mangle_index = 0 class PackageMangler: """ Used on import, to ensure that all modules imported have a shared mangle parent. """ def __init__(self): global _mangle_index self._mangle_index = _mangle_index # Increm...
1,854
28.444444
84
py
pytorch
pytorch-main/torch/package/glob_group.py
import re from typing import Iterable, Union GlobPattern = Union[str, Iterable[str]] class GlobGroup: """A set of patterns that candidate strings will be matched against. A candidate is composed of a list of segments separated by ``separator``, e.g. "foo.bar.baz". A pattern contains one or more segment...
3,610
42.506024
110
py
pytorch
pytorch-main/torch/package/_directory_reader.py
import os.path from glob import glob from typing import cast import torch from torch.types import Storage __serialization_id_record_name__ = ".data/serialization_id" # because get_storage_from_record returns a tensor!? class _HasStorage: def __init__(self, storage): self._storage = storage def stor...
1,894
28.609375
83
py
pytorch
pytorch-main/torch/ao/__init__.py
# torch.ao is a package with a lot of interdependencies. # We will use lazy import to avoid cyclic dependencies here. __all__ = [ "nn", "ns", "quantization", "pruning", ] def __getattr__(name): if name in __all__: import importlib return importlib.import_module("." + name, __name_...
398
22.470588
74
py
pytorch
pytorch-main/torch/ao/nn/quantized/functional.py
r""" Functional interface (quantized).""" from typing import List, Optional import warnings import torch from torch import Tensor from torch.nn.modules.utils import _pair, _triple from torch.jit.annotations import BroadcastingList2 from .modules.utils import _pair_from_first # Although some of the functions and docs...
29,279
44.395349
130
py
pytorch
pytorch-main/torch/ao/nn/quantized/reference/modules/sparse.py
import torch.nn as nn import torch.nn.functional as F from torch import Tensor from .utils import ReferenceQuantizedModule from typing import Optional, Dict, Any __all__ = ['Embedding', 'EmbeddingBag'] class Embedding(nn.Embedding, ReferenceQuantizedModule): """ A reference quantized Embedding module that fits in...
4,192
43.136842
126
py
pytorch
pytorch-main/torch/ao/nn/quantized/reference/modules/utils.py
import torch import typing __all__ = [ "ReferenceQuantizedModule", ] class ReferenceQuantizedModule(torch.nn.Module): def _init_weight_qparams(self, weight_qparams, device): if weight_qparams is None: weight_qparams = { "qscheme": torch.per_tensor_affine, "d...
14,295
43.123457
122
py
pytorch
pytorch-main/torch/ao/nn/quantized/reference/modules/linear.py
import torch import torch.nn as nn import torch.nn.functional as F from typing import Optional, Dict, Any from .utils import ReferenceQuantizedModule __all__ = ['Linear'] class Linear(nn.Linear, ReferenceQuantizedModule): """ A reference quantized linear module that fits into the FX Graph Mode Quantization wo...
2,183
36.655172
87
py
pytorch
pytorch-main/torch/ao/nn/quantized/reference/modules/rnn.py
import torch import torch.nn as nn from torch import Tensor from .utils import _quantize_and_dequantize_weight from .utils import _quantize_weight from typing import Optional, Dict, Any, Tuple from torch import _VF from torch.nn.utils.rnn import PackedSequence __all__ = ['RNNCellBase', 'RNNCell', 'LSTMCell', 'GRUCell'...
27,012
42.923577
131
py
pytorch
pytorch-main/torch/ao/nn/quantized/reference/modules/conv.py
import torch import torch.nn as nn import torch.nn.functional as F from typing import Optional, Dict, Any, List from torch.nn.common_types import _size_1_t from .utils import ReferenceQuantizedModule __all__ = ['Conv1d', 'Conv2d', 'Conv3d', 'ConvTranspose1d', 'ConvTranspose2d', 'ConvTranspose3d'] class _ConvNd(torch....
13,459
41.194357
117
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/embedding_ops.py
import torch import torch.nn as nn from torch import Tensor # noqa: F401 from torch._jit_internal import Optional, List # noqa: F401 from .utils import _hide_packed_params_repr from .utils import _quantize_weight __all__ = ['EmbeddingPackedParams', 'Embedding', 'EmbeddingBag'] class EmbeddingPackedParams(torch.nn....
13,538
44.739865
132
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/activation.py
import torch from warnings import warn __all__ = [ "ReLU6", "Hardswish", "ELU", "LeakyReLU", "Sigmoid", "Softmax", "MultiheadAttention", "PReLU" ] class ReLU6(torch.nn.ReLU): r"""Applies the element-wise function: :math:`\text{ReLU6}(x) = \min(\max(x_0, x), q(6))`, where :math:...
11,218
36.396667
103
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/batchnorm.py
import torch import torch.ao.nn.intrinsic as nni __all__ = [ "BatchNorm2d", "BatchNorm3d" ] class _BatchNorm(torch.nn.modules.batchnorm._BatchNorm): def __init__(self, num_features, eps=1e-5, momentum=0.1, device=None, dtype=None) -> None: factory_kwargs = {'device': device, 'dtype': dtype} ...
3,915
35.598131
94
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/utils.py
import abc import torch import itertools import collections from torch.nn.modules.module import _addindent __all__ = [ "WeightedQuantizedModule", ] class WeightedQuantizedModule(torch.nn.Module, metaclass=abc.ABCMeta): """Wrapper for quantized modules than can be lowered from reference modules.""" @classm...
4,579
37.813559
100
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/functional_modules.py
from typing import List import torch from torch import Tensor from torch._ops import ops __all__ = ['FloatFunctional', 'FXFloatFunctional', 'QFunctional'] class FloatFunctional(torch.nn.Module): r"""State collector class for float operations. The instance of this class can be used instead of the ``torch.`` ...
8,303
34.487179
101
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/linear.py
from collections.abc import Iterable import torch import torch.nn as nn import torch.ao.nn.intrinsic as nni import torch.ao.nn.intrinsic.qat as nniqat from torch.nn.utils.fusion import fuse_linear_bn_weights from torch.nn.utils.parametrize import type_before_parametrizations from typing import Optional from .utils i...
12,598
40.444079
128
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/dropout.py
import torch __all__ = ['Dropout'] class Dropout(torch.nn.Dropout): r"""This is the quantized equivalent of :class:`~torch.nn.Dropout`. And this is a placeholder to enable models where fp32 tensors had dropout to work with quantized tensors in train and eval mode. Args: p: probability...
743
25.571429
77
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/__init__.py
import torch # The quantized modules use `torch.nn` and `torch.ao.nn.quantizable` # packages. However, the `quantizable` package uses "lazy imports" # to avoid circular dependency. # Hence we need to include it here to make sure it is resolved before # they are used in the modules. import torch.ao.nn.quantizable from...
4,315
31.69697
106
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/rnn.py
import torch __all__ = [ "LSTM", ] class LSTM(torch.ao.nn.quantizable.LSTM): r"""A quantized long short-term memory (LSTM). For the description and the argument types, please, refer to :class:`~torch.nn.LSTM` Attributes: layers : instances of the `_LSTMLayer` .. note:: To access...
1,812
33.865385
88
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/conv.py
# coding=utf-8 r"""Quantized convolution modules.""" from typing import Optional, List, TypeVar import torch import torch.nn as nn import torch.nn.functional as F import torch.ao.nn.intrinsic as nni import torch.ao.nn.intrinsic.qat as nniqat from torch._ops import ops from torch.nn.common_types import _size_1_t from...
39,402
40.608237
113
py
pytorch
pytorch-main/torch/ao/nn/quantized/modules/normalization.py
import torch __all__ = ['LayerNorm', 'GroupNorm', 'InstanceNorm1d', 'InstanceNorm2d', 'InstanceNorm3d'] class LayerNorm(torch.nn.LayerNorm): r"""This is the quantized version of :class:`~torch.nn.LayerNorm`. Additional args: * **scale** - quantization scale of the output, type: double. * **ze...
8,081
39.41
100
py
pytorch
pytorch-main/torch/ao/nn/quantized/dynamic/modules/linear.py
import torch import torch.ao.nn.quantized as nnq from torch.ao.nn.quantized.modules.utils import _quantize_weight import torch.ao.nn.intrinsic as nni __all__ = [ "Linear", ] class Linear(nnq.Linear): r""" A dynamic quantized linear module with floating point tensor as inputs and outputs. We adopt the...
6,025
44.308271
104
py
pytorch
pytorch-main/torch/ao/nn/quantized/dynamic/modules/rnn.py
import numbers import warnings import torch import torch.nn as nn from torch import Tensor # noqa: F401 from torch._jit_internal import Tuple, Optional, List, Union, Dict # noqa: F401 from torch.nn.utils.rnn import PackedSequence from torch.ao.nn.quantized.modules.utils import _quantize_weight __all__ = ['pack_weig...
48,666
43.162432
126
py
pytorch
pytorch-main/torch/ao/nn/quantized/dynamic/modules/conv.py
# coding=utf-8 r"""Dynamically quantized convolution modules.""" import torch import torch.nn as nn import torch.nn.functional as F from torch import Tensor from torch._ops import ops from torch.nn.common_types import _size_1_t from torch.nn.modules.utils import _single, _pair, _triple from torch.ao.nn.quantized.modu...
17,025
41.458853
124
py
pytorch
pytorch-main/torch/ao/nn/sparse/quantized/linear.py
from typing import Optional import torch from torch.ao.nn.quantized.modules.utils import _quantize_weight, _hide_packed_params_repr __all__ = ['LinearPackedParams', 'Linear'] # TODO (zaf): Inherit from `quantized.LinearPackedParams` (T83294430) class LinearPackedParams(torch.nn.Module): _version = 1 def __i...
8,560
42.237374
116
py
pytorch
pytorch-main/torch/ao/nn/sparse/quantized/__init__.py
from torch.ao.nn.sparse.quantized import dynamic from .linear import Linear from .linear import LinearPackedParams __all__ = [ "dynamic", "Linear", "LinearPackedParams", ]
186
16
48
py
pytorch
pytorch-main/torch/ao/nn/sparse/quantized/dynamic/linear.py
from typing import Optional import torch import torch.ao.nn.intrinsic as nni from torch.ao.nn.sparse.quantized import linear from torch.ao.nn.sparse.quantized.utils import LinearBlockSparsePattern from torch.ao.nn.quantized.modules.utils import _quantize_weight, _hide_packed_params_repr __all__ = ['Linear'] class L...
6,080
41.823944
112
py
pytorch
pytorch-main/torch/ao/nn/qat/modules/embedding_ops.py
import torch from torch import Tensor import torch.nn as nn import torch.nn.functional as F __all__ = ['Embedding', 'EmbeddingBag'] class Embedding(nn.Embedding): r""" An embedding bag module attached with FakeQuantize modules for weight, used for quantization aware training. We adopt the same interf...
7,056
48.006944
110
py
pytorch
pytorch-main/torch/ao/nn/qat/modules/linear.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.ao.nn.intrinsic import LinearReLU from torch.nn.utils.parametrize import ( is_parametrized, type_before_parametrizations, transfer_parametrizations_and_params, ) __all__ = [ "Linear" ] class Linear(nn.Linear): r""" A...
2,874
34.060976
103
py
pytorch
pytorch-main/torch/ao/nn/qat/modules/conv.py
import torch import torch.nn as nn from torch.nn.modules.utils import _single, _pair, _triple from torch.ao.nn.intrinsic import _FusedModule from typing import Tuple, TypeVar, Union from torch.nn.common_types import _size_1_t, _size_2_t, _size_3_t __all__ = [ "Conv1d", "Conv2d", "Conv3d" ] MOD = TypeVar('...
9,424
33.778598
102
py
pytorch
pytorch-main/torch/ao/nn/qat/dynamic/modules/linear.py
import torch __all__ = ["Linear"] class Linear(torch.ao.nn.qat.Linear): r""" A linear module attached with FakeQuantize modules for weight, used for dynamic quantization aware training. We adopt the same interface as `torch.nn.Linear`, please see https://pytorch.org/docs/stable/nn.html#torch.nn.L...
933
34.923077
88
py
pytorch
pytorch-main/torch/ao/nn/quantizable/modules/activation.py
import torch import torch.jit # this is needed to avoid a circular import from torch import nn import torch.nn.functional as nnF from torch import Tensor from typing import Optional, Tuple import warnings __all__ = [ "MultiheadAttention" ] class MultiheadAttention(nn.MultiheadAttention): _FLOAT_MODULE = nn...
22,335
46.93133
126
py
pytorch
pytorch-main/torch/ao/nn/quantizable/modules/rnn.py
import numbers from typing import Optional, Tuple import warnings import torch from torch import Tensor """ We will recreate all the RNN modules as we require the modules to be decomposed into its building blocks to be able to observe. """ __all__ = [ "LSTMCell", "LSTM" ] class LSTMCell(torch.nn.Module): ...
17,023
40.82801
107
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/modules/conv_add.py
import torch import torch.ao.nn.intrinsic import torch.ao.nn.intrinsic.qat import torch.nn.functional as F import torch.ao.nn.quantized as nnq _reverse_repeat_padding = nnq.modules.conv._reverse_repeat_padding class ConvAdd2d(nnq.Conv2d): r""" A ConvAdd2d module is a fused module of Conv2d and Add We ado...
3,700
38.37234
84
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/modules/bn_relu.py
import torch import torch.ao.nn.intrinsic import torch.ao.nn.intrinsic.qat import torch.ao.nn.quantized as nnq __all__ = [ "BNReLU2d", "BNReLU3d" ] class BNReLU2d(nnq.BatchNorm2d): r""" A BNReLU2d module is a fused module of BatchNorm2d and ReLU We adopt the same interface as :class:`torch.ao.nn...
2,807
32.831325
94
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/modules/conv_relu.py
import torch import torch.ao.nn.intrinsic import torch.ao.nn.intrinsic.qat import torch.nn.functional as F import torch.ao.nn.quantized as nnq from torch.nn.utils import fuse_conv_bn_weights __all__ = [ "ConvReLU1d", "ConvReLU2d", "ConvReLU3d", ] _reverse_repeat_padding = nnq.modules.conv._reverse_repea...
7,062
39.82659
91
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/modules/linear_relu.py
import torch import torch.ao.nn.quantized as nnq import torch.ao.nn.intrinsic as nni from torch.ao.nn.quantized.modules.utils import _quantize_weight __all__ = [ "LinearReLU", "LinearLeakyReLU", "LinearTanh", ] class LinearReLU(nnq.Linear): r""" A LinearReLU module fused from Linear and ReLU modul...
6,492
35.477528
108
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/dynamic/modules/__init__.py
import torch from .linear_relu import LinearReLU __all__ = [ 'LinearReLU', ]
82
10.857143
35
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/quantized/dynamic/modules/linear_relu.py
import torch import torch.ao.nn.quantized.dynamic as nnqd import torch.ao.nn.intrinsic as nni __all__ = [ "LinearReLU" ] class LinearReLU(nnqd.Linear): r""" A LinearReLU module fused from Linear and ReLU modules that can be used for dynamic quantization. Supports both, FP16 and INT8 quantization. ...
1,855
32.142857
85
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/modules/fused.py
import torch from torch.nn import Conv1d, Conv2d, Conv3d, ReLU, Linear, BatchNorm1d, BatchNorm2d, BatchNorm3d from torch.nn.utils.parametrize import type_before_parametrizations __all__ = ['ConvReLU1d', 'ConvReLU2d', 'ConvReLU3d', 'LinearReLU', 'ConvBn1d', 'ConvBn2d', 'ConvBnReLU1d', 'ConvBnReLU2d', 'ConvBn...
9,596
55.786982
130
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/qat/modules/linear_fused.py
import torch import torch.nn as nn import torch.ao.nn.intrinsic as nni import torch.nn.functional as F from torch.nn import init from torch.nn.parameter import Parameter from torch.nn.utils.fusion import fuse_linear_bn_weights __all__ = [ "LinearBn1d", ] class LinearBn1d(nn.modules.linear.Linear, nni._FusedModule...
6,209
35.315789
96
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/qat/modules/conv_fused.py
import math import torch import torch.nn as nn import torch.ao.nn.intrinsic as nni import torch.ao.nn.qat as nnqat import torch.nn.functional as F from torch.nn import init from torch.nn.utils import fuse_conv_bn_weights from torch.nn.modules.utils import _single, _pair, _triple from torch.nn.parameter import Parameter...
29,514
34.775758
123
py
pytorch
pytorch-main/torch/ao/nn/intrinsic/qat/modules/linear_relu.py
import torch import torch.ao.nn.qat as nnqat import torch.ao.nn.intrinsic as nni import torch.nn.functional as F class LinearReLU(nnqat.Linear, nni._FusedModule): r""" A LinearReLU module fused from Linear and ReLU modules, attached with FakeQuantize modules for weight, used in quantization aware train...
1,577
31.204082
92
py
pytorch
pytorch-main/torch/ao/ns/_numeric_suite.py
import torch import torch.nn as nn import torch.ao.nn.quantized as nnq import torch.ao.nn.quantized.dynamic as nnqd from torch.ao.quantization import prepare from typing import Dict, List, Optional, Any, Union, Callable, Set from torch.ao.quantization.quantization_mappings import ( get_default_compare_output_modul...
19,527
36.055028
107
py
pytorch
pytorch-main/torch/ao/ns/_numeric_suite_fx.py
""" This module contains tooling to compare weights and activations across models. Example usage:: import copy import torch import torch.ao.quantization.quantize_fx as quantize_fx import torch.ao.ns._numeric_suite_fx as ns m = torch.nn.Sequential(torch.nn.Conv2d(1, 1, 1)).eval() mp = quantize_...
40,669
38.639376
103
py
pytorch
pytorch-main/torch/ao/ns/fx/qconfig_multi_mapping.py
from __future__ import annotations import copy from typing import Any, Callable, Dict, List, Union import torch from torch.ao.quantization import QConfigMapping from torch.ao.quantization.qconfig_mapping import _QCONFIG_STYLE_ORDER from torch.ao.quantization.qconfig import QConfigAny __all__ = ["QConfigMultiMapping"...
10,076
40.29918
122
py
pytorch
pytorch-main/torch/ao/ns/fx/pattern_utils.py
import torch import torch.nn as nn import torch.nn.functional as F toq = torch.ops.quantized from torch.fx import GraphModule from torch.fx.graph import Node from torch.ao.quantization.backend_config import get_native_backend_config from torch.ao.quantization.fx.quantize_handler import _get_pattern_to_quantize_handle...
8,311
40.353234
91
py
pytorch
pytorch-main/torch/ao/ns/fx/n_shadows_utils.py
import torch import torch.fx from torch.fx import ( Node, GraphModule, Graph, ) from torch.ao.ns.fx.utils import ( # TODO(future PR): make this work correctly for methods get_target_type_str, get_normalized_nth_input, ) from torch.ao.ns.fx.ns_types import ( NSSingleResultValuesType, NSR...
50,016
37.093679
119
py
pytorch
pytorch-main/torch/ao/ns/fx/graph_matcher.py
import collections import enum import torch toq = torch.ops.quantized from torch.fx import GraphModule from torch.fx.graph import Graph, Node from torch.ao.quantization.utils import getattr_from_fqn from .ns_types import NSSubgraph, NSNodeTargetType from .mappings import ( get_base_name_to_sets_of_related_ops, ...
19,233
40.722343
100
py
pytorch
pytorch-main/torch/ao/ns/fx/mappings.py
import operator import torch import torch.nn as nn import torch.nn.functional as F toq = torch.ops.quantized import torch.ao.nn.quantized as nnq import torch.ao.nn.quantized.dynamic as nnqd import torch.ao.nn.intrinsic.quantized as nniq import torch.ao.nn.intrinsic.quantized.dynamic as nniqd import torch.ao.nn.intrin...
18,270
22.97769
104
py
pytorch
pytorch-main/torch/ao/ns/fx/ns_types.py
import enum from typing import NamedTuple from torch.fx.graph import Node from typing import Dict, Any, List, Union, Callable class NSSingleResultValuesType(str, enum.Enum): WEIGHT = 'weight' NODE_OUTPUT = 'node_output' NODE_INPUT = 'node_input' NSSubgraph = NamedTuple( 'NSSubgraph', [('start_no...
2,378
35.6
83
py
pytorch
pytorch-main/torch/ao/ns/fx/utils.py
import enum import operator import torch import torch.nn as nn import torch.ao.nn.intrinsic.quantized as nniq import torch.ao.nn.quantized as nnq toq = torch.ops.quantized from typing import Tuple, Callable, Dict, Set, List, Optional, Union from torch.fx import GraphModule from torch.fx.graph import Node from torch....
20,595
37.569288
118
py
pytorch
pytorch-main/torch/ao/ns/fx/graph_passes.py
import torch from torch.fx import GraphModule, map_arg from torch.fx.graph import Graph, Node from torch.ao.quantization.fx.utils import get_new_attr_name_with_prefix from .utils import ( get_node_first_input_and_output_type, getattr_from_fqn, NodeInputOrOutputType, return_first_non_observer_node, ...
40,641
41.736067
106
py
pytorch
pytorch-main/torch/ao/ns/fx/weight_utils.py
import torch import torch.nn as nn import torch.nn.functional as F import torch.ao.nn.quantized.dynamic as nnqd import torch.ao.nn.quantized as nnq import torch.ao.nn.intrinsic.qat as nniqat import torch.ao.nn.qat as nnqat import torch.ao.nn.intrinsic as nni import torch.ao.nn.intrinsic.quantized as nniq toq = torch.op...
11,225
39.673913
93
py
pytorch
pytorch-main/torch/ao/pruning/_mappings.py
__all__ = [ "get_static_sparse_quantized_mapping", "get_dynamic_sparse_quantized_mapping", ] def get_static_sparse_quantized_mapping(): import torch.ao.nn.sparse _static_sparse_quantized_mapping = { torch.nn.Linear: torch.ao.nn.sparse.quantized.Linear, } return _static_sparse_quantized_...
566
28.842105
69
py
pytorch
pytorch-main/torch/ao/pruning/sparsifier/utils.py
from typing import Any, Dict, Optional, Type from torch.nn.utils.parametrize import type_before_parametrizations, is_parametrized from itertools import chain from torch import nn __all__ = [ "module_contains_param", "swap_module", "module_to_fqn", "fqn_to_module", "get_arg_info_from_tensor_fqn", ...
4,809
33.855072
104
py
pytorch
pytorch-main/torch/ao/pruning/sparsifier/weight_norm_sparsifier.py
from functools import reduce from typing import Callable, Optional, Tuple, Union import torch import torch.nn.functional as F from .base_sparsifier import BaseSparsifier __all__ = ["WeightNormSparsifier"] def _flat_idx_to_2d(idx, shape): rows = idx // shape[1] cols = idx % shape[1] return rows, cols cl...
8,872
43.365
120
py
pytorch
pytorch-main/torch/ao/pruning/sparsifier/base_sparsifier.py
import abc import copy from collections import defaultdict from typing import Any, Dict, Optional, Set, Tuple, List, Type import torch from torch import nn from torch.nn.utils import parametrize from torch.nn.utils.parametrize import type_before_parametrizations from .utils import ( module_contains_param, swa...
13,797
37.867606
113
py
pytorch
pytorch-main/torch/ao/pruning/sparsifier/nearly_diagonal_sparsifier.py
import torch from . import base_sparsifier class NearlyDiagonalSparsifier(base_sparsifier.BaseSparsifier): r"""Nearly Diagonal Sparsifier This sparsifier creates a nearly diagonal mask to be applied to the weight matrix. Nearly Diagonal Matrix is a matrix that contains non-zero elements near the diagona...
2,189
38.107143
116
py
pytorch
pytorch-main/torch/ao/pruning/scheduler/base_scheduler.py
from torch.ao.pruning import BaseSparsifier from functools import wraps import warnings import weakref __all__ = ["BaseScheduler"] class BaseScheduler: def __init__(self, sparsifier, last_epoch=-1, verbose=False): # Attach sparsifier if not isinstance(sparsifier, BaseSparsifier): r...
6,491
38.345455
108
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/pruner/lstm_saliency_pruner.py
from typing import cast import torch from .base_structured_sparsifier import BaseStructuredSparsifier, FakeStructuredSparsity class LSTMSaliencyPruner(BaseStructuredSparsifier): """ Prune packed LSTM weights based on saliency. For each layer {k} inside a LSTM, we have two packed weight matrices - weig...
2,050
40.857143
103
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/pruner/prune_functions.py
""" Collection of conversion functions for linear / conv2d structured pruning Also contains utilities for bias propagation """ from typing import cast, Optional, Callable, Tuple import torch from torch import nn, Tensor from torch.nn.utils import parametrize from torch.nn.utils.parametrize import ParametrizationList f...
18,831
38.563025
120
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/pruner/base_structured_sparsifier.py
from itertools import chain from operator import getitem import torch import torch.nn.functional as F from torch import nn from torch.fx import symbolic_trace from torch.nn.utils import parametrize from typing import Type, Set, Dict, Callable, Tuple, Optional, Union from torch.ao.pruning import BaseSparsifier from .pa...
10,824
33.807074
123
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/pruner/match_utils.py
""" Contains utility functions to check if a pattern is in the graph and return the matching nodes """ import torch from torch import nn from torch.ao.quantization.utils import ( MatchAllNode, ) from torch.fx import Node from torch.nn.utils import parametrize from typing import Any, Dict, List, Optional, Tuple, Uni...
1,967
31.8
98
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/pruner/parametrization.py
import torch from torch import nn from torch.nn.utils.parametrize import is_parametrized def module_contains_param(module, parametrization): if is_parametrized(module): # see if any of the module tensors have a parametriztion attached that matches the one passed in return any( any(isin...
1,818
29.316667
104
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/data_norm_sparsifier.py
import torch from torch.nn import functional as F from functools import reduce from typing import Any, List, Optional, Tuple from .base_data_sparsifier import BaseDataSparsifier __all__ = ['DataNormSparsifier'] class DataNormSparsifier(BaseDataSparsifier): r"""L1-Norm Sparsifier This sparsifier computes the...
7,508
48.078431
123
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/base_data_sparsifier.py
import abc import torch from typing import Optional, Tuple, List, Any, Dict from ...sparsifier import base_sparsifier from collections import defaultdict from torch import nn import copy from ...sparsifier import utils from torch.nn.utils import parametrize import sys import warnings if not sys.warnoptions: # to s...
13,046
41.087097
132
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/quantization_utils.py
import torch import torch.nn as nn from torch.ao.pruning.sparsifier.utils import module_to_fqn, fqn_to_module from typing import Dict, List, Optional SUPPORTED_MODULES = { nn.Embedding, nn.EmbeddingBag } def _fetch_all_embeddings(model): """Fetches Embedding and EmbeddingBag modules from the model ""...
5,966
44.549618
118
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/benchmarks/evaluate_forward_time.py
from typing import Dict, List import torch from dlrm_s_pytorch import unpack_batch # type: ignore[import] import numpy as np # type: ignore[import] import time from dlrm_utils import make_test_data_loader, fetch_model, dlrm_wrap # type: ignore[import] import pandas as pd # type: ignore[import] import argparse def...
3,908
34.862385
109
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/benchmarks/dlrm_utils.py
import torch from dlrm_s_pytorch import DLRM_Net # type: ignore[import] import numpy as np # type: ignore[import] from dlrm_data_pytorch import CriteoDataset, collate_wrapper_criteo_offset # type: ignore[import] import zipfile import os class SparseDLRM(DLRM_Net): """The SparseDLRM model is a wrapper around th...
4,906
32.380952
106
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/benchmarks/evaluate_model_metrics.py
from typing import Dict, List import torch from dlrm_s_pytorch import unpack_batch # type: ignore[import] import numpy as np # type: ignore[import] import sklearn # type: ignore[import] from dlrm_utils import make_test_data_loader, dlrm_wrap, fetch_model # type: ignore[import] import pandas as pd # type: ignore[im...
4,868
35.609023
99
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/benchmarks/evaluate_disk_savings.py
from typing import Dict, List import torch import time from torch.ao.pruning._experimental.data_sparsifier import DataNormSparsifier import os from dlrm_utils import get_dlrm_model, get_valid_name # type: ignore[import] import copy import zipfile from zipfile import ZipFile import pandas as pd # type: ignore[import] ...
6,405
39.0375
125
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/lightning/callbacks/data_sparsity.py
from collections import defaultdict from copy import deepcopy import torch from typing import Any, Optional, Dict import pytorch_lightning as pl # type: ignore[import] from ._data_sparstity_utils import ( _attach_model_to_data_sparsifier, _log_sparsified_level, _get_valid_name ) class PostTrainingDataSp...
6,473
38
128
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/lightning/callbacks/_data_sparstity_utils.py
import logging from torch.ao.pruning._experimental.data_sparsifier.base_data_sparsifier import SUPPORTED_TYPES logger: logging.Logger = logging.getLogger(__name__) def _attach_model_to_data_sparsifier(module, data_sparsifier, config=None): """Attaches a data sparsifier to all the layers of the module. Essent...
1,590
38.775
99
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_sparsifier/lightning/tests/test_callbacks.py
from torch.ao.pruning._experimental.data_sparsifier.data_norm_sparsifier import DataNormSparsifier from torch.ao.pruning._experimental.data_scheduler.base_data_scheduler import BaseDataScheduler import torch import torch.nn as nn from typing import List from torch.ao.pruning._experimental.data_sparsifier.lightning.call...
11,720
41.467391
116
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/activation_sparsifier/activation_sparsifier.py
from typing import Any, Dict, List, Optional import torch from collections import defaultdict from torch import nn import copy from ...sparsifier.utils import fqn_to_module, module_to_fqn import warnings __all__ = ['ActivationSparsifier'] class ActivationSparsifier: r""" The Activation sparsifier class aims ...
18,186
42.405728
126
py
pytorch
pytorch-main/torch/ao/pruning/_experimental/data_scheduler/base_data_scheduler.py
from functools import wraps import weakref import abc import warnings from ..data_sparsifier import BaseDataSparsifier __all__ = ['BaseDataScheduler'] class BaseDataScheduler: r""" The BaseDataScheduler is the abstract scheduler class specifically for the BaseDataSparsifier class. This class controls a ...
7,430
40.055249
113
py
pytorch
pytorch-main/torch/ao/quantization/fake_quantize.py
""" This module implements modules which are used to perform fake quantization during QAT. """ import torch from torch.nn import Module from torch.ao.quantization.observer import ( MovingAverageMinMaxObserver, HistogramObserver, MovingAveragePerChannelMinMaxObserver, FixedQParamsObserver, default_f...
24,091
44.20075
129
py
pytorch
pytorch-main/torch/ao/quantization/_equalize.py
import torch import copy from typing import Dict, Any __all__ = [ "set_module_weight", "set_module_bias", "get_module_weight", "get_module_bias", "max_over_ndim", "min_over_ndim", "channel_range", "cross_layer_equalization", "equalize", "converged", ] _supported_types = {torch....
6,799
36.777778
122
py
pytorch
pytorch-main/torch/ao/quantization/quantize_pt2e.py
from torch.fx import GraphModule from .pt2e.prepare import prepare from .pt2e._propagate_annotation import propagate_annotation from .pt2e.qat_utils import ( _fuse_conv_bn_qat, _fold_conv_bn_qat, ) from .pt2e.utils import ( _get_node_name_to_scope, _fuse_conv_bn_, _rearrange_weight_observer_for_dec...
4,161
31.515625
82
py
pytorch
pytorch-main/torch/ao/quantization/fuse_modules.py
import copy import torch.nn as nn from torch.ao.quantization.fuser_method_mappings import get_fuser_method # for backward compatibility from torch.ao.quantization.fuser_method_mappings import fuse_conv_bn # noqa: F401 from torch.ao.quantization.fuser_method_mappings import fuse_conv_bn_relu # noqa: F401 from torch...
6,740
37.301136
126
py
pytorch
pytorch-main/torch/ao/quantization/quantize_jit.py
import torch from torch.ao.quantization.qconfig import QConfig from torch.ao.quantization.quant_type import QuantType from torch.jit._recursive import wrap_cpp_module __all__ = [ "script_qconfig", "script_qconfig_dict", "fuse_conv_bn_jit", "prepare_jit", "prepare_dynamic_jit", "convert_jit", ...
14,605
42.470238
125
py
pytorch
pytorch-main/torch/ao/quantization/stubs.py
from torch import nn class QuantStub(nn.Module): r"""Quantize stub module, before calibration, this is same as an observer, it will be swapped as `nnq.Quantize` in `convert`. Args: qconfig: quantization configuration for the tensor, if qconfig is not provided, we will get qconfig from...
2,010
29.938462
81
py
pytorch
pytorch-main/torch/ao/quantization/_learnable_fake_quantize.py
import torch from torch.nn.parameter import Parameter from typing import List __all__: List[str] = [] class _LearnableFakeQuantize(torch.ao.quantization.FakeQuantizeBase): r""" This is an extension of the FakeQuantize module in fake_quantize.py, which supports more generalized lower-bit quantization and suppo...
7,269
45.305732
111
py
pytorch
pytorch-main/torch/ao/quantization/utils.py
""" Utils shared by different modes of quantization (eager/graph) """ import functools import warnings from collections import OrderedDict from inspect import getfullargspec, signature from typing import Any, Callable, Dict, Optional, Tuple, Union import torch from torch.ao.quantization.quant_type import QuantType fro...
25,265
35.938596
125
py
pytorch
pytorch-main/torch/ao/quantization/quantize_fx.py
from typing import Any, Dict, Optional, Tuple, Union import warnings import torch import copy from torch.fx import GraphModule from torch.fx.graph_module import _USER_PRESERVED_ATTRIBUTES_KEY from .fx.tracer import QuantizationTracer from .fx.tracer import ( # noqa: F401 Scope, ScopeContextManager ) from .fx....
32,024
42.990385
131
py
pytorch
pytorch-main/torch/ao/quantization/qconfig.py
from collections import namedtuple from typing import Optional, Any, Union, Type import torch import torch.nn as nn from torch.ao.quantization.fake_quantize import ( FakeQuantize, FakeQuantizeBase, default_fake_quant, default_dynamic_fake_quant, default_per_channel_weight_fake_quant, default_we...
25,871
45.117647
131
py
pytorch
pytorch-main/torch/ao/quantization/quantization_mappings.py
import copy import torch from torch import 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.intrinsic.qat as nniqat import torch.ao.nn.quantized as nnq import torch.ao.nn.qua...
13,907
38.851003
109
py
pytorch
pytorch-main/torch/ao/quantization/__init__.py
# flake8: noqa: F403 from .fake_quantize import * # noqa: F403 from .fuse_modules import fuse_modules # noqa: F403 from .fuse_modules import fuse_modules_qat # noqa: F403 from .fuser_method_mappings import * # noqa: F403 from .observer import * # noqa: F403 from .qconfig import * # noqa: F403 from .qconfig_mappi...
5,652
31.488506
91
py
pytorch
pytorch-main/torch/ao/quantization/quantize.py
import copy import itertools import warnings import torch import torch.nn as nn import torch.ao.nn.quantized as nnq from torch.ao.nn.intrinsic import _FusedModule from torch.ao.quantization.quantization_mappings import ( get_default_dynamic_quant_module_mappings, get_default_static_quant_module_mappings, ...
28,315
41.644578
132
py
pytorch
pytorch-main/torch/ao/quantization/fuser_method_mappings.py
import torch.nn as nn import torch.ao.nn.intrinsic as nni from typing import Union, Callable, Tuple, Dict, Optional, Type from torch.ao.quantization.utils import Pattern, get_combined_dict, MatchAllNode import itertools __all__ = [ "fuse_conv_bn", "fuse_conv_bn_relu", "fuse_linear_bn", "fuse_convtrans...
9,880
38.682731
118
py
pytorch
pytorch-main/torch/ao/quantization/_correct_bias.py
import torch import torch.nn as nn import torch.ao.nn.quantized as nnq import torch.ao.quantization import torch.ao.ns._numeric_suite as ns __all__ = [ "get_module", "parent_child_names", "get_param", "MeanShadowLogger", "bias_correction", ] _supported_modules = {nn.Linear, nn.Conv2d} _supported_...
5,074
36.043796
125
py
pytorch
pytorch-main/torch/ao/quantization/qconfig_mapping.py
from __future__ import annotations from collections import OrderedDict from typing import Any, Callable, Dict, Tuple, Union, List import torch from .fake_quantize import ( default_weight_fake_quant, FixedQParamsFakeQuantize, ) from .observer import ( _PartialWrapper, default_fixed_qparams_range_0to1_o...
14,598
40.592593
118
py