# Stratified sampling: fast estimation of quantization effects on DNN

Quentin Milot, Mickaël Dardaillon, Daniel Menard

► To cite this version:

Quentin Milot, Mickaël Dardaillon, Daniel Menard. Stratified sampling: fast estimation of quantization effects on DNN. 2025 IEEE 28th International Symposium on Design and Diagnostics of Electronic Circuits and Systems (DDECS), May 2025, Lyon, France. pp.157-160, 10.1109/ddecs63720.2025.11006808 . hal-05097594

HAL Id: hal-05097594

https://hal.science/hal-05097594v1

Submitted on 27 Jun 2025

**HAL** is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Stratified sampling: fast estimation of quantization effects on DNN

MILOT Quentin

Univ Rennes, INSA Rennes

CNRS, IETR - UMR 6164

F-35000, Rennes, France

quentin.milot@insa-rennes.fr

DARDAILLON Mickaël

Univ Rennes, INSA Rennes

CNRS, IETR - UMR 6164

F-35000, Rennes, France

mickael.dardaillon@insa-rennes.fr

MENARD Daniel

Univ Rennes, INSA Rennes

CNRS, IETR - UMR 6164

F-35000, Rennes, France

daniel.menard@insa-rennes.fr

**Abstract**— Deep neural networks complexity has exploded in recent years. This explosion brought new challenges in terms of memory, execution time and power requirements. One way of meeting these challenges is to use finite precision. However, this solution may result in a degradation in output quality. This degradation needs to be estimated, balancing between time and confidence in the estimation.

This paper proposes a parametric method to estimate the degradation caused by finite precision in data processing oriented applications such as deep learning. This method aims to reduce the estimation time and energy requirements while maintaining confidence in the results. This method takes advantage of a priori information about the inputs to select more informative inputs. A method to obtain this a priori information is also proposed. The results obtained are similar to a simple degradation estimation with a time reduction of one order of magnitude.

***Index Terms***—Quantization, Confidence Interval, Stratified Sampling, Deep learning

## I. INTRODUCTION

Artificial intelligence, especially deep learning (DNN, Deep Neural Network), has transformed several fields such as signal and image processing. DNNs yield superior performance compared to manually designed algorithms. This improvement is achieved at the cost of increasing network complexity. Several approaches are considered to reduce the main problem of DNNs, the complexity of the networks and the large amount of computing and memory resources required. One of the promising levers is to reduce the precision (bitwidth) of network data and parameters, since DNNs are inherently error-tolerant. However, exploiting precision refinement requires that the quality of the DNN output is maintained or slightly degraded.

Best solutions are obtained by exploring a large precision design space for which a specific precision is considered for each DNN layer or kernel. As a result, optimization times are very long and become prohibitive due to the quality evaluation process. This phenomena is amplified when quantization aware training is considered. The quality degradation due to finite precision is evaluated with Monte-Carlo Simulation (MCS) [1, 2]. Changing the accuracy of a single datum requires a new quality evaluation i.e. MCS. Each MCS takes a long time due to the emulation of finite precision data types which are not native on general-purpose computing resources, and due to

the large number of input required to have a minimum level of confidence in the statistics of the quality metric and to ensure that the DNN is robust to the diversity of the DNN inputs. MCS is input dependent and requires to define the level of confidence on the estimated quality metric. Using a large number of inputs unnecessarily increases optimization time, while using too few inputs can lead to incorrect quality estimation. Finding the minimal number of inputs for a given confidence is a crucial step to reduce the time required to evaluate the quality degradation. This minimal number of inputs is dependent on the value to estimate, and the variance of the data used to estimate it. Reducing this variance can be achieved using variance reduction sampling methods.

In this paper we propose to exploit stratified sampling to accelerate the evaluation of quality degradation due to quantization. Stratified sampling is a variance reduction sampling method. Our proposed iterative approach exploits the features of the inputs to reduce the number of inputs required to evaluate the quality degradation. Firstly, the results show that using our approach doesn't modify the quality of the degradation estimation and the results for a complete quantization optimization process. Secondly, the results show a reduction of an order of magnitude in the number of inputs required compared to a classical MCS without stratification.

