parameters: (self, parameter_groups_number, freeze_strategy, freeze_p, total_steps)
docstring: r"""
          Generate index sequence for gradient freezing training.
  
          Args:
              parameter_groups_number (int): The number of parameter groups.
              freeze_strategy (int): Gradient freeze grouping strategy, select from [0, 1].
              freeze_p (float): Gradient freezing probability.
              total_steps (int): Total training steps.
docstring_summary: r"""
          Generate index sequence for gradient freezing training.
docstring_tokens: r Generate index sequence for gradient freezing training .
function: def generate_freeze_index_sequence(self, parameter_groups_number, freeze_strategy, freeze_p, total_steps):
          r"""
          Generate index sequence for gradient freezing training.
  
          Args:
              parameter_groups_number (int): The number of parameter groups.
              freeze_strategy (int): Gradient freeze grouping strategy, select from [0, 1].
              freeze_p (float): Gradient freezing probability.
              total_steps (int): Total training steps.
          """
          total_step = int(total_steps * 1.01)
          if parameter_groups_number <= 1:
              return [0 for _ in range(total_step)]
          # local continuous freezing training strategy, as '00001234'
          if freeze_strategy == CONTINUOUS_STRATEGY:
              zero_cnt = int(
                  freeze_p * (parameter_groups_number - 1) / (1 - freeze_p) + 0.5)
              sub_idx = [0] * zero_cnt + list(range(1, parameter_groups_number))
              freeze_idxes = []
              while len(freeze_idxes) < total_step:
                  freeze_idxes += sub_idx
              return freeze_idxes
          # interval freezing training strategy, as '01020304'
          if freeze_strategy == INTERVAL_STRATEGY:
              index_all = list(range(1, parameter_groups_number))
              prob = [x / sum(index_all) for x in index_all]
              freeze_idxes = [0]
              zero_cnt = 1
              freeze_cnt = 0
              while len(freeze_idxes) < total_step:
                  freeze_p_cur = 1.0 * freeze_cnt / (zero_cnt + freeze_cnt)
                  if freeze_p_cur < 1 - freeze_p:
                      freeze_idxes.append(
                          int(np.random.choice(index_all[::-1], p=prob)))
                      freeze_cnt += 1
                  else:
                      freeze_idxes.append(0)
                      zero_cnt += 1
              return freeze_idxes
          raise ValueError(
              f"Unsupported freezing training strategy '{freeze_strategy}'")
function_tokens: def generate_freeze_index_sequence ( self , parameter_groups_number , freeze_strategy , freeze_p , total_steps ) : total_step = int ( total_steps * 1.01 ) if parameter_groups_number <= 1 : return [ 0 for _ in range ( total_step ) ] # local continuous freezing training strategy, as '00001234' if freeze_strategy == CONTINUOUS_STRATEGY : zero_cnt = int ( freeze_p * ( parameter_groups_number - 1 ) / ( 1 - freeze_p ) + 0.5 ) sub_idx = [ 0 ] * zero_cnt + list ( range ( 1 , parameter_groups_number ) ) freeze_idxes = [ ] while len ( freeze_idxes ) < total_step : freeze_idxes += sub_idx return freeze_idxes # interval freezing training strategy, as '01020304' if freeze_strategy == INTERVAL_STRATEGY : index_all = list ( range ( 1 , parameter_groups_number ) ) prob = [ x / sum ( index_all ) for x in index_all ] freeze_idxes = [ 0 ] zero_cnt = 1 freeze_cnt = 0 while len ( freeze_idxes ) < total_step : freeze_p_cur = 1.0 * freeze_cnt / ( zero_cnt + freeze_cnt ) if freeze_p_cur < 1 - freeze_p : freeze_idxes . append ( int ( np . random . choice ( index_all [ : : - 1 ] , p = prob ) ) ) freeze_cnt += 1 else : freeze_idxes . append ( 0 ) zero_cnt += 1 return freeze_idxes raise ValueError ( f"Unsupported freezing training strategy '{freeze_strategy}'" )