arXiv:2610.23328cs.LGOct 2026

Manuscript Offprint

arXiv:2610.23328

Peak-Memory Schedules You Can Trust: Exact Realization, Certified Optimality, and the Limits of Recomputation for Inference

Ivan Fomin, Ivan Koryabkin, Boris Sheludko

ABSTRACT

Real-time inference on small devices needs low activation memory without extra latency, which makes operator order the most valuable memory lever: it is free in time. We show that the usual way of deploying a better order, handing it back to the compiler and regenerating code, is unreliable. In PyTorch Inductor the regenerated program misses its predicted peak in 22 of 54 CPU configurations. It is worse than the stock program in 9 of them and in 19 of 50 on a GPU, and on the GPU it also changes numerical results. We instead profile the generated program, build an exact model of its memory behaviour from its own statements and their read/write effects, and permute those statements. We prove that this realizes the modeled peak whenever allocation does not depend on history. It does so to the byte, with bitwise-identical results, in every one of our CPU runs. On the GPU we characterize why the caching allocator breaks the condition. To know when to stop, we give forward and reverse “trap” lower bounds, each computable with O(n2)O(n^2) minimum cuts. They certify the found order optimal for 94% of held-out wrapper graphs and for all 16 microcontroller-class models we study, in under a second. The certificates show that most inference graphs are already scheduled optimally. Branching networks are the exception, where reordering is free and pays, e.g. 10.0% on DeepLabV3. In compiled training we save up to 7.6%. Beyond the certified optimum we study selective recomputation with per-operator caps. It is strongly NP-hard for every fixed cap even at treewidth two, it encodes knapsack exactly on series–parallel graphs, and it is solvable exactly on bounded treewidth. It is useless on public tiny models whose peak is a single layer, but on architectures that hold a cheap value for a late reuse it pays: on the public ReDimNet speaker networks, whose order is already optimal, it lowers the peak by 5.2–6.1% at under 0.4% extra MACs, with bitwise-identical outputs.

1 INTRODUCTION

A neural network that runs in real time on a phone, a hearing aid or a microcontroller has to fit its activations into a fixed, small memory budget, and it has to do so without slowing down. Most of the familiar levers for reducing activation memory trade it for time. Rematerialization recomputes values instead of storing them (Chen et al., 2016; Jain et al., 2020). Offloading moves them to slower memory. Patch-based execution recomputes overlapping receptive fields (Lin et al., 2021). For training these trades are usually acceptable, because a few percent of throughput buys a larger batch. For real-time inference they often are not: a keyword spotter or a streaming speech model has a hard deadline per frame. The interesting levers there are the ones that are free in time, such as the order in which operators run, and the recomputations that cost very little time but remove a large buffer.

Operator order is already exploited. PyTorch Inductor ships a peak-memory reordering pass that is enabled by default (Ansel et al., 2024). TensorFlow Lite Micro plans a static arena for the order it is given (David et al., 2021). A line of work schedules irregular graphs exactly or hierarchically (Ahn et al., 2020; Wang et al., 2022; Steiner et al., 2023; Jin et al., 2023). These systems share an implicit assumption: if a better order is found on the compiler's graph, the deployed program will be better by the predicted amount. They also leave a practical question unanswered, namely when to stop. A deployment engineer who has run a scheduler cannot tell whether the result is optimal or whether a better order exists that the heuristic missed.

This paper makes peak-memory scheduling trustworthy in both senses. We show that the assumption above is false in a mainstream compiler, give a realization method for which it is true by construction, and give certificates that settle the question of when to stop. We then ask what selective

1^{1}Yandex, Moscow, Russia. Correspondence to: Ivan Fomin ash-ivanfomin@yandex-team.ru, Ivan Koryabkin koryabkin@yandex-team.ru, Boris Sheludko bsheludko@yandex-team.ru.

Preprint.

recomputation can add once the order is exhausted. The answer is a mix of good and bad news that we think is useful to state precisely.

Regeneration is unreliable. The usual way to deploy a better order is to hand it back to the compiler and regenerate code. Code generation, however, runs after scheduling. It decides how kernels are grouped into calls, which dead buffers are reused in place, and when references are dropped, and a new order changes those decisions. Across 54 compiled CPU configurations of 16 architectures, the regenerated program misses its own predicted peak in 22 cases and is worse than the stock program in 9. On a GPU it is worse than stock in 19 of 50 configurations and, in addition, changes numerical results (Section 5.1).

Fixed-wrapper realization is exact. We instead take the generated program as it is, profile one execution, and build an exact model of its memory behaviour at the granularity of its statements. We then permute the program's own statements. Kernels, arguments and buffer reuse stay untouched; only the order and the placement of allocations and releases change. Under an explicit contract the realized peak equals the modeled peak (Theorem 1). On CPU this holds to the byte in all 78 training runs and all 22 inference runs, and outputs and gradients are bitwise identical to the stock program. On a GPU the CUDA caching allocator violates one condition of the contract, and we characterize exactly how (Section 5.6).

Certificates tell us when to stop. We give two lower bounds on the optimal peak, a forward and a reverse “trap” bound. Each is computable with O(n2)O(n^{2}) minimum cuts, and each dominates the classical event-cut bound. Together they prove the found order optimal for 115 of 122 held-out wrapper graphs, in well under a second, and for all 16 microcontroller-class models we study. This changes the practical conversation. For most inference graphs the certificate shows that the stock order is already optimal, so no scheduler can help. The exception is branching networks, where reordering is free and the saving can be large: 10.0% on DeepLabV3 inference.

The limits of recomputation. When the certified optimum is still above the budget, recomputation is the next lever, and for inference it is attractive only if it is selective, recomputing a few cheap values rather than whole subgraphs. We model this with per-operator recomputation caps kvk_{v}, as in Moccasin (Bartan et al., 2023), and prove three things.

• Peak feasibility is strongly NP-hard for every fixed uniform cap, already at treewidth two.

• Minimizing extra work under cap two is exactly a knapsack problem on series–parallel graphs.

• An exact algorithm exists on bounded treewidth, but with a necessary dependence on the numeric budget.

Empirically, recomputation at tensor granularity cannot help the public tiny models we study. In every one of them the peak is set by a single operator's inputs and output, a bound no schedule of whole tensors can beat (Section 5.2). Recomputation pays off where a large value is held across the network only for a late reuse and can be recreated cheaply from a small ancestor. The public ReDimNet speaker-embedding networks have exactly this structure. In all seven sizes their order is already optimal, yet recomputing the stem once lowers the peak by 5.2–6.1% at no more than 0.34% extra MACs (Section 5.3). For such values our model of caps and our certificates apply directly; for tiny models whose peak is a single layer, savings require splitting tensors, as patch-based inference does (Lin et al., 2021).

We do not propose a new search heuristic; the search in our pipeline is an existing exact capacity search. Our contributions are the realization method, the certificates, the measurements that show where scheduling can and cannot help, and the complexity results that delimit selective recomputation.

References (22)