The paper is organized as follows. Section II presents the state of the art for quantization for DNN. In Section III, a parametric representation of confidence is detailed. Section IV explains stratified sampling and the adaptation proposed for quantization quality degradation estimation. Section V details the results of experiments conducted on an image classification network. Finally, conclusions are drawn in Section VI.

## II. BACKGROUND & STATE OF THE ART

Deep Neural Network (DNN) aims at solving classification or regression tasks by adapting the network parameters thanks to a training process. DNNs have to face to the increase of the number of parameters to achieve high performance. This increases the DNN complexity, the network inference time and the memory usage. Quantization has been identified as a way to reduce the network implementation cost by limiting the number of bits for encoding the network parameters and the intermediate results. For DNN quantization, two main approaches are considered : Quantization aware training and

<footnote>This work was supported by the ANR project AI4SDA (ANR-20-THIA-0018) and WeDoLow company.</footnote>
post-training quantization. Quantization aware training consists in adding the quantization parameters as training parameters. The quantization will then be considered at each step of the training. The errors brought by training parameters and the quantization of these parameters will then be backpropagated and the DNN will adapt the parameter values according to this error. This method leads to good results in terms of DNN inference time and cost without degrading too much the quality [3, 4]. However, this method has two major drawbacks. First of all, it increases the training time significantly. Secondly, the quantization is hardware dependant which leads to the necessity to retrain for new targets. Post Training Quantization (PTQ) aims to resolve this issues. For the PTQ, the quantization of the parameters and intermediate results is carried-out after the DNN training process. Multiple configurations of quantization are tested in an optimization algorithm [5, 6]. This aims to allow a flexibility for the target but it increases the design time and reduces the performances. The PTQ can significantly decrease the quality.

Both of these methods require to evaluate the quality degradation due to finite precision. The quality degradation evaluation has been explored through multiple points of view in the literature.

The first point of view is to use an analytical model. This analytical model evaluates the quantization errors due to bitwidth reduction and propagates them inside the systems toward the output. This method has been implemented in different frameworks [7, 8] for fixed-point and floating-point arithmetics. These approaches are efficient in terms of error evaluation time but they are limited to systems containing only smooth operations. An operation is considered as smooth if the output is a continuous and differentiable function of the inputs. This method is then really efficient for application such as linear time invariant systems which are only composed of smooth operations. However, it hardly fits for application such as DNN which are composed of smooth operations, like convolutional layer, and unsmooth operations, like pooling layer.

The second point of view is to use simulation. Simulation will, for each tested bitwidth configuration, subject input to the application and determine through their outputs the quality of the configuration. The quality degradation is estimated using Monte-Carlo Simulation (MCS) [1, 2]. Due to the emulation of finite precision, each MCS take a long time. Furthermore, to obtain a confidence in the statistics of the quality metric, it is important to use an important amount of inputs in the MCS. To define a minimal number of tested inputs, it is important to quantify the confidence in the quality in the inputs. Furthermore, quantifying this confidence allows to find tools to reduce this minimal number of inputs.

### III. QUALITY ESTIMATION AND CONFIDENCE INTERVAL

In this paper, we consider data processing oriented applications for which the quality criteria for finite precision refinement is based on the comparison between $y_T$, the output obtained with the tested model (i.e. finite precision), and $y_R$, the golden reference output (figure 1).

<figure><img src="image_2.png" /><figcaption>Fig. 1. Simulation of an input sample $x$ for a configuration</figcaption></figure>

The result of the comparison of $y_T$ and $y_R$ is a boolean $\varphi$ with value 0 when $y_T$ and $y_R$ are not identical (failure) or 1 otherwise (success). In the context of DNN used for solving classification tasks, $\varphi = 1$ if the Top-M classes (i.e the M output classes with the highest probabilities) obtained with the tested model are identical to the Top-M classes obtained with the golden reference.

