Altifigence Academy

1 / 24 · Concept

Inference and training

If only the output channels increase from three to six, how do MAC count and stored bias count change?

Define the computation before the datapath

Inference applies fixed, previously chosen weights to an input in a forward pass. Training also calculates a loss, propagates gradients and updates weights. A circuit that performs forward convolution therefore demonstrates an inference operation; it does not by itself demonstrate training. This course builds a small integer inference path. Gradient hardware, optimizers, classification accuracy and automatic model import are outside the exercises.

Write a contract for batch N, input channels C, spatial dimensions H and W, output channels M and kernel R by S. We use NCHW ordering. A conventional output element accumulates C×R×S products. For an output of shape N×M×Ho×Wo, count N×M×Ho×Wo×C×R×S MACs. Here one MAC means one multiply with accumulation. A floating-point operations report may count the multiply and add separately, so state the counting rule before comparing reports.

Worked example

Take N=1, C=2, H=W=5, M=3 and a 3×3 kernel, with stride one and no padding. The spatial output is 3×3. There are 27 output elements, each accumulating 18 products, for 486 MACs. A bias vector contains three stored numbers, one per output channel, but the bias is added at 27 output positions. Report those additions separately rather than silently changing the MAC definition.

Ordering is part of correctness. A channel-first input read combined with a spatial-first interpretation of the weights pairs the wrong operands even when every value is legal. Label reference outputs with both channel and spatial coordinates. Begin with one batch, specify each tensor file and extend the batch dimension only after the basic contract is stable.

Record accepted shapes, strides, padding and numerical ranges. Reject unsupported requests explicitly. A flexible software array does not prove that an RTL implementation supports every size. Likewise, reference output cannot measure frequency, power or model accuracy. Later exercises distinguish exact values from a cycle estimate with stated assumptions. For the forward, backward and update stages of training, consult the official PyTorch tutorial.

Try it yourself

If only the output channels increase from three to six, how do MAC count and stored bias count change?

Read the explanation

There are 54 outputs and 54×18=972 MACs. Store six biases. Input size stays the same; weight storage doubles.

Your choice applies to this browser. Change it any time using the footer.