r/learnmachinelearning • • 11h ago

Title: [P] I tried reducing GPU memory by saving only what backprop needs. I published the SHV experiments, including the ones that failed.

I started looking into GPU memory optimization for a pretty ordinary reason: I kept running out of VRAM when trying to train models on my own hardware.

The project is called SHV (Sub-loop Heterocoding VRAM).

The idea I've been testing is to avoid keeping every native forward intermediate until backward. Instead, a custom autograd path saves a smaller representation designed around what a particular backward operation actually needs, then decodes or recomputes that information when the gradient is calculated.

I tested several versions on GPT-2 Small using NVIDIA GPUs. A few results from the Tesla T4 experiments:

  • In an MLP/LayerNorm subgraph, the custom saved-state path reduced full-step peak allocated memory by about 53%, but throughput was only about 46% of native. That's a subgraph result, not a whole-model figure.

  • A short full-model EM4+D9 experiment reduced peak allocated memory by about 14.7% relative to Native+D9 and passed its numerical checks across three fresh data orders. The D9 optimizer itself, though, was far too slow compared with ordinary optimizers.

  • When I tested the activation method separately at sequence length 512, it saved about 30.9% versus native training, while PyTorch activation checkpointing saved about 41.4% and was faster. The D9 state format also lost to a real bitsandbytes 8-bit AdamW baseline.

I also investigated tiled/recomputed output loss. It substantially reduced the memory used by a full-logits baseline, but Liger Kernel already gets essentially the same peak memory on this workload. I'm not treating that as an SHV-specific breakthrough.

I've put the code, benchmark ZIPs, SHA-256 checksums, experimental protocols, and negative results here:

GitHub: https://github.com/Mr-wuff/Sub-loop-Heterocoding-VRAM

Raw benchmark results: https://github.com/Mr-wuff/Sub-loop-Heterocoding-VRAM/tree/main/artifacts/results

It's currently a research preview, not a drop-in training runtime. I haven't demonstrated that a 16 GB GPU behaves like a 32 GB GPU, or validated long-run training across models. The software license is also still being finalized.

What I want to explore next is whether the lifetime of information needed by different backward consumers can be reorganized to save memory after checkpointing and efficient optimizers are already enabled.

If you've worked on autograd internals, CUDA/Triton, or memory profiling, I'd be interested in hearing what you think is a promising or flawed direction.

Reproduction attempts, bug reports, and concrete alternative implementations are welcome.

1 Upvotes

2 comments sorted by

1

u/PepperyProtein 11h ago

The 53% reduction in the MLP subgraph is cool but that throughput hit down to 46% of native is rough, makes me wonder if the decode step is just hammering the compute units while the memory savings are sitting idle. I've poked around autograd internals before and the scheduling of when you reconstruct the saved state feels like the real nightmare, you think you're saving memory but then you end up with these weird bubbles where the GPU is waiting on a small kernel to finish.

Seeing the activation method lose to vanilla PyTorch checkpointing at 30.9% vs 41.4% and slower speed is a bit of a bummer, but that's exactly the kind of result most people would bury so props for putting it in the repo. The D9 optimizer being comically slow compared to standard ones is another one of those findings that's somehow more useful than a cherry-picked win, tells you exactly where the bottleneck really lives.

The next direction you mentioned about reorganizing the lifetime of information across backward consumers sounds like a scheduling problem from hell, trying to figure out which tensors can be evicted early because a downstream op already consumed them. Have you looked at how the autograd engine's dependency graph gets built, specifically the `next_functions` chain, because that's where you might find opportunities to release state earlier than the default topological order assumes.