[v2.0] Refactor code hierarchy (part 2) (#2987)

This commit is contained in:
liuzhe-lz 2020-10-26 23:21:59 +08:00 коммит произвёл GitHub
Родитель f98ee6721a
Коммит e21a6984cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
232 изменённых файлов: 668 добавлений и 371 удалений

10
.gitignore поставляемый
Просмотреть файл

@ -1,6 +1,10 @@
/nni_node/node
/nni_node/node.exe
/toolchain
/nni_node/
/toolchain/
# unit test generated files
/test/model_path/
/test/temp.json
/test/ut/sdk/*.pth
# Logs

Просмотреть файл

@ -1,74 +0,0 @@
SHELL := /bin/bash
_INFO := $(shell echo -e '\033[1;36m')
_END := $(shell echo -e '\033[0m')
## Detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
OS_SPEC := linux
else ifeq ($(UNAME_S), Darwin)
OS_SPEC := darwin
else
$(error platform $(UNAME_S) not supported)
endif
_PWD := $(PWD)
YARN ?= PATH=$(_PWD)/nni_node:$${PATH} $(PWD)/toolchain/yarn/bin/yarn
.PHONY: build
build: nni_node/node create-symlinks
#$(_INFO) Building NNI Manager $(_END)
cd ts/nni_manager && $(YARN) && $(YARN) build
cp -rf ts/nni_manager/config ts/nni_manager/dist/
#$(_INFO) Building WebUI $(_END)
cd ts/webui && $(YARN) && $(YARN) build
#$(_INFO) Building NAS UI $(_END)
cd ts/nasui && $(YARN) && $(YARN) build
nni_node/node:
mkdir -p toolchain
wget https://nodejs.org/dist/v10.22.1/node-v10.22.1-$(OS_SPEC)-x64.tar.xz -O toolchain/node.tar.xz
wget https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz -O toolchain/yarn.tar.gz
mkdir -p toolchain/node toolchain/yarn
tar -xf toolchain/node.tar.xz -C toolchain/node --strip-components 1
tar -xf toolchain/yarn.tar.gz -C toolchain/yarn --strip-components 1
cp toolchain/node/bin/node nni_node/
.PHONY: create-symlinks
create-symlinks:
ln -sfT ../ts/nni_manager/dist/common nni_node/common
ln -sfT ../ts/nni_manager/dist/config nni_node/config
ln -sfT ../ts/nni_manager/dist/core nni_node/core
ln -sfT ../ts/nni_manager/dist/rest_server nni_node/rest_server
ln -sfT ../ts/nni_manager/dist/training_service nni_node/training_service
ln -sfT ../ts/nni_manager/dist/main.js nni_node/main.js
ln -sfT ../ts/nni_manager/package.json nni_node/package.json
ln -sfT ../ts/nni_manager/node_modules nni_node/node_modules
ln -sfT ../ts/webui/build nni_node/static
mkdir -p nni_node/nasui
ln -sfT ../../ts/nasui/build nni_node/nasui/build
ln -sfT ../../ts/nasui/server.js nni_node/nasui/server.js
.PHONY: clean
clean:
-rm nni_node/node
-rm -rf toolchain
-rm -rf nni_node/common
-rm -rf nni_node/config
-rm -rf nni_node/core
-rm -rf nni_node/rest_server
-rm -rf nni_node/training_service
-rm -rf nni_node/main.js
-rm -rf nni_node/package.json
-rm -rf nni_node/node_modules
-rm -rf nni_node/nasui
-rm -rf nni_node/static

Просмотреть файл

@ -14,8 +14,7 @@ jobs:
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: 'Install python tools'
- script: |
make
python3 -m pip install -U -e .
python3 setup.py develop
displayName: 'Install nni toolkit via source code'
- script: |
set -e
@ -46,10 +45,10 @@ jobs:
cd test
python3 nni_test/nnitest/run_tests.py --config config/pr_tests.yml
displayName: 'Simple test'
- script: |
cd docs/en_US/
sphinx-build -M html . _build -W
displayName: 'Sphinx Documentation Build check'
#- script: |
# cd docs/en_US/
# sphinx-build -M html . _build -W
# displayName: 'Sphinx Documentation Build check'
- job: 'ubuntu_1804_python36_legacy_torch_tf'
pool:
@ -65,8 +64,7 @@ jobs:
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: 'Install python tools'
- script: |
make
python3 -m pip install -U -e .
python3 setup.py develop
displayName: 'Install nni toolkit via source code'
- script: |
set -e

Просмотреть файл

@ -3,7 +3,7 @@
NNI client is a python API of `nnictl`, which implements the most commonly used commands. Users can use this API to control their experiments, collect experiment results and conduct advanced analyses based on experiment results in python code directly instead of using command line. Here is an example:
```
from nni.nnicli import Experiment
from nni.experiment import Experiment
# create an experiment instance
exp = Experiment()
@ -28,14 +28,14 @@ exp.stop_experiment()
## References
```eval_rst
.. autoclass:: nni.nnicli.Experiment
.. autoclass:: nni.experiment.Experiment
:members:
.. autoclass:: nni.nnicli.TrialJob
.. autoclass:: nni.experiment.TrialJob
:members:
.. autoclass:: nni.nnicli.TrialHyperParameters
.. autoclass:: nni.experiment.TrialHyperParameters
:members:
.. autoclass:: nni.nnicli.TrialMetricData
.. autoclass:: nni.experiment.TrialMetricData
:members:
.. autoclass:: nni.nnicli.TrialResult
.. autoclass:: nni.experiment.TrialResult
:members:
```

Просмотреть файл

@ -3,13 +3,13 @@
__version__ = '999.0.0-developing'
from .env_vars import dispatcher_env_vars
from .runtime.env_vars import dispatcher_env_vars
from .utils import ClassArgsValidator
if dispatcher_env_vars.SDK_PROCESS != 'dispatcher':
from .trial import *
from .smartparam import *
from .nas_utils import training_update
from .common.nas_utils import training_update
class NoMoreTrialError(Exception):
def __init__(self, ErrorInfo):

Просмотреть файл

@ -7,9 +7,9 @@ import logging
import json
import base64
from .common import enable_multi_thread, enable_multi_phase
from .msg_dispatcher import MsgDispatcher
from .package_utils import create_builtin_class_instance, create_customized_class_instance
from .runtime.common import enable_multi_thread, enable_multi_phase
from .runtime.msg_dispatcher import MsgDispatcher
from .tools.package_utils import create_builtin_class_instance, create_customized_class_instance
logger = logging.getLogger('nni.main')
logger.debug('START')

Просмотреть файл

@ -5,7 +5,7 @@ import logging
import torch
from schema import And, Optional
from ..utils.config_validation import CompressorSchema
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from .constants import MASKER_DICT
from .one_shot import OneshotPruner

Просмотреть файл

@ -13,8 +13,8 @@ import logging
import torch
from schema import And, Optional
from .constants import MASKER_DICT
from ..utils.config_validation import CompressorSchema
from ..compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
__all__ = ['AGPPruner']

Просмотреть файл

@ -9,7 +9,7 @@ import numpy as np
import torch
from torch.utils.tensorboard import SummaryWriter
from nni.compression.torch.compressor import Pruner
from nni.compression.pytorch.compressor import Pruner
from .channel_pruning_env import ChannelPruningEnv
from .lib.agent import DDPG
from .lib.utils import get_output_folder

Просмотреть файл

@ -10,7 +10,7 @@ import numpy as np
import torch
import torch.nn as nn
from nni.compression.torch.compressor import PrunerModuleWrapper
from nni.compression.pytorch.compressor import PrunerModuleWrapper
from .. import AMCWeightMasker
_logger = logging.getLogger(__name__)

Просмотреть файл

@ -8,10 +8,10 @@ import torch
from schema import And, Optional
from nni.utils import OptimizeMode
from nni.compression.torch import ModelSpeedup
from nni.compression.pytorch import ModelSpeedup
from ..compressor import Pruner
from ..utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from .simulated_annealing_pruner import SimulatedAnnealingPruner
from .admm_pruner import ADMMPruner

Просмотреть файл

@ -2,7 +2,7 @@
# Licensed under the MIT license.
from ..pruning import LevelPrunerMasker, SlimPrunerMasker, L1FilterPrunerMasker, \
from . import LevelPrunerMasker, SlimPrunerMasker, L1FilterPrunerMasker, \
L2FilterPrunerMasker, FPGMPrunerMasker, TaylorFOWeightFilterPrunerMasker, \
ActivationAPoZRankFilterPrunerMasker, ActivationMeanRankFilterPrunerMasker

Просмотреть файл

@ -5,8 +5,8 @@ import copy
import logging
import torch
from schema import And, Optional
from ..utils.config_validation import CompressorSchema
from ..compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
from .finegrained_pruning import LevelPrunerMasker
logger = logging.getLogger('torch pruner')

Просмотреть файл

@ -10,9 +10,9 @@ from schema import And, Optional
from nni.utils import OptimizeMode
from ..compressor import Pruner
from ..utils.config_validation import CompressorSchema
from ..utils.num_param_counter import get_total_num_weights
from nni.compression.pytorch.compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from nni.compression.pytorch.utils.num_param_counter import get_total_num_weights
from .constants_pruner import PRUNER_DICT

Просмотреть файл

@ -3,11 +3,11 @@
import logging
from schema import And, Optional, SchemaError
from nni._graph_utils import TorchModuleGraph
from nni.compression.torch.utils.shape_dependency import ChannelDependency, GroupDependency
from nni.common.graph_utils import TorchModuleGraph
from nni.compression.pytorch.utils.shape_dependency import ChannelDependency, GroupDependency
from .constants import MASKER_DICT
from ..utils.config_validation import CompressorSchema
from ..compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
__all__ = ['LevelPruner', 'SlimPruner', 'L1FilterPruner', 'L2FilterPruner', 'FPGMPruner',

Просмотреть файл

@ -8,10 +8,10 @@ import logging
import torch
from schema import And, Optional
from ..compressor import Pruner
from ..utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from .constants_pruner import PRUNER_DICT
from ..utils.sensitivity_analysis import SensitivityAnalysis
from nni.compression.pytorch.utils.sensitivity_analysis import SensitivityAnalysis
MAX_PRUNE_RATIO_PER_ITER = 0.95

Просмотреть файл

@ -12,8 +12,8 @@ from schema import And, Optional
from nni.utils import OptimizeMode
from ..compressor import Pruner
from ..utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Pruner
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from .constants_pruner import PRUNER_DICT

Просмотреть файл

@ -5,8 +5,8 @@ import logging
import copy
import torch
from schema import Schema, And, Or, Optional
from ..utils.config_validation import CompressorSchema
from ..compressor import Quantizer, QuantGrad, QuantType
from nni.compression.pytorch.utils.config_validation import CompressorSchema
from nni.compression.pytorch.compressor import Quantizer, QuantGrad, QuantType
__all__ = ['NaiveQuantizer', 'QAT_Quantizer', 'DoReFaQuantizer', 'BNNQuantizer']

Просмотреть файл

@ -1,6 +1,6 @@
import tensorflow as tf
from ..compressor import Pruner
from nni.compression.tensorflow import Pruner
__all__ = [
'OneshotPruner',

Просмотреть файл

@ -14,10 +14,10 @@ import ConfigSpace as CS
import ConfigSpace.hyperparameters as CSH
from nni import ClassArgsValidator
from nni.protocol import CommandType, send
from nni.msg_dispatcher_base import MsgDispatcherBase
from nni.runtime.protocol import CommandType, send
from nni.runtime.msg_dispatcher_base import MsgDispatcherBase
from nni.utils import OptimizeMode, MetricType, extract_scalar_reward
from nni.common import multi_phase_enabled
from nni.runtime.common import multi_phase_enabled
from .config_generator import CG_BOHB

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -15,9 +15,9 @@ import numpy as np
from schema import Schema, Optional
from nni import ClassArgsValidator
from nni.common import multi_phase_enabled
from nni.msg_dispatcher_base import MsgDispatcherBase
from nni.protocol import CommandType, send
from nni.runtime.common import multi_phase_enabled
from nni.runtime.msg_dispatcher_base import MsgDispatcherBase
from nni.runtime.protocol import CommandType, send
from nni.utils import NodeType, OptimizeMode, MetricType, extract_scalar_reward
from nni import parameter_expressions

Просмотреть файл

@ -5,8 +5,8 @@ import os
import random
import sys
import nni.metis_tuner.lib_acquisition_function as lib_acquisition_function
import nni.metis_tuner.lib_constraint_summation as lib_constraint_summation
from .. import lib_acquisition_function
from .. import lib_constraint_summation
sys.path.insert(1, os.path.join(sys.path[0], '..'))

Просмотреть файл

@ -9,8 +9,8 @@ import os
import sys
from multiprocessing.dummy import Pool as ThreadPool
import nni.metis_tuner.Regression_GP.CreateModel as gp_create_model
import nni.metis_tuner.Regression_GP.Prediction as gp_prediction
from . import CreateModel as gp_create_model
from . import Prediction as gp_prediction
sys.path.insert(1, os.path.join(sys.path[0], '..'))

Просмотреть файл

@ -5,10 +5,10 @@ import os
import random
import sys
import nni.metis_tuner.lib_acquisition_function as lib_acquisition_function
import nni.metis_tuner.lib_constraint_summation as lib_constraint_summation
import nni.metis_tuner.lib_data as lib_data
import nni.metis_tuner.Regression_GP.Prediction as gp_prediction
from .. import lib_acquisition_function
from .. import lib_constraint_summation
from .. import lib_data
from . import Prediction as gp_prediction
sys.path.insert(1, os.path.join(sys.path[0], '..'))

Просмотреть файл

@ -11,7 +11,7 @@ import numpy
from scipy.stats import norm
from scipy.optimize import minimize
import nni.metis_tuner.lib_data as lib_data
from . import lib_data
def next_hyperparameter_expected_improvement(fun_prediction,

Просмотреть файл

Просмотреть файл

@ -15,14 +15,14 @@ import numpy as np
from schema import Schema, Optional
from nni import ClassArgsValidator
import nni.metis_tuner.lib_constraint_summation as lib_constraint_summation
import nni.metis_tuner.lib_data as lib_data
import nni.metis_tuner.Regression_GMM.CreateModel as gmm_create_model
import nni.metis_tuner.Regression_GMM.Selection as gmm_selection
import nni.metis_tuner.Regression_GP.CreateModel as gp_create_model
import nni.metis_tuner.Regression_GP.OutlierDetection as gp_outlier_detection
import nni.metis_tuner.Regression_GP.Prediction as gp_prediction
import nni.metis_tuner.Regression_GP.Selection as gp_selection
from . import lib_constraint_summation
from . import lib_data
from .Regression_GMM import CreateModel as gmm_create_model
from .Regression_GMM import Selection as gmm_selection
from .Regression_GP import CreateModel as gp_create_model
from .Regression_GP import OutlierDetection as gp_outlier_detection
from .Regression_GP import Prediction as gp_prediction
from .Regression_GP import Selection as gp_selection
from nni.tuner import Tuner
from nni.utils import OptimizeMode, extract_scalar_reward

Просмотреть файл

@ -13,9 +13,9 @@ from scipy.optimize import linear_sum_assignment
from sklearn.metrics.pairwise import rbf_kernel
from nni.utils import OptimizeMode
from nni.networkmorphism_tuner.graph_transformer import transform
from nni.networkmorphism_tuner.utils import Constant
from nni.networkmorphism_tuner.layers import is_layer
from .graph_transformer import transform
from .utils import Constant
from .layers import is_layer
def layer_distance(a, b):

Просмотреть файл

@ -9,7 +9,7 @@ from queue import Queue
import numpy as np
import torch
from nni.networkmorphism_tuner.layer_transformer import (
from .layer_transformer import (
add_noise,
wider_bn,
wider_next_conv,
@ -20,7 +20,7 @@ from nni.networkmorphism_tuner.layer_transformer import (
init_conv_weight,
init_bn_weight,
)
from nni.networkmorphism_tuner.layers import (
from .layers import (
StubAdd,
StubConcatenate,
StubReLU,
@ -36,7 +36,7 @@ from nni.networkmorphism_tuner.layers import (
layer_description_extractor,
layer_description_builder,
)
from nni.networkmorphism_tuner.utils import Constant
from .utils import Constant
class NetworkDescriptor:

Просмотреть файл

@ -5,8 +5,8 @@ from copy import deepcopy
from random import randrange, sample
from nni.networkmorphism_tuner.graph import NetworkDescriptor
from nni.networkmorphism_tuner.layers import (
from .graph import NetworkDescriptor
from .layers import (
StubDense,
StubReLU,
get_batch_norm_class,
@ -15,7 +15,7 @@ from nni.networkmorphism_tuner.layers import (
get_pooling_class,
is_layer,
)
from nni.networkmorphism_tuner.utils import Constant
from .utils import Constant
def to_wider_graph(graph):

Просмотреть файл

@ -3,7 +3,7 @@
import numpy as np
from nni.networkmorphism_tuner.layers import (
from .layers import (
StubDense,
StubReLU,
get_batch_norm_class,

Просмотреть файл

@ -7,7 +7,7 @@ from collections.abc import Iterable
import torch
from torch import nn
from torch.nn import functional
from nni.networkmorphism_tuner.utils import Constant
from .utils import Constant
class AvgPool(nn.Module):

Просмотреть файл

@ -10,10 +10,10 @@ import os
from schema import Optional, Schema
from nni.tuner import Tuner
from nni.utils import OptimizeMode, extract_scalar_reward
from nni.networkmorphism_tuner.bayesian import BayesianOptimizer
from nni.networkmorphism_tuner.nn import CnnGenerator, MlpGenerator
from nni.networkmorphism_tuner.utils import Constant
from nni.networkmorphism_tuner.graph import graph_to_json, json_to_graph
from .bayesian import BayesianOptimizer
from .nn import CnnGenerator, MlpGenerator
from .utils import Constant
from .graph import graph_to_json, json_to_graph
from nni import ClassArgsValidator
logger = logging.getLogger("NetworkMorphism_AutoML")

Просмотреть файл

@ -3,14 +3,14 @@
from abc import abstractmethod
from nni.networkmorphism_tuner.graph import Graph
from nni.networkmorphism_tuner.layers import (StubDense, StubDropout1d,
from .graph import Graph
from .layers import (StubDense, StubDropout1d,
StubReLU, get_batch_norm_class,
get_conv_class,
get_dropout_class,
get_global_avg_pooling_class,
get_pooling_class)
from nni.networkmorphism_tuner.utils import Constant
from .utils import Constant
class NetworkGenerator:

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше