Tensorunfolded

unfold.py
1def unfold(T: nuke.Tensor) -> nuke.Tensor:
2    """Values are fixed; structure is a choice.
3       m ≤ Φ ≤ c·m   — unfolding moves the store to Φ = m.
4       m: number of draws · Φ: fetch count · c: word capacity"""

Neural Unfolded Kernel Engine

NukeTorch is a Tensor Engine. Its kernels and framework are built from our own mathematical formulation.

Unfolding lays out the tensor’s values to match how processors read them.UnfoldFold

Unfolding

A tensor’s values are fixed. How they are stored and read is a choice. Unfolding is changing that choice.

Memory is one line. Several values share one machine word, and a kernel takes a handful of values at a time. If its handful is spread over many words, it fetches many words to use a few values. If a word holds c values and the kernel makes m draws, the words it must fetch, Φ, obey:

m ≤ Φ ≤ c·m

Unfolding moves the store to the low end, Φ = m. A real case: a public four-bit model packs eight neighbouring codes into each 32-bit word, but each lane of our decode kernel takes every 32nd code. Unfolded, the eight codes a lane needs share one word, and word fetches fall from 256 to 32 per block.

One block of 256 four-bit codes, in the file's order and unfolded

On one matrix, a test kernel that reads the file as it is ran 4.9× faster than our engine’s loop: 516 GB per second, 94% of the 546 GB per second that Apple states for the chip.

The detail is in our paper, Unfolding Tensors: Storage Order and Fetch Cost of Four-Bit Weights.

Shaping cuts each computation into the shape the processor runs fastest.UnfoldFold

Shaping neural simulation

A matrix product in it has three axes: rows M, output width N, and reduction length K, the number of products summed into each output value.

We expected the size of a program to set its speed. It did not. The rate was set by one axis, the length of the sum K. Past a knee, doubling K halves the rate. So we cut one long sum into P shorter ones and add the partial sums.

Rate of one layer pair cut into P pieces, by input channels and by output channels, on M4 Max and M5 Max

On that layer pair, shaping raised the rate 3.12 to 3.46×, while cutting by output channels left it at 0.99 to 1.00×. With the same change, Whisper large-v3-turbo transcription took 21.5% and 21.9% less time on an M4 Max and an M5 Max.

The full detail is in Input-Dimension Shaping for Matrix Products on Apple Silicon.

Pipeline splits one model across machines and keeps each machine computing.UnfoldFold

Pipeline parallelism

We named ours the Choo-Choo Relay Train. Like a train, it connects machines in a line, with a single Thunderbolt cable between them. You can see our setup in the video on our X.

The usual way to use four machines is data parallel: every machine holds the whole model. Apple’s WWDC26 run was data parallel. In a pipeline, each machine holds only its assigned layers, and together they work as one distributed machine.

  • It keeps the speed. Four Macs ran at 93% of four single Macs.
  • It uses a fraction of the memory. Spread a model over N machines, and each needs 1/N of the RAM for the weights that data parallelism needs.
  • It does not require an optical interconnect. Each Mac connects to the next with a single Thunderbolt cable.
Mac 1
its own layers
→
Mac 2
its own layers
→
Mac 3
its own layers
→
Mac 4
its own layers and the loss
One model across four Macs, one Thunderbolt cable between neighbours. Activations go forward; gradients come back.

Performance

ModelResult on MacBook Pro M5 Max
Nubotics 1.7B18.81 ms per decision (1 Mac)Report
GR00T N1.744.34 ms per decision (1 Mac)Report
Qwen3.5 9B LoRA fine-tuning5,358.5 tok/s (4 Macs)Report
Qwen3.8 125B Flash Next 4-bit177.7 tok/s @ 1 user (4 Macs) · 859.0 tok/s @ 32 users (4 Macs)Report
Qwen3.6 35B-A3B 4-bit517.5 tok/s @ 1 user (1 Mac) · 3,799.6 tok/s @ 32 users (4 Macs)Report
Qwen3.8 27B 4-bit200.3 tok/s @ 1 user (1 Mac) · 1,906.2 tok/s @ 32 users (4 Macs)Report
Whisper large-v3-turbo89.2× real time · 2.97% word error rate (1 Mac)Report

Who it’s for

AI service providers and start-upsServe more users on each machine, with less processing and energy.
AI model makersMake your models run faster.
AI data centersLess RAM and electricity on each machine, and no special interconnect.

Interested in trying your model or AI service on NukeTorch? Contact us.