ViCCo-Group / thingsvision

Python package for extracting representations from state-of-the-art computer vision models
https://vicco-group.github.io/thingsvision/
MIT License
157 stars 21 forks source link

CKA speedups + PyTorch 2.0+ support #167

Closed LukasMut closed 7 months ago

LukasMut commented 7 months ago
Alxmrphi commented 7 months ago

Just wondering while you're "in the zone" with refactoring CKA, maybe you can add the debiased version of CKA? It's an alteration of HSIC and only a minor change, already given in the PyTorch implementation of Simon's notebook demo:

https://github.com/google-research/google-research/blob/master/representation_similarity/Demo.ipynb

I have some recent work looking at some issues with the regular formulation of CKA and that the debiased/unbiased version might actually be what people need to be looking at in some cases:

https://openreview.net/forum?id=E1NRrGtIHG

Super, super busy at the moment otherwise I would add it. I still might, if you can't, but the changes to be made are in the notebook above and should only require an extra parameter to the CKA call.

LukasMut commented 7 months ago

Just wondering while you're "in the zone" with refactoring CKA, maybe you can add the debiased version of CKA? It's an alteration of HSIC and only a minor change, already given in the PyTorch implementation of Simon's notebook demo:

https://github.com/google-research/google-research/blob/master/representation_similarity/Demo.ipynb

I have some recent work looking at some issues with the regular formulation of CKA and that the debiased/unbiased version might actually be what people need to be looking at in some cases:

https://openreview.net/forum?id=E1NRrGtIHG

Super, super busy at the moment otherwise I would add it. I still might, if you can't, but the changes to be made are in the notebook above and should only require an extra parameter to the CKA call.

Done. I just added it. See most recent pushes.

codecov[bot] commented 7 months ago

Codecov Report

Attention: Patch coverage is 81.28655% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 74.37%. Comparing base (a467d0f) to head (f4ea770).

Files Patch % Lines
thingsvision/core/cka/cka_torch.py 75.00% 14 Missing and 5 partials :warning:
thingsvision/core/cka/cka_numpy.py 86.79% 5 Missing and 2 partials :warning:
thingsvision/core/cka/cka_base.py 80.00% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #167 +/- ## ========================================== + Coverage 74.13% 74.37% +0.23% ========================================== Files 33 36 +3 Lines 1705 1826 +121 Branches 231 240 +9 ========================================== + Hits 1264 1358 +94 - Misses 373 395 +22 - Partials 68 73 +5 ``` | [Flag](https://app.codecov.io/gh/ViCCo-Group/thingsvision/pull/167/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ViCCo-Group) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ViCCo-Group/thingsvision/pull/167/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ViCCo-Group) | `74.37% <81.28%> (+0.23%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ViCCo-Group#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Alxmrphi commented 7 months ago

Great! Thanks for adding that. Code looks nice!

LukasMut commented 7 months ago

Great! Thanks for adding that. Code looks nice!

No worries. Glad to hear you like the code! @Alxmrphi Could you approve the PR?