Skip to content
Writing

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
  1. The CPU peak was 16 to 32 times too low
  2. The timers had their own bugs
  3. Counting the right operations
  4. The benchmarks weren’t comparing the same networks
  5. Benchmarks you can rerun for free
  6. What’s still open

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, window and q_offset and 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:

ModelPyTorchJAXTensorFlow
FF DNN50.4 MFLOP50.4 MFLOP0.24 MFLOP
ConvNeXt8.9 GFLOP1.1 GFLOP—
Transformer48.5 GFLOP8.1 GFLOP0.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:

BackendBound violationsCalibrated error (LOO MAPE)
PyTorch CUDA033.5%
JAX GPU010.4%
TensorFlow GPU012.7%
PyTorch CPU034.4%
JAX CPU071.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.

Let's connect

Spot something I got wrong?

Corrections, follow-up questions, or a war story of your own. I read every message and reply to the ones that aren't a template.

Email me

Usually replies within a day or two · St. Louis, Missouri

esc

Home

Main landing page & highlights

Page

Work

All engineering projects & case studies

Page

Writing

Technical notes & engineering articles

Page

Games

Browser games, several against real models

Page

About

Background, career timeline & skills

Page

Contact

Email, inquiries & consultation

Page

Copy Email Address

davidgraymi@gmail.com

Action

Toggle Light / Dark Theme

Switch color theme

Action

Resume

Web page, with a PDF download

Read

Visit GitHub

github.com/davidgraymi

External

Visit LinkedIn

linkedin.com/in/david-gray-mi

External

Four in a row

Connect Four against my recursive thinking model. It decides how long to think, and you watch its pick change at every step.

Game

Beat the bot

Tetris against the value network from my reinforcement-learning project. Same pieces, two minutes, most lines wins.

Game

Draw a digit

Draw 0–9 and watch a weighted KNN classifier find its nearest MNIST neighbours as you go.

Game

Is it poisonous?

A real mushroom from the UCI dataset. Make your call, then watch an ID3 decision tree make its own.

Game

Route the robots

Draw a warehouse, place robots and goals, and race a LaCAM multi-agent path-finding solver to the shortest plan.

Game

Daily Wordlet

One five-letter word a day, the same for everyone. Six guesses.

Game

Bot or human?

14 rounds. One line from a public-domain classic, one written by a language model. Spot the bot.

Game

Reaction test

Wait for the panel to light up amber, then hit it as fast as you can.

Game

Lost signal

The 404 page's dodge game. Packets rain down; steer the receiver out of the way.

Game

neural-cost

A framework-neutral Python library that tells you how fast a neural network should run, not just how fast it does — FLOPs, tensor traffic and a roofline model across PyTorch, JAX and TensorFlow.

Personal

Sign Language Interpretation System

Control any smart device with American Sign Language — hand tracking, a gesture classifier and grammar correction, wired together over a client-server link.

Capstone

Bindersnap

Production policy and procedure management software for small healthcare providers. Every approved version carries a permanent, exportable record of who reviewed and signed off on it.

Product

Patient Care Portal Triage

An NLP pipeline that routes patient portal messages to the right team and surfaces relevant evidence-based research while they wait for a human.

Research

Threat modeling a zero-trust deployment pipeline

A continuous deployment pipeline for configuration-as-code and infrastructure-as-code into Kubernetes, designed from its threat model outward so the release process does the security review.

Professional

Moving three toolchain apps to Kubernetes on Azure

Three toolchain applications moved to Kubernetes on Azure, deployed one way with Helm and infrastructure-as-code, and secured with an Istio service mesh.

Professional

A processor built from the ground up

Kernel, task scheduler and communication protocol written from nothing, in C and Ada, now in production and distributed globally.

Professional

A system library that runs anywhere

One portable C++ library targeting any RTOS or bare-metal system, packaged with Docker, Bazel and GitLab CI — cutting porting work by 4×.

Professional

LaCam for Multi-Agent Path Finding

A from-scratch LaCam solver for CS440 — agents searching a space of joint configurations, each expanded by a constraint tree that rules out collisions and swaps.

School

Wordlet

A word guessing game built in Flutter and compiled to the web — playable right here, no install, no account.

Personal

Reinforcement Learning applied to Tetris

An agent that learns to play Tetris — a genuinely fun excuse to get hands-on with reward shaping.

School

Handwritten digit recognition with weighted KNN

A KNN classifier for handwritten digits, plus a k-value optimizer that collapses repeated distance calculations into a single pass.

School

ID3 mushroom classification

A from-scratch ID3 decision tree that predicts whether a mushroom is edible or poisonous from its attributes.

School

Healthcare length-of-stay estimator

A data mining project predicting how long a patient will stay, from admission-time features.

School

This website

A static site built with Astro, hosted free on GitHub Pages, designed so writing a post costs one markdown file and nothing else.

Personal

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.

Post

Teaching a network to think longer

My CS440 project asked whether a recursive network can stand in for search. It learned to think in steps. It did not learn when to stop. You can play it below.

Post

A roofline number should say what it doesn't know

I pointed neural-cost at my own AlphaZero chess net and got a confident 69% efficiency that was wrong three ways. Here is what it now reports instead, and the four bugs that only showed up on a real Apple GPU.

Post

Bindersnap's new look, and why most of it isn't color

Bindersnap now has a warm redesign, its own home at bindersnap.com, the app at app.bindersnap.com, and a landing page that paints in 2.4 s on a phone.

Post

An Unexpected Email, REPRO-SIGN, and 11 Citations on Google Scholar

Years after our college capstone, an out-of-the-blue email from European AI researchers wanting to reproduce our sign language paper sent me to Google Scholar, where we've been cited 11 times.

Post

Connecting the Dots: How a Sign Language Capstone Got Me Hooked on AI

Looking back at my senior capstone project at Missouri State — building a real-time American Sign Language smart home controller with MediaPipe, custom CNNs, and networking — and how it sparked my path in machine learning.

Post

GPU vs. CPU: Roofline Benchmarks on Apple Silicon MPS with neural-cost v0.2.0

The neural-cost v0.2.0 GPU benchmark moves from CPU roofline analysis to Apple Silicon's MPS GPU backend — measuring PyTorch and JAX across five architectures, four batch sizes, and both eager and compiled execution modes.

Post

PyTorch vs. JAX vs. TensorFlow: A Roofline Benchmark Across 5 Architectures

An empirical investigation comparing PyTorch 2.14, JAX 0.11, and TensorFlow across five model architectures and four batch sizes, measuring compiler speedups, kernel overheads, and hardware limits on Apple Silicon.

Post

neural-cost: Roofline Analysis Across PyTorch, JAX, and TensorFlow

A framework-neutral Python library that estimates a neural network's FLOPs and tensor traffic, measures its runtime, and uses a roofline model to tell you exactly where performance is being left on the table.

Post

I rebuilt this site so that publishing costs one file

The old site was a single 41,000-character index.html. Every change was archaeology. Here is what I replaced it with and why the constraint was maintenance, not design.

Post
↑ ↓ to move↵ to openesc to close

Terminal