Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Integration test #3088

Merged
merged 5 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions deployment/docker/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

FROM nvidia/cuda:9.2-cudnn7-runtime-ubuntu18.04

ARG NNI_RELEASE

LABEL maintainer='Microsoft NNI Team<[email protected]>'

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -y update && \
apt-get -y install sudo \
RUN apt-get -y update
RUN apt-get -y install \
sudo \
apt-utils \
git \
curl \
Expand All @@ -26,28 +29,27 @@ RUN apt-get -y update && \
python3-dev \
python3-pip \
python3-tk \
libcupti-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
libcupti-dev
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

#
# generate python script
#
RUN cp /usr/bin/python3 /usr/bin/python
RUN ln -s python3 /usr/bin/python

#
# update pip
#
RUN python3 -m pip install --upgrade pip==20.0.2 setuptools==41.0.0
RUN python3 -m pip install --upgrade pip==20.2.4 setuptools==50.3.2

# numpy 1.14.3 scipy 1.1.0
RUN python3 -m pip --no-cache-dir install \
numpy==1.14.3 scipy==1.1.0
RUN python3 -m pip --no-cache-dir install numpy==1.14.3 scipy==1.1.0

#
# Tensorflow 1.15
# TensorFlow
#
RUN python3 -m pip --no-cache-dir install tensorflow-gpu==1.15.0
RUN python3 -m pip --no-cache-dir install tensorflow==2.3.1

#
# Keras 2.1.6
Expand All @@ -73,15 +75,15 @@ RUN python3 -m pip --no-cache-dir install pandas==0.23.4 lightgbm==2.2.2
#
# Install NNI
#
RUN python3 -m pip --no-cache-dir install nni
COPY dist/nni-${NNI_RELEASE}-py3-none-manylinux1_x86_64.whl .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the install method?

Copy link
Contributor Author

@liuzhe-lz liuzhe-lz Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile might be used by two category of users:

  1. Customers
  2. NNI devs

For customers, if they want NNI image of latest release version, they can simply pull from docker hub. So if a customer uses Dockerfile, they are most likely using a modified NNI package, in which case they won't want latest NNI from pypi.

For us, we use pipelines to build and upload docker images. The release pipeline always builds docker image together with wheel, so there is no benefit to push then pull. It can use the same wheel file for pypi and docker.

RUN python3 -m pip install nni-${NNI_RELEASE}-py3-none-manylinux1_x86_64.whl

#
# install aml package
#
RUN python3 -m pip --no-cache-dir install azureml
RUN python3 -m pip --no-cache-dir install azureml-sdk


ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/root/.local/bin:/usr/bin:/bin:/sbin

WORKDIR /root
2 changes: 1 addition & 1 deletion examples/model_compress/BNN_quantizer_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import BNNQuantizer
from nni.algorithms.compression.pytorch.quantization import BNNQuantizer


class VGG_Cifar10(nn.Module):
Expand Down
4 changes: 2 additions & 2 deletions examples/model_compress/DoReFaQuantizer_torch_mnist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import DoReFaQuantizer
from nni.algorithms.compression.pytorch.quantization import DoReFaQuantizer


class Mnist(torch.nn.Module):
Expand Down Expand Up @@ -86,4 +86,4 @@ def main():


if __name__ == '__main__':
main()
main()
2 changes: 1 addition & 1 deletion examples/model_compress/L1_torch_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import L1FilterPruner
from nni.algorithms.compression.pytorch.pruning import L1FilterPruner
from models.cifar10.vgg import VGG


Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/QAT_torch_quantizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import QAT_Quantizer
from nni.algorithms.compression.pytorch.quantization import QAT_Quantizer


class Mnist(torch.nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/amc/amc_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import torch
import torch.nn as nn
from torchvision.models import resnet
from nni.compression.torch import AMCPruner
from nni.algorithms.compression.pytorch.pruning import AMCPruner
from data import get_split_dataset
from utils import AverageMeter, accuracy

Expand Down
6 changes: 3 additions & 3 deletions examples/model_compress/amc/amc_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from tensorboardX import SummaryWriter
from torchvision.models import resnet

from nni.compression.torch.pruning.amc.lib.net_measure import measure_model
from nni.compression.torch.pruning.amc.lib.utils import get_output_folder
from nni.compression.torch import ModelSpeedup
from nni.algorithms.compression.pytorch.pruning.amc.lib.net_measure import measure_model
from nni.algorithms.compression.pytorch.pruning.amc.lib.utils import get_output_folder
from nni.compression.pytorch import ModelSpeedup

from data import get_dataset
from utils import AverageMeter, accuracy, progress_bar
Expand Down
8 changes: 4 additions & 4 deletions examples/model_compress/auto_pruners_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from models.mnist.lenet import LeNet
from models.cifar10.vgg import VGG
from models.cifar10.resnet import ResNet18, ResNet50
from nni.compression.torch import L1FilterPruner, L2FilterPruner, FPGMPruner
from nni.compression.torch import SimulatedAnnealingPruner, ADMMPruner, NetAdaptPruner, AutoCompressPruner
from nni.compression.torch import ModelSpeedup
from nni.compression.torch.utils.counter import count_flops_params
from nni.algorithms.compression.pytorch.pruning import L1FilterPruner, L2FilterPruner, FPGMPruner
from nni.algorithms.compression.pytorch.pruning import SimulatedAnnealingPruner, ADMMPruner, NetAdaptPruner, AutoCompressPruner
from nni.compression.pytorch import ModelSpeedup
from nni.compression.pytorch.utils.counter import count_flops_params


def get_data(dataset, data_dir, batch_size, test_batch_size):
Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/lottery_torch_mnist_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch.utils.data
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from nni.compression.torch import LotteryTicketPruner
from nni.algorithms.compression.pytorch.pruning import LotteryTicketPruner

class fc1(nn.Module):

Expand Down
12 changes: 10 additions & 2 deletions examples/model_compress/model_prune_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@

from models.cifar10.vgg import VGG
import nni
from nni.compression.torch import LevelPruner, SlimPruner, FPGMPruner, L1FilterPruner, \
L2FilterPruner, AGPPruner, ActivationMeanRankFilterPruner, ActivationAPoZRankFilterPruner
from nni.algorithms.compression.pytorch.pruning import (
LevelPruner,
SlimPruner,
FPGMPruner,
L1FilterPruner,
L2FilterPruner,
AGPPruner,
ActivationMeanRankFilterPruner,
ActivationAPoZRankFilterPruner
)

prune_config = {
'level': {
Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/model_speedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch.nn.functional as F
from torchvision import datasets, transforms
from models.cifar10.vgg import VGG
from nni.compression.torch import apply_compression_results, ModelSpeedup
from nni.compression.pytorch import apply_compression_results, ModelSpeedup

torch.manual_seed(0)
use_mask = True
Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/pruning_kd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import L1FilterPruner
from nni.algorithms.compression.pytorch.pruning import L1FilterPruner
from knowledge_distill.knowledge_distill import KnowledgeDistill
from models.cifar10.vgg import VGG

Expand Down
2 changes: 1 addition & 1 deletion examples/model_compress/slim_torch_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
from nni.compression.torch import SlimPruner
from nni.algorithms.compression.pytorch.pruning import SlimPruner
from models.cifar10.vgg import VGG

def updateBN(model):
Expand Down
2 changes: 1 addition & 1 deletion examples/nas/classic_nas/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from torchvision import datasets, transforms

from nni.nas.pytorch.mutables import LayerChoice, InputChoice
from nni.nas.pytorch.classic_nas import get_and_apply_next_architecture
from nni.algorithms.nas.pytorch.classic_nas import get_and_apply_next_architecture


logger = logging.getLogger('mnist_AutoML')
Expand Down
1 change: 0 additions & 1 deletion nni/algorithms/compression/pytorch/pruning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from .finegrained_pruning import *
from .structured_pruning import *
from .apply_compression import apply_compression_results
from .one_shot import *
from .agp import *
from .lottery_ticket import LotteryTicketPruner
Expand Down
1 change: 1 addition & 0 deletions nni/compression/pytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

from .speedup import ModelSpeedup
from .compressor import Compressor, Pruner, Quantizer
from .pruning import apply_compression_results
4 changes: 4 additions & 0 deletions nni/compression/pytorch/pruning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from .apply_compression import apply_compression_results
29 changes: 29 additions & 0 deletions nni/compression/pytorch/pruning/apply_compression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import logging
import torch

logger = logging.getLogger('torch apply compression')

def apply_compression_results(model, masks_file, map_location=None):
"""
Apply the masks from ```masks_file``` to the model
Note: this API is for inference, because it simply multiplies weights with
corresponding masks when this API is called.

Parameters
----------
model : torch.nn.Module
The model to be compressed
masks_file : str
The path of the mask file
map_location : str
the device on which masks are placed, same to map_location in ```torch.load```
"""
masks = torch.load(masks_file, map_location)
for name, module in model.named_modules():
if name in masks:
module.weight.data = module.weight.data.mul_(masks[name]['weight'])
if hasattr(module, 'bias') and module.bias is not None and 'bias' in masks[name]:
module.bias.data = module.bias.data.mul_(masks[name]['bias'])
12 changes: 6 additions & 6 deletions nni/tools/nnictl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@
INSTALLABLE_PACKAGE_META = {
'SMAC': {
'type': 'tuner',
'class_name': 'nni.smac_tuner.smac_tuner.SMACTuner',
'class_name': 'nni.algorithms.hpo.smac_tuner.smac_tuner.SMACTuner',
'code_sub_dir': 'smac_tuner',
'class_args_validator': 'nni.smac_tuner.smac_tuner.SMACClassArgsValidator'
'class_args_validator': 'nni.algorithms.hpo.smac_tuner.smac_tuner.SMACClassArgsValidator'
},
'BOHB': {
'type': 'advisor',
'class_name': 'nni.bohb_advisor.bohb_advisor.BOHB',
'class_name': 'nni.algorithms.hpo.bohb_advisor.bohb_advisor.BOHB',
'code_sub_dir': 'bohb_advisor',
'class_args_validator': 'nni.bohb_advisor.bohb_advisor.BOHBClassArgsValidator'
'class_args_validator': 'nni.algorithms.hpo.bohb_advisor.bohb_advisor.BOHBClassArgsValidator'
},
'PPOTuner': {
'type': 'tuner',
'class_name': 'nni.ppo_tuner.ppo_tuner.PPOTuner',
'class_name': 'nni.algorithms.hpo.ppo_tuner.ppo_tuner.PPOTuner',
'code_sub_dir': 'ppo_tuner',
'class_args_validator': 'nni.ppo_tuner.ppo_tuner.PPOClassArgsValidator'
'class_args_validator': 'nni.algorithms.hpo.ppo_tuner.ppo_tuner.PPOClassArgsValidator'
}
}

Expand Down
75 changes: 75 additions & 0 deletions pipelines/full-test-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
trigger: none
pr: none
schedules:
- cron: 0 16 * * *
branches:
include: [ master ]

jobs:
- job: linux
pool: NNI CI GPU3
timeoutInMinutes: 120

steps:
- script: |
echo "##vso[task.setvariable variable=PATH]${PATH}:${HOME}/.local/bin"
echo "##vso[task.setvariable variable=NNI_RELEASE]999.$(date -u +%Y%m%d%H%M%S)"

python3 -m pip install -U --upgrade pip setuptools
python3 -m pip install -U pytest
displayName: Prepare

- script: |
set -e
python3 setup.py build_ts
python3 setup.py bdist_wheel -p manylinux1_x86_64
python3 -m pip install dist/nni-${NNI_RELEASE}-py3-none-manylinux1_x86_64.whl
displayName: Install NNI

- script: |
set -e
python3 -m pip install -U scikit-learn==0.23.2
python3 -m pip install -U torchvision==0.4.2
python3 -m pip install -U torch==1.3.1
python3 -m pip install -U keras==2.1.6
python3 -m pip install -U tensorflow==2.3.1 tensorflow-estimator==2.3.0
python3 -m pip install -U thop
sudo apt-get install swig -y
nnictl package install --name=SMAC
nnictl package install --name=BOHB
nnictl package install --name=PPOTuner
displayName: Install extra dependencies

- script: |
set -e
cd examples/tuners/customized_tuner
python3 setup.py develop --user
nnictl package install .
displayName: Install customized tuner

- script: |
set -e
(cd test && python3 -m pytest ut)
export PATH=$PATH:$PWD/toolchain/yarn/bin
export CI=true
(cd ts/nni_manager && yarn test)
(cd ts/nasui && yarn test)
displayName: Unit test
continueOnError: true

- script: |
cd test
python3 nni_test/nnitest/run_tests.py --config config/integration_tests.yml --ts local
displayName: Integration test
continueOnError: true

- script: |
cd test
source scripts/nas.sh
displayName: NAS test
continueOnError: true

- script: |
cd test
source scripts/model_compression.sh
displayName: Model compression test
Loading