Skip to main content

solvers.EfficiencyModel

solvers.EfficiencyModel()

Models the gap between peak and achieved FLOPS (Wall 3: Software Efficiency).

This model quantifies the software efficiency of a workload — the fraction of peak hardware FLOPS that the software stack actually converts into useful computation. It decomposes Model FLOPs Utilization (MFU) by workload type, accounting for kernel fusion efficiency, SM occupancy, and memory access patterns.

Literature Source: 1. Chowdhery et al. (2022), “PaLM: Scaling Language Modeling with Pathways.” (First systematic MFU reporting for large Transformers.) 2. Dao et al. (2022), “FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness.” (FlashAttention MFU improvement.) 3. NVIDIA (2023), “Hopper Architecture Tuning Guide.” (SM Occupancy model.)

Methods

Name Description
solve Estimate achievable MFU and FLOPS from kernel IO-complexity and Roofline bounds.

solve

solvers.EfficiencyModel.solve(
    model,
    hardware,
    workload_type='ffn',
    use_flash_attention=False,
    precision='fp16',
    efficiency=0.5,
    seq_len=2048,
    batch_size=1,
)

Estimate achievable MFU and FLOPS from kernel IO-complexity and Roofline bounds.

Parameters

Name Type Description Default
model Workload Workload supplying hidden geometry or lowered graph work/bytes. required
hardware HardwareNode Target accelerator supplying precision peak FLOP/s and HBM bandwidth. required
workload_type str Dominant kernel family: 'attention', 'ffn', or 'conv'. 'ffn'
use_flash_attention bool Tile attention in SRAM so HBM traffic avoids O(S^2) score/softmax materialization (applies when workload_type == 'attention'). False
precision str Registered numerical format controlling element byte width and peak FLOP/s. 'fp16'
efficiency float Compute-pipe / SM occupancy ceiling eta_comp (clamped to [0, 1]). 0.5
seq_len int Positive sequence length S for attention and FFN kernel intensity. 2048
batch_size int Positive batch size B scaling token count or image batch reuse. 1

Returns

Name Type Description
EfficiencyResult Roofline-bounded MFU, achievable FLOP/s, peak FLOP/s, and an exact partition of unity mfu + occupancy_loss + memory_stall == 1.

Notes

Equation: with eta_comp = clamp(efficiency, 0, 1) and peak ridge point I_peak = F_peak / BW_HBM, mfu = min(eta_comp, I_kernel / I_peak), occupancy_loss = 1 - eta_comp, and memory_stall = eta_comp - mfu. Kernel arithmetic intensity I_kernel at byte width b is: unfused causal attention 2 * S^2 * d_h / ((4 * S * d_h + 4 * S^2) * b); FlashAttention 2 * S^2 * d_h / (4 * S * d_h * b) = S / (2 * b); two-projection H x 4H FFN over T = B * S tokens 16 * T * H^2 / ((8 * H^2 + 4 * T * H) * b); convolution/generic (B * F_sample) / (W + B * A_sample).

Assumptions: HBM bandwidth is evaluated at peak device rate; eta_comp caps compute throughput; missing Transformer geometry defaults to H = 4096 and d_h = 128 when evaluating attention or FFN kernels on non-Transformer workloads.

Excludes: SRAM tile-size capacity spills for huge head dimensions, kernel launch latency, and multi-device communication.

References

Williams, Waterman, and Patterson (2009), “Roofline: An Insightful Visual Performance Model for Multicore Architectures.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Dao et al. (2022), “FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness.” https://arxiv.org/abs/2205.14135 (bibliography key: dao2022).

Examples

>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import EfficiencyModel
>>> r = EfficiencyModel().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100)
>>> bool(0 <= r.mfu <= 1 and r.achievable_flops <= r.peak_flops)
True
Back to top