ConvLayerScenario
Training scenarios · Implementation: mlsysim/engine/scenario_definitions/training.py.
Construct this scenario with keyword inputs. The fields below show the types and defaults declared by this class.
One kernel-by-kernel convolution, stride one, over a height-by-width-by-in_channels input to out_channels feature maps; values of bytes_per_value each.
same_padding keeps the output the size of the input; without it the window stays inside the input (“valid”), as an unpadded unfold does.
Notes
Equation: Each output position reuses k*k*Cin*Cout weights; batch FLOPs are twice positions*weights*batch.
Assumptions: Stride one, same or valid padding, and one-pass traffic at the declared precisions.
Excludes: Dilation, groups other than the separate depthwise illustration, workspace, and measured kernel traffic.
References
Derivation: A convolution filter contains k*k*Cin weights for each output channel. Applying that filter at each output location repeats its MACs without adding new parameters. The separate depthwise-plus-pointwise construction uses one spatial filter per input channel followed by channel mixing.
Examples
>>> from mlsysim import Scenarios
>>> s = Scenarios.MnistFirstConvLayer
>>> s.variant(batch_size=2*s.batch_size).flops == 2*s.flops
TrueAttributes
| Name | Description |
|---|---|
| activation_bytes | Output activation footprint in bytes for one example. |
| activation_to_weight_ratio | Dimensionless one-example output footprint divided by filter storage. |
| batch_input_bytes | Input activation bytes read once for the whole batch. |
| batch_output_bytes | Output activation bytes written once for the whole batch. |
| batch_size | |
| bytes_per_value | |
| dense_weights | Weights of a dense layer from the whole input to out_channels outputs. |
| depthwise_weights | One kernel-by-kernel filter per input channel (multiply-adds per position). |
| flops | 2 x batch x MACs: one multiply and one add per weight per position. |
| height | |
| in_channels | |
| input_values | Input activation count across spatial positions and channels. |
| kernel | |
| macs | Multiply-accumulate count for one example, reusing each filter at every output position. |
| max_copies | Most rows of the patch matrix one input value can appear in. |
| out_channels | |
| output_height | Output rows for stride-one same or valid padding. |
| output_width | Output columns for stride-one same or valid padding. |
| outputs | Output activation values for one example. |
| pointwise_weights | A 1x1 convolution mixing in_channels into out_channels (multiply-adds per position). |
| positions | Output positions per feature map, each a reuse of every filter weight. |
| same_padding | |
| separable_fraction | Depthwise-separable parameter fraction relative to a standard convolution. |
| separable_limit | The ratio’s limit with many output channels: the filter area. |
| separable_ratio | Standard over depthwise separable weights (and multiply-adds per position). |
| separable_weights | Combined depthwise and pointwise weight count. |
| sharing_ratio | Dense weights over convolution weights for the same input and feature count. |
| traffic_bytes | Batch input read, weights read, and batch output written once each. |
| traffic_intensity | FLOP per byte of the one-pass traffic. |
| unfolded_entries | Entries of the im2col patch matrix: one row of kernel**2 * in_channels per position. |
| weight_bytes | Filter storage in bytes, using a separate weight width when supplied. |
| weight_bytes_per_value | |
| weights | Filter weight count across spatial kernel, input channels, and output channels. |
| width |
Methods
| Name | Description |
|---|---|
| dense_weight_growth | Factor by which the dense layer’s weights grow when the input becomes height by width. |
dense_weight_growth
engine.scenario_types.ConvLayerScenario.dense_weight_growth(height, width)Factor by which the dense layer’s weights grow when the input becomes height by width.
Equation: height * width / (height * width).
height
Type: int.
Declared default: required.
width
Type: int.
Declared default: required.
kernel
Type: int.
Declared default: required.
in_channels
Type: int.
Declared default: required.
out_channels
Type: int.
Declared default: required.
bytes_per_value
Type: Quantity.
Declared default: required.
same_padding
Type: bool.
Declared default: True.
weights
engine.scenario_types.ConvLayerScenario.weights
Filter weight count across spatial kernel, input channels, and output channels.
Equation: kernel * kernel * in_channels * out_channels.
output_height
engine.scenario_types.ConvLayerScenario.output_height
Output rows for stride-one same or valid padding.
Equation: height if same_padding else height - kernel + 1.
output_width
engine.scenario_types.ConvLayerScenario.output_width
Output columns for stride-one same or valid padding.
Equation: width if same_padding else width - kernel + 1.
positions
engine.scenario_types.ConvLayerScenario.positions
Output positions per feature map, each a reuse of every filter weight.
Equation: output_height * output_width.
macs
engine.scenario_types.ConvLayerScenario.macs
Multiply-accumulate count for one example, reusing each filter at every output position.
Equation: positions * weights.
outputs
engine.scenario_types.ConvLayerScenario.outputs
Output activation values for one example.
Equation: positions * out_channels.
batch_size
Type: int.
Declared default: 1.
weight_bytes_per_value
Type: Optional[Quantity].
Declared default: None.
weight_bytes
engine.scenario_types.ConvLayerScenario.weight_bytes
Filter storage in bytes, using a separate weight width when supplied.
Equation: (weights * (weight_bytes_per_value or bytes_per_value)).to('byte').
activation_bytes
engine.scenario_types.ConvLayerScenario.activation_bytes
Output activation footprint in bytes for one example.
Equation: (outputs * bytes_per_value).to('byte').
flops
engine.scenario_types.ConvLayerScenario.flops
2 x batch x MACs: one multiply and one add per weight per position.
Equation: Q_(2 * batch_size * macs, 'flop').
batch_input_bytes
engine.scenario_types.ConvLayerScenario.batch_input_bytes
Input activation bytes read once for the whole batch.
Equation: (batch_size * input_values * bytes_per_value).to('byte').
batch_output_bytes
engine.scenario_types.ConvLayerScenario.batch_output_bytes
Output activation bytes written once for the whole batch.
Equation: (batch_size * outputs * bytes_per_value).to('byte').
traffic_bytes
engine.scenario_types.ConvLayerScenario.traffic_bytes
Batch input read, weights read, and batch output written once each.
Equation: batch_input_bytes + weight_bytes + batch_output_bytes.
traffic_intensity
engine.scenario_types.ConvLayerScenario.traffic_intensity
FLOP per byte of the one-pass traffic.
Equation: (flops / traffic_bytes).to('flop/byte').magnitude.
activation_to_weight_ratio
engine.scenario_types.ConvLayerScenario.activation_to_weight_ratio
Dimensionless one-example output footprint divided by filter storage.
Equation: (activation_bytes / weight_bytes).to('').magnitude.
input_values
engine.scenario_types.ConvLayerScenario.input_values
Input activation count across spatial positions and channels.
Equation: height * width * in_channels.
dense_weights
engine.scenario_types.ConvLayerScenario.dense_weights
Weights of a dense layer from the whole input to out_channels outputs.
Equation: input_values * out_channels.
sharing_ratio
engine.scenario_types.ConvLayerScenario.sharing_ratio
Dense weights over convolution weights for the same input and feature count.
Equation: dense_weights / weights.
unfolded_entries
engine.scenario_types.ConvLayerScenario.unfolded_entries
Entries of the im2col patch matrix: one row of kernel**2 * in_channels per position.
Equation: positions * kernel * kernel * in_channels.
max_copies
engine.scenario_types.ConvLayerScenario.max_copies
Most rows of the patch matrix one input value can appear in.
Equation: kernel * kernel.
depthwise_weights
engine.scenario_types.ConvLayerScenario.depthwise_weights
One kernel-by-kernel filter per input channel (multiply-adds per position).
Equation: kernel * kernel * in_channels.
pointwise_weights
engine.scenario_types.ConvLayerScenario.pointwise_weights
A 1x1 convolution mixing in_channels into out_channels (multiply-adds per position).
Equation: in_channels * out_channels.
separable_weights
engine.scenario_types.ConvLayerScenario.separable_weights
Combined depthwise and pointwise weight count.
Equation: depthwise_weights + pointwise_weights.
separable_ratio
engine.scenario_types.ConvLayerScenario.separable_ratio
Standard over depthwise separable weights (and multiply-adds per position).
Equation: weights / separable_weights.
separable_fraction
engine.scenario_types.ConvLayerScenario.separable_fraction
Depthwise-separable parameter fraction relative to a standard convolution.
Equation: _separable_fraction(kernel, out_channels).
separable_limit
engine.scenario_types.ConvLayerScenario.separable_limit
The ratio’s limit with many output channels: the filter area.
Equation: kernel * kernel.