In modern deep learning, we often encounter "the memory wall." This happens when a single training example is not a single image, but a massive collection of data that must be processed together to produce a single prediction. Whether it is a "bag" of hundreds of high-resolution CT slices in medical imaging, a large "support set" in meta-learning, or thousands of Monte Carlo samples in diffusion models, the problem is the same: the GPU memory required to store the computational graph for backpropagation scales linearly with the number of instances.
When the input size exceeds hardware limits, researchers typically resort to biased approximations, such as training on small random subsets or using aggressive downsampling. However, a growing body of research—spanning set encoding, multi-instance learning (MIL), and reinforcement learning—has converged on a more elegant solution. By using a combination of chunked forward passes and stochastic backpropagation, it is possible to compute gradients that are mathematically unbiased while maintaining a constant memory footprint, regardless of the input size.
The Forward-Backward Asymmetry
The core intuition behind these methods is that the memory requirements for the forward pass and the backward pass are fundamentally different.
In a forward pass, we can often process data in chunks. For a set-based model that aggregates instances (e.g., via a mean or a sum), we can compute the aggregate representation by streaming the data through the GPU, keeping only the running sum in memory. However, standard backpropagation requires storing the intermediate activations for every instance to compute the chain-rule derivatives. This is what causes the memory to explode.
To break this link, Jeffrey Willette, Juho Lee, and their colleagues introduced Universal Mini-Batch Consistency (UMBC) in their 2023 paper. Their framework allows models like Set Transformers to process massive sets in small chunks while guaranteeing the exact same output as a full-set forward pass. The "trick" to training these models lies in how they handle the gradient.
The Stop-Gradient Trick
The mechanism for achieving constant-memory training relies on a clever application of the "stop-gradient" operator. The process works as follows:
- Full Forward Pass: You process the entire set (or bag) in chunks to compute the global aggregate (e.g., the mean embedding of all instances). During this phase, you do not store the computational graph for most instances.
- Stochastic Sampling: You select a small, random subset of the instances to be the "active" members for this step.
- Gradient Estimation: You construct a gradient estimator where the "active" instances are allowed to pass gradients, while the rest of the set is treated as a constant (using a stop-gradient operator).
As John Bronskill and Katja Hofmann demonstrate with their LITE (Large Image and Task Episodic training) scheme in 2021, if you scale the gradients of the sampled subset correctly, the result is an unbiased estimator of the full-set gradient. In other words, while the gradient for a single step might be noisy, its expected value is identical to the gradient you would have calculated if you had enough memory to process the entire set at once.
Scaling to Medical Imaging and Reinforcement Learning
This pattern of decoupling memory from input size appears across several distinct domains:
- Multi-Instance Learning (MIL): In medical diagnosis, a single label is often assigned to a "bag" of many high-resolution images. Dixian Zhu and Milan Sonka developed a provable MIL framework that uses stochastic pooling. By combining partial instance sampling with stored bag states, they achieve convergence on high-resolution data that would otherwise trigger "Out of Memory" errors.
- Diffusion LLMs: Training Diffusion Large Language Models (dLLMs) via Reinforcement Learning requires many Monte Carlo samples to get accurate policy updates. Nianyi Lin and Lei Hou proposed Boundary-Guided Policy Optimization (BGPO) in 2025. They use a linear surrogate objective that allows gradients to be accumulated across samples sequentially. This enables the use of massive sample batches with constant memory usage.
- Large-Scale MDPs: Even in theoretical reinforcement learning, Alan Malek and Peter Bartlett showed that stochastic subgradient descent combined with importance sampling can generate unbiased updates for massive state spaces, making computational complexity independent of the total state space size.
Why It Works: The Power of Linearity
The reason these methods work is that the gradient of a sum is the sum of the gradients. If our model's objective function involves an aggregation (like the mean of instances in a bag or the expectation over Monte Carlo samples), the total gradient is just an average of individual contributions.
By calculating the "global context" in a memory-efficient forward pass and then backpropagating through only a few "representative" instances, we are essentially performing a form of internal mini-batching within a single training example. This allows us to trade off computation time (more iterations to handle the noise of the estimator) for memory capacity, enabling the training of high-capacity models on datasets—like whole-slide medical images or massive sets—that were previously considered unreachable.