MIT Formalizes How Neural Networks Actually Move Data in Lean
MIT researchers propose the heterogeneous taped category, a category theoretic framework that models broadcasting, parameters, randomness and backprop tapes under one roof.
Takeaways
- MIT's Abbott and Zardini introduce the heterogeneous taped category for deep learning data flows.
- Framework captures broadcasting, parameter loading, backprop tapes, randomness as Markov processes, and LIFO reuse in UNets.
- Grab-drop expressions model save and retrieve, realized as hypergraphs with cuts and glue operations.
- Built from an I-family of SMCs and structure functors, allowing contravariant chains for reverse-mode gradients.
- Companion LeanNCD library formalizes the constructions in Lean 4 on Mathlib.
- Paper is 21 pages, 23 figures; no benchmarks, aimed at theoretical analysis and compiler-level reasoning.
Deep learning systems compose mathematical functions, yet their execution graphs also broadcast tensors, load parameters, preserve activations, sample random values, and route gradients backward. Vincent Abbott and Gioele Zardini of MIT propose an algebra that represents those data flows explicitly.
Their preprint, titled Grab, Drop, Glue: Formalizing Deep Learning’s Data Flows, introduces the heterogeneous taped category (HTC). The accompanying LeanNCD repository implements the definitions and proofs in Lean 4 on top of Mathlib, allowing the proof assistant to check each formal claim.
What f : X → Y leaves out
The function type f : X → Y records a domain and codomain while omitting several behaviors common in neural networks. Operations may broadcast across batch or spatial axes, read shared parameters, save activations for differentiation, use random state, or retrieve earlier values through skip connections and LIFO-style tapes.
PyTorch and JAX implement these behaviors through execution graphs, traces, transformations, and runtime bookkeeping. Those mechanisms calculate results and gradients, but their operational representations provide limited support for algebraic proofs about when two data-flow expressions describe the same computation.
Abbott and Zardini address that gap by making storage, retrieval, direction, and cross-chain transfer part of the mathematical object. The resulting notation can express forward computation, reverse differentiation, parameter flow, broadcasting, and stochastic behavior within one compositional framework.
Grab, drop, and glue
The construction begins with an indexed family of symmetric monoidal categories. A symmetric monoidal category supports sequential composition and a tensor product for placing computations side by side. HTC adds explicit data-transfer chains and the operations required to separate, reconnect, and rearrange them.
| Element | Role |
|---|---|
| Grab | Retrieves a value from a named node in a data-transfer chain. |
| Drop | Deposits a value at a named node for later use. |
| Cut | Isolates one chain and converts cross-chain transfers into matching boundary grabs or drops. |
| Glue | Reconnects cuts by renaming shared node identifiers so their boundaries align. |
| Transfer move | Rearranges expressions under equations that preserve the represented data flow. |
| HTC | Combines chains that may use different categories or run in different directions. |
Different chains can carry different kinds of state. One may contain deterministic activations, another random state, another parameters, and another gradients. Structure functors connect these categories, and contravariant functors allow a reverse-directed chain to accompany forward computation.
The cut-and-glue mechanism gives those chains a shared representation. Cuts expose the relevant boundaries; glue identifies matching nodes; transfer and congruence rules specify which rearrangements remain mathematically equivalent.
Inside LeanNCD
LeanNCD formalizes the paper’s categorical machinery, including grab-drop categories, heterogeneous taped categories, cuts, glue, transfer moves, congruence rules, optics, reverse derivatives, broadcasting, and sparse axes. Its API targets mathematical definitions and proofs, with no tensor runtime, training loop, benchmark suite, or replacement for an autograd engine.
| Repository area | Contents |
|---|---|
data_structure |
Axes, arrays, terms, sparse structures, and broadcasted categories. |
para |
Grab-drop constructions, heterogeneous multidirectional taped categories, cuts, glue, transfers, combs, optics, and backpropagation. |
Lean 4 checks that definitions are well typed and that theorem terms prove the stated propositions from the declared assumptions. This mechanization catches gaps such as missing cases or invalid rewrites. Empirical coverage of real model graphs, compiler integrations, and runtime behavior remains a separate engineering and research task.
Who could use it
The framework offers several potential uses for researchers working below the model-training API:
- Compiler and IR research: state graph rewrites algebraically and prove that they preserve the represented computation.
- Automatic differentiation: connect optics and reverse derivatives to explicit storage and retrieval paths.
- Architecture analysis: represent skip connections, reused activations, and reverse-flow dependencies in models such as U-Nets.
- Formal methods: extend the framework with additional data-flow patterns while retaining machine-checked definitions and proofs.
The paper’s evidence consists of formal definitions, worked diagrams, proofs, and the Lean library. It reports no accuracy results, runtime speedups, production-scale graph evaluations, or direct integration with PyTorch or JAX.
Broader adoption will depend on mappings from framework graphs into HTC expressions, manageable proof obligations for realistic networks, and evidence that the algebra scales to compiler-sized programs. The current contribution provides a mechanized language for specifying neural-network data flow and proving relationships between expressions that combine broadcasting, parameters, randomness, saved values, and reverse differentiation.