Skip to content

Use kernel.diag instead of materializing K(X, X) for the diagonal#49

Closed
bwengals wants to merge 1 commit into
mainfrom
fix/greedy-variance-diag
Closed

Use kernel.diag instead of materializing K(X, X) for the diagonal#49
bwengals wants to merge 1 commit into
mainfrom
fix/greedy-variance-diag

Conversation

@bwengals

@bwengals bwengals commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes #46.

greedy_variance_init (inducing.py:602) and _compute_kernel_health (inducing.py:296) both compiled pt.diag(kernel(X_sym)), which materializes the full K(X, X) gram (K separate N x N grams for a K-factor ProductKernel) only to slice out its diagonal. Peak memory was O(K*N^2) instead of O(N).

Both now call the existing O(N) kernel.diag(X_sym). The issue reported line 602; line 296 had the identical pattern and is fixed in the same change.

Verified the compiled diagonal graph for a 3-factor product kernel drops from 5 materialized 2D nodes to 0, and the 66 inducing/kernel-health tests pass.


📚 Documentation preview 📚: https://ptgp--49.org.readthedocs.build/en/49/

greedy_variance_init and _compute_kernel_health compiled
pt.diag(kernel(X_sym)), building the full N x N gram (K separate grams
for a K-factor ProductKernel) only to slice out the diagonal. Peak
memory was O(K*N^2) instead of O(N). Call the existing O(N)
kernel.diag(X_sym) instead.

Closes #46
@bwengals

Copy link
Copy Markdown
Collaborator Author

Closing as a duplicate of #47, which makes the identical fix at both call sites and adds a regression test. #47 supersedes this.

@bwengals bwengals closed this Jul 19, 2026
@bwengals
bwengals deleted the fix/greedy-variance-diag branch July 19, 2026 01:08
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.

greedy_variance_init builds full N×N gram(s) just to take the kernel diagonal

1 participant