Estimate the work of one training step from forward matrix multiplications and a supplied forward attention cost. Count each multiplication and addition as one FLOP, and use twice the forward cost as the backward estimate.
Fforward=m∑2BmDmKm+Fattention Fbackward=2Fforward Ftotal=Fforward+FbackwardHere m indexes entries in matmuls; B is row count, D is input width, and K is output width for that entry. The four F values are the attention, forward, backward, and total operation counts; attention_flops supplies the attention term and defaults to zero. An empty multiplication list or a zero dimension contributes no matrix-multiplication work.
Return a Python dictionary with exactly the keys forward_flops, backward_flops, and total_flops, each holding an exact Python integer count under this estimate.
Input: matmuls = [[2,4,4]], attention_flops = 32
Output: {"forward_flops":96,"backward_flops":192,"total_flops":288}
Explanation: The matrix multiplication costs 64 FLOPs and attention adds 32, so forward costs 96. Backward costs twice the forward pass.
Input: matmuls = [[8,16,16],[8,16,4]], attention_flops = 0
Output: {"forward_flops":5120,"backward_flops":10240,"total_flops":15360}
Input: matmuls = [[0,512,512],[10,512,512]], attention_flops = 2000
Output: {"forward_flops":5244880,"backward_flops":10489760,"total_flops":15734640}
Tuple unpacking names the three dimensions in each entry.
Python integers retain exact products beyond fixed-width integer limits.
Accepts: array
Accepts: number
Estimate the work of one training step from forward matrix multiplications and a supplied forward attention cost. Count each multiplication and addition as one FLOP, and use twice the forward cost as the backward estimate.
Fforward=m∑2BmDmKm+Fattention Fbackward=2Fforward Ftotal=Fforward+FbackwardHere m indexes entries in matmuls; B is row count, D is input width, and K is output width for that entry. The four F values are the attention, forward, backward, and total operation counts; attention_flops supplies the attention term and defaults to zero. An empty multiplication list or a zero dimension contributes no matrix-multiplication work.
Return a Python dictionary with exactly the keys forward_flops, backward_flops, and total_flops, each holding an exact Python integer count under this estimate.
Input: matmuls = [[2,4,4]], attention_flops = 32
Output: {"forward_flops":96,"backward_flops":192,"total_flops":288}
Explanation: The matrix multiplication costs 64 FLOPs and attention adds 32, so forward costs 96. Backward costs twice the forward pass.
Input: matmuls = [[8,16,16],[8,16,4]], attention_flops = 0
Output: {"forward_flops":5120,"backward_flops":10240,"total_flops":15360}
Input: matmuls = [[0,512,512],[10,512,512]], attention_flops = 2000
Output: {"forward_flops":5244880,"backward_flops":10489760,"total_flops":15734640}
Tuple unpacking names the three dimensions in each entry.
Python integers retain exact products beyond fixed-width integer limits.
Accepts: array
Accepts: number