How Tensor Bytes Move
Data flowWhere tensor bytes enter and leave Lucid — the bridges, the three Storage variants, and which moves copy.
12 nodes · 3 guided chapters
Key facts
Copying is the default
- tensor, from_numpy and as_tensor all copy, despite from_numpy's 'shares memory' docstring
- Eager reshape, permute and slice allocate a new buffer on CPU
Where zero-copy happens
- A kDLMetal DLPack capsule is adopted as an MLX array
- CPU numpy(), SharedStorage cpu_view, compile feeds and Core ML inputs
GPU is lazy
- GpuStorage stays an MLX graph until evaluated
- item, numpy, repr and save force eval plus a CPU download
Guided chapters
- 01
Ways in
Outside values pass one of three bridges and are almost always copied into CpuStorage.
- 02
Two devices
to('metal') is an upload copy; SharedStorage is read on CPU through cpu_view without a copy.
- 03
Ways out
Three exits: numpy views, checkpoints, and compile or Core ML.