Skip to content

Conversation

@mrlj-hash
Copy link

No description provided.

@kayween kayween self-assigned this Nov 13, 2025
@kayween kayween self-requested a review November 13, 2025 21:30
Copy link
Collaborator

@kayween kayween left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mrlj-hash, thank you for the PR! I left some comments. Can you also update the PR description to include a brief summary (e.g., what was the bug and how it's fixed).

actual_value = torch.tensor(3.0).view_as(kernel.alpha)
self.assertLess(torch.norm(kernel.alpha - actual_value), 1e-5)

def test_last_layer_alpha(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only verifies the kernel matrix can be computed, but it does not verify if the computation is correct. Can we improve the test case by checking the kernel matrix against the ground truth (like other test cases in this file)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do deterministic tests like other test cases in this file (i.e., no torch.randn)? Note that determinism is not guaranteed on different devices even with fixed random seeds by torch.manual_seed.

You could do something like

x1 = torch.arange(24).view(2, 2, 3, 2)
x2 = torch.arange(16).view(2, 2, 2, 2)

alpha = alpha.unsqueeze(-1)

# for loop above overruns by 1 in deep GPs due to additional sampling dimension
if len(alpha) > 1 and alpha.shape[0] != dist_mat.shape[0]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern with this if-statement is that it seems a bit ad hoc. This line checks if the first dimension is broadcastable, and does an unsqueeze if not.

If alpha.shape[0] is equal to dist_mat.shape[0] by accident, we might accidentally broadcast alpha and dist_mat in a wrong way and potentially compute the kernel matrix incorrectly, even in situations when an unsqueeze is indeed required.

mrlj-hash and others added 4 commits November 16, 2025 09:53
Implement manual conditional unsqueezing of alpha

Co-authored-by: Kaiwen Wu <[email protected]>
Need last_dim_is_batch parameter to do the conditional unsqueezing of alpha
@kayween
Copy link
Collaborator

kayween commented Nov 16, 2025

@mrlj-hash It's recommended to install a linter locally (e.g., flake8) or a pre-commit hook aid your development, see CONTRIBUTING.md. (That way those minor lint errors in the github workflow can be fixed more easily.)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Rational Quadratic Kernel with Deep GPs - crashes due to shape mismatch

3 participants