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

Support for multidim outputs #266

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Support for multidim outputs #266

wants to merge 7 commits into from

Conversation

wiseodd
Copy link
Collaborator

@wiseodd wiseodd commented Dec 6, 2024

Closes #252

Thanks to Kazuki for updating asdfghjkl on PyPI, we can now handle 3D tensor outputs (e.g. in LLMs) with GLM predictive.

@wiseodd wiseodd added the enhancement New feature or request label Dec 6, 2024
@wiseodd wiseodd requested review from aleximmer and runame December 6, 2024 16:34
@wiseodd wiseodd self-assigned this Dec 6, 2024
@wiseodd
Copy link
Collaborator Author

wiseodd commented Dec 6, 2024

WIP adding an article based on lm_example.py to the docs.

@wiseodd wiseodd marked this pull request as ready for review December 6, 2024 17:31
@wiseodd
Copy link
Collaborator Author

wiseodd commented Dec 6, 2024

@runame @aleximmer ready to review!

Copy link
Owner

@aleximmer aleximmer left a comment

Choose a reason for hiding this comment

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

Thanks for the useful addition. To make sure this breaks nothing, I would recommend the test mentioned in the review, otherwise LGTM.

},
batch_size=[100],
) # simulates a dataset
dl = DataLoader(ds, batch_size=BATCH_SIZE, shuffle=False, collate_fn=lambda x: x)
Copy link
Owner

Choose a reason for hiding this comment

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

Does it not work with the default collate_fn?


def _check_jacobians(self, Js: torch.Tensor) -> None:
if not isinstance(Js, torch.Tensor):
raise ValueError("Jacobians have to be torch.Tensor.")
if not Js.device == self._device:
raise ValueError("Jacobians need to be on the same device as Laplace.")
m, k, p = Js.size()
if p != self.n_params:
if Js.shape[-1] != self.n_params:
Copy link
Owner

Choose a reason for hiding this comment

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

For consistency with previous assertion, perhaps add and Js.ndim >= 3?

@@ -1335,7 +1397,7 @@ def _nn_predictive_classification(

vector_to_parameters(self.mean, self.params)

return py
return torch.as_tensor(py)
Copy link
Owner

Choose a reason for hiding this comment

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

Just to make sure: I suppose this is for typing?

return_outputs=True,
batch_size=self._get_batch_size(x),
)
Ji, f = batch_gradient(self.model, closure, return_outputs=True)
Copy link
Owner

Choose a reason for hiding this comment

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

Why is the batch_size argument no needed anymore, or perhaps, why was it even needed before?

Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a test where you test for equivalence between a "trivial" multidimensional model and a previously supported model? This can be just a linear model that mapped previously from [num_data, D] -> [num_data, K] and now from [num_data / L, L, D] -> [num_data / L, L, K], that is, the data set is simply reshaped. This should give an equivalent posterior and predictive. Maybe to make sure also have the option to use a NN for the test, not only the linear model case.

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

Successfully merging this pull request may close these issues.

3D input tensors and feature reduction
2 participants