A free Colab machine found 21 broken roofline bounds in my profiler
neural-cost v0.20 checks its roofline lower bounds against real measurements on an Apple M3 and an NVIDIA Tesla T4. Here is what that check caught: wrong CPU peaks, timers that stopped early, double-counted profiler events, and benchmarks that compared different networks.
On this page
A roofline bound makes one promise: this network can’t run faster than this. That makes it the rare performance number you can prove wrong. If a measured run ever beats its own lower bound, either the hardware spec is wrong, the operation count is wrong, or the timer is.
neural-cost has shipped a validation harness since October that checks exactly that. Its October run on my Apple M3 passed, but for the wrong reason: CPU runs were being bounded by the GPU’s spec, which is far more forgiving. Bounded by the CPU’s own spec, seven of them beat their lower bound.
Then the check ran off a Mac for the first time, on GitHub’s Linux runners and on a free Google Colab VM with a Tesla T4 attached. The GPU was fine. On the VM’s Xeon CPU, PyTorch beat its lower bound on 21 of 23 workloads.
Both failures came out of a week of work: 23 pull requests since my last post, v0.12 to v0.20 on PyPI. Here’s what changed.
The CPU peak was 16 to 32 times too low
Off Apple Silicon, hardware detection assumed every core does 2 FP32 FLOPs per cycle, which is one scalar fused multiply-add. A modern x86 core with two vector units does 32 with AVX2, and 64 with AVX-512. So the “fastest possible” time was 16 to 32 times too slow, and ordinary runs beat it.
detect_hardware() now reads the SIMD flags (AVX-512, AVX2+FMA, AVX, SSE2, SVE,
NEON) and the CPU model name from /proc/cpuinfo, or from sysctl on Intel
Macs. That fixed most of the violations. The rest were memory-bound, and they
had two causes:
- The bandwidth probe was too slow. The NumPy STREAM triad allocated a 256 MB temporary on every pass and measured 4.7 GB/s on a machine where a plain copy reaches 11.6 GB/s. It now runs on every core, in cache-sized blocks, with no temporaries.
- Caches are real. A 134 MB MLP on a CPU with a 38 MB L3 keeps part of its weights cached between calls, so it beat even a correct DRAM bound. The bound now charges DRAM only for traffic beyond the largest cache.
JAX’s 8 of 13 violations had one more cause. On a CUDA host, the jax-cpu
backend was quietly running on the GPU: 1.1 TFLOP/s from a 2-vCPU machine. Each
JAX backend now commits its inputs to its own device.
After those fixes: 0 violations on PyTorch, JAX and TensorFlow CPU on the Colab VM, down from 21 of 23 for PyTorch and 8 of 13 for JAX.
The Apple side had the same disease in different places. The M3’s CPU peak
ignored the AMX matrix units that Accelerate uses: 0.69 TFLOP/s instead of
2.43. Its bandwidth came from a single-threaded triad, 41 GB/s instead of the
chip’s 100. Together they let CPU runs beat their bounds by up to 1.56×. And the GPU core count was being read from the CPU section of
system_profiler, which lists its own “Total Number of Cores” first. Every
Apple GPU was sized by its CPU. An M3’s 10-core GPU came out as 8-core with a
2.88 TFLOP/s peak instead of 3.6.
The timers had their own bugs
A correct bound means nothing if the measurement is wrong. So I also audited the timing in every adapter, and every adapter had something.
TensorFlow never waited for the GPU. The adapter synchronized with
tf.experimental.async_wait, which doesn’t exist in TensorFlow 2.21. The call
was a silent no-op, so eager GPU timings stopped the clock when the kernels were
queued, not when they finished. It now uses
tf.test.experimental.sync_devices.
PyTorch timed with the profiler attached. That added 15–22% to the median
on small models. Worse, device time summed inclusive times over every
profiler event, so aten::linear and its child aten::addmm both counted, and
CPU device time came out about twice the wall time. Samples are now timed in a
clean loop, and a separate profiled pass collects trace statistics using self
time.
Peak memory was fiction in two frameworks. PyTorch’s CPU peak summed every
allocation, reporting 2,000 MB for a function whose real peak is 100 MB. JAX’s
peak_bytes_in_use is a lifetime counter that can’t be reset, so it reported
whatever earlier work had left behind. JAX now falls back to XLA’s compiled
memory plan: arguments + outputs + temporaries − aliases.
Sync overhead swamped short kernels. On MPS, a 64-element add measured
290 µs per call with a device wait after each call, and 24 µs per call back to
back. neural-cost now measures that overhead directly and warns when it’s more
than 10% of the median. Pass --min-sample-ms to batch short calls into longer
samples.
Two smaller additions came out of the same audit. Every measurement reports its spread (interquartile range over median) and warns when it’s above 10%. And JAX and TensorFlow now report device busy time on GPUs and TPUs, read from the XSpace trace both profilers write, which only PyTorch had before.
Counting the right operations
Two FLOP-counting gaps would have hit anyone profiling a modern model:
- Causal attention was counted as dense. A causal mask hides half the score
matrix, and the counter charged for all of it. Worse, a KV-cache decode step,
one query against a 1,024-token cache, was counted as scoring one key. Attention
now takes
kv_len,causal,windowandq_offsetand counts only visible pairs. - Only 2-D convolutions existed. Audio, video, U-Net decoders and MobileNet-style models silently lost most of their compute. 1-D and 3-D, transposed, depthwise and separable convolutions are now modeled in all three frameworks.
The benchmarks weren’t comparing the same networks
This one stung. The benchmark suite builds each architecture once per framework, and when I lined up the FLOP counts, they didn’t match:
| Model | PyTorch | JAX | TensorFlow |
|---|---|---|---|
| FF DNN | 50.4 MFLOP | 50.4 MFLOP | 0.24 MFLOP |
| ConvNeXt | 8.9 GFLOP | 1.1 GFLOP | — |
| Transformer | 48.5 GFLOP | 8.1 GFLOP | 0.026 GFLOP |
JAX’s ConvNeXt had two stages with one block each. TensorFlow had its own micro-sized model set and no ConvNeXt at all. A cross-framework speed comparison on those models measures model size, not frameworks.
Every framework now builds from one shared config table, and the Keras and JAX models mirror PyTorch layer for layer. A test holds FLOPs within 5% and parameters within 3% across all three. In practice their FLOP counts agree within 0.5% at standard scale. JAX’s run slightly high because it counts LayerNorm and GELU as separate primitives.
Benchmarks you can rerun for free
Finding all of this needed hardware I don’t own, so the suite now runs on
hardware nobody has to own. benchmarks/cloud_gpu_benchmark.ipynb runs the
validation and GPU sweeps on a free Colab or Kaggle GPU at any commit, and
packages the results.
Getting that notebook to work was its own small saga. Colab preinstalls one JAX CUDA plugin, so installing a second one stopped JAX from starting. And NVIDIA’s CUPTI allows only one profiler subscriber per process, so after PyTorch’s profiler ran, JAX and TensorFlow got no device time at all. The notebook now runs one framework per process and appends the results.
Every result file is also stamped with the neural-cost version, git commit, dirty flag, framework versions and device, and the report prints that on its first line. After every release, a CI workflow reruns the CPU validation on a GitHub-hosted Linux runner and fails if any measurement beats its bound. It’s the same check that failed on 12 measurements while the x86 peak was still wrong.
The T4 numbers, where the calibrated column is a leave-one-out fit predicting each workload’s runtime from all the others:
| Backend | Bound violations | Calibrated error (LOO MAPE) |
|---|---|---|
| PyTorch CUDA | 0 | 33.5% |
| JAX GPU | 0 | 10.4% |
| TensorFlow GPU | 0 | 12.7% |
| PyTorch CPU | 0 | 34.4% |
| JAX CPU | 0 | 71.3% |
On the M3, the five backends ran 95 workloads with 0 violations. JAX jit on the M3’s CPU has a mean error of 5.2%. The M3 tables are in the project docs, which now have their own site, and the T4 report is in the repo.
What’s still open
The cross-framework results in the repo’s M3 reports are still invalid. The JAX and TensorFlow records predate the shared model configs, and I haven’t rerun them because that machine has been busy. The repo flags them. The full T4 GPU sweep is also missing, because Colab kept answering “Service Unavailable” when I asked for a T4. And JAX on the Colab VM’s CPU, at 71% error, is the backend the calibrated model understands least.
Like the last round, this work started with real hardware disagreeing with the tool. The free T4 is what made it possible: it took a check that had always passed on my laptop and gave it a machine to fail on.
pip install -U neural-cost
If you profile models on NVIDIA hardware, I’d especially like to hear where the bound breaks for you.