Exact AdaptiveAvgPool2d encoding in NCET¶
AdaptiveAvgPool2d chooses its pooling windows from the input shape and a
requested output shape. Once those shapes are static, it is a fixed linear
operator and can be encoded exactly without binary variables.
1. Adaptive windows¶
Let the per-sample input and output shapes be (C,H_in,W_in) and
(C,H_out,W_out). For output row \(i\) and column \(j\), PyTorch uses
The valid window is the Cartesian product of these half-open intervals. When an input dimension is not divisible by its output dimension, adjacent windows may overlap.
2. Scalar formula¶
Define
Each channel is pooled independently:
For output size (1,1), this reduces to global average pooling over each
channel.
3. Sparse matrix formulation¶
Using C-order vectorization, NCET constructs a sparse matrix \(A_{\mathrm{adaptive}}\) with
The exact CVXPY equality is
4. Interval bounds¶
All matrix coefficients are nonnegative, so the operation is monotone. Given \(L_X\le X\le U_X\), NCET propagates
These are the exact elementwise output ranges over the input box. Correlations between overlapping output windows are not retained by IBP.
5. Supported forms¶
NCET supports nn.AdaptiveAvgPool2d and
torch.nn.functional.adaptive_avg_pool2d on per-sample (C,H,W) tensors.
The output size must be static and may be a positive integer or a length-two
sequence whose entries are positive integers or None. A None entry keeps
the corresponding input dimension. Normalization resolves every accepted form
to a fixed (H_out,W_out) GraphIR attribute.