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

Rsg devel #54

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

Rsg devel #54

wants to merge 21 commits into from

Conversation

rsanchezgarc
Copy link
Collaborator

  • Set of changes to allow extract_central_slices_rfft compilation
  • New def compute_vol_dtf function extracted from project_fourier.project_fourier to be used outside. Avoids computing the dft many times if several projections are going to be computed at different times.
  • Minor api changes to select devices

Copy link
Member

@alisterburt alisterburt left a comment

Choose a reason for hiding this comment

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

Hey Ruben, nice to see you here and happy new year!!

Thank you, there's loads of great stuff in this PR and i general most changes are small and easy to get in - a couple require a little bit of discussion. For the future, smaller PRs with isolated changes should be easier to get merged quickly

Let's try to get this in ASAP!!

src/libtilt/ctf/ctf_2d.py Outdated Show resolved Hide resolved
src/libtilt/ctf/ctf_2d.py Outdated Show resolved Hide resolved
src/libtilt/grids/central_slice_grid.py Outdated Show resolved Hide resolved
Comment on lines 52 to 53
[samples] = einops.unpack(samples, pattern='*', packed_shapes=ps)
# [samples] = einops.unpack(samples, pattern='*', packed_shapes=ps)
samples = samples.reshape(*ps) #Ask Alister if this will work in any situation
Copy link
Member

Choose a reason for hiding this comment

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

interesting, is this a significant performance gain? I don't think this works in the general case but it should always work here as far as I can tell

Copy link
Member

Choose a reason for hiding this comment

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

ohhh I see - torch compile couldn't go through unpack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. This is a requirement for the compiler

src/libtilt/interpolation/interpolate_dft_3d.py Outdated Show resolved Hide resolved
Comment on lines 95 to 80
conjugate_mask = einops.repeat(conjugate_mask, '... -> ... 3')
# conjugate_mask = einops.repeat(conjugate_mask, '... -> ... 3')
conjugate_mask.unsqueeze(-1).repeat(1, 1, 1, 3)
Copy link
Member

Choose a reason for hiding this comment

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

repeat should be creating a view here and shouldn't be memory intensive even though the tensor is huge - is this not the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I am correct, is expand and not repeat the one that is a view. This change was again a requirement for the compiler.

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right for the torch API but einops it creates a view where possible - regardless, compilation is super important.

I'm a little hesitant to lose the rank polymorphism here and it looks like this unsqueeze/repeat is specific to b h w 3 rather than ... h w 3 -> could you try adding some code to intepret the current shape and unsqueeze/repeat according to that? This should allow us to maintain the current flexibility and have compatibility with the compiler

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should work conjugate_mask.unsqueeze(-1).expand(*[-1] * len(conjugate_mask.shape), 3) and being more memory efficient, since it is a view.

src/libtilt/projection/project_real.py Show resolved Hide resolved
src/libtilt/shapes/soft_edge.py Outdated Show resolved Hide resolved
src/libtilt/projection/project_fourier.py Outdated Show resolved Hide resolved
pad: bool = True,
pad_length: int | None = None
) -> Tuple[torch.Tensor, Tuple[int,int,int], int]:
"""Project a cubic volume by sampling a central slice through its DFT.
Copy link
Member

Choose a reason for hiding this comment

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

this docstring needs fixing

src/libtilt/projection/project_fourier.py Outdated Show resolved Hide resolved
src/libtilt/projection/project_fourier.py Outdated Show resolved Hide resolved
src/libtilt/projection/project_fourier.py Outdated Show resolved Hide resolved
@alisterburt
Copy link
Member

I changed compute_vol_dft to _compute_dft and left in in the same place as a temporary API - agree this is useful to have factored out but not sure on the best API yet.

Everything else that was easy to resolve is resolved and issues #55 #56 and #57 are now open

@rsanchezgarc
Copy link
Collaborator Author

Happy New Year too! And sorry for not answering before, I had a few unexpected issues to solve before going into this.
I think I got all your changes implemented. Is there any test we can run to make sure that everything works as expected?

@alisterburt
Copy link
Member

sorry for the delay here @rsanchezgarc - travelled back to the US and been a bit hectic

I just found some interesting notes on how to make einops work with torch.compile so will probably revert to einops in a few places - I'm aiming to take a look at this final version over the next few days :)

@rsanchezgarc
Copy link
Collaborator Author

No problem at all! Good to know about the hack for the einops!

@rsanchezgarc
Copy link
Collaborator Author

@alisterburt what is the status of this PR?

@alisterburt
Copy link
Member

@rsanchezgarc still need to finalise it, free time has been taken up with preparing taxes and my partner visiting - will find some time ASAP!

@rsanchezgarc
Copy link
Collaborator Author

@alisterburt . No need to rush! Good luck with your taxes

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.

2 participants