Let $\lambda$, be the probability that, for an input $x$, $\varphi = 1$ and $1-\lambda$ the probability that $\varphi = 0$. The random variable $\varphi$ follows a Bernoulli distribution of parameter $\lambda$. $\varphi$ is then a model that defines the simulation of a configuration to an input.

A sample mean of N inputs $\lambda$ is the maximum likelihood of the parameter $\lambda$ as expressed in Equation 1 [9].

$$ \hat{\lambda} = \frac{1}{N} \sum_{k=1}^{N} \varphi(x_k) \qquad (1) $$

As an estimator, the obtained value $\hat{\lambda}$ depends on the N tested inputs $x$. The histogram of possible values for $\hat{\lambda}$ can be modeled through a Gaussian distribution using the law of large numbers. The mean of the Gaussian is equal to the real value of $\lambda$ and its variance depends on the number of inputs used for the estimation [10]. To define a confidence in the estimator, two values are required: the absolute error $\varepsilon$ and the confidence interval $\delta$. $\varepsilon$ represents the quantile for $\delta$ of the distance between the real value $\lambda$ and the estimated one $\hat{\lambda}$. To find the minimal number of samples required, the user can define $\varepsilon_{max}$ which sets the maximal $\varepsilon$ that the user tolerate.

$\delta$ represents the probability that the estimation $\hat{\lambda}$ is at a maximal distance $\varepsilon$ of the real value $\lambda$ [11]. The expression of the confidence interval $\delta$ is given in Equation 2 and illustrated in Fig. 2.

$$ \mathbb{P}(\sqrt{N}|\hat{\lambda} - \lambda| \le \varepsilon) = \delta \qquad (2) $$

The minimum number of input samples $N_s$ to obtain a given confidence can be derived using the inverse cumulative distribution function for the normal distribution $z$ with the following expression

$$ N_s \ge z(\bar{q})^2 \frac{\sigma^2}{\varepsilon_{max}^2} \qquad (3) $$

with $\bar{q} = \frac{1+\delta}{2}$ the upper quantile as illustrated in Fig. 2.
<figure><img src="image_3.png" /><figcaption>Fig. 2. Histogram for the estimator $\hat{\lambda}$.</figcaption></figure>

For a set $(\delta, \varepsilon_{max})$, the only parameter remaining is the variance of the simulation result $\sigma$. Since $\varphi(x)$ follows a Bernoulli distribution, $\sigma$ can be estimated through the unbiased estimator $\hat{\sigma}$ presented in Equation 4 [10].

$$ \hat{\sigma} = \hat{\lambda}(1 - \hat{\lambda}) \frac{N}{N-1} \quad (4) $$

To tend to the minimal number of samples, an iterative algorithm such as described in Algorithm 1 can be used. This algorithm uses batch of size $N_b$. At each iteration, $N_b$ new inputs will be drawn. These new inputs will be added to the list of drawn inputs. This list will be evaluated through $\varphi$ to estimate $\hat{\lambda}$ and $\hat{\sigma}$. The corresponding $\hat{\varepsilon}$ is then estimated. If $\hat{\varepsilon} \ge \varepsilon_{max}$, a new iteration starts. Otherwise, the quality estimated $\hat{\lambda}$ is returned.

### Algorithm 1 MCS estimation for bitwidth optimization

1. **Input**: $z(\bar{q}), \varepsilon_{max}$ and $N_b$

2. $X = \emptyset$

3. $k \leftarrow 0$

4. **while** $\hat{\varepsilon} \ge \varepsilon_{max}$ **do**

5. $k \leftarrow k + 1$

6. $I \leftarrow \text{Draw } N_b$ images

7. $X \leftarrow X \cup I$

8. $\hat{\lambda} \leftarrow \frac{1}{kN_b} \sum_{i=0}^{kN_b} \varphi(X_i)$

9. $\hat{\sigma} \leftarrow \hat{\lambda}(1 - \hat{\lambda}) \frac{kN_b}{kN_b - 1}$

10. $\hat{\varepsilon} \leftarrow z(\bar{q}) \frac{\hat{\sigma}}{\sqrt{kN_b}}$

11. **end while**
**return** $\hat{\lambda}$

