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
[Retiarii] Weight-sharing trainers #3137
Merged
ultmaster
merged 9 commits into
microsoft:dev-retiarii
from
ultmaster:retiarii/ws-trainer
Dec 5, 2020
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9796e24
First commit for WS in Retiarii
ultmaster 941129c
Refactor ENAS trainer
ultmaster db7587f
Fix DARTS trainer
ultmaster 3964072
Fix ENAS trainer
ultmaster a3c2857
Fix issues in DARTS and Proxyless
ultmaster debf81c
Fix ProxylessNAS and Random trainer
ultmaster cb63acb
Merge branch 'dev-retiarii' into retiarii/ws-trainer
ultmaster 8eeac4c
Refactor mask
ultmaster 12fb38e
Merge branch 'retiarii/ws-trainer' of github.com:ultmaster/nni into r…
ultmaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,36 +26,55 @@ | |
parser.add_argument("--search-for", choices=["macro", "micro"], default="macro") | ||
parser.add_argument("--epochs", default=None, type=int, help="Number of epochs (default: macro 310, micro 150)") | ||
parser.add_argument("--visualization", default=False, action="store_true") | ||
parser.add_argument("--v1", default=False, action="store_true") | ||
args = parser.parse_args() | ||
|
||
dataset_train, dataset_valid = datasets.get_dataset("cifar10") | ||
mutator = None | ||
ctrl_kwargs = {} | ||
if args.search_for == "macro": | ||
model = GeneralNetwork() | ||
num_epochs = args.epochs or 310 | ||
mutator = None | ||
elif args.search_for == "micro": | ||
model = MicroNetwork(num_layers=6, out_channels=20, num_nodes=5, dropout_rate=0.1, use_aux_heads=True) | ||
model = MicroNetwork(num_layers=6, out_channels=20, num_nodes=5, dropout_rate=0.1, use_aux_heads=False) | ||
num_epochs = args.epochs or 150 | ||
mutator = enas.EnasMutator(model, tanh_constant=1.1, cell_exit_extra_step=True) | ||
if args.v1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest to directly abandon v1 |
||
mutator = enas.EnasMutator(model, tanh_constant=1.1, cell_exit_extra_step=True) | ||
else: | ||
ctrl_kwargs = {"tanh_constant": 1.1} | ||
else: | ||
raise AssertionError | ||
|
||
criterion = nn.CrossEntropyLoss() | ||
optimizer = torch.optim.SGD(model.parameters(), 0.05, momentum=0.9, weight_decay=1.0E-4) | ||
lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=num_epochs, eta_min=0.001) | ||
|
||
trainer = enas.EnasTrainer(model, | ||
loss=criterion, | ||
metrics=accuracy, | ||
reward_function=reward_accuracy, | ||
optimizer=optimizer, | ||
callbacks=[LRSchedulerCallback(lr_scheduler), ArchitectureCheckpoint("./checkpoints")], | ||
batch_size=args.batch_size, | ||
num_epochs=num_epochs, | ||
dataset_train=dataset_train, | ||
dataset_valid=dataset_valid, | ||
log_frequency=args.log_frequency, | ||
mutator=mutator) | ||
if args.visualization: | ||
trainer.enable_visualization() | ||
trainer.train() | ||
if args.v1: | ||
trainer = enas.EnasTrainer(model, | ||
loss=criterion, | ||
metrics=accuracy, | ||
reward_function=reward_accuracy, | ||
optimizer=optimizer, | ||
callbacks=[LRSchedulerCallback(lr_scheduler), ArchitectureCheckpoint("./checkpoints")], | ||
batch_size=args.batch_size, | ||
num_epochs=num_epochs, | ||
dataset_train=dataset_train, | ||
dataset_valid=dataset_valid, | ||
log_frequency=args.log_frequency, | ||
mutator=mutator) | ||
if args.visualization: | ||
trainer.enable_visualization() | ||
trainer.train() | ||
else: | ||
from nni.retiarii.trainer.pytorch.enas import EnasTrainer | ||
trainer = EnasTrainer(model, | ||
loss=criterion, | ||
metrics=accuracy, | ||
reward_function=reward_accuracy, | ||
optimizer=optimizer, | ||
batch_size=args.batch_size, | ||
num_epochs=num_epochs, | ||
dataset=dataset_train, | ||
log_frequency=args.log_frequency, | ||
ctrl_kwargs=ctrl_kwargs) | ||
trainer.fit() |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .base import PyTorchImageClassificationTrainer | ||
from .darts import DartsTrainer | ||
from .enas import EnasTrainer | ||
from .proxyless import ProxylessTrainer | ||
from .random import RandomTrainer, SinglePathTrainer |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is complicated, why?