Esempio n. 1
0
 def register_statistics(self, model, stats_collector):
     model = deepcopy(model)
     fqut.insert_fake_quantize_nodes(self._config, model, self.params)
     activation_statistics_layout = self.__get_activations_statistics_layout(
         model, qscheme=self.params)
     layers_mapping = fqut.create_renamed_layers_mapping(
         model, activation_statistics_layout)
     stats_collector.register(self.name, activation_statistics_layout,
                              self._sampler, layers_mapping)
     self._stats_collector = stats_collector
Esempio n. 2
0
    def get_parameter_meta(self, model, optimizer_state):
        param_grid = []
        if 'range_estimator' in self._config.tuning_scope:
            for variable in self._config.estimator_tuning_scope:
                self._config.tuning_scope.append('estimator_' + variable)
        config = deepcopy(self._config)
        if optimizer_state['first_iteration'] or optimizer_state[
                'fully_quantized']:
            config['tuning_scope'] = []

        hardware_config = load_hardware_config(config)
        model = deepcopy(model)
        fqut.insert_fake_quantize_nodes(config, model)
        fq_configuration = read_all_fake_quantize_configurations(
            config, hardware_config, model)

        nodes_config = {}
        for fq in get_nodes_by_type(model, ['FakeQuantize']):
            node_input = get_node_input(fq, 0)
            op_type = 'weights' if node_input.type == 'Const' else 'activations'
            fq_node_config = fq_configuration[fq.name][op_type]
            for child_name, child_config in fq_node_config:
                if child_name not in nodes_config:
                    nodes_config[child_name] = {
                        'weights': [],
                        'activations': []
                    }
                nodes_config[child_name][op_type].extend(child_config)

        for node_name, node_config in nodes_config.items():
            if 'activations' in node_config:
                node_config['activations'] = ut.append_estimator_configs(
                    node_config['activations'], False, config,
                    self.params[node_name]
                    if not optimizer_state['fully_quantized']
                    and node_name in self.params else None)
            if 'weights' in node_config:
                node_config['weights'] = ut.append_estimator_configs(
                    node_config['weights'], True, config,
                    self.params[node_name]
                    if not optimizer_state['fully_quantized']
                    and node_name in self.params else None)

        for node_name, node_config in nodes_config.items():
            op_config = ut.get_quantize_op_config(
                node_config, config, self.params[node_name]
                if not optimizer_state['fully_quantized']
                and node_name in self.params else None)
            param_grid.append((node_name, 'choice', op_config))
        return param_grid
Esempio n. 3
0
    def get_parameter_meta(self, model):
        param_grid = []
        config = deepcopy(self._config)

        hardware_config = load_hardware_config(config)
        model = deepcopy(model)
        fqut.insert_fake_quantize_nodes(config, model)
        fq_configuration = read_all_fake_quantize_configurations(
            config, hardware_config, model)

        nodes_config = {}
        for fq in get_nodes_by_type(model, ['FakeQuantize']):
            node_input = get_node_input(fq, 0)
            op_type = 'weights' if node_input.type == 'Const' else 'activations'
            fq_node_config = fq_configuration[fq.fullname][op_type]
            for child_name, child_config in fq_node_config:
                if child_name not in nodes_config:
                    nodes_config[child_name] = {
                        'weights': [],
                        'activations': []
                    }
                nodes_config[child_name][op_type].extend(child_config)

        for node_name, node_config in nodes_config.items():
            if 'activations' in node_config:
                node_config['activations'] = ut.append_estimator_configs(
                    node_config['activations'], False, config,
                    self.params[node_name]
                    if node_name in self.params else None)
            if 'weights' in node_config:
                node_config['weights'] = ut.append_estimator_configs(
                    node_config['weights'], True, config,
                    self.params[node_name]
                    if node_name in self.params else None)

        for node_name, node_config in nodes_config.items():
            op_config = ut.get_quantize_op_config(
                node_config, config,
                self.params[node_name] if node_name in self.params else None)
            param_grid.append((node_name, 'choice', op_config))
        return param_grid