microsoft / nni

An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
https://nni.readthedocs.io
MIT License
13.98k stars 1.81k forks source link

PPO Tuner Unavailable for Classical NAS #3328

Closed Garen-Wang closed 3 years ago

Garen-Wang commented 3 years ago

Environment:

Log message:

What issue meet, what's expected?:

PPO Tuner failed to load when creating new classcial NAS experiments, which also occurs on version 1.9.

How to reproduce it?:

Manually prepare a CNN model and code for auto-generation, run nni ss_gen to auto-generate the search space file, and configure config.yml according to the example. When running nni create command, error seems to occur.

Additional information:

my config.yml:

authorName: default
experimentName: example_with_cifar_classical_NAS
trialConcurrency: 1
maxExecDuration: 100h
maxTrialNum: 10
#choice: local, remote, pai
trainingServicePlatform: local
#please use `nnictl ss_gen` to generate search space file first
# searchSpacePath: <the_generated_search_space_path>
searchSpacePath: nni_auto_gen_search_space.json
useAnnotation: false
tuner:
  builtinTunerName: PPOTuner
  classArgs:
    optimize_mode: maximize
trial:
  command: python classical.py
  codeDir: .
  gpuNum: 0

my nni_auto_gen_search_space.json:

{
  "conv1": {
    "_type": "layer_choice",
    "_value": [
      "conv3*3",
      "conv5*5"
    ]
  },
  "mid_conv": {
    "_type": "layer_choice",
    "_value": [
      "0",
      "1"
    ]
  },
  "skip_conv": {
    "_type": "input_choice",
    "_value": {
      "candidates": [
        "",
        ""
      ],
      "n_chosen": 1
    }
  }
}

my model for NAS:

class NeuralNet(nn.Module):
    def __init__(self):
        super(NeuralNet, self).__init__()
        self.conv1 = mutables.LayerChoice(OrderedDict([
            ("conv3*3", nn.Conv2d(3, 8, 3, 1)),
            ("conv5*5", nn.Conv2d(3, 8, 5, 1))
        ]), key='conv1')
        self.mid_conv = mutables.LayerChoice([
            nn.Conv2d(8, 8, 3, 1, padding=1),
            nn.Conv2d(8, 8, 5, 1, padding=2)
        ], key='mid_conv')
        self.conv2 = nn.Conv2d(8, 16, 5, 1)
        self.pool = nn.MaxPool2d(2, 2)
        self.func1 = nn.Linear(16 * 5 * 5, 120)
        self.func2 = nn.Linear(120, 84)
        self.func3 = nn.Linear(84, 10)
        self.input_switch = mutables.InputChoice(n_candidates=2, n_chosen=1, key="skip_conv")

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        old_x = x
        zero_x = torch.zeros_like(old_x)
        skip_x = self.input_switch([zero_x, old_x])
        x = F.relu(self.mid_conv(x))
        x += skip_x
        x = self.pool(F.relu(self.conv2(x)))
        x = x.view(-1, 16 * 5 * 5)
        x = F.relu(self.func1(x))
        x = F.relu(self.func2(x))
        x = self.func3(x)
        return x
QuanluZhang commented 3 years ago

@Garen-Wang thanks for reporting this issue. PPOTuner requires additional packages, so need to install with python3 -m pip install nni[PPOTuner]. We will update doc accordingly.

Garen-Wang commented 3 years ago

@QuanluZhang Thanks a lot for your help. Having installed nni[PPOTuner] plus tensorflow, now it works properly.

kvartet commented 3 years ago

@QuanluZhang, it seems that classic NAS has been refactored in Retiarii, so should we update the doc of tuners used by NAS in the HPO part?

QuanluZhang commented 3 years ago

@kvartet we can remove PPOTuner from HPO tuners, as PPO has been supported in Retiarii framework (i.e., nni.retiarii.strategy.PolicyBasedRL)