Exemple #1
0
 def get_uniform_sample_cand(*, timeout=500):
     idx = np.random.randint(len(bins))
     l, r = bins[idx]
     for i in range(timeout):
         cand = get_random_cand()
         if l * 1e6 <= get_cand_flops(cand) <= r * 1e6:
             return cand
     return get_random_cand()
Exemple #2
0
 def get_uniform_sample_cand(*,timeout=500):
     idx = np.random.randint(len(bins))
     l, r = bins[idx]
     for i in range(timeout):
         cand = get_random_cand()
         if l*1e6 <= get_cand_flops(cand) <= r*1e6:
             # print("the {} iters is {}.\n".format(iters, cand))
             return cand
     return get_random_cand()
Exemple #3
0
def main():
    info = torch.load('../Search/log/checkpoint.pth.tar')['vis_dict']
    cands = sorted([cand for cand in info if 'err' in info[cand]],
                   key=lambda cand: info[cand]['err'])[:1]

    dst_dir = 'data'
    if not os.path.exists(dst_dir):
        os.makedirs(dst_dir)

    for cand in cands:
        flops = get_cand_flops(cand)
        dst_path = os.path.join(dst_dir, str(cand))
        if os.path.exists(dst_path):
            continue
        print(cand, flops)
        print(cand, info[cand]['err'], flops)
        os.system('cp -r {} \'{}\''.format('template', dst_path))
        with open(os.path.join(dst_path, 'arch.pkl'), 'wb') as f:
            pickle.dump(cand, f)
    def is_legal(self, cand):
        assert isinstance(cand, tuple) and len(cand) == self.nr_layer
        if cand not in self.vis_dict:
            self.vis_dict[cand] = {}
        info = self.vis_dict[cand]
        if 'visited' in info:
            return False

        if 'flops' not in info:
            info['flops'] = get_cand_flops(cand)

        print(cand, info['flops'])

        if info['flops'] > self.flops_limit:
            print('flops limit exceed')
            return False

        info['err'] = get_cand_err(self.model, cand, self.args)
        info['visited'] = True
        return True