Speed

Max-Pooling, Exactly

Partition a feature map into non-overlapping two-by-two tiles and keep the maximum entry of each tile with zero learnable weights.

The problem

Once a convolutional layer has measured where a pattern activates, the exact single-pixel coordinate of each peak matters less than which neighborhood contains it. Keeping every pixel through many layers inflates memory and forces deeper filters to span wider windows before seeing whole parts of an object.

Max-pooling with pool size k partitions each channel independently into non-overlapping k by k tiles — equivalent to window size k with stride k — and writes the single largest entry of each tile. It introduces zero learnable weights and zero biases, halving height and width when k = 2.

Work through the numbers

Take the four-by-four activation table [[3, 3, 1, 2], [1, 5, 4, 0], [2, 0, 1, 3], [6, 1, 2, 2]] and apply two-by-two max-pooling. Four non-overlapping tiles cover the sixteen cells without sharing a single entry.

Top-left tile (rows 0..1, cols 0..1) holds [[3, 3], [1, 5]] with maximum 5 at (1, 1). Top-right tile (rows 0..1, cols 2..3) holds [[1, 2], [4, 0]] with maximum 4 at (1, 2). Bottom-left tile [[2, 0], [6, 1]] peaks at 6, and bottom-right tile [[1, 3], [2, 2]] peaks at 3, giving [[5, 4], [6, 3]].

Compare naive top-left subsampling, which reads (0, 0), (0, 2), (2, 0), and (2, 2) and returns [[3, 1], [2, 1]], missing every single peak because none of the four winners sat in the upper-left corner of its tile.

The live model

The demo adds peak_add (default 5, or 0 for the unboosted table [[5, 4], [6, 3]]) to row 0 at column peak_col before pooling. With peak_add = 5, peak_col = 0 ([8, 3, 1, 2]) and peak_col = 1 ([3, 8, 1, 2]) both pool to [[8, 4], [6, 3]] inside the top-left tile, whereas peak_col = 2 crosses into the top-right tile for [[5, 6], [6, 3]] and peak_col = 3 gives [[5, 7], [6, 3]].

Four-by-four activation grid with boosted peak 8 at (0, 1) partitioned into four two-by-two tiles and pooled to [[8,4],[6,3]].
torch.grad_enabled(false);
let peak_add = scene.parameter("peak_add", 5.0, 0.0, 5.0, 5.0);
let peak_col = int(scene.parameter("peak_col", 1.0, 0.0, 3.0, 1.0));
let grid = torch.zeros(16);
for (i in range(0, 16)) { grid.set(i, input.value(i)); }
grid.set(peak_col, grid.value(peak_col) + peak_add);
let pool = torch.sequential().max_pool2d(2);
let answer = pool.forward(grid.reshape(1, 1, 4, 4)).reshape(2, 2);
out.set("peak_col", peak_col).set("grid", grid.reshape(4, 4));
out.set("pooled", answer);
{
  "peak_col": 1,
  "grid": [
    [
      3,
      8,
      1,
      2
    ],
    [
      1,
      5,
      4,
      0
    ],
    [
      2,
      0,
      1,
      3
    ],
    [
      6,
      1,
      2,
      2
    ]
  ],
  "pooled": [
    [
      8,
      4
    ],
    [
      6,
      3
    ]
  ]
}

Your turn

On the unboosted four-by-four table, the starter outputs [[3, 1], [2, 1]] instead of [[5, 4], [6, 3]]: reading only the upper-left corner of each two-by-two tile misses every tile's true peak (5, 4, 6, and 3), throwing away strong activations one pixel to the right or below. Summarize each disjoint two-by-two tile by its largest entry instead. Check runs unseen four-by-four maps and rejects tile averaging, global max broadcasting, and hardcoded outputs.

Four-by-four activation grid partitioned into two-by-two tiles beside starter corner subsample [[3,1],[2,1]].
torch.grad_enabled(false);
let x = input.to(DType.F32);
let sub = torch.zeros(4);
sub.set(0, x.value(0));
sub.set(1, x.value(2));
sub.set(2, x.value(8));
sub.set(3, x.value(10));
let answer = sub.reshape(2, 2);
out.set("pooled", answer);
{
  "pooled": [
    [
      3,
      1
    ],
    [
      2,
      1
    ]
  ]
}

Summarize each non-overlapping two-by-two tile of the four-by-four input table by its largest entry.

Read the result carefully

Max-pooling provides within-tile shift tolerance, not global shift invariance: nudging a peak inside one tile leaves its pooled value unchanged, whereas nudging it one pixel across a tile border moves the response to the neighboring output cell. During backpropagation, each tile routes 100% of its incoming gradient to the winning input cell and 0 to the other three cells.

Recap

  • max_pool2d(2) splits each channel into disjoint two-by-two tiles and outputs the maximum of every four-cell block.
  • Pooling layers have zero trainable parameters and process each channel independently without mixing across channels.
  • Moving a peak within a tile preserves the pooled output, while crossing a tile boundary jumps the peak into the adjacent pooled cell.