v9.1.1
Menu

Calculate Parameter Count for Grouped Convolutions

mediumPROConvNextNeural Networks, MathAdvanced Architectures

Implement a function to calculate the parameter count ratio between grouped convolutions and standard convolutions. Grouped convolutions are a technique used in ConvNext architectures to reduce computational costs by splitting input and output channels into GG groups, where each group operates on a subset of the channels.

This process can be broken down into the following steps:

  1. Determine the number of parameters in a standard convolution, given by KW×KH×Cin×CoutK_W \times K_H \times C_{in} \times C_{out}.
  2. Calculate the number of parameters in a grouped convolution, where each of the GG groups operates on Cin/GC_{in}/G input channels producing Cout/GC_{out}/G output channels. The key formula for the ratio of parameters is
Ratio=ParamsGParamsS\text{Ratio} = \frac{\text{Params}_G}{\text{Params}_S}

This technique is widely used in deep learning models for image classification tasks.

Example

Input
K_W=3, K_H=3, C_in=256, C_out=256, G=4
Output
0.25
Reasoning
  • Inputs: a 3×33 \times 3 kernel (KW=KH=3K_W = K_H = 3), Cin=256C_{in} = 256 input channels, Cout=256C_{out} = 256 output channels, and G=4G = 4 groups. Every weight connects one kernel position, one input channel and one output channel.
  • Standard convolution: every output channel sees all input channels, so ParamsS=3×3×256×256=589,824\text{Params}_S = 3 \times 3 \times 256 \times 256 = 589{,}824.
  • One group: it sees only 256/4=64256 / 4 = 64 input channels and produces 256/4=64256 / 4 = 64 output channels, so it holds 3×3×64×64=36,8643 \times 3 \times 64 \times 64 = 36{,}864 weights.
  • All groups: ParamsG=4×36,864=147,456\text{Params}_G = 4 \times 36{,}864 = 147{,}456.
  • Ratio: 147,456589,824=0.25\frac{147{,}456}{589{,}824} = 0.25, returned as a float 0.25.
  • Notice: both channel counts are divided by GG but only one factor of GG is multiplied back, so the kernel size and channel counts cancel and the ratio is 1G\frac{1}{G}. With G=1G = 1 you get 1.0 (a standard convolution); with G=16G = 16, 0.0625.

Constraints

  • KW=KH=3K_W = K_H = 3 (kernel size)
  • Cin=Cout=256C_{in} = C_{out} = 256 (channels)
  • GG is a divisor of CinC_{in}: 1≤G≤Cin1 \leq G \leq C_{in}

More from Advanced Architectures

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.