Search is not available for this dataset
repo stringlengths 2 152 ⌀ | file stringlengths 15 239 | code stringlengths 0 58.4M | file_length int64 0 58.4M | avg_line_length float64 0 1.81M | max_line_length int64 0 12.7M | extension_type stringclasses 364
values |
|---|---|---|---|---|---|---|
nni | nni-master/nni/common/hpo_utils/dedup.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Deduplicate repeated parameters.
No guarantee for forward-compatibility.
"""
from __future__ import annotations
import logging
import typing
import nni
from .formatting import FormattedParameters, FormattedSearchSpace, ParameterSpec, defo... | 3,498 | 35.072165 | 101 | py |
nni | nni-master/nni/common/hpo_utils/formatting.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Helper class and functions for tuners to deal with search space.
This script provides a more program-friendly representation of HPO search space.
The format is considered internal helper and is not visible to end users.
You will find this u... | 9,155 | 36.52459 | 119 | py |
nni | nni-master/nni/common/hpo_utils/optimize_mode.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from enum import Enum
class OptimizeMode(Enum):
Minimize = 'minimize'
Maximize = 'maximize'
| 175 | 18.555556 | 38 | py |
nni | nni-master/nni/common/hpo_utils/validation.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import Any
common_search_space_types = [
'choice',
'randint',
'uniform',
'quniform',
'loguniform',
'qloguniform',
'normal',
'qnormal',
'lognormal'... | 3,368 | 38.174419 | 119 | py |
nni | nni-master/nni/compression/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .utils.evaluator import LightningEvaluator, TorchEvaluator, TransformersEvaluator, DeepspeedTorchEvaluator
| 186 | 36.4 | 111 | py |
nni | nni-master/nni/compression/base/__init__.py | 0 | 0 | 0 | py | |
nni | nni-master/nni/compression/base/apply_method.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from typing import Any
import torch
from .target_space import PruningTargetSpace, QuantizationTargetSpace, TargetSpace, TargetType
def bypass(target: torch.Tensor, target_space: TargetSpace):
return target * 1.
def lsq_clamp_round(targe... | 10,898 | 40.919231 | 140 | py |
nni | nni-master/nni/compression/base/compressor.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from copy import deepcopy
import logging
from typing import Any, Dict, List, Literal, Callable
import torch
from torch.utils._pytree import tree_map
from .config import tra... | 22,255 | 48.238938 | 140 | py |
nni | nni-master/nni/compression/base/config.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from copy import deepcopy
import re
from typing import Any, Dict, List, Literal, Tuple
from schema import Schema, Optional, Or
import torch
from .setting import INPUT_PREFI... | 10,442 | 44.012931 | 131 | py |
nni | nni-master/nni/compression/base/fuse_modules.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from typing import Dict, Union, Tuple, Callable, Optional
from collections.abc import Iterable
from itertools import repeat
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch import Tensor
from .target_space import Ta... | 10,253 | 39.054688 | 121 | py |
nni | nni-master/nni/compression/base/setting.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from copy import deepcopy
from typing import Any, Dict, Literal, Type
import torch
INPUT_PREFIX = '_input_'
OUTPUT_PREFIX = '_output_'
_SETTING = Dict[str, Dict[str, Any]]
class ModuleSetting:
"""
T... | 9,005 | 34.456693 | 123 | py |
nni | nni-master/nni/compression/base/target_space.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import abc
from copy import deepcopy
from enum import Enum
from typing import Any, Dict, List, Literal, Tuple
import torch
from torch import Tensor
from ..utils.scaling import Scaling
class... | 15,116 | 34.907363 | 131 | py |
nni | nni-master/nni/compression/base/wrapper.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
import inspect
import functools
from typing import Any, Callable, Dict, List, Tuple, Type, Union, Literal
import torch
import torch.nn as nn
from torch import... | 28,936 | 49.855888 | 139 | py |
nni | nni-master/nni/compression/distillation/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .basic_distiller import DynamicLayerwiseDistiller, Adaptive1dLayerwiseDistiller
| 159 | 31 | 84 | py |
nni | nni-master/nni/compression/distillation/basic_distiller.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
from typing import Any, Callable, Dict, List, overload
import torch
import torch.nn.functional as F
from torch.utils._pytree import tree_map
from ..base.comp... | 16,466 | 46.869186 | 139 | py |
nni | nni-master/nni/compression/pruning/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .basic_pruner import LevelPruner, L1NormPruner, L2NormPruner, FPGMPruner
from .movement_pruner import MovementPruner
from .scheduled_pruner import LinearPruner, AGPPruner
from .slim_pruner import SlimPruner
from .taylor_pruner import TaylorP... | 326 | 35.333333 | 77 | py |
nni | nni-master/nni/compression/pruning/basic_pruner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import Dict, List, Literal, Tuple, overload
import torch
from .tools import _DATA, _METRICS, _MASKS, active_sparse_targets_filter, norm_metrics, fpgm_metrics, generate_sparsity
from... | 7,592 | 37.739796 | 131 | py |
nni | nni-master/nni/compression/pruning/movement_pruner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
from typing import Dict, List, overload
import torch
from torch.optim import Adam
from .scheduled_pruner import ScheduledPruner
from .tools import is_active_... | 10,849 | 46.379913 | 137 | py |
nni | nni-master/nni/compression/pruning/scheduled_pruner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
from typing import Dict, List
import torch
from ..base.compressor import Pruner
from ..base.wrapper import ModuleWrapper
from ..utils import Evaluator, _EVAL... | 8,079 | 41.303665 | 124 | py |
nni | nni-master/nni/compression/pruning/slim_pruner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
from typing import Dict, List, Literal, Tuple, overload
import torch
from torch.optim import Adam
from .tools import _METRICS, _MASKS, generate_sparsity, is_... | 8,921 | 43.834171 | 126 | py |
nni | nni-master/nni/compression/pruning/taylor_pruner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import functools
import logging
from typing import Callable, Dict, List, Literal, Tuple, overload
import torch
from .tools import _METRICS, _MASKS, norm_metrics, generate_s... | 7,568 | 44.596386 | 188 | py |
nni | nni-master/nni/compression/pruning/tools/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .collect_data import _DATA, active_sparse_targets_filter
from .calculate_metrics import _METRICS, norm_metrics, fpgm_metrics
from .sparse_gen import _MASKS, generate_sparsity
from .utils import is_active_target
| 290 | 35.375 | 67 | py |
nni | nni-master/nni/compression/pruning/tools/calculate_metrics.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from typing import Dict
import torch
from .collect_data import _DATA
from ...base.compressor import _PRUNING_TARGET_SPACES
_METRICS = Dict[str, Dict[str, torch.Tensor]]
... | 2,348 | 38.15 | 119 | py |
nni | nni-master/nni/compression/pruning/tools/collect_data.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from typing import Dict
import torch
from .utils import is_active_target
from ...base.compressor import _PRUNING_TARGET_SPACES
_DATA = Dict[str, Dict[str, torch.Tensor]]
... | 828 | 29.703704 | 95 | py |
nni | nni-master/nni/compression/pruning/tools/sparse_gen.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from functools import reduce
import heapq
from typing import Callable, Dict, List, Tuple
import numpy
import torch
from .calculate_metrics import _METRICS
from ...base.comp... | 15,984 | 49.746032 | 138 | py |
nni | nni-master/nni/compression/pruning/tools/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from ...base.target_space import PruningTargetSpace
def is_active_target(target_space: PruningTargetSpace):
return target_space.sparse_ratio is not None or target_space.sparse_threshold is not None
| 314 | 27.636364 | 93 | py |
nni | nni-master/nni/compression/quantization/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .qat_quantizer import QATQuantizer
from .bnn_quantizer import BNNQuantizer
from .dorefa_quantizer import DoReFaQuantizer
from .lsq_quantizer import LsqQuantizer
from .ptq_quantizer import PtqQuantizer
from .lsqplus_quantizer import LsqPlusQu... | 443 | 36 | 113 | py |
nni | nni-master/nni/compression/quantization/bnn_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import List, Dict, overload
import torch
from torch import Tensor
from ..base.compressor import Compressor, Quantizer
from ..base.wrapper import ModuleWrapper
from ..base.target_spa... | 5,407 | 41.582677 | 138 | py |
nni | nni-master/nni/compression/quantization/dorefa_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import List, Dict, Union, overload
import torch
import torch.nn as nn
from torch import Tensor
from nni.common.version import torch_version_is_2
from ..base.compressor import Compre... | 12,208 | 50.083682 | 136 | py |
nni | nni-master/nni/compression/quantization/lsq_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import List, Dict, overload
import torch
from torch import Tensor
from ..base.compressor import Compressor, Quantizer
from ..base.wrapper import ModuleWrapper
from ..utils import Eva... | 6,972 | 42.310559 | 118 | py |
nni | nni-master/nni/compression/quantization/lsqplus_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing import List, Dict, overload
import torch
from torch import Tensor
from ..base.compressor import Compressor, Quantizer
from ..base.wrapper import ModuleWrapper
from ..utils import Eva... | 7,067 | 43.734177 | 180 | py |
nni | nni-master/nni/compression/quantization/ptq_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from typing import List, Dict, Union, overload
import torch
from torch import Tensor
from ..base.compressor import Compressor, Quantizer
from ..base.wrapper import ModuleWrapper
from ..base.target_space import... | 7,810 | 43.634286 | 118 | py |
nni | nni-master/nni/compression/quantization/qat_quantizer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from typing import Dict, List, overload
import torch
from torch import Tensor
from ..base.compressor import Compressor, Quantizer
from ..base.wrapper import ModuleWrapper
from ..utils import Evaluator, _EVALU... | 10,494 | 49.215311 | 130 | py |
nni | nni-master/nni/compression/quantization_speedup/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .integrated_tensorrt import ModelSpeedupTensorRT | 127 | 31 | 53 | py |
nni | nni-master/nni/compression/quantization_speedup/backend.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
class BaseModelSpeedup:
"""
Base speedup class for backend engine
"""
def __init__(self, model, config):
"""
Parameters
----------
model : pytorch model
The model to speedup by quantizat... | 1,588 | 30.156863 | 90 | py |
nni | nni-master/nni/compression/quantization_speedup/calibrator.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import os
import logging
import tensorrt as trt
import pycuda.driver as cuda
logger = logging.getLogger(__name__)
class Calibrator(trt.IInt8Calibrator):
def __init__(self, training_data, cache_file, batch_size=64, algorithm=trt.CalibrationA... | 3,425 | 33.606061 | 122 | py |
nni | nni-master/nni/compression/quantization_speedup/frontend_to_onnx.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import onnx
import onnx.numpy_helper
from ..utils import set_nested_attr
"""
The main function of this page is to convert pytorch model to onnx model.
Convertion from pytorch model to onnx model is primary so that a critical
problem... | 5,235 | 37.218978 | 140 | py |
nni | nni-master/nni/compression/quantization_speedup/integrated_tensorrt.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import time
import logging
import tensorrt as trt
import numpy as np
import torch
from . import frontend_to_onnx as fonnx
from . import trt_pycuda as common # NOTE pycuda becomes a dependency, consider adding it to dependencies
from .backend imp... | 14,915 | 37.742857 | 107 | py |
nni | nni-master/nni/compression/quantization_speedup/trt_pycuda.py | #
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at... | 3,776 | 35.669903 | 113 | py |
nni | nni-master/nni/compression/speedup/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .dependency import auto_set_denpendency_group_ids
from .model_speedup import ModelSpeedup
| 169 | 27.333333 | 54 | py |
nni | nni-master/nni/compression/speedup/container.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from typing import TYPE_CHECKING
import torch
from torch.fx.node import Node
if TYPE_CHECKING:
from .mask_updater import MaskUpdater
class NodeInfo:
"""
Stores the infomation of each intermediate... | 825 | 25.645161 | 98 | py |
nni | nni-master/nni/compression/speedup/dependency.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
import operator
from copy import deepcopy
from typing import (Any, Dict, List, Set)
from uuid import uuid4
import numpy as np
import torch
import torch.fx
from torch.fx.passes.shape_prop import TensorMetadata
from nni.compression... | 17,571 | 38.48764 | 140 | py |
nni | nni-master/nni/compression/speedup/error_code.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# Error Code of the speedup
class SpeedupError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return str(self.msg)
class EmptyLayerError(SpeedupError):
def __init__(self):
super(EmptyLa... | 1,113 | 34.935484 | 101 | py |
nni | nni-master/nni/compression/speedup/mask_conflict.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
from typing import Dict
import numpy as np
import torch
import torch.fx
from .dependency import (build_channel_dependency, build_group_dependency,
build_weight_sharing_dependency)
_logger = logging.getLog... | 18,178 | 41.474299 | 132 | py |
nni | nni-master/nni/compression/speedup/mask_updater.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from typing import TYPE_CHECKING, Tuple
if TYPE_CHECKING:
from .container import NodeInfo
from .model_speedup import ModelSpeedup
import operator
import torch
from torch.nn import functional as F
from ... | 20,408 | 43.079914 | 140 | py |
nni | nni-master/nni/compression/speedup/model_speedup.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import inspect
import logging
from pathlib import Path
import tempfile
from typing import Any, Dict, List
import torch
import torch.fx
from torch.fx import GraphModule
from torch.fx._compatibility import compa... | 20,874 | 45.081678 | 132 | py |
nni | nni-master/nni/compression/speedup/replacement.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
import math
import torch
import torch.nn as nn
from .error_code import EmptyLayerError, ShapeMisMatchError, InputsNumberError, OutputTypeError, UnBalancedGroupError
_logger = logging.getLogger(__name__)
replace_module = {
'Ba... | 38,509 | 39.536842 | 139 | py |
nni | nni-master/nni/compression/speedup/replacer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
from typing import TYPE_CHECKING, Callable, Dict
from torch.utils._pytree import tree_map
from ..utils import get_nested_attr, set_nested_attr
if TYPE_CHECKING:
from .model_speedup import ModelSpeedup
_logger = logging.getL... | 2,670 | 39.469697 | 123 | py |
nni | nni-master/nni/compression/speedup/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from copy import deepcopy
import logging
from typing import Any, Dict, List, Tuple
import torch
from torch.fx.immutable_collections import immutable_dict, immutable_list
from torch.utils._pytree import tree_map, tree_flatten, tree_unflatten, _re... | 4,032 | 34.377193 | 117 | py |
nni | nni-master/nni/compression/utils/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .check_ddp import check_ddp_model, reset_ddp_model
from .dependency import auto_set_denpendency_group_ids
from .evaluator import (Evaluator,
LightningEvaluator,
TorchEvaluator,
... | 1,087 | 35.266667 | 130 | py |
nni | nni-master/nni/compression/utils/attr.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from functools import reduce
from typing import Any, overload
@overload
def get_nested_attr(__o: object, __name: str) -> Any:
...
@overload
def get_nested_attr(__o: object, __name: str, __default: Any) -> Any:
...
def get_nested_attr(... | 1,482 | 30.553191 | 102 | py |
nni | nni-master/nni/compression/utils/check_ddp.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from typing import Dict
import torch
import torch.nn as nn
def check_ddp_model(model: nn.Module):
is_ddp_model = False
ddp_params = {}
if isinstance(model, torch.nn.parallel.DistributedDataParallel):
attr_dicts = model.__dict... | 1,704 | 42.717949 | 100 | py |
nni | nni-master/nni/compression/utils/constructor_helper.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from copy import deepcopy
from typing import Callable, Dict, List, Type
from torch import Tensor
from torch.nn import Module
from torch.optim import Optimizer
from nni.common.serializer import is_traceable
fr... | 5,163 | 41.327869 | 123 | py |
nni | nni-master/nni/compression/utils/counter.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import functools
from collections import Counter
from prettytable import PrettyTable
import torch
import torch.nn as nn
from torch.nn.utils.rnn import PackedSequence
from nni.compression.base.wrapper import ModuleWrapper
__all__ = ['count_flop... | 14,692 | 34.924205 | 124 | py |
nni | nni-master/nni/compression/utils/dependency.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from copy import deepcopy
from typing import Any, Dict, List
import uuid
import torch
from .shape_dependency import ChannelDependency, GroupDependency
from ..base.config import select_modules_by_config, trans... | 2,133 | 34.566667 | 133 | py |
nni | nni-master/nni/compression/utils/docstring.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
_EVALUATOR_DOCSTRING = r"""NNI will use the evaluator to intervene in the model training process,
so as to perform training-aware model compression.
All training-aware model compression will use the evaluator as the entry for int... | 3,880 | 51.445946 | 144 | py |
nni | nni-master/nni/compression/utils/evaluator.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections.abc import Sequence, MutableMapping
from copy import deepcopy
import logging
import types
from typing import Dict, List, Tuple, Union, Any, Callable, Optional
import torch
from torch import Te... | 82,712 | 49.281459 | 140 | py |
nni | nni-master/nni/compression/utils/fused_utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from typing import List, Dict, Any, Tuple
import torch
import torch.nn as nn
from ..base.setting import OUTPUT_PREFIX
FUSED_MODULES_TYPES_LIST = [nn.Linear, nn.Conv1d, nn.Conv2d, nn.Conv3d, nn.ConvTranspose1d, \
nn.ConvTranspose2d, nn... | 3,060 | 42.728571 | 139 | py |
nni | nni-master/nni/compression/utils/mask_conflict.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import os
import logging
import torch
import numpy as np
from .attr import get_nested_attr
from .shape_dependency import ChannelDependency, GroupDependency, InputChannelDependency
# logging.basicConfig(level = logging.DEBUG)
_logger = logging.getL... | 18,065 | 41.508235 | 137 | py |
nni | nni-master/nni/compression/utils/mask_counter.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from copy import deepcopy
import math
from typing import Dict, List, Tuple
import torch
from torch import Tensor
from torch.nn import Module
def compute_sparsity_compact2origin(origin_model: Module, compact_model: Module, config_list: List[Dic... | 7,686 | 49.907285 | 135 | py |
nni | nni-master/nni/compression/utils/scaling.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from functools import reduce
from typing import Callable, List
from typing_extensions import Literal
import torch
from torch import Tensor
class Scaling:
"""
In the process of generating masks, a larg... | 10,907 | 50.45283 | 128 | py |
nni | nni-master/nni/compression/utils/shape_dependency.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import csv
import logging
import torch
import numpy as np
from .attr import get_nested_attr
__all__ = ['ChannelDependency', 'GroupDependency', 'ReshapeDependency',
'InputChannelDependency', 'AttentionWeightDependency']
CONV_TYPE =... | 31,869 | 37.77129 | 127 | py |
nni | nni-master/nni/compression/utils/external/__init__.py | 0 | 0 | 0 | py | |
nni | nni-master/nni/compression/utils/external/external_replacer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
import logging
import re
from typing import TYPE_CHECKING, List
import torch
from torch.utils._pytree import tree_map
from .huggingface import parser_factory, HuggingfaceMo... | 6,739 | 49.298507 | 126 | py |
nni | nni-master/nni/compression/utils/external/huggingface.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
import re
from typing import Tuple
from torch.nn import Module
try:
from transformers import (
PreTrainedModel,
BartConfig,
BertConfig,
DistilBertConfig,
... | 6,358 | 35.545977 | 139 | py |
nni | nni-master/nni/compression/utils/quantization/__init__.py | 0 | 0 | 0 | py | |
nni | nni-master/nni/compression/utils/quantization/literal.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from enum import Enum, EnumMeta
class _QuantLiteralEnumMeta(EnumMeta):
def __contains__(cls, item):
try:
cls(item) # pylint: disable=no-value-for-parameter
except ValueError:
return False
ret... | 1,837 | 25.637681 | 94 | py |
nni | nni-master/nni/compression/utils/quantization/observers.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from torch.quantization import default_weight_observer, default_histogram_observer
from torch.quantization import RecordingObserver as _RecordingObserver
__all__ = ["default_weight_observer", "default_histogram_observer", "RecordingObserver"]
... | 557 | 28.368421 | 88 | py |
nni | nni-master/nni/compression/utils/quantization/settings.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from typing import Any, Optional
from .literal import QuantDtype, QuantType, QuantScheme
from .utils import calculate_qmin_qmax, get_bits_length
# default settings for quantization module
quant_default_settings = {
QuantType.WEIGHT: {
... | 4,654 | 37.155738 | 98 | py |
nni | nni-master/nni/compression/utils/quantization/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
from nni.common.version import TORCH_VERSION
from .literal import QuantDtype, QuantScheme, QuantType
def calculate_qmin_qmax(bits, dtype):
if dtype == QuantDtype.INT:
qmin, qmax = -2 ** (bits - 1) + 1, 2 ** (bits - 1)... | 2,651 | 29.482759 | 104 | py |
nni | nni-master/nni/contrib/__init__.py | 0 | 0 | 0 | py | |
nni | nni-master/nni/contrib/distillation/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
| 73 | 23.666667 | 38 | py |
nni | nni-master/nni/contrib/distillation/label_patcher.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import abc
import logging
from os import PathLike
from pathlib import Path
from typing import Any, Callable, Dict, List, Literal, Type, cast
from torch.utils.data import DataLoader, Dataset
f... | 9,325 | 49.410811 | 140 | py |
nni | nni-master/nni/contrib/distillation/storage.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
import os
from os import PathLike
from pathlib import Path
import shutil
import tempfile
from typing import Any, Dict, List, Literal
try:
import h5py
except ImportError:
h5py = None
imp... | 9,101 | 33.873563 | 140 | py |
nni | nni-master/nni/contrib/distillation/uid_dataset.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from collections import defaultdict
from typing import Any, Callable, Dict, List, Type
import torch
from torch.utils.data import Dataset, IterableDataset
from .utils import _default_get_rngs_state, _default_s... | 6,474 | 38.969136 | 134 | py |
nni | nni-master/nni/contrib/distillation/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from pathlib import Path
import pickle
import random
from typing import Dict, List
import numpy
import torch
def _to_tensor(sample):
if isinstance(sample, torch.Tensor):
return sample
elif isinstance(sample, numpy.ndarray):
... | 1,800 | 26.287879 | 116 | py |
nni | nni-master/nni/contrib/training_service/__init__.py | 0 | 0 | 0 | py | |
nni | nni-master/nni/contrib/training_service/file_channel.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
import time
from pathlib import Path
Command = str
class _PrefixAdapter(logging.LoggerAdapter):
def process(self, msg, kwargs):
if isinstance(self.extra, dict) and 'prefix' in self... | 7,926 | 38.834171 | 116 | py |
nni | nni-master/nni/contrib/training_service/trial_client.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
from typing_extensions import Literal
import requests
import nni
from nni.typehint import ParameterRecord, TrialMetric
from nni.runtime.env_vars import trial_env_vars
from nni.runtime.trial_com... | 2,567 | 35.169014 | 124 | py |
nni | nni-master/nni/contrib/training_service/trial_runner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import atexit
import argparse
import json
import logging
import os
import subprocess
import sys
import threading
import time
from collections import deque
from functools import partial
from http.server import B... | 16,872 | 36.579065 | 134 | py |
nni | nni-master/nni/contrib/training_service/typehint.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
from typing import TypedDict, Any, Type, TypeVar, get_origin
from typing_extensions import Literal, TypeGuard
_logger = logging.getLogger(__name__)
T = TypeVar('T')
def typed_dict_validation(typ: Type[T], instance: Any) -> Typ... | 3,209 | 30.470588 | 98 | py |
nni | nni-master/nni/contrib/training_service/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import logging
import signal
import sys
import time
from pathlib import Path
from subprocess import Popen, PIPE
_logger = logging.getLogger(__name__)
_logger_init: bool = False
def graceful_kill(popen: Pope... | 4,193 | 29.172662 | 132 | py |
nni | nni-master/nni/experiment/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .config import *
from .experiment import Experiment, RunMode
from .data import *
| 160 | 22 | 43 | py |
nni | nni-master/nni/experiment/data.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
from dataclasses import dataclass
import json
from typing import Any, List, Optional
@dataclass
class TrialResult:
"""
TrialResult stores the result information of a trial job.
Attributes
---... | 4,221 | 26.776316 | 135 | py |
nni | nni-master/nni/experiment/experiment.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import atexit
from enum import Enum
import logging
from pathlib import Path
import socket
from subprocess import Popen
import time
from typing import Any, cast
import psutil
from typing_extensions import Liter... | 21,543 | 33.860841 | 133 | py |
nni | nni-master/nni/experiment/launcher.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from __future__ import annotations
import contextlib
from dataclasses import dataclass, fields
from datetime import datetime
import logging
import os.path
from pathlib import Path
import socket
from subprocess import Popen
import sys
import time... | 10,266 | 36.064982 | 121 | py |
nni | nni-master/nni/experiment/management.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from pathlib import Path
from random import Random
import string
import re
def generate_experiment_id() -> str:
return ''.join(Random().sample(string.ascii_lowercase + string.digits, 8))
def is_valid_experiment_id(experiment_id: str) -> b... | 660 | 25.44 | 78 | py |
nni | nni-master/nni/experiment/pipe.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
import os
import sys
_logger = logging.getLogger(__name__)
if sys.platform == 'win32':
import _winapi
import msvcrt
class WindowsPipe:
def __init__(self, experiment_id: str):
self.path: str = r'\\... | 2,107 | 27.106667 | 107 | py |
nni | nni-master/nni/experiment/rest.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
from typing import Any, Optional
import requests
# API URL must be synchronized with:
# - ts/nni_manager/rest_server/index.ts
# - ts/webui/src/static/constant.ts
# Remember to update them if the values are changed, or if this f... | 1,724 | 31.54717 | 111 | py |
nni | nni-master/nni/experiment/config/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .experiment_config import ExperimentConfig
from .algorithm import AlgorithmConfig, CustomAlgorithmConfig
from .training_services import *
from .shared_storage import *
| 247 | 30 | 61 | py |
nni | nni-master/nni/experiment/config/algorithm.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Config classes for tuner and assessor algorithms.
Use ``AlgorithmConfig`` to specify a built-in algorithm;
use ``CustomAlgorithmConfig`` to specify a custom algorithm.
Check the reference_ for explaination of each field.
You may also want ... | 2,121 | 29.314286 | 117 | py |
nni | nni-master/nni/experiment/config/base.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
``ConfigBase`` class. Nothing else.
Docstrings in this file are mainly for NNI contributors instead of end users.
"""
__all__ = ['ConfigBase']
import copy
import dataclasses
from pathlib import Path
import yaml
from . import utils
class... | 10,414 | 35.416084 | 120 | py |
nni | nni-master/nni/experiment/config/convert.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import copy
import logging
_logger = logging.getLogger(__name__)
def to_v2(v1):
v1 = copy.deepcopy(v1)
platform = v1.pop('trainingServicePlatform')
assert platform in ['local', 'remote', 'pai', 'aml', 'kubeflow', 'frameworkcontrolle... | 12,661 | 40.927152 | 116 | py |
nni | nni-master/nni/experiment/config/experiment_config.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Top level experiement configuration class, ``ExperimentConfig``.
"""
__all__ = ['ExperimentConfig']
from dataclasses import dataclass
import json
import logging
from pathlib import Path
from typing import Any, List, Optional, Union
from typ... | 9,497 | 45.558824 | 119 | py |
nni | nni-master/nni/experiment/config/shared_storage.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from dataclasses import dataclass
from typing import Optional
from .base import ConfigBase
from .utils import PathLike
__all__ = ['NfsConfig', 'AzureBlobConfig']
@dataclass(init=False)
class SharedStorageConfig(ConfigBase):
storage_type: s... | 966 | 25.861111 | 46 | py |
nni | nni-master/nni/experiment/config/training_service.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
``TrainingServiceConfig`` class.
Docstrings in this file are mainly for NNI contributors, or training service authors.
"""
__all__ = ['TrainingServiceConfig']
from dataclasses import dataclass
from pathlib import Path
from typing import Op... | 1,784 | 29.775862 | 118 | py |
nni | nni-master/nni/experiment/config/training_services/__init__.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from .local import *
from .remote import *
from .openpai import *
from .k8s_storage import *
from .kubeflow import *
from .frameworkcontroller import *
from .aml import *
from .dlc import *
| 264 | 21.083333 | 38 | py |
nni | nni-master/nni/experiment/config/training_services/aml.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Configuration for AML training service.
Check the reference_ for explaination of each field.
You may also want to check `AML training service doc`_.
.. _reference: https://nni.readthedocs.io/en/stable/reference/experiment_config.html
.. _... | 851 | 24.058824 | 95 | py |
nni | nni-master/nni/experiment/config/training_services/dlc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from dataclasses import dataclass
from typing import Optional
from typing_extensions import Literal
from ..training_service import TrainingServiceConfig
__all__ = ['DlcConfig']
@dataclass(init=False)
class DlcConfig(TrainingServiceConfig):
... | 813 | 27.068966 | 110 | py |
nni | nni-master/nni/experiment/config/training_services/frameworkcontroller.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Configuration for FrameworkController training service.
Check the reference_ for explaination of each field.
You may also want to check `FrameworkController training service doc`_.
.. _reference: https://nni.readthedocs.io/en/stable/refere... | 1,872 | 31.293103 | 127 | py |