Since the parameters $\delta$ and $\varepsilon_{max}$ are user-defined, to reduce the number of sample required for a confident estimation, $\sigma$ needs to be reduced. In the next section, we described stratified sampling as a method to reduce this variance. We proposed an adaptation for quantization effect evaluation.

## IV. STRATIFIED SAMPLING

### A. Concept

Stratified sampling is a variance reduction sampling method. It is based on conditional probability and requires a stratification of a space $\Omega$ into independent subspaces $\Omega_j$ for which we know the probability to be drawn [12, 13]:

$$ p_j = \mathbb{P}[\Omega_j] \quad (5) $$

Every subdivision that meet that requirement can be used for stratified sampling. However not all subdivision can lead to a variance reduction. Stratified sampling relies on the idea that a subdivision in which the inputs share common features can lead to a smaller variance.

In this context, the resilience of the input images to the quantization process is considered to subdivide the global input image database. We introduce the difficulty metric which aims at representing for a given input image, its resilience to quantization. A method to define this difficulty metric is detailed in section IV-B. This difficulty metric will regroup inputs with similar behavior and so a variance within this difficulty close to 0. So any information brought by this subgroup will not impact the mean estimator's variance. Stratified sampling then determines the mean and the variance of the system as a weighted sum of the means of each subgroup.

However, the use of subdivisions leads to an adjustment of the mean estimator with the following unbiased estimator:

$$ \hat{\mu}_{strat} = \sum_{j=1}^{S} p_j \frac{1}{n_j} \sum_{k=0}^{n_j} \varphi(x_k^j) = \sum_{j=1}^{S} p_j \hat{\mu}_{n_j} \quad (6) $$

with $x_k^j$ an input drawn in the subspace $\Omega_j$.

Using this estimator requires to adapt the variance estimator as follows:

$$ \hat{\sigma}_{strat} = \sum_{j=1}^{S} \frac{p_j^2}{n_j} \hat{\sigma}_j^2 \quad (7) $$

with $\hat{\sigma}_j^2$ the variance as defined in equation 4 for inputs $x_k^j$.

This variance is in the worst case equal to the variance of classical Monte-Carlo, otherwise it is smaller. The variance reduction is dependent of the number of samples drawn $n_j$ for a subdivision. An optimal $n_j^*$ exists as defined in equation:

$$ n_j^* = \frac{p_j \sigma_j}{\sum_{i=1}^{S} p_i \sigma_i} \quad (8) $$

However, this optimal depends on $\sigma_j$ which has to be estimated. A good alternative is to draw for each subspace $\Omega_j$, a number of inputs $n_j$ proportional to $N$, the total number of inputs that we want to draw

$$ n_j = p_j \cdot N \quad (9) $$

### B. Subdivision of the space for quantization

In order to use stratified sampling for bitwidth optimization, it is necessary to define a method to divide the inputs into subspaces. In this paper, we propose to divide the space into subdivision composed by inputs with similar features and to use a metric that represents the resilience of an input to quantization. All the inputs having the same resilience will be grouped together inside a same subspace. This metric is defined using a uniform bitwidth for all the data inside the whole application. The value $d_x$ for an input $x$ is the minimal
value for which $\varphi_d(x) = 1$. For a DNN, this value corresponds to the lowest bitwidth for which the Top-M matches with the golden reference. The value $d_x$ can be found for each input using a dichotomy approach as described in Algorithm 2.

<caption>**Algorithm 2** Algorithm to find the difficulty for an input</caption>

1: **Input** : $\varphi$ and $x$
2: Top $\leftarrow d_{max}$
3: Bottom $\leftarrow d_{min}$
4: **while** Top-1 $\neq$ Bottom **do**
5: &nbsp;&nbsp;&nbsp;&nbsp;$d \leftarrow \frac{Top+Bottom}{2}$
6: &nbsp;&nbsp;&nbsp;&nbsp;Compute $\varphi_d(x)$
7: &nbsp;&nbsp;&nbsp;&nbsp;**if** $\varphi_d(x) == 1$ **then**
8: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Top $\leftarrow d$
9: &nbsp;&nbsp;&nbsp;&nbsp;**else**
10: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bottom $\leftarrow d$
11: &nbsp;&nbsp;&nbsp;&nbsp;**end if**
12: **end while**
13: **return** $d$

