I

I built a 2nd-order PyTorch optimizer for LLMs that runs on 16GB GPUs

Hacker News

I built a 2nd-order PyTorch optimizer for LLMs that runs on 16GB GPUs

Hi HN, I'm Danilo. I've been struggling with the limitations of AdamW when fine-tuning LLMs locally. Second-order optimizers (like Shampoo or SOAP) offer significantly better step-convergence by exploiting Kronecker-factored curvature. The problem? They require O(d^2) memory and O(d^3) compute per layer, which immediately OOMs consumer hardware like a 16GB T4 or RTX 3090. I wanted Shampoo-quality preconditioning on my home setup, so I built SCAO (Sparse Curvature-Aware Optimizer). It's a PyTorch optimizer that acts as a drop-in replacement for AdamW, but it implements a few strict architectural changes to survive on consumer cards: 1. Adaptive Rank Selection: Instead of full-rank Kronecker factors, it truncates the eigenspace to retain >=95% of spectral mass. 2. Int8 EMA Quantization: The curvature accumulators are stored in symmetric int8, which yields a 4x memory reduction with zero degradation in perplexity. 3. Quantization Stability: Standard Shampoo usually crashes at step 1 during 4-bit QLoRA fine-tuning due to SVD ill-conditioning in quantized spaces. SCAO exploits sparse approximations to bypass this. 4. Fused CUDA kernels: I wrote custom kernels to fix an O(k * m^2 * n) complexity bottleneck in the naive projection implementation. The Benchmark: I recently ran a head-to-head benchmark on a single T4 (16GB VRAM) fine-tuning Qwen2.5-3B (4-bit QLoRA, rank 16): - Shampoo: Failed at Step 1 (SVD mathematical collapse). - SCAO: 100% stability, peaked at exactly 7.14 GB VRAM, with a smooth loss descent. It is pip-installable (pip install scao). I've written a technical report detailing the regret bounds, ablation studies, and scaling laws (published on Zenodo), but I really wanted to get this community's eyes on the CUDA kernels and the PyTorch implementation. GitHub: https://github.com/whispering3/scao Technical Report (DOI): https://doi.org/10.5281/zenodo.19870556 I'd love any feedback, code roasts, or questions about the math behind it!

Share card

Actual performance

2points
4comments
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: perplexity, single, code · Missing: mac, agents, macos
85%85% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
80%80% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
43%43% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: io · Missing: https docs, excited, just released
37%37% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
TrustMRRLess likely to generate early MRR · Missing: mobile apps, ios, personal
32%32% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
22%22% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

NL
NLP PyTorch Tutorial (fire up the GPUs)47%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

NLP PyTorch Tutorial (fire up the GPUs)

Hacker News1
He
Heroku for GPUs39%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Heroku for GPUs

Hacker News2
Fr
Fractional GPUs for AI32%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Fractional GPUs for AI

Hacker News8
Sy
Systema Robotica, a treatise on the order and evolution of robotkind56%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Systema Robotica, a treatise on the order and evolution of robotkind

Hacker News3
DK Optimizer
DK Optimizer17%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Draftking Predictor and Optimizer

Indie Hackerscommitment-side-project
Au
Automatic prompt optimizer for LLMs43%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Automatic prompt optimizer for LLMs

Hacker News126
Oc
Oceananigans.jl: A fast ocean model in Julia that runs on CPUs and GPUs51%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Oceananigans.jl: A fast ocean model in Julia that runs on CPUs and GPUs

Hacker News16
Ho
How to find the best GPUs for you59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

How to find the best GPUs for you

Hacker News3
Fr
Freeing GPUs stuck by runaway jobs44%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Freeing GPUs stuck by runaway jobs

Hacker News37
Order Tramadol Online
Order Tramadol Online25%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Order Tramadol Online

Indie Hackers