(self, mode="arch_ratio")
mode: "min"|"max"|"random"|"arch_ratio"(default)
mode: "min"|"max"|"random"|"arch_ratio"(default)
mode : min | max | random | arch_ratio ( default )
def sample_prun_ratio(self, mode="arch_ratio"):
        '''
        mode: "min"|"max"|"random"|"arch_ratio"(default)
        '''
        assert mode in ["min", "max", "random", "arch_ratio"]
        if mode == "arch_ratio":
            ratios = self._arch_names[self.arch_idx]["ratios"]
            ratios0 = getattr(self, ratios[0])
            ratios0_sampled = []
            for layer in range(self._layers - 1):
                ratios0_sampled.append(gumbel_softmax(F.log_softmax(ratios0[layer], dim=-1), hard=True))
            ratios1 = getattr(self, ratios[1])
            ratios1_sampled = []
            for layer in range(self._layers - 1):
                ratios1_sampled.append(gumbel_softmax(F.log_softmax(ratios1[layer], dim=-1), hard=True))
            ratios2 = getattr(self, ratios[2])
            ratios2_sampled = []
            for layer in range(self._layers - 2):
                ratios2_sampled.append(gumbel_softmax(F.log_softmax(ratios2[layer], dim=-1), hard=True))
            return [ratios0_sampled, ratios1_sampled, ratios2_sampled]
        elif mode == "min":
            ratios0_sampled = []
            for layer in range(self._layers - 1):
                ratios0_sampled.append(self._width_mult_list[0])
            ratios1_sampled = []
            for layer in range(self._layers - 1):
                ratios1_sampled.append(self._width_mult_list[0])
            ratios2_sampled = []
            for layer in range(self._layers - 2):
                ratios2_sampled.append(self._width_mult_list[0])
            return [ratios0_sampled, ratios1_sampled, ratios2_sampled]
        elif mode == "max":
            ratios0_sampled = []
            for layer in range(self._layers - 1):
                ratios0_sampled.append(self._width_mult_list[-1])
            ratios1_sampled = []
            for layer in range(self._layers - 1):
                ratios1_sampled.append(self._width_mult_list[-1])
            ratios2_sampled = []
            for layer in range(self._layers - 2):
                ratios2_sampled.append(self._width_mult_list[-1])
            return [ratios0_sampled, ratios1_sampled, ratios2_sampled]
        elif mode == "random":
            ratios0_sampled = []
            for layer in range(self._layers - 1):
                ratios0_sampled.append(np.random.choice(self._width_mult_list))
            ratios1_sampled = []
            for layer in range(self._layers - 1):
                ratios1_sampled.append(np.random.choice(self._width_mult_list))
            ratios2_sampled = []
            for layer in range(self._layers - 2):
                ratios2_sampled.append(np.random.choice(self._width_mult_list))
            return [ratios0_sampled, ratios1_sampled, ratios2_sampled]
def sample_prun_ratio ( self , mode = "arch_ratio" ) : assert mode in [ "min" , "max" , "random" , "arch_ratio" ] if mode == "arch_ratio" : ratios = self . _arch_names [ self . arch_idx ] [ "ratios" ] ratios0 = getattr ( self , ratios [ 0 ] ) ratios0_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios0_sampled . append ( gumbel_softmax ( F . log_softmax ( ratios0 [ layer ] , dim = - 1 ) , hard = True ) ) ratios1 = getattr ( self , ratios [ 1 ] ) ratios1_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios1_sampled . append ( gumbel_softmax ( F . log_softmax ( ratios1 [ layer ] , dim = - 1 ) , hard = True ) ) ratios2 = getattr ( self , ratios [ 2 ] ) ratios2_sampled = [ ] for layer in range ( self . _layers - 2 ) : ratios2_sampled . append ( gumbel_softmax ( F . log_softmax ( ratios2 [ layer ] , dim = - 1 ) , hard = True ) ) return [ ratios0_sampled , ratios1_sampled , ratios2_sampled ] elif mode == "min" : ratios0_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios0_sampled . append ( self . _width_mult_list [ 0 ] ) ratios1_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios1_sampled . append ( self . _width_mult_list [ 0 ] ) ratios2_sampled = [ ] for layer in range ( self . _layers - 2 ) : ratios2_sampled . append ( self . _width_mult_list [ 0 ] ) return [ ratios0_sampled , ratios1_sampled , ratios2_sampled ] elif mode == "max" : ratios0_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios0_sampled . append ( self . _width_mult_list [ - 1 ] ) ratios1_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios1_sampled . append ( self . _width_mult_list [ - 1 ] ) ratios2_sampled = [ ] for layer in range ( self . _layers - 2 ) : ratios2_sampled . append ( self . _width_mult_list [ - 1 ] ) return [ ratios0_sampled , ratios1_sampled , ratios2_sampled ] elif mode == "random" : ratios0_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios0_sampled . append ( np . random . choice ( self . _width_mult_list ) ) ratios1_sampled = [ ] for layer in range ( self . _layers - 1 ) : ratios1_sampled . append ( np . random . choice ( self . _width_mult_list ) ) ratios2_sampled = [ ] for layer in range ( self . _layers - 2 ) : ratios2_sampled . append ( np . random . choice ( self . _width_mult_list ) ) return [ ratios0_sampled , ratios1_sampled , ratios2_sampled ]