id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
23,743
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,744
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,745
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,746
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
replace_torch_lstm_with_stacked_lstm
23,747
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,748
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,749
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,750
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,751
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,752
import importlib.util import os import sys from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List import itertools import torch import torch.nn as nn import torch.nn.functional as F import nndct_shared.utils as nndct_utils import pytorch_nndct.utils.jit_utils as jit_utils import pytorch_nndct.utils.mo...
null
23,753
import copy import os import torch from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.utils import (AddXopError, NndctOption, NndctScreenLogger, option_util, QError, QWarning, set_option_value) from pytorch_nndct.utils.torch_utils import CmpFlag, compare_tor...
null
23,754
import copy import os import torch from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.utils import (AddXopError, NndctOption, NndctScreenLogger, option_util, QError, QWarning, set_option_value) from pytorch_nndct.utils.torch_utils import CmpFlag, compare_tor...
null
23,755
import copy import os import torch from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.utils import (AddXopError, NndctOption, NndctScreenLogger, option_util, QError, QWarning, set_option_value) from pytorch_nndct.utils.torch_utils import CmpFlag, compare_tor...
null
23,756
import copy import functools import itertools import types import torch from torch.utils._python_dispatch import _disable_current_modes from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.nndct_graph import (Block, Graph, Node, convert_graph_to_block_no...
null
23,757
import copy import functools from functools import partial import os import numpy as np import torch import nndct_shared.utils as nndct_utils from nndct_shared.quantization import quantize_data2int import pytorch_nndct.parse.torch_op_def as torch_op_def import pytorch_nndct.utils.tensor_util as py_tensor_util from pyto...
null
23,758
import torch _FLOAT_32 = 4 _GB = 1024 * _MB def tensor_size(tensor): assert isinstance(tensor, torch.Tensor) return torch.numel(tensor) * _FLOAT_32 / _GB
null
23,759
import torch _FLOAT_32 = 4 _GB = 1024 * _MB def tensor_size_by_num(num): return num * _FLOAT_32 / _GB
null
23,760
import copy import os from typing import Any, List, Optional, Sequence, Union import re import torch from pytorch_nndct.version import __version__, Ctorch_version import nndct_shared.utils as nndct_utils from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.compile import CompilerFactory, Dep...
r"""converts module to xmodel for deployment compilation only works when quantm model = 2. The xmodel and some checking data will be generated under work dir. Args: deploy_check(bool): if true, can dump blobs and parameters of model for deployment verification Returns: None
23,761
import copy import os from typing import Any, List, Optional, Sequence, Union import re import torch from pytorch_nndct.version import __version__, Ctorch_version import nndct_shared.utils as nndct_utils from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.compile import CompilerFactory, Dep...
null
23,762
import copy import os from typing import Any, List, Optional, Sequence, Union import re import torch from pytorch_nndct.version import __version__, Ctorch_version import nndct_shared.utils as nndct_utils from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.compile import CompilerFactory, Dep...
null
23,763
import copy import os from typing import Any, List, Optional, Sequence, Union import re import torch from pytorch_nndct.version import __version__, Ctorch_version import nndct_shared.utils as nndct_utils from nndct_shared.base import GLOBAL_MAP, NNDCT_KEYS, NNDCT_OP from nndct_shared.compile import CompilerFactory, Dep...
null
23,764
from torch import nn from typing import Any, List, Mapping import os import torch import torch.onnx from nndct_shared.expanding.spec import ExpandingSpec from nndct_shared.pruning import logging from pytorch_nndct.expanding.structured import ExpandingRunner from pytorch_nndct.utils import profiler import logging as _l...
null
23,765
from torch import nn from pytorch_nndct.nn import quantization as nnq from pytorch_nndct.quantization import module_transform from pytorch_nndct.utils import fusion from pytorch_nndct.utils import module_util as mod_util The provided code snippet includes necessary dependencies for implementing the `quantize_conv_bn` ...
Given the conv and bn modules, fuses them and returns the fused module Args: conv: Module instance of (nn.Conv2d, nn.Conv3d) bn: nn.BatchNorm2d or nn.BatchNorm3d instance that needs to be fused with the conv spec: Runtime specification used to initialize the fused module. Return: The fused module.
23,766
import abc from torch import nn from torch import Tensor from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.commander import OptimizeCommander from nndct_shared.utils import registry from pytorch_nndct import parse fr...
null
23,767
import abc from torch import nn from torch import Tensor from typing import Any, NoReturn, Optional, Sequence, Tuple, Union, List from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.commander import OptimizeCommander from nndct_shared.utils import registry from pytorch_nndct import parse fr...
null
23,768
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,769
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,770
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,771
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,772
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,773
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,774
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,775
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,776
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,777
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,778
import copy import os import torch import types from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.optimizer import QuantOptimizer from nndct_shared.utils import NndctOption from nndct_shared.utils import NndctScreenLogger from nndct_shared.utils import io as io_util from nndct_shared.util...
null
23,779
import abc from torch import nn from nndct_shared.base import NNDCT_OP as OpTypes from nndct_shared.optimization.commander import OptimizeCommander from nndct_shared.utils import registry from pytorch_nndct import parse from pytorch_nndct.nn import quantization as nnq from pytorch_nndct.nn.nonlinear import mode from py...
null
23,780
import copy import numpy as np from abc import ABC, abstractmethod import torch from nndct_shared.base import key_names, NNDCT_OP from nndct_shared.utils import tensor_util, NndctOption, NndctScreenLogger, QWarning, QError from pytorch_nndct.nn import fake_quantize_per_tensor def has_inf_nan(): return hasattr(torch, ...
null
23,781
import copy import numpy as np from abc import ABC, abstractmethod import torch from nndct_shared.base import key_names, NNDCT_OP from nndct_shared.utils import tensor_util, NndctOption, NndctScreenLogger, QWarning, QError from pytorch_nndct.nn import fake_quantize_per_tensor def convert_datatype_to_pytorch_type(datat...
null
23,782
import copy import numpy as np from abc import ABC, abstractmethod import torch from nndct_shared.base import key_names, NNDCT_OP from nndct_shared.utils import tensor_util, NndctOption, NndctScreenLogger, QWarning, QError from pytorch_nndct.nn import fake_quantize_per_tensor def convert_datatype_to_index(datatype): ...
null
23,783
import sys import numpy as np from abc import ABC, abstractmethod from scipy.stats import entropy from scipy import stats import torch from collections import Counter import pytorch_nndct as py_nndct from pytorch_nndct.nn.modules.fix_ops import diffs_fix_pos from nndct_shared.utils import NndctOption, NndctScreenLogger...
null
23,784
import abc import copy from torch import nn from pytorch_nndct.nn.modules import functional from pytorch_nndct.utils import logging from pytorch_nndct.utils import module_util as mod_util def quantize_input(module, index, quantizer): """Insert a quantizer for quantizing the input of the module. The input module i...
Insert quantizer for quantizing input/output of a module. The quantization of weight/bias is handled by quantized module itself.
23,785
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def get_module(model, submodule_key): tokens = submodule_key.s...
null
23,786
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def state_dict_from_node(node): def create_module_by_node(modul...
null
23,787
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def slim_model_from_state_dict(model, state_dict): """Modify m...
Transform a sparse model to a slim model by pruning results. Args: model: A sparse torch.nn.Module instance. path: File path that saves pruning results. Returns: A slim model.
23,788
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def setattr_if_has(module, name, attr): if not hasattr(module...
null
23,789
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def enable_dump_blob(model, graph=False, mode='print'): def ena...
null
23,790
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def enable_dump_blob(model, graph=False, mode='print'): node_a...
null
23,791
from torch import nn import numpy as np import torch import types from nndct_shared.base import NNDCT_OP from nndct_shared.pruning.pruner import load_pruning_info from pytorch_nndct.utils import TorchGraphSymbol from pytorch_nndct.utils import tensor_util def visualize_tensors(model): from nndct_shared.utils import ...
null
23,792
from nndct_shared.pruning.pruning_lib import PruningSpec from nndct_shared.nndct_graph import Graph from nndct_shared.pruning.sensitivity import NetSensitivity from typing import Mapping, List from pytorch_nndct.utils import TorchGraphSymbol, logging def extract_scope_name(node_name: str) -> str: def extract_scope_name...
null
23,793
from nndct_shared.pruning.pruning_lib import PruningSpec from nndct_shared.nndct_graph import Graph from nndct_shared.pruning.sensitivity import NetSensitivity from typing import Mapping, List from pytorch_nndct.utils import TorchGraphSymbol, logging def extract_scope_name(node_name: str) -> str: def extract_scope_name...
null
23,794
import torch def fuse_conv_bn_weight(conv_weight, conv_bias, running_mean, running_var, gamma, beta, eps, transposed=False): if conv_bias is None: ...
null
23,801
import torch from pytorch_nndct.utils.torch_utils import CmpFlag, compare_torch_version class CmpFlag(Enum): """ Enum for comparison flags """ EQUAL = 0 LESS = 1 LESS_EQUAL = 2 GREATER = 3 GREATER_EQUAL = 4 NOT_EQUAL = 5 def compare_torch_version(compare_type:CmpFlag, version:str): if compare_ty...
null
23,802
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,803
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,804
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,805
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,806
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,807
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,808
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,809
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,810
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
Returns chains of attribute access starting from root_getattr_node For example, given attribute "block", as in "self.block" when "self" points to the top level torch.nn.Module, it returns lists of attribute "chains", e.g. ['block', '2'], ['block', '1'], ['block', '0', '_packed_params'] These sets of attributes form ful...
23,811
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,812
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,813
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,814
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,815
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,816
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,817
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,818
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,819
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,820
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,821
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,822
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,823
import contextlib import re import itertools import torch.jit from torch.jit import _unique_state_dict from torch.nn import ModuleList from .schema import SchemaHelper, convert_type_str from .torch_const import TorchGraphSymbol from nndct_shared.utils import DeprecatedAPIError, NndctScreenLogger, NndctDebugLogger, Nndc...
null
23,824
import functools import inspect import types from typing import List, Optional from nndct_shared.utils import GLOBAL_MAP, NNDCT_KEYS, NndctScreenLogger, NNDCT_OP, QError, QWarning, QNote import torch from .nndct2torch_op_map import add_mapping_item from .torch_const import TorchSymbol from .torch_op_attr import gen_at...
null
23,825
import functools import inspect import types from typing import List, Optional from nndct_shared.utils import GLOBAL_MAP, NNDCT_KEYS, NndctScreenLogger, NNDCT_OP, QError, QWarning, QNote import torch from .nndct2torch_op_map import add_mapping_item from .torch_const import TorchSymbol from .torch_op_attr import gen_at...
null
23,826
import functools import inspect import types from typing import List, Optional from nndct_shared.utils import GLOBAL_MAP, NNDCT_KEYS, NndctScreenLogger, NNDCT_OP, QError, QWarning, QNote import torch from .nndct2torch_op_map import add_mapping_item from .torch_const import TorchSymbol from .torch_op_attr import gen_at...
null
23,827
import functools import inspect import types from typing import List, Optional from nndct_shared.utils import GLOBAL_MAP, NNDCT_KEYS, NndctScreenLogger, NNDCT_OP, QError, QWarning, QNote import torch from .nndct2torch_op_map import add_mapping_item from .torch_const import TorchSymbol from .torch_op_attr import gen_at...
The decorator is used to register the function as a custom operation. Args: op_type(str): The operator type registered into quantizer. The type should not conflict with pytorch_nndct attrs_list(Optional[List[str]], optional): the name list of attributes that define operation flavor. For example, Convolution operation h...
23,828
from typing import NamedTuple from typing import Iterator, Iterable import math import numpy as np PRECISIONS, EXPONENT_RANGES, DTYPES = {}, {}, {} The provided code snippet includes necessary dependencies for implementing the `min_positive_subnormal` function. Write a Python function `def min_positive_subnormal(dtype...
Returns the smallest positive subnormal number
23,829
from typing import NamedTuple from typing import Iterator, Iterable import math import numpy as np def to_fp32(x): """Returns `np.float32(x)`""" return np.float32(x) def to_fp16(x): """Returns `np.float16(x)`""" return np.float16(x) def to_fp64(x): """Returns `np.float64(x)`""" return np.float64(x) def to_b...
Converts an input array to another data type. Args: x (ArrayLike): Input array dtype_str: Use `bf16` or `bfloat16` for the Google Brain 16-bit floating-point format, `tf32` for the Nvidia TF32 format, which has the precsion of fp16 and the dynamic range of fp32, `fp16` or `float16` for IEEE `binary16`, and `fp32` or `f...
23,830
from typing import NamedTuple from typing import Iterator, Iterable import math import numpy as np The provided code snippet includes necessary dependencies for implementing the `float_generator` function. Write a Python function `def float_generator(precision: int, exponent_range: Iterable[int], ...
Generates all positive floating-point numbers in the exponent range according to the precision. Examples: The following examples enumerate all normal floating-point numbers for the IEEE `binary16` format in the `numpy` array `x_fp16` and for the Google Brain Float `bfloat16` format in `x_bf16`. >>> x_fp16 = np.array([i...
23,831
from typing import NamedTuple from typing import Iterator, Iterable import math import numpy as np The provided code snippet includes necessary dependencies for implementing the `block_float` function. Write a Python function `def block_float(x, precision, block_size, block_axis)` to solve the following problem: Force...
Forces a block of floating-point numbers to share an exponent, which is the maximum exponent of the numbers in the block. Numbers with non-maximum exponents lose precision and may become zero. Args: x (ArrayLike): Input array block_size (int): Every consecutive `block_size` numbers along `block_axis` share an exponent....
23,832
import torch import numpy as np from enum import Enum, unique def sqrt(input): x = input.to(torch.float32) # input tensor, float32 x2 = x*0.5 # float32 magic = 0x5f37 y = np.float32(x.cpu().detach().numpy()) # float32 i = y.view(np.int32) # int32 i = (magic - np.int32(i >> 17)) << 16 # int32 y = i.view...
null
23,833
import torch import numpy as np from enum import Enum, unique def isqrt(input): from bfloat16 import bfloat16 def downshift_onebit(i): # input: int16, numpy ndarray x = (i >> 1).reshape(-1) b = (i&1).reshape(-1) y = x for j in range(len(x)): if x[j]&1 == 1: # odd y[j] = y[j] + b[j] ...
null
23,834
import torch import numpy as np from enum import Enum, unique def invsqrt(number): x2 = number.astype(np.float32) x2 = x2 * 0.5 y = number.astype(np.float32) threehalfs = 1.5 i = y.view(np.int32) i = 0x5f3759df - (i >> 1) y = i.view(np.float32) y = y * (threehalfs - (x2 * y * y)) y = y * (threehalf...
null
23,835
import torch import numpy as np from enum import Enum, unique def aie_add_v8(v8): # input: tensor (L, 8) v4 = v8[:, 0:4] + v8[:, 4:] v2 = v4[:, 0:2] + v4[:, 2:] v1 = v2[:, 0] + v2[:, 1] return v1 # output: tensor (L,)
null
23,836
import torch import numpy as np from enum import Enum, unique def aie_add_v16(v16): # input: tensor (L, 16) v8 = v16[:, 0:8] + v16[:, 8:] v4 = v8[:, 0:4] + v8[:, 4:] v2 = v4[:, 0:2] + v4[:, 2:] v1 = v2[:, 0] + v2[:, 1] return v1 # output: tensor (L,)
null
23,837
import inspect from typing import Callable, Dict, Tuple import torch from nndct_shared.base import NNDCT_KEYS, GLOBAL_MAP from .torch_const import TorchOpClassType from .jit_utils import find_builtin, modules_containing_builtins, builtin_ops from .schema import SchemaHelper def get_torch_op_attr_map(): global _TORCH...
null
23,838
import inspect from typing import Callable, Dict, Tuple import torch from nndct_shared.base import NNDCT_KEYS, GLOBAL_MAP from .torch_const import TorchOpClassType from .jit_utils import find_builtin, modules_containing_builtins, builtin_ops from .schema import SchemaHelper from functools import namedtuple TorchOp = n...
null
23,839
import re def convert_type_str(typing_str): if '[' not in typing_str: return typing_str special_type = typing_str.split('[')[0] pattern, rlp_fn = patterns_rlp_pair[special_type] return pattern.sub(rlp_fn, typing_str) def _match_optional(match): typing_str = match[1] return convert_type_...
null
23,840
import re def convert_type_str(typing_str): if '[' not in typing_str: return typing_str special_type = typing_str.split('[')[0] pattern, rlp_fn = patterns_rlp_pair[special_type] return pattern.sub(rlp_fn, typing_str) def _match_list(match): typing_str = match[1] return convert_type_str(...
null
23,841
import re def convert_type_str(typing_str): if '[' not in typing_str: return typing_str special_type = typing_str.split('[')[0] pattern, rlp_fn = patterns_rlp_pair[special_type] return pattern.sub(rlp_fn, typing_str) def _match_tuple(match): x_typing_str = match[1] y_typing_str = match[...
null
23,842
import re def convert_type_str(typing_str): if '[' not in typing_str: return typing_str special_type = typing_str.split('[')[0] pattern, rlp_fn = patterns_rlp_pair[special_type] return pattern.sub(rlp_fn, typing_str) def _match_dict(match): x_typing_str = match[1] y_typing_str = match[2...
null
23,843
import re def convert_type_str(typing_str): def _match_brackets(match): outer_type_str = match[1] inner_type_str = match[2] return outer_type_str + '(' + convert_type_str(inner_type_str) + ')'
null
23,844
from enum import Enum, unique def get_enum_val(en): return en.value
null
23,845
from glob import glob from nndct_shared.base import NNDCT_OP from nndct_shared.utils import NndctScreenLogger def get_nndct_op_2_torch_op_map(): global _NNDCT_OP_2_TORCH_OP if len(_NNDCT_OP_2_TORCH_OP) == 0: raise Exception('please build the nndct_op -> torch_op map') return _NNDCT_OP_2_TORCH_OP def get_torc...
null
23,846
from glob import glob from nndct_shared.base import NNDCT_OP from nndct_shared.utils import NndctScreenLogger def get_torch_op_2_nndct_op_map(): global _TORCH_OP_2_NNDCT_OP if len(_TORCH_OP_2_NNDCT_OP) == 0: raise Exception('please build the torch_op -> nndct_op map') return _TORCH_OP_2_NNDCT_OP def get_nndc...
null
23,847
import time import torch from torch import nn from nndct_shared.utils import common from pytorch_nndct.utils import logging from pytorch_nndct.utils import torch_utils class MetricName(object): MACs = 'MACs' FLOPs = 'FLOPs' TrainableParams = 'trainable' NonTrainableParams = 'non-trainable' def _accumulate_metri...
null
23,848
import time import torch from torch import nn from nndct_shared.utils import common from pytorch_nndct.utils import logging from pytorch_nndct.utils import torch_utils class MetricName(object): MACs = 'MACs' FLOPs = 'FLOPs' TrainableParams = 'trainable' NonTrainableParams = 'non-trainable' def _accumulate_metri...
null