All the inputs with the same value $d_x$ are grouped together in the subspace $d$. Since each input is associated to a single value $d_x$, each $d$ are independent of each others. Finally, the probability of drawing an image in $d$ is known, since drawing in $\Omega$ is a uniform law. Each input has a similar probability of being drawn. The probability of drawing any input in a space $d$, $p(d)$, is the proportion of images in $d$ compared to the number of inputs in $\Omega$.

$$p(d) = \frac{card(d)}{card(\Omega)} \qquad (10)$$

Every condition described in IV-A is met, allowing stratified sampling to be used. Furthermore, this subdivision also brings a priori information to reduce the variance of any space $\hat{\sigma}_j$. Since each subdivision $d$ is defined using the quantization model $\varphi$, the input inside it will have a similar behavior to $\varphi$ and so a similar resilience to quantization. This leads to a reduction of $\hat{\sigma}_d$ and then a reduction of $\hat{\sigma}$.

### C. Adaptation for quantization

To adapt the stratified sampling for quantization we propose Algorithm 3. As seen in equation 3, the minimal number of samples $N_s$ depends on the variance $\sigma$ of the drawn inputs and this variance can not be determined in advance. Consequently, an iterative process is used to refine progressively the minimal number of samples.

This algorithm takes as input each subspace $d$ in $\Omega$ and its probability of being drawn $p(d)$. It also requires the maximal absolute error $\varepsilon_{max}$ and the confidence interval $\delta$ selected by the user. Finally, a batch size $N_b$ is defined and the number of tested images will be a multiple of $N_b$. A small value for $N_b$ will lead to a number of tested images close to $N_s$. However, $N_b$ needs to be large enough so that each iteration of the process follows the law of large numbers. For that reason, $N_b$ is set to 50.

This iterative process continues while the estimated absolute error $\hat{\varepsilon}$ exceeds the user-defined maximal absolute error $\varepsilon_{max}$

or all inputs have been tested (line 4). For all $d$, the number of inputs $n_d$ is computed according to equation 9 (line 7). From the remaining inputs in $d$, $n_d$ inputs are drawn (line 8). These inputs are added to the list of all inputs that has been drawn for this subdivision (line 9). If all inputs in a difficulty $d$ have been drawn, the list of inputs remains the same for each subsequent iteration. This list of inputs is then used to determine the quality $\hat{\lambda}_d$ and the variance $\hat{\sigma}_d$ for this subdivision according to Equation 1 and Equation 4 (lines 10,11). Once $\hat{\lambda}_d$ and $\hat{\sigma}_d$ have been estimated for all $d$, the quality $\tilde{\lambda}$ and the absolute error $\hat{\varepsilon}$ for the configuration is estimated (lines 13,14,15). If the estimated absolute error is lower than the maximal absolute error, the algorithm returns the last quality estimate. Otherwise, it performs another iteration with $N_b$ new inputs.

<caption>**Algorithm 3** Sampling monte carlo estimation for bitwidth optimization</caption>

