Example #1
0
    def receive_trial_result(self, parameter_id, parameters, value, **kwargs):
        '''
        Record an observation of the objective function
        parameter_id : int
        parameters : dict of parameters
        value: final metrics of the trial, including reward
        '''
        logger.debug('acquiring lock for param {}'.format(parameter_id))
        self.thread_lock.acquire()
        logger.debug('lock for current acquired')
        reward = extract_scalar_reward(value)
        if self.optimize_mode is OptimizeMode.Minimize:
            reward = -reward

        logger.debug('receive trial result is:\n')
        logger.debug(str(parameters))
        logger.debug(str(reward))

        indiv = Individual(indiv_id=int(
            os.path.split(parameters['save_dir'])[1]),
                           graph_cfg=graph_loads(parameters['graph']),
                           result=reward)
        self.population.append(indiv)
        logger.debug('releasing lock')
        self.thread_lock.release()
        self.events[indiv.indiv_id].set()
Example #2
0
        cfg = GAGConfig()
        cfg.batch_size = args.batch_size
        cfg.learning_rate = float(args.learning_rate)
        cfg.dropout = args.dropout_rate
        cfg.rnn_units = args.rnn_units
        cfg.labelsmoothing = args.labelsmoothing
        cfg.num_heads = args.num_heads
        timer = Timer()

        qp_pairs, dev_qp_pairs = load_data()
        logger.debug('Init finish.')

        original_params = nni.get_next_parameter()
        '''
        with open('data.json') as f:
            original_params = json.load(f)
        '''
        try:
            graph = graph.graph_loads(original_params)
        except Exception:
            logger.debug('Can\'t load graph.')
        train_loss, best_acc = train_with_graph(graph, qp_pairs, dev_qp_pairs)

        logger.debug('Send best acc: %s', str(best_acc))
        nni.report_final_result(best_acc)
        logger.debug('Send final result done')
    except:
        logger.exception('Catch exception in trial.py.')
        raise
Example #3
0
        cfg.learning_rate = float(args.learning_rate)
        cfg.dropout = args.dropout_rate
        cfg.rnn_units = args.rnn_units
        cfg.labelsmoothing = args.labelsmoothing
        cfg.num_heads = args.num_heads
        timer = Timer()

        qp_pairs, dev_qp_pairs = load_data()
        logger.debug('Init finish.')

        original_params = nni.get_next_parameter()
        '''
        with open('data.json') as f:
            original_params = json.load(f)
        '''
        p_graph = graph.graph_loads(original_params['graph'])
        save_path = original_params['save_dir']
        os.makedirs(save_path)
        restore_path = original_params['restore_dir']
        restore_shared = [
            hash_id + '/' for hash_id in original_params['shared_id']
        ] if original_params['shared_id'] is not None else [] + [
            'word_embed', 'char_embed', 'char_encoding/'
        ]
        train_loss, best_acc = train_with_graph(p_graph, qp_pairs,
                                                dev_qp_pairs)

        logger.debug('Send best acc: %s', str(best_acc))
        nni.report_final_result(best_acc)
        logger.debug('Send final result done')
    except: