コード例 #1
0
    def costs(self, rescaler: _PruningPointRescaler,
              use_max: bool) -> List[Tuple[float, Union[None, float]]]:
        """
        :param rescaler: the rescaler to use to rescale the optimized values
            to the [0.0, 1.0] range
        :param use_max: True to use the max value for all measurements,
            False to interpolate between. Max value is used for FLOPS performance
            because the slopes for smaller convs are less and therefore prioritized
            improperly by optimization
        :return: a list of tuples containing (sparsity, cost)
        """
        if not self.data_optimization:
            return [(float(index) / 100.0, None) for index in range(100)]

        def _get_val(v: float) -> float:
            return rescaler(v if not use_max else self.value_optimized_max)

        measurements = [(val.sparsity, _get_val(val.value))
                        for val in self.data_optimization]

        # creates the data at increments of 1% levels from 0 to 99
        costs = interpolate_list_linear(
            measurements, [float(index) / 100.0 for index in range(100)])

        return costs
コード例 #2
0
    def estimated_value(self, sparsity: Union[None,
                                              float]) -> Union[None, float]:
        if not self.data:
            return None

        if not sparsity:
            return self.value_baseline

        measurements = [(val.sparsity, val.value) for val in self.data]
        _, interpolated = interpolate_list_linear(measurements, sparsity)[0]

        return interpolated
コード例 #3
0
    def sparse(self,
               sparsity: Union[None, float],
               smooth: bool = False) -> Union[None, float]:
        """
        :param sparsity: the sparsity to get a measurement for
        :param smooth: True to pull from the measurements_smoothed,
            False otherwise
        :return: the measurement at the given sparsity
        """
        if not self._measurements:
            return None

        if not sparsity:
            return self.baseline

        _, interpolated = interpolate_list_linear(
            self._measurements if not smooth else self._measurements_smoothed,
            sparsity)[0]

        return interpolated
コード例 #4
0
    def sparse_measurements(
            self,
            smooth: bool = False) -> List[Tuple[float, Union[None, float]]]:
        """
        :param smooth: True to pull from the measurements_smoothed,
            False otherwise
        :return: a list of tuples containing the sparsity from
            0 to 99% at increments of 1% and the associated measurements
        """
        sparsities = [v / 100.0 for v in range(100)]

        if not self._measurements:
            return [
                v for v in zip(sparsities,
                               [None for _ in range(len(sparsities))])
            ]

        interpolated = interpolate_list_linear(
            self._measurements if not smooth else self._measurements_smoothed,
            sparsities,
        )

        return interpolated