This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix layer choice on IT and deprecate "choices" and "length" (#2386)
- Loading branch information
Showing
11 changed files
with
152 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
from .layer_choice_only import LayerChoiceOnlySearchSpace | ||
from .mutable_scope import SpaceWithMutableScope | ||
from .naive import NaiveSearchSpace | ||
from .nested import NestedSpace |
38 changes: 38 additions & 0 deletions
38
src/sdk/pynni/tests/models/pytorch_models/layer_choice_only.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
|
||
from nni.nas.pytorch.mutables import LayerChoice | ||
|
||
|
||
class LayerChoiceOnlySearchSpace(nn.Module): | ||
def __init__(self, test_case): | ||
super().__init__() | ||
self.test_case = test_case | ||
self.conv1 = LayerChoice([nn.Conv2d(3, 6, 3, padding=1), nn.Conv2d(3, 6, 5, padding=2)]) | ||
self.pool = nn.MaxPool2d(2, 2) | ||
self.conv2 = LayerChoice([nn.Conv2d(6, 16, 3, padding=1), nn.Conv2d(6, 16, 5, padding=2)], | ||
return_mask=True) | ||
self.conv3 = nn.Conv2d(16, 16, 1) | ||
self.bn = nn.BatchNorm2d(16) | ||
|
||
self.gap = nn.AdaptiveAvgPool2d(1) | ||
self.fc = nn.Linear(16, 10) | ||
|
||
def forward(self, x): | ||
bs = x.size(0) | ||
|
||
x = self.pool(F.relu(self.conv1(x))) | ||
x0, mask = self.conv2(x) | ||
self.test_case.assertEqual(mask.size(), torch.Size([2])) | ||
x1 = F.relu(self.conv3(x0)) | ||
|
||
x = self.pool(self.bn(x1)) | ||
self.test_case.assertEqual(mask.size(), torch.Size([2])) | ||
|
||
x = self.gap(x).view(bs, -1) | ||
x = self.fc(x) | ||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters