CanyonWind / Single-Path-One-Shot-NAS-MXNet

Single Path One-Shot NAS MXNet implementation with full training and searching pipeline. Support both Block and Channel Selection. Searched models better than the original paper are provided.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in random_channel_mask

xieydd opened this issue · comments

if i set epoch_start_cs=30 and when epoch=0, and epoch_after_cs will be -30.

epoch_delay_early = {0: 0,  # 8
                             1: 1, 2: 1,  # 7
                             3: 2, 4: 2, 5: 2,  # 6
                             6: 3, 7: 3, 8: 3, 9: 3,  # 5
                             10: 4, 11: 4, 12: 4, 13: 4, 14: 4,
                             15: 5, 16: 5, 17: 5, 18: 5, 19: 5, 20: 5,
                             21: 6, 22: 6, 23: 6, 24: 6, 25: 6, 27: 6, 28: 6,
                             29: 6, 30: 6, 31: 6, 32: 6, 33: 6, 34: 6, 35: 6, 36: 7,
                           }
        epoch_delay_late = {0: 0,
                            1: 1,
                            2: 2,
                            3: 3,
                            4: 4, 5: 4,  # warm up epoch: 2 [1.0, 1.2, ... 1.8, 2.0]
                            6: 5, 7: 5, 8: 5,  # warm up epoch: 3 ...
                            9: 6, 10: 6, 11: 6, 12: 6,  # warm up epoch: 4 ...
                            13: 7, 14: 7, 15: 7, 16: 7, 17: 7,  # warm up epoch: 5 [0.4, 0.6, ... 1.8, 2.0]
                            18: 8, 19: 8, 20: 8, 21: 8, 22: 8, 23: 8}  # warm up epoch: 6, after 17, use all scales

        if 0 <= epoch_after_cs <= 23 and self.stage_out_channels[0] >= 64:
            delayed_epoch_after_cs = epoch_delay_late[epoch_after_cs]
        elif 0 <= epoch_after_cs <= 36 and self.stage_out_channels[0] < 64:
            delayed_epoch_after_cs = epoch_delay_early[epoch_after_cs]
        else:
            delayed_epoch_after_cs = epoch_after_cs # delayed_epoch_after_cs = -30

                        channel_scale_start = max(2, 10 - (-30) - 2) # channel_scale_start=38
                        channel_choice = random.randint(channel_scale_start, len(self.candidate_scales) - 1) #random.randint(38, 9) will be error ValueError: empty range for randrange() (38,10, -28)
                        

And why epoch_delay_early doesn`t have the key 26

commented

There is an unit test specifically for verifying whether cs-warm-up working well.

To do so, please change FIX_ARCH to False here
https://github.com/CanyonWind/MXNet-Single-Path-One-Shot-NAS/blob/ce755214e07a38d6d45213d31270b257e004717d/oneshot_nas_network.py#L365

and run python oneshot_nas_network.py

As far as my experiment, CS starts from epoch 30 and gradually grows to all [0.6 - 2.0] choices correctly. The bug cannot be reproduced.

Epoch 0: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 1: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 2: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 3: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 4: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 5: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 6: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 7: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 8: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 9: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 10: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
Epoch 11: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,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, 4, 7, 7, 3, 3, 3, 5, 5, 9, 4, 6, 3, 3, 3, 4]
Epoch 118: [4, 8, 2, 4, 5, 2, 5, 6, 8, 7, 9, 3, 7, 4, 6, 9, 4, 8, 5, 9]
Epoch 119: [2, 9, 9, 7, 9, 2, 8, 6, 4, 6, 7, 9, 2, 2, 6, 8, 6, 3, 5, 4]
commented

Please provide a reimplementable example so that I can help to locate your problem.

Otherwise, if you don't understand how it works in the details. Going through line by line with pdb or any IDE debugging should help.

@CanyonWind , Tks, i solve the problem because i make a mistake the logic:
When you use epoch_start_cs, use_all_channels = True, i will close the issue.

@CanyonWind @xieydd
Hello, I just ran latest code with the script unchanged and found same thing happens.

Traceback (most recent call last):
  File "train_imagenet.py", line 738, in <module>
    main()
  File "train_imagenet.py", line 734, in main
    train(context)
  File "train_imagenet.py", line 710, in train
    err_top1_val, err_top5_val = test(ctx, val_data, epoch)
  File "train_imagenet.py", line 438, in test
    ignore_first_two_cs=opt.ignore_first_two_cs)
  File "/home/nas/Single-Path-One-Shot-NAS-MXNet/oneshot_nas_network.py", line 248, in random_channel_mask
    channel_choice = random.randint(channel_scale_start, len(self.candidate_scales) - 1)
  File "/root/anaconda3/envs/singleshot/lib/python3.6/random.py", line 221, in randint
    return self.randrange(a, b+1)
  File "/root/anaconda3/envs/singleshot/lib/python3.6/random.py", line 199, in randrange
    raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (68,10, -58)

If I use option "--epoch-start-cs 60" and "--cs-warm-up" at the same time, the variable "epoch_after_cs=epoch-opt.epoch_start_cs" becomes negative number in early epochs.
Can you tell me proper usage of these 2 options? Thank you!