Skip to content

Commit

Permalink
[v2.0] Refactor code hierarchy (part 2) (microsoft#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhe-lz authored Oct 26, 2020
1 parent f98ee67 commit e21a698
Show file tree
Hide file tree
Showing 232 changed files with 671 additions and 374 deletions.
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
74 changes: 0 additions & 74 deletions Makefile

This file was deleted.

14 changes: 6 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/en_US/nnicli_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
```
4 changes: 2 additions & 2 deletions nni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions nni/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
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')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
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']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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']

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tensorflow as tf

from ..compressor import Pruner
from nni.compression.tensorflow import Pruner

__all__ = [
'OneshotPruner',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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], '..'))

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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], '..'))

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
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], '..'))

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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,
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e21a698

Please sign in to comment.