Skip to content

Implement dual ridge regression for memory optimization - #2364

Closed
KartikP wants to merge 5 commits into
masterfrom
kp/dual-ridge
Closed

KartikP wants to merge 5 commits into
masterfrom
kp/dual-ridge

Conversation

@KartikP

@KartikP KartikP commented Apr 10, 2026 •

Copy link
Copy Markdown
Collaborator

Ridge and RidgeCV regression now use the dual kernel form when n_samples < n_features. This is common in Brain-Score which there are only hundreds of stimuli but thousands to hundreds of thousands of model features. This avoids materializing the coefficient matrix (n_features, n_targets) which can produce OOM for large models on fMRI benchmarks.

This PR adds DualRidgeRegression and DualRidgeCVRegression in the metrics/regression_correlation/metric.py.

Instead of solving for the full weight matrix, we precompute a small project matrix and apply it to the neural target in chunks.

This PR effectively reduces a coefficient matrix for ViT-L at 148k features on Allen2022 at 52k neuroids stored at 8 bytes from 62GB down to ~1MB.

Validation

  • All 4 Allen2022 surface ridge benchmarks produce identical raw scores
  • Identical predictions across alpha values
  • RidgeCV selects the sample alpha as sklearn

@KartikP
KartikP requested a review from KogniJannis April 15, 2026 16:01
@KartikP

KartikP commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #2383, which landed the minimal version of this work on 2026-05-26 — master now has DualRidgeRegression, DualRidgeCVRegression and the dual_ridge_split / dual_ridgecv_split metrics. That is why this branch shows a conflict: it is stale against its own merged descendant.

The remaining work is not reviving this PR but applying the switch to the benchmarks #2383 did not cover. Evidence that it matters, from brainscore_resource_usage:

benchmark OOM rate path
Papale2025.V1-ridgecv 68% primal
Papale2025.IT-ridgecv 64% primal
Papale2025.V4-ridgecv 62% primal
Gifford2022.IT-ridgecv 60% primal
Hebart2023_fmri.*-ridgecv 32–43% primal
Zerbe2026_fmri.*-ridgecv 23–48% primal
Li2026.V1-ridgecv 7% dual

Every primal benchmark OOMs at 23–68%; the one dual benchmark sits at 7% despite a 121.9 GB peak. Follow-up PR switching the remainder is in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant