Why it matters on small hardware: 21× the tokens costs 201× the time in one layer, and detection and segmentation
inputs can easily be 1024 px or more.
Next, #2: VMamba’s four-direction scan, using its own code.
Efficient Vision #1: Attention’s quadratic tax
A 224 px image is 196 tokens for a ViT. A 1024 px image is 4,096.
One PyTorch attention layer on my notebook
GPU: 0.351 ms → 70.5 ms (201×).
A linear layer: 0.054 ms → 0.515 ms (10×).
Slope 1.9 vs 0.8.
Attention that returns its weights builds an N × N table: 1,536 MiB at 4,096 tokens (batch 8, 3 heads), 3,144 MiB peak.
The fused path needs 144 MiB.
But its time is still quadratic: 41.9 ms, slope 1.8.
Memory is fixable. Compute isn’t.
DLU #1: Big-O isn’t wall time
Multiplying 16 numbers on my GPU: 5.2 µs.
Multiplying 65,536 numbers: 5.5 µs.
4,096× more work, same time.
Big-O tells you how cost grows. It doesn’t tell you what you pay. Small ops are pure overhead.
Attention vs a selective scan (Mamba’s core op), same CPU, plain PyTorch:
• attention: slope 2.02, O(N²)
• scan: slope 1.00, O(N)
• 16,384 tokens: 855 ms vs 472 ms
But up to ~10,000 tokens attention is still faster. Linear isn’t automatically fast.
Code ↓
Building my 𝕏 profile from scratch.
Sharing my journey across AI, Machine Learning, Deep Learning, Computer Vision, and ML Systems : ideas, experiments, practical insights, challenges, and lessons learned along the way.
Learning, building, and sharing in public.
If you're exploring similar areas or building something interesting, let's connect.
The Five Differential Operators of Physics
Five operators built from one symbol, nabla, all moving at once.
Divergence: div F = dFx/dx + dFy/dy + dFz/dz, the net flux out of a tiny closed surface (source or sink strength).
Gradient: grad phi = (dphi/dx, dphi/dy, dphi/dz) points to the steepest increase of phi, always at a right angle to the contour lines, and is longest where they are tightest.
Curl: curl F measures the spin of the field around a point. The vector stands on the axis of the whirl, and flips when the whirl reverses.
Laplacian: the sum of the second derivatives. On the bowl z = x^2 + y^2 the Laplacian is 4, so the average around any circle of radius r sits exactly r^2 above its centre.
D'Alembertian: box F = (1/c^2) d^2F/dt^2 - Laplacian F. A wave running at speed c makes it zero, which is why it appears in the wave equation and in relativity.