1: **Input** : $z(\bar{q})$, $\varepsilon_{max}$, $N_b$, $D$ and $p$
2: $X_{s_d} = \emptyset$ $\forall d \in \Omega$
3: $k \leftarrow 0$
4: **while** $\hat{\varepsilon} \ge \varepsilon_{max}$ and $kN_b < card(\Omega)$ **do**
5: &nbsp;&nbsp;&nbsp;&nbsp;$k \leftarrow k + 1$
6: &nbsp;&nbsp;&nbsp;&nbsp;**for** $d \in \Omega$ **do**
7: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$n_d \leftarrow round(N_b p(d))$
8: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$X_d \leftarrow$ Draw $n_d$ images
9: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$X_{s_d} \leftarrow X_{s_d} \cup X_d$
10: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Estimate $\hat{\lambda}_d$ on $X_{s_d}$
11: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Estimate $\hat{\sigma}_d$ on $X_{s_d}$
12: &nbsp;&nbsp;&nbsp;&nbsp;**end for**
13: &nbsp;&nbsp;&nbsp;&nbsp;$\tilde{\lambda} \leftarrow \sum_{d \in \Omega} p(d) \hat{\lambda}_d$
14: &nbsp;&nbsp;&nbsp;&nbsp;$\hat{\sigma} \leftarrow \sum_{d \in \Omega} \frac{p(d)^2}{kn_d} \sigma_d^2$
15: &nbsp;&nbsp;&nbsp;&nbsp;$\hat{\varepsilon} \leftarrow z(\bar{q}) \sqrt{\frac{\hat{\lambda}(1-\hat{\lambda})}{kN-1}}$
16: **end while**
17: **return** $\tilde{\lambda}$

In figure 3 we illustrate this iterative process with and without stratified sampling. The graph depicts the boundaries of the estimated quality according to the number of samples used for the estimation. These two versions have been tested on a bitwidth configuration leading to a quality $\lambda = 0.77$. For both of them, $\bar{q}$ and $q$ has been reported to represent the interval for $\delta = 95\%$. The red curve represents the boundaries $(\bar{q}$ and $q)$ for MCS without stratified sampling as described in algorithm 1. The purple curve represents the boundaries for MCS with stratified sampling as described in algorithm 3.

We can observe that the boundaries tend to the real value $\lambda$ over the iteration. Furthermore, the boundaries for an MCS without Stratified cross $\varepsilon_{max}$ set to 0.01 for 2600 inputs used. On the other hand, with stratified sampling, the boundaries cross $\varepsilon_{max}$ with only one batch of 50 inputs.

## V. EXPERIMENTS

To show the efficiency of the proposed approach, the experiments have been conducted on a bitwidth optimization algorithm for custom floating-point arithmetic and the quality is evaluated by Monte-Carlo Simulation. This optimization aims
<figure><img src="image_4.png" /><figcaption>Fig. 3. Evolution of the confidence with and without Stratified using a batch size of $N_b = 50$.</figcaption></figure>

at minimizing the implementation cost $\hat{C}$ while maintaining the quality $\hat{\lambda}$ above a given threshold $\lambda_{min}$ as described in Equation 11.

$$ \min_{\mathbf{w}} (\hat{C}(\mathbf{w})) \quad \text{subject to} \quad \hat{\lambda}(\mathbf{w}) \geq \lambda_{min} \quad (11) $$

This optimization process used the MIN+1 algorithm [14] to explore multiple bitwidth configurations $\mathbf{w}$. This algorithm is composed of two phases:

1) Determination of the pivot value for each variable $\mathbf{w}_i$. This pivot value is the lowest value for which $\hat{\lambda} \geq \lambda_{min}$, while other bitwidths are set to their maximal value.

2) Refinement of the solution. All variables are set to their pivot value, then the optimization algorithm climb up by increasing by 1 the value of a variable $\mathbf{w}_j$. The variable $\mathbf{w}_j$ is selected by following the greatest quality gradient. The algorithm will continue to climb up until $\hat{\lambda} < \lambda_{min}$.

At each tested configuration, the process will determine the implementation cost based on a model and the quality using simulations as described in section III. For this study, the power consumption is considered for the implementation cost. This cost model is computed thanks to a library of operators for 28nm FDSOI technology [15].

The targeted application is the Squeezenet Convolutional Neural Network (CNN). Two versions of a Squeezenet CNN are considered. Squeezenet is used for image classification and is composed of 14 layers. The two squeezed versions differ in the number of variables to optimize, which affects the complexity of the MIN+1 algorithm. For the smaller one (SQUEEZENET-8v), 8 variables are involved in the optimization process and for the bigger one (SQUEEZENET-15v) 15 variables are involved in the optimization process. In this experiment, the $\phi$ function returns 0 if the Top-1 is different between the golden reference (floating-point version - FP32) and the tested version. The $\phi$ function returns 1 otherwise. The tested version is based on the acfloat library [16].

