Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make matrix.py capable handling weight-sharing dim #253

Open
wiseodd opened this issue Nov 21, 2024 · 0 comments
Open

Make matrix.py capable handling weight-sharing dim #253

wiseodd opened this issue Nov 21, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@wiseodd
Copy link
Collaborator

wiseodd commented Nov 21, 2024

Currently KronLaplace doesn't work with arbitrary batch shape since matrix.py checks for at most 3-dim tensor. This is problematic when multiplying with Jacobians of shape (..., n_classes, n_params).

See https://github.com/aleximmer/Laplace/blob/glm-multidim/examples/lm_example.py for use case.

@runame, @aleximmer, any pointer on what to do? Is the fix simply to reshape into (-1, n_classes, n_params)?

if W.ndim == 1:
return self._bmm(W.unsqueeze(0).unsqueeze(0)).squeeze()
elif W.ndim == 2:
return self._bmm(W.unsqueeze(1)).squeeze()
elif W.ndim == 3:
return self._bmm(W)
else:
raise ValueError("Invalid shape for W")

@wiseodd wiseodd added the enhancement New feature or request label Nov 21, 2024
@wiseodd wiseodd self-assigned this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant