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 9 commits into
base: main
Choose a base branch
from
Open

Support for multidim outputs #266

wants to merge 9 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.

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.

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

Choose a reason for hiding this comment

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

@runame @aleximmer do you know what happened here?

...
Ji, f = batch_gradient(self.model, closure, return_outputs=True)
print("Jac")
print(Ji)
...

with these setup:

X, Y = torch.randn(10, 3), torch.randn(10, 1)
X_multidim, Y_multidim = X.reshape(5, 2, 3), Y.reshape(5, 2, 1)

model_std = nn.Linear(3, 1)
model_multidim = deepcopy(model_std)

...

la = Laplace(model_multidim, ...)
la.fit(...)

la(X_multidim)

prints

Jac
tensor([[ 0.2302,  0.1006,  0.4197,  1.0000],
        [ 0.0000,  0.0000,  0.0000,  0.0000],
        [ 0.3055,  1.1884, -0.4010,  1.0000],
        [ 0.0000,  0.0000,  0.0000,  0.0000],
        [-2.0167,  1.4216, -0.5488,  1.0000],
        [ 0.0000,  0.0000,  0.0000,  0.0000],
        [-0.4076,  0.2810, -1.7831,  1.0000],
        [ 0.0000,  0.0000,  0.0000,  0.0000],
        [ 0.1297,  0.2202, -0.5024,  1.0000],
        [ 0.0000,  0.0000,  0.0000,  0.0000]]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Notice that the returned Ji has row [0 ... 0]. Seems like ASDL's issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To reproduce: uv run pytest -k "test_predictive_multidim

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