To evaluate the impact of Stratified sampling, we compare our proposed approach described in algorithm 3 with the classical MCS described in algorithm 1. The input database is made-up of 4520 images. The subdivision into difficulties is

<table><caption>TABLE I
RESULTS OF THE OPTIMIZATION PROCESS FOR SQUEEZENET-8V AND SQUEEZENET-15V WITH AND WITHOUT STRATIFIED SAMPLING</caption><thead><tr><th rowspan="2"></th><th rowspan="2">Stratified</th><th colspan="2">SQUEEZENET-15v</th><th colspan="2">SQUEEZENET-8v</th></tr><tr><th>Without</th><th>With</th><th>Without</th><th>With</th></tr></thead><tbody><tr><th>Relative</th><td>Mean</td><td>0.179</td><td>0.188</td><td>0.149</td><td>0.175</td></tr><tr><th>Cost</th><td>Variance</td><td>1E-4</td><td>1E-4</td><td>6E-5</td><td>5E-4</td></tr><tr><th rowspan="2">λ</th><td>Mean</td><td>0.984</td><td>0.957</td><td>0.974</td><td>0.967</td></tr><tr><td>Variance</td><td>2E-4</td><td>1E-6</td><td>3E-4</td><td>1E-4</td></tr></tbody></table>

done beforehand as described in part IV-B. For each difficulty value, the proportion of images is shown in Figure 4.

<figure><img src="image_5.png" /><figcaption>Fig. 4. Proportion of images according to their difficulty estimated for the 4520 images in the dataset.</figcaption></figure>

The optimization process determines a relative cost gain compared to the initial version based on FP32. The estimation being a random process, it can impact the optimization process and consequently the final result. We perform 5 optimizations with the same parameters ($\lambda_{min} = 0.95, \delta = 99\%, \varepsilon_{max} = 0.01$) to compensate for possible variations in the results. The mean and the variance of the relative cost and the quality obtained at the end the optimization process are presented in Table V. These results show that the solution of the optimization process is not significantly modified by Stratified sampling. However, for a same confident interval the results with stratified require less images as shown in Figure 5.

The figure 5 illustrates the mean number of images required to estimate the quality $\hat{\lambda}$ of a configuration $\mathbf{w}$. The number of images used by the approach based on classical MCS is on average equal to 523 for the SQUEEZENET-15v and 748 for the SQUEEZENET-8v. The number of images used by our approach based on stratified sampling is on average equal to 66 for the SQUEEZENET-15v and 69 for the SQUEEZENET-8v. The number of images used by the approach based on classical MCS is higher of an order of magnitude compared to the proposed approach based on stratified sampling. For stratified sampling, the number of images used is then, on average, close to the minimal number, which is the batch size $N_b = 50$.

This reduction of number of images is even more important when scaled by the number of configurations tested to find a solution in the MIN+1 algorithm. This is illustrated in Figure 6. In our proposed approach a pre-processing phase is required to compute the difficulty associated to each image. This phase is
<figure><img src="image_6.png" /><figcaption>Fig. 5. Mean number of images required for one quality estimation for SQUEEZENET-15v and SQUEEZENET-8v with and without stratified sampling.</figcaption></figure>

done only once and then can be used for the different bitwidth optimization processes. For the 4520 input images, 18062 simulations have been carried-out to compute the difficulty of all input images. Even if this phase is taken into account, our approach is still faster than the approach based on classical MCS.

<figure><img src="image_7.png" /><figcaption>Fig. 6. Mean number of images required for a complete optimization process for SQUEEZENET-15v and SQUEEZENET-8v with and without stratified sampling.</figcaption></figure>

## VI. CONCLUSION

This paper proposes a method to reduce the number of inputs to obtain a confident estimation of quality degradation due to quantization. This method relies on a variance reduction method of Monte-Carlo simulation : Stratified sampling. The use of Stratified sampling requires subdividing the input dataset into subspaces. This subdivision will define the variance reduction.

The proposed approach use the function to optimize to determine similar features between the inputs. A difficulty metric is computed for each input image and inputs having the same difficulty are grouped together in the same subdivision.

With these difficulties, we propose an iterative algorithm to determine the quality of a system. This iterative algorithm computes a quality estimation using successive batches of inputs to tend to the theoretical minimal required number of

inputs. For each batch, the quality and their respective variance are estimated by simulation in every difficulty. The number of inputs used for each of these estimation being proportional to the size of the difficulty subdivision. A weighted sum of these estimation gives the global quality estimation.

We experiment this method on a complete bitwidth optimization for two versions of a Squeezenet CNN. We compare the results and the number of inputs required with and without the stratified method. The results show a similarity in the output of the optimization process but a reduction of one order of magnitude of the number of inputs tested with the Stratified approach.

## REFERENCES

[1] Ha Van-Phu et al. "Towards Generic and Scalable Word-Length Optimization". In: *Design, Automation & Test in Europe Conference & Exhibition (DATE)*. IEEE, Mar. 2020, pp. 1668–1673.

[2] Paulius Micikevicius et al. "Fp8 formats for deep learning". In: *arXiv preprint arXiv:2209.05433* (2022).

[3] Jonghoon Kwak et al. "Quantization Aware Training with Order Strategy for CNN". In: *IEEE International Conference on Consumer Electronics-Asia (ICCE-Asia)*. Oct. 2022, pp. 1–3.

[4] Het Shah et al. "KD-Lib: A PyTorch library for Knowledge Distillation, Pruning and Quantization". In: *ArXiv* (Nov. 30, 2020).

[5] Darryl D. Lin, Sachin S. Talathi, and V. Sreekanth Anna-pureddy. "Fixed point quantization of deep convolutional networks". In: *International Conference on Machine Learning*. ICML'16. New York, 2016, pp. 2849–2858.

[6] Uday et al Kulkarni. "A Survey on Quantization Methods for Optimization of Deep Neural Networks". In: *International Conference on Automation, Computing and Renewable Systems (ICACRS)*. Dec. 2022, pp. 827–834.

[7] A.A Gaffar et al. "Unifying bit-width optimisation for fixed-point and floating-point designs". In: *Symposium on Field-Programmable Custom Computing Machines*. Apr. 2004, pp. 79–88.

[8] Thibault Hilaire, Daniel Menard, and Olivier Sentieys. "Bit accurate roundoff noise analysis of fixed-point linear controllers". In: *2008 IEEE International Conference on Computer-Aided Control Systems*. IEEE. 2008, pp. 607–612.

[9] Luengo et al. "A survey of Monte Carlo methods for parameter estimation". In: *EURASIP Journal on Advances in Signal Processing* 2020.1 (May 2020), p. 25.

[10] Sean Wallis. "Binomial Confidence Intervals and Contingency Tests: Mathematical Fundamentals and the Evaluation of Alternative Methods". In: *Journal of Quantitative Linguistics* 20 (Aug. 2013), pp. 178–208.

[11] Carl et al Graham. *Stochastic Simulation and Monte Carlo Methods: Mathematical Foundations of Stochastic Simulation*. Vol. 68. Stochastic Modelling and Applied Probability. Berlin, Heidelberg: Springer, 2013.

[12] Bruno Tuffin. *La Simulation de Monte-Carlo*. Lavoisier. méthodes stochastiques appliquées. ISBN: 978-2-7462-2551-3.

[13] Ravindra et al Singh. "Stratified Sampling". In: *Elements of Survey Sampling*. Springer, Dordrecht, 1996, pp. 102–144.

[14] Gabriel Caffarena. "Wordlength Optimization of Fixed-Point Algorithms". In: *Approximate Computing Techniques: From Component-to Application-Level*. Springer, 2022, pp. 261–284.

[15] B.Barrois et al. "Customizing fixed-point and floating-point arithmetic — A case study in K-means clustering". In: *International Workshop on Signal Processing Systems (SiPS)*. Oct. 2017, pp. 1–6.

[16] SIEMENS EDA. *Algorithmic C Datatypes reference manual*. Aug. 2022.