profile_mlp.py
from neural_cost import analyze_gap, detect_hardware, estimate_operations
from neural_cost.adapters import TorchAdapter
adapter = TorchAdapter(use_profiler=False)
ops = adapter.operations(model, (x,))
measurement = adapter.benchmark(model, x, repeats=20)
hardware, _ = detect_hardware(device="cpu")
print(analyze_gap(estimate_operations(ops), measurement, hardware).render())
Neural cost gap analysis
bound: 0.680 ms (compute 0.435 ms, memory 0.680 ms)
observed: 1.270 ms
roofline efficiency: 53.5% (memory-bound)
achieved: 237.834 GFLOP/s, 15.651 GB/s
next: Memory-bound: consider fusion, reduced precision,
or fewer materialized tensors.